📄 contactsservices.java
字号:
GenericValue partyData = delegator.findByPrimaryKey("PartySupplementalData", UtilMisc.toMap("partyId", contactPartyId)); if (partyData == null) { // create a new one partyData = delegator.makeValue("PartySupplementalData", UtilMisc.toMap("partyId", contactPartyId)); partyData.create(); } partyData.setNonPKFields(context); partyData.store(); } catch (GenericServiceException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateContactFail", locale, module); } catch (GenericEntityException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateContactFail", locale, module); } return ServiceUtil.returnSuccess(); } public static Map assignContactToAccount(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Security security = dctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); String contactPartyId = (String) context.get("contactPartyId"); String accountPartyId = (String) context.get("accountPartyId"); try { // check if this contact is already a contact of this account EntityConditionList searchConditions = new EntityConditionList(UtilMisc.toList( new EntityExpr("partyIdFrom", EntityOperator.EQUALS, contactPartyId), new EntityExpr("partyIdTo", EntityOperator.EQUALS, accountPartyId), new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, "CONTACT"), new EntityExpr("roleTypeIdTo", EntityOperator.EQUALS, "ACCOUNT"), new EntityExpr("partyRelationshipTypeId", EntityOperator.EQUALS, "CONTACT_REL_INV"), EntityUtil.getFilterByDateExpr()), EntityOperator.AND); List existingRelationships = delegator.findByCondition("PartyRelationship", searchConditions, null, null); if (existingRelationships.size() > 0) { return UtilCommon.createAndLogServiceError("CrmErrorContactAlreadyAssociatedToAccount", locale, module); } // check if userLogin has CRMSFA_ACCOUNT_UPDATE permission for this account if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, accountPartyId)) { return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module); } // create the party relationship between the Contact and the Account PartyHelper.createNewPartyToRelationship(accountPartyId, contactPartyId, "CONTACT", "CONTACT_REL_INV", null, UtilMisc.toList("ACCOUNT"), false, userLogin, delegator, dispatcher); } catch (GenericServiceException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignContactToAccountFail", locale, module); } catch (GenericEntityException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignContactToAccountFail", locale, module); } return ServiceUtil.returnSuccess(); } public static Map reassignContactResponsibleParty(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Security security = dctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); String contactPartyId = (String) context.get("contactPartyId"); String newPartyId = (String) context.get("newPartyId"); // ensure reassign permission on this contact if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, contactPartyId)) { return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module); } try { // reassign relationship using a helper method boolean result = createResponsibleContactRelationshipForParty(newPartyId, contactPartyId, userLogin, delegator, dispatcher); if (result == false) { return UtilCommon.createAndLogServiceError("CrmErrorReassignFail", locale, module); } } catch (GenericServiceException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorReassignFail", locale, module); } catch (GenericEntityException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorReassignFail", locale, module); } return ServiceUtil.returnSuccess(); } public static Map removeContactFromAccount(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Security security = dctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); String contactPartyId = (String) context.get("contactPartyId"); String accountPartyId = (String) context.get("accountPartyId"); // ensure update permission on account if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, accountPartyId)) { return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module); } try { // find and expire all contact relationships between the contact and account List relations = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdTo", accountPartyId, "partyIdFrom", contactPartyId, "partyRelationshipTypeId", "CONTACT_REL_INV")); PartyHelper.expirePartyRelationships(relations, UtilDateTime.nowTimestamp(), dispatcher, userLogin); } catch (GenericServiceException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorRemoveContactFail", locale, module); } catch (GenericEntityException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorRemoveContactFail", locale, module); } return ServiceUtil.returnSuccess(); } public static Map deactivateContact(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Security security = dctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); // what contact we're expiring String contactPartyId = (String) context.get("partyId"); // check that userLogin has CRMSFA_CONTACT_DEACTIVATE permission for this contact if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, contactPartyId)) { return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module); } // when to expire the contact Timestamp expireDate = (Timestamp) context.get("expireDate"); if (expireDate == null) { expireDate = UtilDateTime.nowTimestamp(); } // in order to deactivate a contact, we expire all party relationships on the expire date try { List partyRelationships = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdFrom", contactPartyId, "roleTypeIdFrom", "CONTACT")); PartyHelper.expirePartyRelationships(partyRelationships, expireDate, dispatcher, userLogin); } catch (GenericEntityException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorDeactivateContactFail", locale, module); } catch (GenericServiceException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorDeactivateContactFail", locale, module); } return ServiceUtil.returnSuccess(); } /**************************************************************************/ /** Helper Methods ***/ /**************************************************************************/ /** * Creates an contact relationship of a given type for the given party and removes all previous relationships of that type. * This method helps avoid semantic mistakes and typos from the repeated use of this code pattern. */ public static boolean createResponsibleContactRelationshipForParty(String partyId, String contactPartyId, GenericValue userLogin, GenericDelegator delegator, LocalDispatcher dispatcher) throws GenericServiceException, GenericEntityException { return PartyHelper.createNewPartyToRelationship(partyId, contactPartyId, "CONTACT", "RESPONSIBLE_FOR", "CONTACT_OWNER", PartyHelper.TEAM_MEMBER_ROLES, true, userLogin, delegator, dispatcher); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -