String workEffortId = activity.runtimeKey();
String partyId = resource.resourcePartyId();
String roleTypeId = resource.resourceRoleId();
if (workEffortId == null)
throw new WfException("WorkEffort could not be found for assignment");
if (partyId == null && roleTypeId == null)
throw new WfException("Both party and role type IDs cannot be null");
if (fromDate == null)
throw new WfException("From date cannot be null");
GenericValue value = null;
Map fields = new HashMap();
fields.put("workEffortId", workEffortId);
fields.put("partyId", partyId);
fields.put("roleTypeId", roleTypeId);
fields.put("fromDate", fromDate);
fields.put("statusId", "CAL_SENT");
// check if one exists
try {
if (valueObject() != null) {
Debug.logVerbose("[WfAssignment.checkAssignment] : found existing assignment.", module);
return;
}
} catch (WfException e) {
Debug.logVerbose("[WfAssignment.checkAssignment] : no existing assignment.", module);
}
if (create) {
// none exist; create a new one
try {
GenericValue v = activity.getDelegator().makeValue("WorkEffortPartyAssignment", fields);
value = activity.getDelegator().create(v);
Debug.logVerbose("[WfAssignment.checkAssignment] : created new party assignment : " + v, module);
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
if (value == null)
throw new WfException("Could not create the assignement");
}
if (value == null)
throw new WfException("No existing assignment found or create failed");
}