Search in sources :

Example 41 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.

the class ProcessManagementServiceSkeleton method processQuery.

/**
 * Query processes based on a {@link org.apache.ode.bpel.common.ProcessFilter} criteria. This is
 * implemented in memory rather than via database calls since the processes
 * are managed by the {@link org.apache.ode.bpel.iapi.ProcessStore} object and we don't want to make
 * this needlessly complicated.
 *
 * @param filter              process filter
 * @param tenantsProcessStore Current Tenant's process store
 * @return ProcessConf collection
 * @throws ProcessManagementException if an error occurred while processing query
 */
private Collection<ProcessConf> processQuery(ProcessFilter filter, TenantProcessStoreImpl tenantsProcessStore) throws ProcessManagementException {
    Map<QName, ProcessConfigurationImpl> processes = tenantsProcessStore.getProcessConfigMap();
    if (log.isDebugEnabled()) {
        for (Map.Entry<QName, ProcessConfigurationImpl> process : processes.entrySet()) {
            log.debug("Process " + process.getKey() + " in state " + process.getValue());
        }
    }
    Set<QName> pids = processes.keySet();
    // Name filter can be implemented using only the PIDs.
    if (filter != null && filter.getNameFilter() != null) {
        // adding escape sequences to [\^$.|?*+(){} characters
        String nameFilter = filter.getNameFilter().replace("\\", "\\\\").replace("]", "\\]").replace("[", "\\[").replace("^", "\\^").replace("$", "\\$").replace("|", "\\|").replace("?", "\\?").replace(".", "\\.").replace("+", "\\+").replace("(", "\\(").replace(")", "\\)").replace("{", "\\{").replace("}", "\\}").replace("*", ".*");
        final Pattern pattern = Pattern.compile(nameFilter + "(-\\d*)?");
        CollectionsX.remove_if(pids, new MemberOfFunction<QName>() {

            @Override
            public boolean isMember(QName o) {
                return !pattern.matcher(o.getLocalPart()).matches();
            }
        });
    }
    if (filter != null && filter.getNamespaceFilter() != null) {
        // adding escape sequences to [\^$.|?*+(){} characters
        String namespaceFilter = filter.getNamespaceFilter().replace("\\", "\\\\").replace("]", "\\]").replace("[", "\\[").replace("^", "\\^").replace("$", "\\$").replace("|", "\\|").replace("?", "\\?").replace(".", "\\.").replace("+", "\\+").replace("(", "\\(").replace(")", "\\)").replace("{", "\\{").replace("}", "\\}").replace("*", ".*");
        final Pattern pattern = Pattern.compile(namespaceFilter);
        CollectionsX.remove_if(pids, new MemberOfFunction<QName>() {

            @Override
            public boolean isMember(QName o) {
                String ns = o.getNamespaceURI() == null ? "" : o.getNamespaceURI();
                return !pattern.matcher(ns).matches();
            }
        });
    }
    // Now we need the process conf objects, we need to be
    // careful since someone could have deleted them by now
    List<ProcessConf> confs = new LinkedList<ProcessConf>();
    for (QName pid : pids) {
        ProcessConf pConf = tenantsProcessStore.getProcessConfiguration(pid);
        if (pConf != null) {
            confs.add(pConf);
        }
    }
    if (filter != null) {
        // Specific filter for deployment date.
        if (filter.getDeployedDateFilter() != null) {
            for (final String ddf : filter.getDeployedDateFilter()) {
                final Date dd;
                try {
                    dd = ISO8601DateParser.parse(Filter.getDateWithoutOp(ddf));
                } catch (ParseException e) {
                    // Should never happen.
                    String errMsg = "Exception while parsing date";
                    log.error(errMsg, e);
                    throw new ProcessManagementException(errMsg, e);
                }
                CollectionsX.remove_if(confs, new MemberOfFunction<ProcessConf>() {

                    @Override
                    public boolean isMember(ProcessConf o) {
                        if (ddf.startsWith("=")) {
                            return !o.getDeployDate().equals(dd);
                        }
                        if (ddf.startsWith("<=")) {
                            return o.getDeployDate().getTime() > dd.getTime();
                        }
                        if (ddf.startsWith(">=")) {
                            return o.getDeployDate().getTime() < dd.getTime();
                        }
                        if (ddf.startsWith("<")) {
                            return o.getDeployDate().getTime() >= dd.getTime();
                        }
                        return ddf.startsWith(">") && (o.getDeployDate().getTime() <= dd.getTime());
                    }
                });
            }
        }
        // Ordering
        if (filter.getOrders() != null) {
            ComparatorChain cChain = new ComparatorChain();
            for (String key : filter.getOrders()) {
                boolean ascending = true;
                String orderKey = key;
                if (key.startsWith("+") || key.startsWith("-")) {
                    orderKey = key.substring(1, key.length());
                    if (key.startsWith("-")) {
                        ascending = false;
                    }
                }
                Comparator c;
                if ("name".equals(orderKey)) {
                    c = new Comparator<ProcessConf>() {

                        public int compare(ProcessConf o1, ProcessConf o2) {
                            return o1.getProcessId().getLocalPart().compareTo(o2.getProcessId().getLocalPart());
                        }
                    };
                } else if ("namespace".equals(orderKey)) {
                    c = new Comparator<ProcessConf>() {

                        public int compare(ProcessConf o1, ProcessConf o2) {
                            String ns1 = o1.getProcessId().getNamespaceURI() == null ? "" : o1.getProcessId().getNamespaceURI();
                            String ns2 = o2.getProcessId().getNamespaceURI() == null ? "" : o2.getProcessId().getNamespaceURI();
                            return ns1.compareTo(ns2);
                        }
                    };
                } else if ("version".equals(orderKey)) {
                    c = new Comparator<ProcessConf>() {

                        public int compare(ProcessConf o1, ProcessConf o2) {
                            return (int) (o1.getVersion() - o2.getVersion());
                        }
                    };
                } else if ("deployed".equals(orderKey)) {
                    c = new Comparator<ProcessConf>() {

                        public int compare(ProcessConf o1, ProcessConf o2) {
                            return o1.getDeployDate().compareTo(o2.getDeployDate());
                        }
                    };
                } else if ("status".equals(orderKey)) {
                    c = new Comparator<ProcessConf>() {

                        public int compare(ProcessConf o1, ProcessConf o2) {
                            return o1.getState().compareTo(o2.getState());
                        }
                    };
                } else {
                    // unrecognized
                    if (log.isDebugEnabled()) {
                        log.debug("unrecognized order key" + orderKey);
                    }
                    continue;
                }
                cChain.addComparator(c, !ascending);
            }
            Collections.sort(confs, cChain);
        }
    }
    return confs;
}
Also used : Pattern(java.util.regex.Pattern) ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain) QName(javax.xml.namespace.QName) ProcessConf(org.apache.ode.bpel.iapi.ProcessConf) ProcessConfigurationImpl(org.wso2.carbon.bpel.core.ode.integration.store.ProcessConfigurationImpl) LinkedList(java.util.LinkedList) Date(java.util.Date) ProcessManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.ProcessManagementException) Comparator(java.util.Comparator) ParseException(java.text.ParseException) Map(java.util.Map)

