📄 workflowservices.java
字号:
String roleType = (String) context.get("roleTypeId");
boolean removeOldAssign = false;
if (context.containsKey("removeOldAssignments")) {
removeOldAssign = ((String) context.get("removeOldAssignments")).equals("true") ? true : false;
}
GenericValue userLogin = (GenericValue) context.get("userLogin");
if (!hasPermission(security, workEffortId, userLogin)) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");
return result;
}
try {
WorkflowClient client = WfFactory.getClient(ctx);
client.assign(workEffortId, partyId, roleType, null, removeOldAssign ? false : true);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
} catch (WfException we) {
we.printStackTrace();
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, we.getMessage());
}
return result;
}
/** Accept an assignment and attempt to start the activity */
public static Map acceptAssignment(DispatchContext ctx, Map context) {
Map result = new HashMap();
String workEffortId = (String) context.get("workEffortId");
String partyId = (String) context.get("partyId");
String roleType = (String) context.get("roleTypeId");
Timestamp fromDate = (Timestamp) context.get("fromDate");
try {
WorkflowClient client = WfFactory.getClient(ctx);
client.acceptAndStart(workEffortId, partyId, roleType, fromDate);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
} catch (WfException we) {
we.printStackTrace();
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, we.getMessage());
}
return result;
}
/** Delegate an assignment */
public static Map delegateAssignment(DispatchContext ctx, Map context) {
Map result = new HashMap();
String workEffortId = (String) context.get("workEffortId");
String fromParty = (String) context.get("fromPartyId");
String fromRole = (String) context.get("fromRoleTypeId");
Timestamp fromFromDate = (Timestamp) context.get("fromFromDate");
String toParty = (String) context.get("toPartyId");
String toRole = (String) context.get("toRoleTypeId");
Timestamp toFromDate = (Timestamp) context.get("toFromDate");
// optional fromDate (default now)
if (toFromDate == null)
toFromDate = UtilDateTime.nowTimestamp();
try {
WorkflowClient client = new WorkflowClient(ctx);
client.delegate(workEffortId, fromParty, fromRole, fromFromDate, toParty, toRole, toFromDate);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
} catch (WfException we) {
we.printStackTrace();
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, we.getMessage());
}
return result;
}
/** Delegate, accept an assignment */
public static Map delegateAcceptAssignment(DispatchContext ctx, Map context) {
Map result = new HashMap();
String workEffortId = (String) context.get("workEffortId");
String fromParty = (String) context.get("fromPartyId");
String fromRole = (String) context.get("fromRoleTypeId");
Timestamp fromFromDate = (Timestamp) context.get("fromFromDate");
String toParty = (String) context.get("toPartyId");
String toRole = (String) context.get("toRoleTypeId");
Timestamp toFromDate = (Timestamp) context.get("toFromDate");
Boolean startObj = (Boolean) context.get("startActivity");
// optional start activity (default false)
boolean start = false;
if (startObj != null)
start = startObj.booleanValue();
// optional fromDate (default now)
if (toFromDate == null)
toFromDate = UtilDateTime.nowTimestamp();
try {
WorkflowClient client = new WorkflowClient(ctx);
client.delegateAndAccept(workEffortId, fromParty, fromRole, fromFromDate, toParty, toRole, toFromDate, start);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
} catch (WfException we) {
we.printStackTrace();
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, we.getMessage());
}
return result;
}
/** Accept a role assignment and attempt to start the activity */
public static Map acceptRoleAssignment(DispatchContext ctx, Map context) {
Map result = new HashMap();
String workEffortId = (String) context.get("workEffortId");
String partyId = (String) context.get("partyId");
String roleType = (String) context.get("roleTypeId");
Timestamp fromDate = (Timestamp) context.get("fromDate");
try {
WorkflowClient client = new WorkflowClient(ctx);
client.delegateAndAccept(workEffortId, "_NA_", roleType, fromDate, partyId, roleType, fromDate, true);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
} catch (WfException we) {
we.printStackTrace();
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, we.getMessage());
}
return result;
}
/** Complete an assignment */
public static Map completeAssignment(DispatchContext ctx, Map context) {
Map result = new HashMap();
GenericDelegator delegator = ctx.getDelegator();
Security security = ctx.getSecurity();
String workEffortId = (String) context.get("workEffortId");
String partyId = (String) context.get("partyId");
String roleType = (String) context.get("roleTypeId");
Timestamp fromDate = (Timestamp) context.get("fromDate");
Map actResults = (Map) context.get("result");
GenericValue userLogin = (GenericValue) context.get("userLogin");
if (!hasPermission(security, workEffortId, userLogin)) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this assignment");
return result;
}
try {
WorkflowClient client = WfFactory.getClient(ctx);
client.complete(workEffortId, partyId, roleType, fromDate, actResults);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
} catch (WfException we) {
we.printStackTrace();
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, we.getMessage());
}
return result;
}
public static Map limitInvoker(DispatchContext ctx, Map context) {
Map result = new HashMap();
GenericDelegator delegator = ctx.getDelegator();
LocalDispatcher dispatcher = ctx.getDispatcher();
String workEffortId = (String) context.get("workEffortId");
String limitService = (String) context.get("serviceName");
Map limitContext = (Map) context.get("serviceContext");
try {
WorkflowClient client = WfFactory.getClient(ctx);
String state = client.getState(workEffortId);
if (state.startsWith("open")) {
dispatcher.runSync(limitService, limitContext);
}
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
} catch (WfException we) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, we.getMessage());
} catch (GenericServiceException se) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, se.getMessage());
}
return result;
}
// -------------------------------------------------------------------
// Service 'Worker' Methods
// -------------------------------------------------------------------
/**
* Checks if a user has permission to access workflow data.
*/
public static boolean hasPermission(Security security, String workEffortId, GenericValue userLogin) {
if (userLogin == null || workEffortId == null) {
Debug.logWarning("No UserLogin object or no Workeffort ID was passed.", module);
return false;
}
if (security.hasPermission("WORKFLOW_MAINT", userLogin)) {
return true;
} else {
String partyId = userLogin.getString("partyId");
List expr = new ArrayList();
expr.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
expr.add(new EntityExpr("workEffortId", EntityOperator.EQUALS, workEffortId));
expr.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime.nowTimestamp()));
Collection c = null;
try {
c = userLogin.getDelegator().findByAnd("WorkEffortAndPartyAssign", expr);
//Debug.logInfo("Found " + c.size() + " records.", module);
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return false;
}
if (c.size() == 0) {
expr = new ArrayList();
expr.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
expr.add(new EntityExpr("workEffortParentId", EntityOperator.EQUALS, workEffortId));
expr.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime.nowTimestamp()));
try {
c = userLogin.getDelegator().findByAnd("WorkEffortAndPartyAssign", expr);
//Debug.logInfo("Found " + c.size() + " records.", module);
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return false;
}
}
if (c.size() > 0) {
return true;
}
}
return false;
}
/**
* Returns the owner of the workflow.
*/
public static GenericValue getOwner(GenericDelegator delegator, String workEffortId) {
try {
GenericValue we = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));
if (we != null && we.getString("workEffortParentId") == null) {
Collection c = delegator.findByAnd("WorkEffortPartyAssignment",
UtilMisc.toMap("workEffortId", workEffortId, "roleTypeId", "WF_OWNER"));
return (GenericValue) c.iterator().next();
} else {
return getOwner(delegator, we.getString("workEffortParentId"));
}
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -