Search in sources :

Example 11 with SubstitutesDataModel

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

the class UserSubstitutionUtils method updateSubstituteInfo.

private static SubstitutesDataModel updateSubstituteInfo(String assignee, String substitute, Date startTime, Date endTime, String taskListString, int tenantId) {
    SubstitutesDataModel dataModel = new SubstitutesDataModel();
    dataModel.setUser(assignee);
    dataModel.setSubstitute(substitute);
    dataModel.setSubstitutionStart(startTime);
    dataModel.setSubstitutionEnd(endTime);
    // by default enabled
    dataModel.setEnabled(true);
    dataModel.setTenantId(tenantId);
    dataModel.setUpdated(new Date());
    dataModel.setTaskList(taskListString);
    SubstitutionDataHolder.getInstance().getActivitiDAO().updateSubstituteInfo(dataModel);
    return dataModel;
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel)

Example 12 with SubstitutesDataModel

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

the class UserSubstitutionUtils method handleChangeSubstitute.

public static void handleChangeSubstitute(String assignee, String substitute, int tenantId) {
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    SubstitutesDataModel existingSubInfo = activitiDAO.selectSubstituteInfo(assignee, tenantId);
    if (existingSubInfo != null) {
        activitiDAO.updateSubstitute(assignee, substitute, tenantId, new Date());
        if (existingSubInfo.isEnabled() && isBeforeActivationInterval(existingSubInfo.getSubstitutionStart())) {
            String existingSub = existingSubInfo.getSubstitute();
            existingSubInfo.setSubstitute(substitute);
            boolean transitivityResolved = updateTransitiveSubstitutes(existingSubInfo, tenantId);
            if (!transitivityResolved) {
                // remove added record
                activitiDAO.updateSubstitute(assignee, existingSub, tenantId, existingSubInfo.getUpdated());
                throw new SubstitutionException("Given Substitute is not available. Provide a different user to substitute.");
            }
        }
    } else {
        throw new SubstitutionException("No substitution record found for the user: " + assignee);
    }
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) ActivitiDAO(org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)

Example 13 with SubstitutesDataModel

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

the class UserSubstitutionUtils method handleNewSubstituteAddition.

/**
 * Handles addition of new substitute record and it's post conditions.
 * @param assignee
 * @param substitute
 * @param startTime
 * @param endTime
 * @param enabled
 * @param taskList
 * @throws SubstitutionException
 */
public static void handleNewSubstituteAddition(String assignee, String substitute, Date startTime, Date endTime, boolean enabled, List<String> taskList, int tenantId) throws SubstitutionException {
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    String taskListStr = getTaskListString(taskList);
    SubstitutesDataModel dataModel = addSubstituteInfo(assignee, substitute, startTime, endTime, taskListStr, tenantId);
    if (dataModel.isEnabled() && isBeforeActivationInterval(dataModel.getSubstitutionStart())) {
        boolean transitivityResolved = updateTransitiveSubstitutes(dataModel, tenantId);
        if (!transitivityResolved) {
            // remove added transitive record
            activitiDAO.removeSubstitute(assignee, tenantId);
            throw new // SubstitutionException
            SubstitutionException("Could not find an available substitute. Use a different user to substitute");
        }
        if (SubstitutionDataHolder.getInstance().isTransitivityEnabled()) {
            // transitive substitute maybe changed, need to retrieve again.
            dataModel = activitiDAO.selectSubstituteInfo(dataModel.getUser(), dataModel.getTenantId());
        }
        if (!SubstitutionDataHolder.getInstance().isTransitivityEnabled() || BPMNConstants.TRANSITIVE_SUB_NOT_APPLICABLE.equals(dataModel.getTransitiveSub())) {
            bulkReassign(dataModel.getUser(), dataModel.getSubstitute(), taskList);
        } else {
            bulkReassign(dataModel.getUser(), dataModel.getTransitiveSub(), taskList);
        }
    }
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) ActivitiDAO(org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)

Example 14 with SubstitutesDataModel

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

the class UserSubstitutionUtils method addSubstituteInfo.

/**
 * Persist the substitute info. Transitive substitute is not added here.
 * @param assignee - User becomes unavailable
 * @param substitute - substitute for the assignee
 * @param startDate - start od the substitution
 * @param endDate - end of the substitution
 * @param taskListString - Comma separated String of task Ids
 * @return added row count.
 * @throws SubstitutionException
 */
public static SubstitutesDataModel addSubstituteInfo(String assignee, String substitute, Date startDate, Date endDate, String taskListString, int tenantId) throws SubstitutionException {
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    // at any given time there could be only one substitute for a single user
    if (activitiDAO.selectSubstituteInfo(assignee, tenantId) != null) {
        log.error("Substitute for user: " + assignee + ", already exist. Try to update the substitute info");
        throw new SubstitutionException("Substitute for user: " + assignee + ", already exist. Try to update the substitute info");
    } else {
        SubstitutesDataModel dataModel = new SubstitutesDataModel();
        dataModel.setUser(assignee);
        dataModel.setSubstitute(MultitenantUtils.getTenantAwareUsername(substitute));
        dataModel.setSubstitutionStart(startDate);
        if (endDate == null) {
            endDate = getEndTimeMaxDate();
        }
        dataModel.setSubstitutionEnd(endDate);
        // by default enabled
        dataModel.setEnabled(true);
        dataModel.setCreated(new Date());
        dataModel.setTenantId(tenantId);
        dataModel.setTaskList(taskListString);
        activitiDAO.insertSubstitute(dataModel);
        return dataModel;
    }
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) ActivitiDAO(org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)

Example 15 with SubstitutesDataModel

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

the class ActivitiDAO method updateSubstituteInfo.

/**
 * Update the substitute record for given user
 * @param substitutesDataModel
 * @return updated row count. Ideally should return 1.
 */
public int updateSubstituteInfo(final SubstitutesDataModel substitutesDataModel) {
    substitutesDataModel.setUpdated(new Date());
    CustomSqlExecution<SubstitutesMapper, Integer> customSqlExecution = new AbstractCustomSqlExecution<SubstitutesMapper, Integer>(SubstitutesMapper.class) {

        public Integer execute(SubstitutesMapper substitutesMapper) {
            return substitutesMapper.updateSubstitute(substitutesDataModel);
        }
    };
    return managementService.executeCustomSql(customSqlExecution);
}
Also used : AbstractCustomSqlExecution(org.activiti.engine.impl.cmd.AbstractCustomSqlExecution) SubstitutesMapper(org.wso2.carbon.bpmn.core.internal.mapper.SubstitutesMapper) Date(java.util.Date)

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