Search in sources :

Example 16 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project carbon-business-process by wso2.

the class ProcessImpl method getLinkArrows.

/**
 * Gets the Link arrow coordinates when there is a FLOW activity in the process
 *
 * @param doc SVG document which defines the components including shapes, gradients etc. of the process
 * @return An element which contains the link arrow coordinates of the Process
 */
private Element getLinkArrows(SVGDocument doc) {
    Element group = doc.createElementNS(SVGNamespace.SVG_NAMESPACE, "g");
    // Checks whether the any links exist
    if (links != null && !links.isEmpty()) {
        // Returns a collection-view of the map with the link names, sources(starting activity) and the target
        // (ending activity)
        Set linksSet = links.entrySet();
        Iterator linksIterator = linksSet.iterator();
        // Iterates through the links
        while (linksIterator.hasNext()) {
            Map.Entry<String, Link> link = (Map.Entry<String, Link>) linksIterator.next();
            // Gets the source/start activity of the link
            ActivityInterface startActivity = link.getValue().getSource();
            // Gets the target/end activity of the link
            ActivityInterface endActivity = link.getValue().getTarget();
            // Get the link name
            String linkName = link.getKey();
            // Check if the source and the target of the link contains a value
            if (endActivity != null && startActivity != null) {
                // Define the link flow/path by giving the coordinates of the start and end activity
                group.appendChild(drawLink(doc, startActivity.getExitArrowCoords().getXLeft(), startActivity.getExitArrowCoords().getYTop(), endActivity.getEntryArrowCoords().getXLeft(), endActivity.getEntryArrowCoords().getYTop(), startActivity.getStartIconWidth(), link.getKey(), linkName));
            }
        }
    }
    return group;
}
Also used : Set(java.util.Set) ActivityInterface(org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) Map(java.util.Map) Link(org.wso2.carbon.bpel.ui.bpel2svg.Link)

Example 17 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project carbon-business-process by wso2.

the class UserSubstitutionService method querySubstitutes.

/**
 * Query the substitution records based on substitute, assignee and enabled or disabled.
 * Pagination parameters, start, size, sort, order are allowed.
 * @return paginated list of substitution info records
 */
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response querySubstitutes() {
    if (!subsFeatureEnabled) {
        return Response.status(405).build();
    }
    Map<String, String> queryMap = new HashedMap();
    for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {
        String value = uriInfo.getQueryParameters().getFirst(entry.getKey());
        if (value != null) {
            queryMap.put(entry.getValue(), value);
        }
    }
    // validate the parameters
    try {
        // replace with tenant aware user names
        String tenantAwareUser = getTenantAwareUser(queryMap.get(SubstitutionQueryProperties.USER));
        queryMap.put(SubstitutionQueryProperties.USER, tenantAwareUser);
        String tenantAwareSub = getTenantAwareUser(queryMap.get(SubstitutionQueryProperties.SUBSTITUTE));
        queryMap.put(SubstitutionQueryProperties.SUBSTITUTE, tenantAwareSub);
        if (!isUserAuthorizedForSubstitute(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername())) {
            String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
            if (!((queryMap.get(SubstitutionQueryProperties.USER) != null && queryMap.get(SubstitutionQueryProperties.USER).equals(loggedInUser)) || (queryMap.get(SubstitutionQueryProperties.SUBSTITUTE) != null && queryMap.get(SubstitutionQueryProperties.SUBSTITUTE).equals(loggedInUser)))) {
                throw new BPMNForbiddenException("Not allowed to view others substitution details. No sufficient permission");
            }
        }
    } catch (UserStoreException e) {
        throw new ActivitiException("Error accessing User Store for input validations", e);
    }
    // validate pagination parameters
    validatePaginationParams(queryMap);
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    List<SubstitutesDataModel> dataModelList = UserSubstitutionUtils.querySubstitutions(queryMap, tenantId);
    int totalResultCount = UserSubstitutionUtils.getQueryResultCount(queryMap, tenantId);
    SubstituteInfoCollectionResponse collectionResponse = new SubstituteInfoCollectionResponse();
    collectionResponse.setTotal(totalResultCount);
    List<SubstituteInfoResponse> responseList = new ArrayList<>();
    for (SubstitutesDataModel subsData : dataModelList) {
        SubstituteInfoResponse response = new SubstituteInfoResponse();
        response.setEnabled(subsData.isEnabled());
        response.setEndTime(subsData.getSubstitutionEnd());
        response.setStartTime(subsData.getSubstitutionStart());
        response.setSubstitute(subsData.getSubstitute());
        response.setAssignee(subsData.getUser());
        responseList.add(response);
    }
    collectionResponse.setSubstituteInfoList(responseList);
    collectionResponse.setSize(responseList.size());
    String sortType = getSortType(queryMap.get(SubstitutionQueryProperties.SORT));
    collectionResponse.setSort(sortType);
    collectionResponse.setStart(Integer.parseInt(queryMap.get(SubstitutionQueryProperties.START)));
    collectionResponse.setOrder(queryMap.get(SubstitutionQueryProperties.ORDER));
    return Response.ok(collectionResponse).build();
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) BPMNForbiddenException(org.wso2.carbon.bpmn.rest.common.exception.BPMNForbiddenException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) HashedMap(org.apache.commons.collections.map.HashedMap) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 18 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project carbon-business-process by wso2.

