Search in sources :

Example 1 with ActivitiDAO

use of org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO in project carbon-business-process by wso2.

the class UserSubstitutionUtils method handleScheduledEventByTenant.

public static synchronized boolean handleScheduledEventByTenant(int tenantId) {
    boolean result = true;
    TransitivityResolver resolver = SubstitutionDataHolder.getInstance().getTransitivityResolver();
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    if (SubstitutionDataHolder.getInstance().isTransitivityEnabled()) {
        // update transitives, only the map is updated here
        result = resolver.resolveTransitiveSubs(true, tenantId);
    } else {
        resolver.subsMap = activitiDAO.selectActiveSubstitutesByTenant(tenantId, new Date(System.currentTimeMillis()));
    }
    // flush into db
    for (Map.Entry<String, SubstitutesDataModel> entry : resolver.subsMap.entrySet()) {
        // go through the updated map
        SubstitutesDataModel model = entry.getValue();
        try {
            // set carbon context
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext context = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            context.setUsername(model.getUser());
            context.setTenantId(tenantId, true);
            if (SubstitutionDataHolder.getInstance().isTransitivityEnabled()) {
                activitiDAO.updateSubstituteInfo(model);
            }
            if (!BPMNConstants.BULK_REASSIGN_PROCESSED.equals(model.getTaskList())) {
                // active substitution, not yet bulk reassigned
                String sub = getActualSubstitute(model);
                if (model.getTaskList() == null) {
                    // reassign all
                    if (sub != null) {
                        bulkReassign(model.getUser(), sub, null);
                    } else {
                        // transitivity undefined, assign to task owner or un-claim
                        assignToTaskOwner(model.getUser(), null);
                    }
                } else {
                    List<String> taskList = getTaskListFromString(model.getTaskList());
                    if (sub != null) {
                        bulkReassign(model.getUser(), sub, taskList);
                    } else {
                        // transitivity undefined, assign to task owner or un-claim
                        assignToTaskOwner(model.getUser(), taskList);
                    }
                }
                model.setTaskList(BPMNConstants.BULK_REASSIGN_PROCESSED);
                activitiDAO.updateSubstituteInfo(model);
            }
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
            PrivilegedCarbonContext.destroyCurrentContext();
        }
    }
    // disable expired records
    disableExpiredRecords(tenantId);
    return result;
}
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) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext)

Example 2 with ActivitiDAO

use of org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO in project carbon-business-process by wso2.

the class UserSubstitutionUtils method handleUpdateSubstitute.

public static void handleUpdateSubstitute(String assignee, String substitute, Date startTime, Date endTime, boolean enabled, List<String> taskList, int tenantId) {
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    SubstitutesDataModel existingSubInfo = activitiDAO.selectSubstituteInfo(assignee, tenantId);
    if (existingSubInfo != null) {
        // need to put existing values for null columns, if not existing data may replace by Null
        if (startTime == null) {
            startTime = existingSubInfo.getSubstitutionStart();
        }
        if (endTime == null) {
            endTime = existingSubInfo.getSubstitutionEnd();
        }
        String taskListString = getTaskListString(taskList);
        if (taskList == null) {
            taskListString = existingSubInfo.getTaskList();
        }
        SubstitutesDataModel dataModel = updateSubstituteInfo(assignee, substitute, startTime, endTime, taskListString, tenantId);
        if (dataModel.isEnabled() && isBeforeActivationInterval(dataModel.getSubstitutionStart())) {
            boolean transitivityResolved = updateTransitiveSubstitutes(dataModel, tenantId);
            if (!transitivityResolved) {
                // remove added transitive record
                activitiDAO.updateSubstituteInfo(existingSubInfo);
                throw new 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);
            }
        }
    } else {
        throw new SubstitutionException("Substitute for user: " + assignee + ", does not exist. Try to add new substitute info record");
    }
}
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 3 with ActivitiDAO

use of org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO in project carbon-business-process by wso2.

the class UserSubstitutionUtils method disableExpiredRecords.

/**
 * Disable the records that are still enabled but expired
 * @param tenantId
 */
public static void disableExpiredRecords(int tenantId) {
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    Map<String, SubstitutesDataModel> map = activitiDAO.getEnabledExpiredRecords(tenantId, new Date(System.currentTimeMillis()));
    for (Map.Entry<String, SubstitutesDataModel> entry : map.entrySet()) {
        activitiDAO.enableSubstitution(false, entry.getKey(), tenantId);
    }
}
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 4 with ActivitiDAO

