📄 partyhelper.java
字号:
} /** * Expires a list of PartyRelationships that are still active on expireDate. */ public static void expirePartyRelationships(List partyRelationships, Timestamp expireDate, LocalDispatcher dispatcher, GenericValue userLogin) throws GenericServiceException { List relationsActiveOnFromDate = EntityUtil.filterByDate(partyRelationships, expireDate); // to expire on expireDate, set the thruDate to the expireDate in the parameter and call updatePartyRelationship service Iterator iter = relationsActiveOnFromDate.iterator(); while (iter.hasNext()) { GenericValue partyRelationship = (GenericValue) iter.next(); Map input = UtilMisc.toMap("partyIdTo", partyRelationship.getString("partyIdTo"), "roleTypeIdTo", partyRelationship.getString("roleTypeIdTo"), "partyIdFrom", partyRelationship.getString("partyIdFrom"), "roleTypeIdFrom", partyRelationship.getString("roleTypeIdFrom")); input.put("fromDate", partyRelationship.getTimestamp("fromDate")); input.put("userLogin", userLogin); input.put("thruDate", expireDate); Map serviceResult = dispatcher.runSync("updatePartyRelationship", input); if (ServiceUtil.isError(serviceResult)) { throw new GenericServiceException("Failed to expire PartyRelationship with values: " + input.toString()); } } } /** * Method to get the current non-expired party responsible for the given account/contact/lead. * * @param partyIdFrom The partyId of the account/contact/lead * @param roleTypeIdFrom The role of the account/contact/lead (e.g., ACCOUNT, CONTACT, LEAD) * @return First non-expired PartySummaryCRMView or null if none found */ public static GenericValue getCurrentResponsibleParty(String partyIdFrom, String roleTypeIdFrom, GenericDelegator delegator) throws GenericEntityException { return getActivePartyByRole("RESPONSIBLE_FOR", partyIdFrom, roleTypeIdFrom, UtilDateTime.nowTimestamp(), delegator); } /** Method to get the current lead owner of a lead */ public static GenericValue getCurrentLeadOwner(String leadPartyId, GenericDelegator delegator) throws GenericEntityException { return getActivePartyByRole("RESPONSIBLE_FOR", leadPartyId, "PROSPECT", "LEAD_OWNER", UtilDateTime.nowTimestamp(), delegator); } /** * Common method used by getCurrentlyResponsibleParty and related methods. This method will obtain the first PartyRelationship found with the given criteria * and return the PartySummaryCRMView with partyId = partyRelationship.partyIdTo. * * @param partyRelationshipTypeId The party relationship (e.g., reps that are RESPONSIBLE_FOR an account) * @param partyIdFrom The partyId of the account/contact/lead * @param roleTypeIdFrom The role of the account/contact/lead (e.g., ACCOUNT, CONTACT, LEAD) * @param securityGroupId Optional securityGroupId of the relationsihp * @param activeDate Check only for active relationships as of this timestamp * @return First non-expired PartySummaryCRMView or null if none found */ public static GenericValue getActivePartyByRole(String partyRelationshipTypeId, String partyIdFrom, String roleTypeIdFrom, String securityGroupId, Timestamp activeDate, GenericDelegator delegator) throws GenericEntityException { Map input = UtilMisc.toMap("partyRelationshipTypeId", partyRelationshipTypeId, "partyIdFrom", partyIdFrom, "roleTypeIdFrom", roleTypeIdFrom); if (securityGroupId != null) input.put("securityGroupId", securityGroupId); List relationships = delegator.findByAnd("PartyRelationship", input); List activeRelationships = EntityUtil.filterByDate(relationships, activeDate); // if none are found, log a message about this and return null if (activeRelationships.size() == 0) { Debug.logInfo("No active PartyRelationships found with relationship [" + partyRelationshipTypeId + "] for party [" + partyIdFrom +"] in role [" + roleTypeIdFrom +"]", module); return null; } // return the related party with partyId = partyRelationship.partyIdTo GenericValue partyRelationship = (GenericValue) activeRelationships.get(0); return delegator.findByPrimaryKey("PartySummaryCRMView", UtilMisc.toMap("partyId", partyRelationship.getString("partyIdTo"))); } /** As above but without security group Id specified */ public static GenericValue getActivePartyByRole(String partyRelationshipTypeId, String partyIdFrom, String roleTypeIdFrom, Timestamp activeDate, GenericDelegator delegator) throws GenericEntityException { return getActivePartyByRole(partyRelationshipTypeId, partyIdFrom, roleTypeIdFrom, null, activeDate, delegator); } /** * Method to copy all "To" relationships of a From party to another From party. For instance, use this method to copy all relationships of an * account (or optionally a specific relationship), such as the managers and reps, over to a team. * NOTE: This service works on unexpired relationships as of now and will need to be refactored for other Dates. * TODO: skip dupes * * @param partyIdFrom * @param roleTypeIdFrom * @param partyRelationshipTypeId optional * @param newPartyIdFrom * @param newRoleTypeIdFrom */ public static void copyToPartyRelationships(String partyIdFrom, String roleTypeIdFrom, String partyRelationshipTypeId, String newPartyIdFrom, String newRoleTypeIdFrom, GenericValue userLogin, GenericDelegator delegator, LocalDispatcher dispatcher) throws GenericEntityException, GenericServiceException { // hardcoded activeDate Timestamp activeDate = UtilDateTime.nowTimestamp(); // first get the unexpired relationships for the From party Map input = UtilMisc.toMap("partyIdFrom", partyIdFrom, "roleTypeIdFrom", roleTypeIdFrom); if (partyRelationshipTypeId != null) input.put("partyRelationshipTypeId", partyRelationshipTypeId); List relationships = delegator.findByAnd("PartyRelationship", input); List activeRelationships = EntityUtil.filterByDate(relationships, activeDate); for (Iterator iter = activeRelationships.iterator(); iter.hasNext();) { GenericValue relationship = (GenericValue) iter.next(); // create the relationship input = UtilMisc.toMap("partyIdTo", relationship.getString("partyIdTo"), "roleTypeIdTo", relationship.getString("roleTypeIdTo")); input.put("partyIdFrom", newPartyIdFrom); input.put("roleTypeIdFrom", newRoleTypeIdFrom); input.put("partyRelationshipTypeId", relationship.getString("partyRelationshipTypeId")); input.put("securityGroupId", relationship.getString("securityGroupId")); input.put("fromDate", relationship.getTimestamp("fromDate")); input.put("thruDate", relationship.getTimestamp("thruDate")); input.put("statusId", relationship.getString("statusId")); input.put("priorityTypeId", relationship.getString("priorityTypeId")); input.put("comments", relationship.getString("comments")); input.put("userLogin", userLogin); Map serviceResult = dispatcher.runSync("createPartyRelationship", input); if (ServiceUtil.isError(serviceResult)) { throw new GenericServiceException(ServiceUtil.getErrorMessage(serviceResult)); } } } /** * Same as above, but passes partyRelationshipTypeId = null so that all relationship types are selected. */ public static void copyToPartyRelationships(String partyIdFrom, String roleTypeIdFrom, String newPartyIdFrom, String newRoleTypeIdFrom, GenericValue userLogin, GenericDelegator delegator, LocalDispatcher dispatcher) throws GenericEntityException, GenericServiceException { copyToPartyRelationships(partyIdFrom, roleTypeIdFrom, null, newPartyIdFrom, newRoleTypeIdFrom, userLogin, delegator, dispatcher); } /** * This array determines the entities in which to delete the party and the order of deletion. * Party should be the very last element. The second element in each row denotes the partyId * field to check. XXX Note: We are deleting historical data. For instance, activity records * involving the partyId will be gone forever! */ private static String[][] CRM_PARTY_DELETE_CASCADE = { {"CustRequestRole", "partyId"}, {"PartyNote", "partyId"}, {"PartyDataSource", "partyId"}, {"WorkEffortPartyAssignment", "partyId"}, {"PartyContactMechPurpose", "partyId"}, {"PartyContactMech", "partyId"}, {"PartySupplementalData", "partyId"}, {"PartyNameHistory", "partyId"}, {"PartyGroup", "partyId"}, {"PartyRelationship", "partyIdFrom"}, {"PartyRelationship", "partyIdTo"}, {"Person", "partyId"}, {"PartyRole", "partyId"}, {"PartyStatus", "partyId"}, {"Party", "partyId"} }; /** * Performs a cascade delete on a party. * * One reason this method can fail is that there were relationships with entities that are not being deleted. * If a party is not being deleted like it should, the developer should take a look at the exception thrown * by this method to see if any relations were violated. If there were violations, consider adding * the entities to the CASCADE array above. * * XXX Warning, this method is very brittle. It is essentially emulating the ON DELETE CASCADE functionality * of well featured databases, but very poorly. As the datamodel evolves, this method would have to be updatd. */ public static void deleteCrmParty(String partyId, GenericDelegator delegator) throws GenericEntityException { for (int i = 0; i < CRM_PARTY_DELETE_CASCADE.length; i++) { String entityName = CRM_PARTY_DELETE_CASCADE[i][0]; String fieldName = CRM_PARTY_DELETE_CASCADE[i][1]; Map input = UtilMisc.toMap(fieldName, partyId); delegator.removeByAnd(entityName, input); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -