Package org.wso2.carbon.registry.core.exceptions

Examples of org.wso2.carbon.registry.core.exceptions.RegistryException


          OMElement itemEl = (OMElement) checkListIterator.next();
          if (itemEl.getQName().equals(new QName("checkitem"))) {
            List<String> items = new ArrayList<String>();
            String itemName = itemEl.getText();
            if (itemName == null) {
              throw new RegistryException(
                  "Checklist items should have a name!");
                        }
            items.add("status:" + name);
            items.add("name:" + itemName);
            items.add("value:false");

            if (itemEl.getAttribute(new QName("order")) != null) {
              items.add("order:"
                  + itemEl.getAttributeValue(new QName(
                      "order")));
            } else {
              items.add("order:" + checklistItemOrder);
            }

            String resourcePropertyNameForItem = "registry.custom_lifecycle.checklist.option"
                + propertyOrder + ".item";

            resource
                .setProperty(resourcePropertyNameForItem, items);
            checklistItemOrder++;
            propertyOrder++;
          } else if (itemEl.getQName().equals(new QName("permissions"))) {
                        Iterator permissionIterator = itemEl.getChildElements();
                        while (permissionIterator.hasNext()) {
                            OMElement permissionItemEl = (OMElement) permissionIterator.next();
                            if (permissionItemEl.getQName().equals(new QName("permission"))) {
                                String action = permissionItemEl.getAttributeValue(
                                        new QName("action"));
                                if (action.toLowerCase().equals(PROMOTE)) {
                                    promoteRoles = permissionItemEl.getAttributeValue(
                                            new QName("roles"));
                                } else if (action.toLowerCase().equals(DEMOTE)) {
                                    demoteRoles = permissionItemEl.getAttributeValue(
                                            new QName("roles"));
                                }
                            }
                        }
                    } else if (itemEl.getQName().equals(new QName("js"))) {
                        Iterator scriptElementIterator = itemEl.getChildElements();
                        while (scriptElementIterator.hasNext()) {
                            OMElement scriptItemEl = (OMElement)scriptElementIterator.next();
                            if (scriptItemEl.getQName().equals(new QName("console"))) {
                                String lifecycleScript = "";
                                String lifecycleScriptCommand = "";
                                Iterator consoleScriptElementIterator = scriptItemEl.getChildElements();
                                while (consoleScriptElementIterator.hasNext()) {
                                    OMElement consoleScriptItemEl = (OMElement)consoleScriptElementIterator.next();
                                    if (consoleScriptItemEl.getQName().equals(new QName("script"))) {
                                        lifecycleScript += consoleScriptItemEl.toString() + "\n";
                                    }
                                }
                                if (scriptItemEl.getAttribute(new QName("demoteFunction")) != null) {
                                    lifecycleScriptCommand =
                                            scriptItemEl.getAttributeValue(new QName("demoteFunction"));
                                    List<String> items = new ArrayList<String>();
                                    items.add(lifecycleScript);
                                    items.add(lifecycleScriptCommand);
                                    String resourcePropertyNameForItem =
                                            "registry.custom_lifecycle.checklist.js.script.console." +
                                                    name + "." + DEMOTE;
                                    resource.setProperty(resourcePropertyNameForItem, items);
                                }
                                if (scriptItemEl.getAttribute(new QName("promoteFunction")) != null) {
                                    lifecycleScriptCommand =
                                            scriptItemEl.getAttributeValue(new QName("promoteFunction"));
                                    List<String> items = new ArrayList<String>();
                                    items.add(lifecycleScript);
                                    items.add(lifecycleScriptCommand);
                                    String resourcePropertyNameForItem =
                                            "registry.custom_lifecycle.checklist.js.script.console." +
                                                    name + "." + PROMOTE;
                                    resource.setProperty(resourcePropertyNameForItem, items);
                                }
                            } else if (scriptItemEl.getQName().equals(new QName("server"))) {
                                String lifecycleScript = "";
                                String lifecycleScriptCommand = "";
                                Iterator serverScriptElementIterator = scriptItemEl.getChildElements();
                                if (serverScriptElementIterator.hasNext()) {
                                    OMElement serverScriptItemEl = (OMElement)serverScriptElementIterator.next();
                                    if (serverScriptItemEl.getQName().equals(new QName("script"))) {
                                        lifecycleScript += serverScriptItemEl.getText();
                                        lifecycleScript = lifecycleScript.trim();
                                    }
                                }
                                if (scriptItemEl.getAttribute(new QName("demoteFunction")) != null) {
                                    lifecycleScriptCommand =
                                            scriptItemEl.getAttributeValue(new QName("demoteFunction"));
                                    List<String> items = new ArrayList<String>();
                                    items.add(lifecycleScript);
                                    items.add(lifecycleScriptCommand);
                                    String resourcePropertyNameForItem =
                                            "registry.custom_lifecycle.checklist.js.script.server." +
                                                    name + "." + DEMOTE;
                                    resource.setProperty(resourcePropertyNameForItem, items);
                                }
                                if (scriptItemEl.getAttribute(new QName("promoteFunction")) != null) {
                                    lifecycleScriptCommand =
                                            scriptItemEl.getAttributeValue(new QName("promoteFunction"));
                                    List<String> items = new ArrayList<String>();
                                    items.add(lifecycleScript);
                                    items.add(lifecycleScriptCommand);
                                    String resourcePropertyNameForItem =
                                            "registry.custom_lifecycle.checklist.js.script.server." +
                                                    name + "." + PROMOTE;
                                    resource.setProperty(resourcePropertyNameForItem, items);
                                }
                            }
                        }
                    }
        }
                if (promoteRoles.equals("#") && demoteRoles.equals("#")) {
                    distributedActionPermissions.add("#");
                } else {
                    distributedActionPermissions.add(promoteRoles + ":" + demoteRoles);
                }
      }

    } catch (XMLStreamException e) {
      throw new RegistryException(
          "Resource does not contain a valid XML configuration: "
              + e.toString());
    }

    resource.setProperty(stateProperty, states.get(0));