Example 42 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.

the class BpelUIUtil method setFailureTypeCleanups.

private static String[] setFailureTypeCleanups(ProcessDeployDetailsList_type0 processDeployDetailsListType) {
    List<String> failureCategories = null;
    if (processDeployDetailsListType.getCleanUpList() != null && processDeployDetailsListType.getCleanUpList().getCleanUp() != null) {
        failureCategories = new ArrayList<String>();
        CleanUpType[] cleanUpTypes = processDeployDetailsListType.getCleanUpList().getCleanUp();
        for (CleanUpType cleanUpType : cleanUpTypes) {
            if (cleanUpType.getOn().getValue().equalsIgnoreCase("failure") && cleanUpType.getCategoryList() != null) {
                CategoryListType categoryList = cleanUpType.getCategoryList();
                if (categoryList.getCategory() != null) {
                    Category_type1[] categories = categoryList.getCategory();
                    for (Category_type1 categoryType1 : categories) {
                        failureCategories.add(categoryType1.getValue());
                    }
                }
            }
        }
    }
    // Collection to array
    String[] failureList = new String[0];
    if (failureCategories != null) {
        failureList = failureCategories.toArray(new String[failureCategories.size()]);
    }
    return failureList;
}
Also used : Category_type1(org.wso2.carbon.bpel.stub.mgt.types.Category_type1) CategoryListType(org.wso2.carbon.bpel.stub.mgt.types.CategoryListType) CleanUpType(org.wso2.carbon.bpel.stub.mgt.types.CleanUpType)

Example 43 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.

the class BpelUIUtil method setSuccessTypeCleanups.