the class HumanTaskJPQLQueryBuilder method buildAdministrableTasksCountQuery.

private Query buildAdministrableTasksCountQuery() {
    boolean hasStatus = false;
    List<TaskStatus> statuses = queryCriteria.getStatuses();
    if (statuses != null && !statuses.isEmpty()) {
        hasStatus = true;
    }
    boolean hasTaskName = false;
    if (!StringUtils.isEmpty(queryCriteria.getTaskName())) {
        hasTaskName = true;
    }
    Query administrableTasksQuery = em.createQuery(SELECT_DISTINCT_TASKS_COUNT + JOIN_HUMAN_ROLES_JOIN_ORG_ENTITIES + OE_NAME_IN_NAMES + AND + HR_TYPE_ROLE_TYPE + (hasTaskName ? AND + FILTER_BY_TASKNAME : "") + AND + T_TYPE_TASK_TYPE + AND + T_TENANT_ID_TENANT_ID + (hasStatus ? AND + T_STATUS_IN_TASK_STATUSES : ""));
    List<String> rolesAndNamesList = getNameListForUser(queryCriteria.getCaller(), true);
    administrableTasksQuery.setParameter(NAMES, rolesAndNamesList);
    administrableTasksQuery.setParameter(TENANT_ID, queryCriteria.getCallerTenantId());
    administrableTasksQuery.setParameter(ROLE_TYPE, GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS);
    administrableTasksQuery.setParameter(TASK_TYPE, TaskType.TASK);
    if (hasStatus) {
        administrableTasksQuery.setParameter(TASK_STATUSES, statuses);
    }
    if (hasTaskName) {
        administrableTasksQuery.setParameter(TASK_NAME, queryCriteria.getTaskName());
    }
    return administrableTasksQuery;
}
Also used : Query(javax.persistence.Query) TaskStatus(org.wso2.carbon.humantask.core.dao.TaskStatus)

Example 19 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project carbon-business-process by wso2.

the class HumanTaskJPQLQueryBuilder method buildNotificationsCountQuery.