View Full Code Here


    String nextLocation = "";

    int stateIndex = states.indexOf(currentState);

    if (stateIndex == -1) {
      throw new RegistryException("State '" + currentState
          + "' is not valid!");
    }

    String newState;
    if (PROMOTE.equals(action)) {
      if (stateIndex == states.size() - 1) {
        throw new RegistryException(
            "Can't promote beyond end of configured lifecycle!");
      }

      // Make sure all conditions are met
      List<Condition> conditions = transitions.get(currentState);
      if (conditions != null) {
        for (Condition condition : conditions) {
          if (!condition.isTrue(resource)) {
            throw new RegistryException("Condition failed - "
                + condition.getDescription());
          }
        }
      }

      if (stateIndex >= distributedLocations.size() - 1) {
        nextLocation = distributedLocations.get(0);
            } else {
        nextLocation = distributedLocations.get(stateIndex + 1);
            }

            if (stateIndex >= distributedRoles.size() - 1) {
        newRoles = distributedRoles.get(0);
            } else {
        newRoles = distributedRoles.get(stateIndex + 1);
            }

      if (!nextLocation.equals("#")) {
        newresourcePath = nextLocation + resourceName;
      }

      newState = states.get(stateIndex + 1);

    } else if (DEMOTE.equals(action)) {

      if (stateIndex == 0) {
        throw new RegistryException(
            "Can't demote beyond start of configured lifecycle!");
      }
      if (stateIndex <= 0) {
        nextLocation = distributedLocations.get(0);
            } else {
        nextLocation = distributedLocations.get(stateIndex - 1);
            }

            if (stateIndex >= distributedRoles.size() - 1) {
        newRoles = distributedRoles.get(0);
            } else {
        newRoles = distributedRoles.get(stateIndex + 1);
            }

      if (!nextLocation.equals("#")) {
        newresourcePath = nextLocation + resourceName;
      }

      newState = states.get(stateIndex - 1);
    }else if(ITEM_CLICK.equals(action)){
            return;
        }
        else {
      throw new RegistryException("Invalid action '" + action + "'");
    }

    resource.setProperty(stateProperty, newState);
    requestContext.getRegistry().put(resourcePath, resource);
   
    if (!nextLocation.equals("#")) {
         try {
          requestContext.getRegistry().move(resourcePath, newresourcePath);
                if (!newRoles.equals("#") &&
                        requestContext.getRegistry().getRegistryContext() != null) {
                    try {
                        AuthorizationManager authManager = CurrentSession.getUserRealm().getAuthorizationManager();
                        authManager.clearResourceAuthorizations(newresourcePath);
                        String[] roles = newRoles.split(",");
                        for (String role: roles) {
                            String roleName = role.trim();
                            authManager.authorizeRole(roleName, newresourcePath,
                                    ActionConstants.GET);
                            authManager.authorizeRole(roleName, newresourcePath,
                                    ActionConstants.PUT);
                            authManager.authorizeRole(roleName, newresourcePath,
                                    ActionConstants.DELETE);
                        }
                    } catch (UserStoreException e) {
                        throw new RegistryException("Unable to setup roles for resource.", e);
                    }

                }
                requestContext.setResourcePath(new ResourcePath(newresourcePath));
      } catch(RegistryException e) {
View Full Code Here

        return updateLifecycle(oldName, payload, registry, rootRegistry);
    }

    public static boolean updateLifecycle(String oldName, String payload, Registry registry, Registry rootRegistry) throws RegistryException, XMLStreamException {
        if (isLifecycleNameInUse(oldName, registry, rootRegistry))
            throw new RegistryException("Could not update lifecycle name since it is already in use!");

        String newName = null;
        OMElement element = AXIOMUtil.stringToOM(payload);
        if (element != null) {
            newName = element.getAttributeValue(new QName("name"));
        }

        if (newName == null || newName.equals(""))
            return false; // invalid configuration

        if (oldName == null || oldName.equals("")) {
            String path = getContextRoot() + newName;
            Resource resource;
            if (lifeCycleExists(newName, registry)) {
                return false; // we are adding a new lifecycle
            }
            else {
                resource = new ResourceImpl();
            }
            resource.setContent(payload);
            try {
                registry.beginTransaction();
                registry.put(path, resource);
                generateAspect(path, registry);
                registry.commitTransaction();
            } catch (Exception e) {
                registry.rollbackTransaction();
                throw new RegistryException("Unable to generate aspect", e);
            }
            return true;
        }

        if (newName.equals(oldName)) {
            //updating the rest of the content
            String oldPath = getContextRoot() + oldName;
            Resource resource;
            if (lifeCycleExists(oldName, registry)) {
                resource = registry.get(oldPath);
            }
            else {
                resource = new ResourceImpl(); // will this ever happen?
            }
            resource.setContent(payload);
            try {
                registry.beginTransaction();
                registry.put(oldPath, resource);
                generateAspect(oldPath, registry);
                registry.commitTransaction();
            } catch (Exception e) {
                registry.rollbackTransaction();
                throw new RegistryException("Unable to generate aspect", e);
            }
            return true;
        }
        else {
            String oldPath = getContextRoot() + oldName;
            String newPath = getContextRoot() + newName;

            if (lifeCycleExists(newName, registry)) {
                return false; // we are trying to use the name of a existing lifecycle
            }

            Resource resource;
            if (lifeCycleExists(oldName, registry)) {
                resource = registry.get(oldPath);
            }
            else {
                resource = new ResourceImpl(); // will this ever happen?
            }

            resource.setContent(payload);
            try {
                registry.beginTransaction();
                registry.put(newPath, resource);
                generateAspect(newPath, registry);
                registry.delete(oldPath);
                removeAspect(oldName, registry);
                registry.commitTransaction();
            } catch (Exception e) {
                registry.rollbackTransaction();
                throw new RegistryException("Unable to renew aspect", e);
            }
            return true;
        }
    }
View Full Code Here

        }
        else
            return false;

        if (isLifecycleNameInUse(name, registry, rootRegistry))
            throw new RegistryException("The added lifecycle name is already in use!");

        String path = getContextRoot() + name;
        Resource resource;
        if (!lifeCycleExists(name, registry)) {
            resource = new ResourceImpl();
        }
        else {
            return false; // Already existing resource.
        }
        resource.setContent(payload);
        try {
            registry.beginTransaction();
            registry.put(path, resource);
            generateAspect(path, registry);
            registry.commitTransaction();
        } catch (Exception e) {
            registry.rollbackTransaction();
            throw new RegistryException("Unable to generate aspect", e);
        }
        return true;
    }
