use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class InstanceManagementServiceSkeleton method isOperationIsValidForTheCurrentTenant.
/**
* Check whether the instance belongs to the current tenant. If not, don't allow any operations.
*
* @param iid instance id
* @throws IllegalAccessException if instance doesn't belong to the current tenant
* @throws ProcessingException if there a error getting instance data
* @throws InstanceManagementException if the processId does not exist
*/
private void isOperationIsValidForTheCurrentTenant(final long iid) throws IllegalAccessException, ProcessingException, InstanceManagementException {
QName processId = getProcess(iid);
TenantProcessStoreImpl processStore = getTenantProcessForCurrentSession();
if (processId != null) {
if (!processStore.containsProcess(processId)) {
log.error("Trying to invoke a illegal operation. Instance ID:" + iid);
throw new IllegalAccessException("Operation is not permitted.");
}
} else {
throw new InstanceManagementException("Process instance for instance ID " + iid + " does not exist");
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class TaskOperationsImpl method getCaller.
private String getCaller() {
// TODO - remove hard coded user name value once moved to task view page.
String userName = "admin";
PeopleQueryEvaluator pqe = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator();
if (StringUtils.isNotEmpty(pqe.getLoggedInUser())) {
userName = pqe.getLoggedInUser();
}
// logged in user.
if (StringUtils.isEmpty(userName)) {
throw new HumanTaskRuntimeException("Cannot determine the user name of the user " + "performing the task operation!");
}
return userName;
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class TaskOperationsImpl method setOutput.
/**
* Set the data for the part of the task's output message.
*
* @param taskIdURI : task identifier
* @param ncName : PartName
* @param o
* @throws IllegalStateFault
* @throws IllegalOperationFault
* @throws IllegalArgumentFault
* @throws IllegalAccessFault
*/
public void setOutput(URI taskIdURI, NCName ncName, Object o) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
try {
final Long taskId = validateTaskId(taskIdURI);
if (ncName != null && o != null) {
final String outputName = ncName.toString();
final Element outputData = DOMUtils.stringToDOM((String) o);
HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {
public Object call() throws Exception {
SetOutput setOutputCommand = new SetOutput(getCaller(), taskId, outputName, outputData);
setOutputCommand.execute();
return null;
}
});
} else {
log.error("The output data for setOutput operation cannot be empty");
throw new IllegalArgumentFault("The output data cannot be empty!");
}
} catch (Exception ex) {
handleException(ex);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class TaskOperationsImpl method addAttachment.
/**
* Add attachment to a task. Returns an identifier for the attachment.
* @param taskIdentifier : task identifier
* @param name : attachment name
* @param accessType : access type
* @param contentType : content type
* @param attachment : attachment ID (String)
* @return
* @throws IllegalStateFault
* @throws IllegalOperationFault
* @throws IllegalArgumentFault
* @throws IllegalAccessFault
*/
public boolean addAttachment(URI taskIdentifier, String name, String accessType, String contentType, Object attachment) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
final Long taskId = validateTaskId(taskIdentifier);
final String attachmentID = (String) attachment;
try {
Boolean isAdded = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Boolean>() {
public Boolean call() throws Exception {
HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
TaskDAO taskDAO = daoConn.getTask(taskId);
validateTaskTenant(taskDAO);
try {
boolean isAdded = taskDAO.addAttachment(TransformerUtils.generateAttachmentDAOFromID(taskDAO, attachmentID));
if (!isAdded) {
throw new HumanTaskException("Attachment with id: " + attachmentID + "was not associated " + "task with id:" + taskId);
}
return isAdded;
} catch (HumanTaskException ex) {
String errMsg = "getAttachmentInfos operation failed. Reason: ";
log.error(errMsg + ex.getLocalizedMessage(), ex);
throw ex;
}
}
});
return isAdded;
} catch (Exception ex) {
handleException(ex);
}
return false;
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-business-process by wso2.
the class TaskOperationsImpl method authoriseToLoadTask.
/**
* Throws an exception if the current user is not allowed to perform loadTask() operation
* @param taskId
*/
private void authoriseToLoadTask(TaskDAO task) throws Exception {
List<GenericHumanRoleDAO.GenericHumanRoleType> allowedRoles = new ArrayList<GenericHumanRoleDAO.GenericHumanRoleType>();
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.TASK_INITIATOR);
HumanTaskEngine taskEngine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
PeopleQueryEvaluator pqe = taskEngine.getPeopleQueryEvaluator();
OrganizationalEntityDAO invoker = taskEngine.getScheduler().execTransaction(new Callable<OrganizationalEntityDAO>() {
@Override
public OrganizationalEntityDAO call() throws Exception {
return HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(getCaller(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
}
});
if (!OperationAuthorizationUtil.authoriseUser(task, invoker, allowedRoles, pqe)) {
String errorMsg = String.format("The user[%s] cannot perform loadTask()" + " operation as either he is in EXCLUDED_OWNERS role or he is not in task roles [%s]", invoker.getName(), allowedRoles);
log.error(errorMsg);
throw new HumanTaskIllegalAccessException("Access Denied. You are not authorized to perform this task");
}
}
Aggregations