use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class CorrelationProcess method addVariables.
protected void addVariables(ExecutionQuery processInstanceQuery, List<QueryVariable> variables, boolean process) {
for (QueryVariable variable : variables) {
if (variable.getVariableOperation() == null) {
throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
}
if (variable.getValue() == null) {
throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
}
boolean nameLess = variable.getName() == null;
Object actualValue = new RestResponseFactory().getVariableValue(variable);
// A value-only query is only possible using equals-operator
if (nameLess && variable.getVariableOperation() != QueryVariable.QueryVariableOperation.EQUALS) {
throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is only supported when using 'equals' operation.");
}
switch(variable.getVariableOperation()) {
case EQUALS:
if (nameLess) {
if (process) {
processInstanceQuery.processVariableValueEquals(actualValue);
} else {
processInstanceQuery.variableValueEquals(actualValue);
}
} else {
if (process) {
processInstanceQuery.processVariableValueEquals(variable.getName(), actualValue);
} else {
processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
}
}
break;
case EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
if (process) {
processInstanceQuery.processVariableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
processInstanceQuery.variableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
}
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case NOT_EQUALS:
if (process) {
processInstanceQuery.processVariableValueNotEquals(variable.getName(), actualValue);
} else {
processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
}
break;
case NOT_EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
if (process) {
processInstanceQuery.processVariableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
processInstanceQuery.variableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
}
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class HistoricProcessInstanceQueryService method addVariables.
protected void addVariables(org.activiti.engine.history.HistoricProcessInstanceQuery processInstanceQuery, List<QueryVariable> variables) {
for (QueryVariable variable : variables) {
if (variable.getVariableOperation() == null) {
throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
}
if (variable.getValue() == null) {
throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
}
boolean nameLess = variable.getName() == null;
Object actualValue = new RestResponseFactory().getVariableValue(variable);
// A value-only query is only possible using equals-operator
if (nameLess && variable.getVariableOperation() != QueryVariable.QueryVariableOperation.EQUALS) {
throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is only supported when using 'equals' operation.");
}
switch(variable.getVariableOperation()) {
case EQUALS:
if (nameLess) {
processInstanceQuery.variableValueEquals(actualValue);
} else {
processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
}
break;
case EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case NOT_EQUALS:
processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
break;
case LIKE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueLike(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported for like, but was: " + actualValue.getClass().getName());
}
break;
case GREATER_THAN:
processInstanceQuery.variableValueGreaterThan(variable.getName(), actualValue);
break;
case GREATER_THAN_OR_EQUALS:
processInstanceQuery.variableValueGreaterThanOrEqual(variable.getName(), actualValue);
break;
case LESS_THAN:
processInstanceQuery.variableValueLessThan(variable.getName(), actualValue);
break;
case LESS_THAN_OR_EQUALS:
processInstanceQuery.variableValueLessThanOrEqual(variable.getName(), actualValue);
break;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class BPMNDeployer method undeploy.
/**
* Undeployment operation for Bpmn Deployer
*
* @param bpmnArchivePath archivePatch
* @throws DeploymentException Deployment failure will result in this exception
*/
public void undeploy(String bpmnArchivePath) throws DeploymentException {
if (isWorkerNode()) {
return;
}
if (System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP) != null && Boolean.parseBoolean(System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP)) || System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP) == null) {
File bpmnArchiveFile = new File(bpmnArchivePath);
if (bpmnArchiveFile.exists()) {
if (log.isTraceEnabled()) {
log.trace("BPMN package: " + bpmnArchivePath + " exists in the deployment folder. " + "Therefore, this can be an update of the package and the undeployment will be aborted.");
}
return;
}
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
log.info("Undeploying BPMN archive " + bpmnArchivePath + " for tenant: " + tenantId);
String deploymentName = FilenameUtils.getBaseName(bpmnArchivePath);
try {
tenantRepository.undeploy(deploymentName, true);
} catch (BPSFault be) {
String errorMsg = "Error un deploying BPMN Package " + deploymentName;
throw new DeploymentException(errorMsg, be);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class TenantRepository method deploy.
/**
* Deploys a BPMN package in the Activiti engine. Each BPMN package has an entry in the registry.
* Checksum of the latest version of the BPMN package is stored in this entry.
* This checksum is used to determine whether a package is a new deployment
* (or a new version of an existing package) or a redeployment of an existing package.
* We have to ignor the later case. If a package is a new deployment, it is deployed in the Activiti engine.
*
* @param deploymentContext DeploymentContext
* @return true, if artifact was deployed, false, if the artifact has not changed & hence not deployed
* @throws DeploymentException if deployment fails
*/
// public boolean deploy(BPMNDeploymentContext deploymentContext) throws DeploymentException {
// ZipInputStream archiveStream = null;
//
// try {
//
// String deploymentName =
// FilenameUtils.getBaseName(deploymentContext.getBpmnArchive().getName());
//
// // Compare the checksum of the BPMN archive with the currently available checksum in the registry
// // to determine whether this is a new deployment.
// String checksum = "";
// try {
// checksum = Utils.getMD5Checksum(deploymentContext.getBpmnArchive());
// } catch (IOException e) {
// log.error("Checksum genration failed for IO operation",e);
// } catch (NoSuchAlgorithmException e) {
// log.error("Checksum genration Algorithm not found",e);
// }
//
// DeploymentMetaDataModel deploymentMetaDataModel =
// activitiDAO.selectTenantAwareDeploymentModel(tenantId.toString(), deploymentName);
//
// if (log.isDebugEnabled()) {
// log.debug("deploymentName=" + deploymentName + " checksum=" + checksum);
// log.debug("deploymentMetaDataModel=" + deploymentMetaDataModel.toString());
// }
//
// if (deploymentMetaDataModel != null) {
// if (checksum.equalsIgnoreCase(deploymentMetaDataModel.getCheckSum())) {
// return false;
// }
// }
//
// ProcessEngineImpl engine =
// (ProcessEngineImpl) BPMNServerHolder.getInstance().getEngine();
//
// RepositoryService repositoryService = engine.getRepositoryService();
// DeploymentBuilder deploymentBuilder =
// repositoryService.createDeployment().tenantId(tenantId.toString()).
// name(deploymentName);
// try {
// archiveStream =
// new ZipInputStream(new FileInputStream(deploymentContext.getBpmnArchive()));
// } catch (FileNotFoundException e) {
// String errMsg = "Archive stream not found for BPMN repsoitory";
// throw new DeploymentException(errMsg, e);
// }
//
// deploymentBuilder.addZipInputStream(archiveStream);
// Deployment deployment = deploymentBuilder.deploy();
//
// if (deploymentMetaDataModel == null) {
//
// deploymentMetaDataModel = new DeploymentMetaDataModel();
// deploymentMetaDataModel.setPackageName(deploymentName);
// deploymentMetaDataModel.setCheckSum(checksum);
// deploymentMetaDataModel.setTenantID(tenantId.toString());
// deploymentMetaDataModel.setId(deployment.getId());
//
// //call for insertion
// this.activitiDAO.insertDeploymentMetaDataModel(deploymentMetaDataModel);
// } else {
// //call for update
// deploymentMetaDataModel.setCheckSum(checksum);
// this.activitiDAO.updateDeploymentMetaDataModel(deploymentMetaDataModel);
// }
//
// } finally {
// if (archiveStream != null) {
// try {
// archiveStream.close();
// } catch (IOException e) {
// log.error("Could not close archive stream", e);
// }
// }
// }
//
// return true;
// }
public void deploy(BPMNDeploymentContext deploymentContext) throws DeploymentException {
ZipInputStream archiveStream = null;
try {
String deploymentName = FilenameUtils.getBaseName(deploymentContext.getBpmnArchive().getName());
// Compare the checksum of the BPMN archive with the currently available checksum in the registry to determine whether this is a new deployment.
String checksum = Utils.getMD5Checksum(deploymentContext.getBpmnArchive());
RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH + BPMNConstants.REGISTRY_PATH_SEPARATOR + deploymentName;
Resource deploymentEntry = null;
if (tenantRegistry.resourceExists(deploymentRegistryPath)) {
deploymentEntry = tenantRegistry.get(deploymentRegistryPath);
} else {
// This is a new deployment
deploymentEntry = tenantRegistry.newCollection();
}
String latestChecksum = deploymentEntry.getProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY);
if (latestChecksum != null && checksum.equals(latestChecksum)) {
// This is a server restart
return;
}
deploymentEntry.setProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY, checksum);
// Deploy the package in the Activiti engine
ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
RepositoryService repositoryService = engine.getRepositoryService();
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().tenantId(tenantId.toString()).name(deploymentName);
archiveStream = new ZipInputStream(new FileInputStream(deploymentContext.getBpmnArchive()));
deploymentBuilder.addZipInputStream(archiveStream);
deploymentBuilder.deploy();
tenantRegistry.put(deploymentRegistryPath, deploymentEntry);
} catch (Exception e) {
String errorMessage = "Failed to deploy the archive: " + deploymentContext.getBpmnArchive().getName();
log.error(errorMessage, e);
// Remove the deployment archive from the tenant's deployment folder
File deploymentArchive = new File(repoFolder, deploymentContext.getBpmnArchive().getName());
FileUtils.deleteQuietly(deploymentArchive);
log.info("Removing the faulty archive : " + deploymentContext.getBpmnArchive().getName());
throw new DeploymentException(errorMessage, e);
} finally {
if (archiveStream != null) {
try {
archiveStream.close();
} catch (IOException e) {
log.error("Could not close archive stream", e);
}
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class CarbonUserManagerBasedPeopleQueryEvaluator method getUserNameListForRole.
public List<String> getUserNameListForRole(String roleName) {
if (isExistingRole(roleName)) {
if (cachingEnabled) {
Cache<String, List<String>> userNameListForRoleCache = getUserNameListForRoleCache();
if (userNameListForRoleCache != null && userNameListForRoleCache.containsKey(roleName)) {
return getUserNameListForRoleCache().get(roleName);
}
}
try {
ArrayList<String> usernameList = new ArrayList<String>(Arrays.asList(getUserRealm().getUserStoreManager().getUserListOfRole(roleName)));
if (cachingEnabled) {
Cache<String, List<String>> userNameListForRoleCache = getUserNameListForRoleCache();
if (userNameListForRoleCache != null) {
getUserNameListForRoleCache().put(roleName, usernameList);
}
Cache<String, Boolean> userNameListCache = getUserNameListCache();
if (userNameListCache != null) {
for (String userName : usernameList) {
userNameListCache.put(userName, true);
}
}
}
return usernameList;
} catch (UserStoreException e) {
throw new HumanTaskRuntimeException("Error occurred while calling" + " to realm service for operation isExistingRole", e);
}
} else {
throw new HumanTaskRuntimeException(String.format("The role name[%s] does not exist.", roleName));
}
}
Aggregations