View Full Code Here

        return registry.resourceExists(getContextRoot() + name);
    }

    public static boolean deleteLifecycle(String name, Registry registry, Registry rootRegistry) throws RegistryException, XMLStreamException {
        if (isLifecycleNameInUse(name, registry, rootRegistry))
            throw new RegistryException("Lifecycle could not be deleted, since it is already in use!");

        String path = getContextRoot() + name;
        if (registry.resourceExists(path)) {
            try {
                registry.beginTransaction();
                registry.delete(path);
                removeAspect(name, registry);
                registry.commitTransaction();
            } catch (Exception e) {
                registry.rollbackTransaction();
                throw new RegistryException("Unable to remove aspect", e);
            }
            return true;
        }
        return false;
    }
View Full Code Here

                while ((str = in.readLine()) != null) {
                    sb.append(str).append("\n");
                }
                in.close();
            } catch (IOException e) {
                throw new RegistryException(e.toString());
            }

            addLifecycle(sb.toString(), registry, rootRegistry);
        }
        else {
            // invoke all the aspects with configurations for lifecycles
            Resource lifecycleRoot = registry.get(getContextRoot());
            if (!(lifecycleRoot instanceof Collection)) {
                String msg = "Failed to continue as the lifecycle configuration root: " + getContextRoot() +
                        " is not a collection.";
                log.error(msg);
                throw new RegistryException(msg);
            }
            Collection lifecycleRootCol = (Collection)lifecycleRoot;
            String[] lifecycleConfigPaths = lifecycleRootCol.getChildren();
            if (lifecycleConfigPaths != null) {
                for (String lifecycleConfigPath: lifecycleConfigPaths) {
View Full Code Here

                    }
                }
                return false;
            }
            else
                throw new RegistryException("Lifecycle Configuration does not cantain the name attribute");
        }

        String sql = null;