private static String[] setSuccessTypeCleanups(ProcessDeployDetailsList_type0 processDeployDetailsListType) {
    List<String> successCategories = null;
    if (processDeployDetailsListType.getCleanUpList() != null && processDeployDetailsListType.getCleanUpList().getCleanUp() != null) {
        successCategories = new ArrayList<String>();
        CleanUpType[] cleanUpTypes = processDeployDetailsListType.getCleanUpList().getCleanUp();
        for (CleanUpType cleanUpType : cleanUpTypes) {
            if (cleanUpType.getOn().getValue().equalsIgnoreCase("success") && cleanUpType.getCategoryList() != null) {
                CategoryListType categoryList = cleanUpType.getCategoryList();
                if (categoryList.getCategory() != null) {
                    Category_type1[] categories = categoryList.getCategory();
                    for (Category_type1 categoryType1 : categories) {
                        successCategories.add(categoryType1.getValue());
                    }
                }
            }
        }
    }
    // Collection to array
    String[] successList = new String[0];
    if (successCategories != null) {
        successList = successCategories.toArray(new String[successCategories.size()]);
    }
    return successList;
}
Also used : Category_type1(org.wso2.carbon.bpel.stub.mgt.types.Category_type1) CategoryListType(org.wso2.carbon.bpel.stub.mgt.types.CategoryListType) CleanUpType(org.wso2.carbon.bpel.stub.mgt.types.CleanUpType)

Example 44 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.

the class WorkflowTaskService method deleteAllLocalTaskVariables.

@DELETE
@Path("/{taskId}/variables")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteAllLocalTaskVariables(@PathParam("taskId") String taskId) {
    TaskService taskService = BPMNOSGIService.getTaskService();
    Task task = getTaskFromRequest(taskId);
    Collection<String> currentVariables = taskService.getVariablesLocal(task.getId()).keySet();
    taskService.removeVariablesLocal(task.getId(), currentVariables);
    return Response.ok().status(Response.Status.NO_CONTENT).build();
}
Also used : BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 45 with Collection

use of org.wso2.carbon.registry.api.Collection in project carbon-business-process by wso2.

the class TenantRepository method fixDeployments.

/**
 * Information about BPMN deployments are recorded in 3 places:
 * Activiti database, Registry and the file system (deployment folder).
 * If information about a particular deployment is not recorded in all these 3 places, BPS may not work correctly.
 * Therefore, this method checks whether deployments are recorded in all these places and undeploys packages, if
 * they are missing in few places in an inconsistent way.
 * <p/>
 * As there are 3 places, there are 8 ways a package can be placed. These cases are handled as follows:
 * (1) Whenever a package is not in the deployment folder, it is undeploye (this covers 4 combinations).
 * (2) If a package is in all 3 places, it is a proper deployment and it is left untouched.
 * (3) If a package is only in the deployment folder, it is a new deployment. This will be handled by the deployer.
 * (4) If a package is in the deployment folder AND it is in either registry or Activiti DB (but not both), then it is an inconsistent deployment. This will be undeployed.
 */