use of org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO 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 5 with ActivitiDAO

use of org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO in project carbon-business-process by wso2.

the class TenantRepository method undeploy.

/**
 * Undeploys a BPMN package.
 * This may be called by the BPMN deployer, when a BPMN package is deleted from the deployment folder or by admin services
 *
 * @param deploymentName package name to be undeployed
 * @param force          forceful deletion of package
 */
// public void undeploy(String deploymentName, boolean force) {
// 
// DeploymentMetaDataModel deploymentMetaDataModel;
// SqlSession sqlSession = null;
// try {
// // Remove the deployment from the tenant's registry
// deploymentMetaDataModel = activitiDAO
// .selectTenantAwareDeploymentModel(tenantId.toString(), deploymentName);
// 
// if ((deploymentMetaDataModel == null) && !force) {
// String msg = "Deployment: " + deploymentName + " does not exist.";
// log.warn(msg);
// return;
// }
// 
// ProcessEngineImpl engine = (ProcessEngineImpl) BPMNServerHolder.getInstance().getEngine();
// 
// DbSqlSessionFactory dbSqlSessionFactory =
// (DbSqlSessionFactory) engine.getProcessEngineConfiguration().
// getSessionFactories().get(DbSqlSession.class);
// 
// SqlSessionFactory sqlSessionFactory = dbSqlSessionFactory.getSqlSessionFactory();
// sqlSession = sqlSessionFactory.openSession();
// DeploymentMapper deploymentMapper = sqlSession.getMapper(DeploymentMapper.class);
// int rowCount = deploymentMapper.deleteDeploymentMetaData(deploymentMetaDataModel);
// 
// if (log.isDebugEnabled()) {
// log.debug("Total row count deleted=" + rowCount);
// }
// 
// // Remove the deployment archive from the tenant's deployment folder
// File deploymentArchive = new File(repoFolder, deploymentName + ".bar");
// FileUtils.deleteQuietly(deploymentArchive);
// 
// // Delete all versions of this package from the Activiti engine.
// RepositoryService repositoryService = engine.getRepositoryService();
// List<Deployment> deployments = repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString()).
// deploymentName(deploymentName).list();
// for (Deployment deployment : deployments) {
// repositoryService.deleteDeployment(deployment.getId());
// }
// 
// //commit metadata
// sqlSession.commit();
// } finally {
// if (sqlSession != null) {
// sqlSession.close();
// }
// }
// 
// }
public void undeploy(String deploymentName, boolean force) throws BPSFault {
    try {
        // Remove the deployment from the tenant's registry
        RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
        Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
        String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH + BPMNConstants.REGISTRY_PATH_SEPARATOR + deploymentName;
        if (!tenantRegistry.resourceExists(deploymentRegistryPath) && !force) {
            String msg = "Deployment: " + deploymentName + " does not exist.";
            log.warn(msg);
            return;
        }
        tenantRegistry.delete(deploymentRegistryPath);
        // Remove the deployment archive from the tenant's deployment folder
        File deploymentArchive = new File(repoFolder, deploymentName + ".bar");
        FileUtils.deleteQuietly(deploymentArchive);
        // Delete all versions of this package from the Activiti engine.
        ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
        RepositoryService repositoryService = engine.getRepositoryService();
        List<Deployment> deployments = repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString()).deploymentName(deploymentName).list();
        for (Deployment deployment : deployments) {
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    } catch (RegistryException e) {
        String msg = "Failed to undeploy BPMN deployment: " + deploymentName + " for tenant: " + tenantId;
        log.error(msg, e);
        throw new BPSFault(msg, e);
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) Deployment(org.activiti.engine.repository.Deployment) Registry(org.wso2.carbon.registry.api.Registry) RegistryService(org.wso2.carbon.registry.api.RegistryService) File(java.io.File) RegistryException(org.wso2.carbon.registry.api.RegistryException) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Aggregations

ActivitiDAO (org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO)8 PaginatedSubstitutesDataModel (org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel)8 SubstitutesDataModel (org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel)6 File (java.io.File)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 RepositoryService (org.activiti.engine.RepositoryService)1 Deployment (org.activiti.engine.repository.Deployment)1 BPSFault (org.wso2.carbon.bpmn.core.BPSFault)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 Registry (org.wso2.carbon.registry.api.Registry)1 RegistryException (org.wso2.carbon.registry.api.RegistryException)1 RegistryService (org.wso2.carbon.registry.api.RegistryService)1