//        if (!registry.resourceExists(searchLCMPropertiesQuery)) {
            if(StaticConfiguration.isVersioningProperties()) {
View Full Code Here

            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

        } catch (AxisFault axisFault) {
            String msg = "Failed to initiate comment service client. " + axisFault.getMessage();
            log.error(msg, axisFault);
            throw new RegistryException(msg, axisFault);
        }
    }
View Full Code Here

    public Registry getRegistry(String username, String password) throws RegistryException {
        if (remoteURL == null) {
            // Here's where we could do things like check system properties, environment
            // vars, etc.
            throw new RegistryException("No remote URL!");
        }
        try {
            if (username == null) {
                return new RemoteRegistry(new URL(remoteURL));
            } else {
                return new RemoteRegistry(new URL(remoteURL), username, password);
            }
        } catch (MalformedURLException e) {
            throw new RegistryException("Bad remote URL '" + remoteURL + "'");
        }
    }
View Full Code Here

                        throw e;
                    } catch (Throwable e) {
                        requestContext.setExecutionStatus(handler, e);
                        // We will be concatenating the incoming exception's message so that it will
                        // be carried forward, and displayed at the client-side.
                        throw new RegistryException(
                                "An exception occurred while executing handler chain. " +
                                        e.getMessage(), e);
                    }
                    if (requestContext.isProcessingComplete() && !evaluateAllHandlers) {
                        break;
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.core.exceptions.RegistryException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.