// public void fixDeployments() {
// 
// // get all deployments in the deployment folder
// List<String> fileArchiveNames = new ArrayList<String>();
// File[] fileDeployments = repoFolder.listFiles();
// if (fileDeployments != null) {
// for (File fileDeployment : fileDeployments) {
// String deploymentName = FilenameUtils.getBaseName(fileDeployment.getName());
// fileArchiveNames.add(deploymentName);
// }
// } else {
// log.error("File deployments returned null for tenant" + tenantId);
// }
// 
// 
// // get all deployments in the Activiti DB
// List<String> activitiDeploymentNames = new ArrayList<String>();
// ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
// RepositoryService repositoryService = engine.getRepositoryService();
// List<Deployment> tenantDeployments =
// repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString())
// .list();
// for (Deployment deployment : tenantDeployments) {
// String deploymentName = deployment.getName();
// activitiDeploymentNames.add(deploymentName);
// }
// 
// // get all deployments in the registry
// List<String> metaDataDeploymentNames = new ArrayList<String>();
// List<DeploymentMetaDataModel> deploymentMetaDataModelList =
// activitiDAO.selectAllDeploymentModel();
// 
// int deploymentMetaDataModelListSize = deploymentMetaDataModelList.size();
// 
// for (int i = 0; i < deploymentMetaDataModelListSize; i++) {
// DeploymentMetaDataModel deploymentMetaDataModel =
// deploymentMetaDataModelList.get(i);
// 
// if (deploymentMetaDataModel != null) {
// String deploymentMetadataName = deploymentMetaDataModel.getPackageName();
// metaDataDeploymentNames.add(deploymentMetadataName);
// }
// }
// 
// // construct the union of all deployments
// Set<String> allDeploymentNames = new HashSet<String>();
// allDeploymentNames.addAll(fileArchiveNames);
// allDeploymentNames.addAll(activitiDeploymentNames);
// allDeploymentNames.addAll(metaDataDeploymentNames);
// 
// for (String deploymentName : allDeploymentNames) {
// 
// if (!(fileArchiveNames.contains(deploymentName))) {
// if (log.isDebugEnabled()) {
// log.debug(deploymentName +
// " has been removed from the deployment folder. Undeploying the package...");
// }
// undeploy(deploymentName, true);
// } else {
// if (activitiDeploymentNames.contains(deploymentName) &&
// !metaDataDeploymentNames.contains(deploymentName)) {
// if (log.isDebugEnabled()) {
// log.debug(deploymentName +
// " is missing in the registry. Undeploying the package to avoid inconsistencies...");
// }
// undeploy(deploymentName, true);
// }
// 
// if (!activitiDeploymentNames.contains(deploymentName) &&
// metaDataDeploymentNames.contains(deploymentName)) {
// if (log.isDebugEnabled()) {
// log.debug(deploymentName +
// " is missing in the BPS database. Undeploying the package to avoid inconsistencies...");
// }
// undeploy(deploymentName, true);
// }
// }
// }
// }
public void fixDeployments() throws BPSFault {
    // get all deployments in the deployment folder
    List<String> fileArchiveNames = new ArrayList<String>();
    File[] fileDeployments = repoFolder.listFiles();
    for (File fileDeployment : fileDeployments) {
        String deploymentName = FilenameUtils.getBaseName(fileDeployment.getName());
        fileArchiveNames.add(deploymentName);
    }
    // get all deployments in the Activiti DB
    List<String> activitiDeploymentNames = new ArrayList<String>();
    ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
    RepositoryService repositoryService = engine.getRepositoryService();
    List<Deployment> tenantDeployments = repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString()).list();
    for (Deployment deployment : tenantDeployments) {
        String deploymentName = deployment.getName();
        activitiDeploymentNames.add(deploymentName);
    }
    // get all deployments in the registry
    List<String> registryDeploymentNames = new ArrayList<String>();
    try {
        RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
        Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
        String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH;
        if (tenantRegistry.resourceExists(deploymentRegistryPath)) {
            Collection registryDeployments = (Collection) tenantRegistry.get(deploymentRegistryPath);
            String[] deploymentPaths = registryDeployments.getChildren();
            for (String deploymentPath : deploymentPaths) {
                String deploymentName = deploymentPath.substring(deploymentPath.lastIndexOf("/") + 1, deploymentPath.length());
                registryDeploymentNames.add(deploymentName);
            }
        }
    } catch (RegistryException e) {
        String msg = "Failed to obtain BPMN deployments from the Registry.";
        log.error(msg, e);
        throw new BPSFault(msg, e);
    }
    // construct the union of all deployments
    Set<String> allDeploymentNames = new HashSet<String>();
    allDeploymentNames.addAll(fileArchiveNames);
    allDeploymentNames.addAll(activitiDeploymentNames);
    allDeploymentNames.addAll(registryDeploymentNames);
    for (String deploymentName : allDeploymentNames) {
        try {
            if (!(fileArchiveNames.contains(deploymentName))) {
                if (log.isDebugEnabled()) {
                    log.debug(deploymentName + " has been removed from the deployment folder. Undeploying the package...");
                }
                undeploy(deploymentName, true);
            } else {
                if (activitiDeploymentNames.contains(deploymentName) && !registryDeploymentNames.contains(deploymentName)) {
                    if (log.isDebugEnabled()) {
                        log.debug(deploymentName + " is missing in the registry. Undeploying the package to avoid inconsistencies...");
                    }
                    undeploy(deploymentName, true);
                }
                if (!activitiDeploymentNames.contains(deploymentName) && registryDeploymentNames.contains(deploymentName)) {
                    if (log.isDebugEnabled()) {
                        log.debug(deploymentName + " is missing in the BPS database. Undeploying the package to avoid inconsistencies...");
                    }
                    undeploy(deploymentName, true);
                }
            }
        } catch (BPSFault e) {
            String msg = "Failed undeploy inconsistent deployment: " + deploymentName;
            log.error(msg, e);
            throw new BPSFault(msg, e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Deployment(org.activiti.engine.repository.Deployment) Registry(org.wso2.carbon.registry.api.Registry) RegistryException(org.wso2.carbon.registry.api.RegistryException) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) Collection(org.wso2.carbon.registry.api.Collection) RegistryService(org.wso2.carbon.registry.api.RegistryService) File(java.io.File) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService) HashSet(java.util.HashSet)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)13 Collection (java.util.Collection)9 ArrayList (java.util.ArrayList)8 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)8 IOException (java.io.IOException)7 Collection (org.wso2.carbon.registry.core.Collection)7 Map (java.util.Map)6 HashSet (java.util.HashSet)5 File (java.io.File)4 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)4 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)4 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)4 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)4 Test (org.testng.annotations.Test)4 TenantProcessStoreImpl (org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)4 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 Response (javax.ws.rs.core.Response)3 JAXBContext (javax.xml.bind.JAXBContext)3