Search in sources :

Example 86 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project charon by wso2.

the class GroupResource method getGroup.

@GET
@Produces({ "application/json", "application/scim+json" })
@ApiOperation(value = "Return groups according to the filter, sort and pagination parameters", notes = "Returns HTTP 404 if the groups are not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Valid groups are found"), @ApiResponse(code = 404, message = "Valid groups are not found") })
public Response getGroup(@ApiParam(value = SCIMProviderConstants.ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @ApiParam(value = SCIMProviderConstants.EXCLUDED_ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes, @ApiParam(value = SCIMProviderConstants.FILTER_DESC, required = false) @QueryParam(SCIMProviderConstants.FILTER) String filter, @ApiParam(value = SCIMProviderConstants.START_INDEX_DESC, required = false) @QueryParam(SCIMProviderConstants.START_INDEX) int startIndex, @ApiParam(value = SCIMProviderConstants.COUNT_DESC, required = false) @QueryParam(SCIMProviderConstants.COUNT) int count, @ApiParam(value = SCIMProviderConstants.SORT_BY_DESC, required = false) @QueryParam(SCIMProviderConstants.SORT_BY) String sortBy, @ApiParam(value = SCIMProviderConstants.SORT_ORDER_DESC, required = false) @QueryParam(SCIMProviderConstants.SORT_ORDER) String sortOrder) throws FormatNotSupportedException, CharonException {
    try {
        // obtain the user store manager
        UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
        // create charon-SCIM group endpoint and hand-over the request.
        GroupResourceManager groupResourceManager = new GroupResourceManager();
        SCIMResponse scimResponse = groupResourceManager.listWithGET(userManager, filter, startIndex, count, sortBy, sortOrder, attribute, excludedAttributes);
        return buildResponse(scimResponse);
    } catch (CharonException e) {
        throw new CharonException(e.getDetail(), e);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) GroupResourceManager(org.wso2.charon3.core.protocol.endpoints.GroupResourceManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 87 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project charon by wso2.

the class GroupResource method createGroup.

@ApiOperation(value = "Return the group which was created", notes = "Returns HTTP 201 if the group is successfully created.")
@POST
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Valid group is created"), @ApiResponse(code = 404, message = "Group is not found") })
public Response createGroup(@ApiParam(value = SCIMProviderConstants.ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @ApiParam(value = SCIMProviderConstants.EXCLUDED_ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes, String resourceString) throws CharonException, FormatNotSupportedException {
    try {
        // obtain the user store manager
        UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
        // create charon-SCIM group endpoint and hand-over the request.
        GroupResourceManager groupResourceManager = new GroupResourceManager();
        SCIMResponse response = groupResourceManager.create(resourceString, userManager, attribute, excludedAttributes);
        return buildResponse(response);
    } catch (CharonException e) {
        throw new CharonException(e.getDetail(), e);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) GroupResourceManager(org.wso2.charon3.core.protocol.endpoints.GroupResourceManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 88 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store 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 89 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project carbon-business-process by wso2.

the class UserSubstitutionService method substitute.

/**
 * Add new addSubstituteInfo record.
 * Following request body parameters are required,
 *  assignee : optional, logged in user is used if not provided
 *  substitute : required
 *  startTime : optional, current timestamp if not provided, the timestamp the substitution should start in ISO format
 *  endTime : optional, considered as forever if not provided, the timestamp the substitution should end in ISO format
 * @param request
 * @return 201 created response with the resource location. 405 if substitution disabled
 */
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response substitute(SubstitutionRequest request) {
    try {
        if (!subsFeatureEnabled) {
            return Response.status(405).build();
        }
        String assignee = getRequestedAssignee(request.getAssignee());
        String substitute = validateAndGetSubstitute(request.getSubstitute(), assignee);
        Date endTime = null;
        Date startTime = new Date();
        DateTime requestStartTime = null;
        if (request.getStartTime() != null) {
            requestStartTime = new DateTime(request.getStartTime());
            startTime = new Date(requestStartTime.getMillis());
        }
        if (request.getEndTime() != null) {
            endTime = validateEndTime(request.getEndTime(), requestStartTime);
        }
        if (!UserSubstitutionUtils.validateTasksList(request.getTaskList(), assignee)) {
            throw new ActivitiIllegalArgumentException("Invalid task list provided, for substitution.");
        }
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        // at this point, substitution is enabled by default
        UserSubstitutionUtils.handleNewSubstituteAddition(assignee, substitute, startTime, endTime, true, request.getTaskList(), tenantId);
        return Response.created(new URI("substitutes/" + assignee)).build();
    } catch (UserStoreException e) {
        throw new ActivitiException("Error accessing User Store", e);
    } catch (URISyntaxException e) {
        throw new ActivitiException("Response location URI creation header", e);
    } catch (ActivitiIllegalArgumentException e) {
        throw new ActivitiIllegalArgumentException(e.getMessage());
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DateTime(org.joda.time.DateTime)

Example 90 with Store

use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project carbon-business-process by wso2.

the class DeployedTasks method getAlldeployedTasks.

public String[] getAlldeployedTasks(int tenantID) {
    String[] noTask = { "No deployed task for the specified tenant" };
    String[] noStore = { "No Human Tasks Store found for the given tenantID" };
    HumanTaskServer humanTaskServer = HumanTaskServiceComponent.getHumanTaskServer();
    HumanTaskStore humanTaskStore = humanTaskServer.getTaskStoreManager().getHumanTaskStore(tenantID);
    if (humanTaskStore == null) {
        return noStore;
    }
    List<HumanTaskBaseConfiguration> humanTaskConfigurations = humanTaskStore.getTaskConfigurations();
    deployedTasks = new String[humanTaskConfigurations.size()];
    for (int i = 0; i < humanTaskConfigurations.size(); i++) {
        deployedTasks[i] = humanTaskConfigurations.get(i).getName() + "\t" + humanTaskConfigurations.get(i).getDefinitionName() + "\t" + humanTaskConfigurations.get(i).getOperation();
    }
    if (deployedTasks.length == 0) {
        return noTask;
    }
    return deployedTasks;
}
Also used : HumanTaskStore(org.wso2.carbon.humantask.core.store.HumanTaskStore) HumanTaskServer(org.wso2.carbon.humantask.core.HumanTaskServer) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)

Aggregations

HashMap (java.util.HashMap)25 Test (org.testng.annotations.Test)21 ArrayList (java.util.ArrayList)18 CharonException (org.wso2.charon3.core.exceptions.CharonException)18 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)18 UserManager (org.wso2.charon3.core.extensions.UserManager)15 Produces (javax.ws.rs.Produces)14 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Path (javax.ws.rs.Path)10 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 Map (java.util.Map)9 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)8 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 UserStoreException (org.wso2.carbon.user.api.UserStoreException)8 Consumes (javax.ws.rs.Consumes)7 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)7 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)7 Response (feign.Response)6 IOException (java.io.IOException)6