// Creates the JPQL query to list notifications applicable for a particular user.
private Query buildNotificationsCountQuery() {
    boolean hasStatus = false;
    List<TaskStatus> statuses = queryCriteria.getStatuses();
    if (statuses != null && !statuses.isEmpty()) {
        hasStatus = true;
    }
    boolean hasTaskName = false;
    if (!StringUtils.isEmpty(queryCriteria.getTaskName())) {
        hasTaskName = true;
    }
    Query notificationsQuery = em.createQuery(SELECT_DISTINCT_TASKS_COUNT + JOIN_HUMAN_ROLES_JOIN_ORG_ENTITIES + OE_NAME_IN_NAMES + AND + HR_TYPE_ROLE_TYPE + AND + T_TENANT_ID_TENANT_ID + AND + T_TYPE_TASK_TYPE + (hasTaskName ? AND + FILTER_BY_TASKNAME : "") + (hasStatus ? AND + T_STATUS_IN_TASK_STATUSES : ""));
    notificationsQuery.setParameter(TENANT_ID, queryCriteria.getCallerTenantId());
    List<String> rolesAndNamesList = getNameListForUser(queryCriteria.getCaller(), true);
    notificationsQuery.setParameter(NAMES, rolesAndNamesList);
    notificationsQuery.setParameter(ROLE_TYPE, GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS);
    notificationsQuery.setParameter(TASK_TYPE, TaskType.NOTIFICATION);
    if (hasTaskName) {
        notificationsQuery.setParameter(TASK_NAME, queryCriteria.getTaskName());
    }
    if (hasStatus) {
        notificationsQuery.setParameter(TASK_STATUSES, statuses);
    }
    return notificationsQuery;
}
Also used : Query(javax.persistence.Query) TaskStatus(org.wso2.carbon.humantask.core.dao.TaskStatus)

Example 20 with Names

use of org.wso2.ballerinalang.compiler.util.Names in project carbon-business-process by wso2.

the class HumanTaskJPQLQueryBuilder method buildClaimableCountQuery.

private Query buildClaimableCountQuery() {
    boolean hasStatus = false;
    List<TaskStatus> statuses = queryCriteria.getStatuses();
    if (statuses != null && !statuses.isEmpty()) {
        hasStatus = true;
    }
    boolean hasTaskName = false;
    if (!StringUtils.isEmpty(queryCriteria.getTaskName())) {
        hasTaskName = true;
    }
    StringBuilder query = new StringBuilder(SELECT_DISTINCT_TASKS_COUNT + JOIN_HUMAN_ROLES_JOIN_ORG_ENTITIES + OE_NAME_IN_NAMES + AND + HR_TYPE_ROLE_TYPE + (hasTaskName ? AND + FILTER_BY_TASKNAME : "") + AND + T_TYPE_TASK_TYPE + AND + T_TENANT_ID_TENANT_ID + AND + T_STATUS_IN_TASK_STATUSES);
    Query claimableTasksQuery = em.createQuery(query.toString());
    List<String> rolesAndNamesList = getNameListForUser(queryCriteria.getCaller(), true);
    claimableTasksQuery.setParameter(NAMES, rolesAndNamesList);
    claimableTasksQuery.setParameter(TENANT_ID, queryCriteria.getCallerTenantId());
    claimableTasksQuery.setParameter(ROLE_TYPE, GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS);
    claimableTasksQuery.setParameter(TASK_TYPE, TaskType.TASK);
    List<TaskStatus> statusList = Arrays.asList(TaskStatus.READY);
    claimableTasksQuery.setParameter(TASK_STATUSES, statusList);
    if (hasStatus) {
        claimableTasksQuery.setParameter(TASK_STATUSES, statuses);
    } else {
        List<TaskStatus> readyList = Arrays.asList(TaskStatus.READY);
        claimableTasksQuery.setParameter(TASK_STATUSES, readyList);
    }
    if (hasTaskName) {
        claimableTasksQuery.setParameter(TASK_NAME, queryCriteria.getTaskName());
    }
    return claimableTasksQuery;
}
Also used : Query(javax.persistence.Query) TaskStatus(org.wso2.carbon.humantask.core.dao.TaskStatus)

Aggregations

ArrayList (java.util.ArrayList)10 Query (javax.persistence.Query)8 TaskStatus (org.wso2.carbon.humantask.core.dao.TaskStatus)8 Test (org.testng.annotations.Test)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 Name (org.wso2.ballerinalang.compiler.util.Name)5 Map (java.util.Map)4 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)4 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)4 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)3 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)3 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)3 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)3 Response (feign.Response)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Arrays (java.util.Arrays)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2