Search in sources :

Example 6 with SubstitutesDataModel

use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.

the class UserSubstitutionUtils method querySubstitutions.

/**
 * Query substitution records by given properties.
 * Allowed properties: user, substitute, enabled.
 * Pagination parameters : start, size, sort, order
 * @param propertiesMap
 * @return Paginated list of PaginatedSubstitutesDataModel
 */
public static List<SubstitutesDataModel> querySubstitutions(Map<String, String> propertiesMap, int tenantId) {
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    PaginatedSubstitutesDataModel model = getPaginatedModelFromRequest(propertiesMap, tenantId);
    String enabled = propertiesMap.get(SubstitutionQueryProperties.ENABLED);
    boolean enabledProvided = false;
    if (enabled != null) {
        enabledProvided = true;
    }
    if (!enabledProvided) {
        return prepareEndTime(activitiDAO.querySubstituteInfoWithoutEnabled(model));
    } else {
        return prepareEndTime(activitiDAO.querySubstituteInfo(model));
    }
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) ActivitiDAO(org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)

Example 7 with SubstitutesDataModel

use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.

the class ActivitiDAO method querySubstituteInfo.

/**
 * Return the list of substitute info based on query parameters.
 * @param model model with only required query parameter values. Leave others as null. By default enabled=false.
 * @return List<SubstitutesDataModel> Result set of substitute info
 */
public List<SubstitutesDataModel> querySubstituteInfo(final PaginatedSubstitutesDataModel model) {
    final RowBounds rw = new RowBounds(model.getStart(), model.getSize());
    CustomSqlExecution<SubstitutesMapper, List<SubstitutesDataModel>> customSqlExecution = new AbstractCustomSqlExecution<SubstitutesMapper, List<SubstitutesDataModel>>(SubstitutesMapper.class) {

        public List<SubstitutesDataModel> execute(SubstitutesMapper substitutesMapper) {
            return substitutesMapper.querySubstitutes(rw, model);
        }
    };
    return managementService.executeCustomSql(customSqlExecution);
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) AbstractCustomSqlExecution(org.activiti.engine.impl.cmd.AbstractCustomSqlExecution) RowBounds(org.apache.ibatis.session.RowBounds) List(java.util.List) SubstitutesMapper(org.wso2.carbon.bpmn.core.internal.mapper.SubstitutesMapper)

Example 8 with SubstitutesDataModel

use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.

the class TransitivityResolver method calculateTransitiveSubstitute.

/**
 * Recursively look for a available substitute for given data model user. Makes a DB call for each recursive iteration.
 * @param substituteDataModel data model that need the transitive sub
 * @return available addSubstituteInfo name
 */
private synchronized String calculateTransitiveSubstitute(SubstitutesDataModel substituteDataModel, String originUser, String originSub) {
    String newSub = null;
    SubstitutesDataModel nextDataModel = subsMap.get(substituteDataModel.getSubstitute());
    if (nextDataModel != null) {
        if (nextDataModel.getSubstitute().equals(originUser) || nextDataModel.getSubstitute().equals(originSub)) {
            // circular dependency, could not resolve
            newSub = BPMNConstants.TRANSITIVE_SUB_UNDEFINED;
        } else if (BPMNConstants.TRANSITIVE_SUB_NOT_APPLICABLE.equals(nextDataModel.getTransitiveSub())) {
            newSub = nextDataModel.getSubstitute();
        } else if (nextDataModel.getTransitiveSub() != null) {
            newSub = nextDataModel.getTransitiveSub();
        } else {
            newSub = calculateTransitiveSubstitute(nextDataModel, originUser, originSub);
        }
    } else {
        // original substitute is available
        newSub = substituteDataModel.getSubstitute();
    }
    updateMap(substituteDataModel, newSub);
    return newSub;
}
Also used : SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel)

Example 9 with SubstitutesDataModel

use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.

the class TransitivityResolver method updateMap.

private void updateMap(SubstitutesDataModel substituteDataModel, String substitute) {
    SubstitutesDataModel model = substituteDataModel;
    if (substituteDataModel.getSubstitute().equals(substitute)) {
        model.setTransitiveSub(BPMNConstants.TRANSITIVE_SUB_NOT_APPLICABLE);
    } else {
        model.setTransitiveSub(substitute);
    }
    subsMap.put(substituteDataModel.getUser(), model);
}
Also used : SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel)

Example 10 with SubstitutesDataModel

use of org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel in project carbon-business-process by wso2.

the class UserSubstitutionService method getSubstitute.

/**
 * Return the substitute info for the given user in path parameter
 * @param user
 * @return SubstituteInfoResponse
 * @throws URISyntaxException
 */
@GET
@Path("/{user}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getSubstitute(@PathParam("user") String user) throws UserStoreException {
    if (!subsFeatureEnabled) {
        return Response.status(405).build();
    }
    user = getTenantAwareUser(user);
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (!loggedInUser.equals(user) && !isUserAuthorizedForSubstitute(loggedInUser)) {
        throw new BPMNForbiddenException("Not allowed to view others substitution details. No sufficient permission");
    }
    SubstitutesDataModel model = UserSubstitutionUtils.getSubstituteOfUser(user, tenantId);
    if (model != null) {
        SubstituteInfoResponse response = new SubstituteInfoResponse();
        response.setSubstitute(model.getSubstitute());
        response.setAssignee(model.getUser());
        response.setEnabled(model.isEnabled());
        response.setStartTime(model.getSubstitutionStart());
        response.setEndTime(model.getSubstitutionEnd());
        return Response.ok(response).build();
    } else {
        return Response.status(404).build();
    }
}
Also used : SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) BPMNForbiddenException(org.wso2.carbon.bpmn.rest.common.exception.BPMNForbiddenException)

Aggregations

SubstitutesDataModel (org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel)15 PaginatedSubstitutesDataModel (org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel)11 ActivitiDAO (org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)7 AbstractCustomSqlExecution (org.activiti.engine.impl.cmd.AbstractCustomSqlExecution)3 SubstitutesMapper (org.wso2.carbon.bpmn.core.internal.mapper.SubstitutesMapper)3 Date (java.util.Date)2 List (java.util.List)2 RowBounds (org.apache.ibatis.session.RowBounds)2 BPMNForbiddenException (org.wso2.carbon.bpmn.rest.common.exception.BPMNForbiddenException)2 ActivitiException (org.activiti.engine.ActivitiException)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1