📄 wfactivityimpl.java
字号:
/*
* $Id: WfActivityImpl.java,v 1.4 2003/09/02 02:17:15 ajzeneski Exp $
*
* Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.ofbiz.workflow.impl;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.ofbiz.base.util.BshUtil;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.util.EntityTypeUtil;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
import org.ofbiz.workflow.AlreadyRunning;
import org.ofbiz.workflow.CannotComplete;
import org.ofbiz.workflow.CannotResume;
import org.ofbiz.workflow.CannotStart;
import org.ofbiz.workflow.CannotStop;
import org.ofbiz.workflow.InvalidData;
import org.ofbiz.workflow.InvalidState;
import org.ofbiz.workflow.NotRunning;
import org.ofbiz.workflow.NotSuspended;
import org.ofbiz.workflow.ResultNotAvailable;
import org.ofbiz.workflow.TransitionNotAllowed;
import org.ofbiz.workflow.WfActivity;
import org.ofbiz.workflow.WfAssignment;
import org.ofbiz.workflow.WfException;
import org.ofbiz.workflow.WfFactory;
import org.ofbiz.workflow.WfProcess;
import org.ofbiz.workflow.WfResource;
/**
* WfActivityImpl - Workflow Activity Object implementation
*
* @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
* @author David Ostrovsky (d.ostrovsky@gmx.de)
* @author Oswin Ondarza and Manuel Soto
* @version $Revision: 1.4 $
* @since 2.0
*/
public class WfActivityImpl extends WfExecutionObjectImpl implements WfActivity {
public static final String module = WfActivityImpl.class.getName();
private static final int CHECK_ASSIGN = 1;
private static final int CHECK_COMPLETE = 2;
protected String processId = null;
public WfActivityImpl(GenericValue value, String processId) throws WfException {
super(value, processId);
this.processId = processId;
init();
}
public WfActivityImpl(GenericDelegator delegator, String workEffortId) throws WfException {
super(delegator, workEffortId);
if (activityId == null || activityId.length() == 0)
throw new WfException("Execution object is not of type WfActivity");
this.processId = getRuntimeObject().getString("workEffortParentId");
}
private void init() throws WfException {
GenericValue valueObject = getDefinitionObject();
// set the activity context
this.setProcessContext(container().contextKey());
// parse the descriptions
this.parseDescriptions(this.processContext());
// check for inheritPriority attribute
boolean inheritPriority = valueObject.getBoolean("inheritPriority").booleanValue() || false;
if (inheritPriority) {
GenericValue runTime = getRuntimeObject();
Map context = processContext();
if (context.containsKey("previousActivity")) {
String previousActivity = (String) context.get("previousActivity");
WfActivity pAct = WfFactory.getWfActivity(getDelegator(), previousActivity);
if (pAct != null) {
try {
runTime.set("priority", new Long(pAct.priority()));
runTime.store();
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
}
}
}
GenericValue performer = null;
if (valueObject.get("performerParticipantId") != null) {
try {
performer = valueObject.getRelatedOne("PerformerWorkflowParticipant");
if (performer == null) {
Map performerFields = UtilMisc.toMap("packageId", valueObject.getString("packageId"),
"packageVersion", valueObject.getString("packageVersion"), "processId", "_NA_",
"processVersion", "_NA_", "participantId", valueObject.getString("performerParticipantId"));
performer = delegator.findByPrimaryKey("WorkflowParticipant", performerFields);
}
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
}
if (performer != null)
createAssignments(performer);
boolean limitAfterStart = valueObject.getBoolean("limitAfterStart").booleanValue();
if (Debug.verboseOn()) {
Debug.logVerbose("[WfActivity.init]: limitAfterStart - " + limitAfterStart, module);
}
if (!limitAfterStart && valueObject.get("limitService") != null && !valueObject.getString("limitService").equals("")) {
Debug.logVerbose("[WfActivity.init]: limit service is not after start, setting up now.", module);
setLimitService();
}
}
private void createAssignments(GenericValue currentPerformer) throws WfException {
GenericValue valueObject = getDefinitionObject();
GenericValue performer = checkPerformer(currentPerformer);
boolean assignAll = false;
if (valueObject.get("acceptAllAssignments") != null) {
assignAll = valueObject.getBoolean("acceptAllAssignments").booleanValue();
}
// first check for single assignment
if (!assignAll) {
if (performer != null) {
Debug.logVerbose("[WfActivity.createAssignments] : (S) Single assignment", module);
assign(WfFactory.getWfResource(performer), false);
}
}
// check for a party group
else if (performer.get("partyId") != null && !performer.getString("partyId").equals("_NA_")) {
GenericValue partyType = null;
GenericValue groupType = null;
try {
Map fields1 = UtilMisc.toMap("partyId", performer.getString("partyId"));
GenericValue v1 = getDelegator().findByPrimaryKey("Party", fields1);
partyType = v1.getRelatedOne("PartyType");
Map fields2 = UtilMisc.toMap("partyTypeId", "PARTY_GROUP");
groupType = getDelegator().findByPrimaryKeyCache("PartyType", fields2);
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
if (EntityTypeUtil.isType(partyType, groupType)) {
// party is a group
Collection partyRelations = null;
try {
Map fields = UtilMisc.toMap("partyIdFrom", performer.getString("partyId"),
"partyRelationshipTypeId", "GROUP_ROLLUP");
partyRelations = getDelegator().findByAnd("PartyRelationship", fields);
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
// make assignments for these parties
Debug.logVerbose("[WfActivity.createAssignments] : Group assignment", module);
Iterator i = partyRelations.iterator();
while (i.hasNext()) {
GenericValue value = (GenericValue) i.next();
assign(
WfFactory.getWfResource(getDelegator(), null, null, value.getString("partyIdTo"), null),
true);
}
} else {
// not a group
Debug.logVerbose("[WfActivity.createAssignments] : (G) Single assignment", module);
assign(WfFactory.getWfResource(performer), false);
}
}
// check for role types
else if (performer.get("roleTypeId") != null && !performer.getString("roleTypeId").equals("_NA_")) {
Collection partyRoles = null;
try {
Map fields = UtilMisc.toMap("roleTypeId", performer.getString("roleTypeId"));
partyRoles = getDelegator().findByAnd("PartyRole", fields);
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
// loop through the roles and create assignments
Debug.logVerbose("[WfActivity.createAssignments] : Role assignment", module);
Iterator i = partyRoles.iterator();
while (i.hasNext()) {
GenericValue value = (GenericValue) i.next();
assign(WfFactory.getWfResource(value.getDelegator(), null, null, value.getString("partyId"), null), true);
}
}
}
private List getAssignments() throws WfException {
List assignments = new ArrayList();
List assignList = this.getAllAssignments();
if (assignList == null)
return assignments;
Iterator i = assignList.iterator();
while (i.hasNext()) {
GenericValue value = (GenericValue) i.next();
String party = value.getString("partyId");
String role = value.getString("roleTypeId");
String status = value.getString("statusId");
java.sql.Timestamp from = value.getTimestamp("fromDate");
if (status.equals("CAL_SENT") || status.equals("CAL_ACCEPTED") || status.equals("CAL_TENTATIVE"))
assignments.add(WfFactory.getWfAssignment(getDelegator(), runtimeKey(), party, role, from));
}
if (Debug.verboseOn()) Debug.logVerbose("Found [" + assignments.size() + "] assignment(s)", module);
return assignments;
}
private List getAllAssignments() throws WfException {
List assignList = null;
try {
assignList = getDelegator().findByAnd("WorkEffortPartyAssignment", UtilMisc.toMap("workEffortId", runtimeKey()));
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
if (assignList != null) {
assignList = EntityUtil.filterByDate(assignList);
} else {
return new ArrayList();
}
return assignList;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -