📄 contactmechservices.java
字号:
} } else { String sucMsg = UtilProperties.getMessage(resource,"contactmechservices.no_changes_made_not_updating", locale); result.put("newContactMechId", contactMechId); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); result.put(ModelService.SUCCESS_MESSAGE, sucMsg); return result; } result.put("newContactMechId", newCmId.toString()); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); return result; } /** * Deletes a ContactMech * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_DELETE permission *@param ctx The DispatchContext that this service is operating in *@param context Map containing the input parameters *@return Map with the result of the service, the output parameters */ public static Map deleteContactMech(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); Security security = ctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Timestamp now = UtilDateTime.nowTimestamp(); String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_DELETE"); String errMsg = null; Locale locale = (Locale) context.get("locale"); if (result.size() > 0) return result; // never delete a contact mechanism, just put a to date on the link to the party String contactMechId = (String) context.get("contactMechId"); GenericValue partyContactMech = null; try { // try to find a PartyContactMech with a valid date range List partyContactMechs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId), UtilMisc.toList("fromDate")), true); partyContactMech = EntityUtil.getFirst(partyContactMechs); } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_contact_info_read", messageMap, locale); return ServiceUtil.returnError(errMsg); } if (partyContactMech == null) { errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_contact_info_no_contact_found", locale); return ServiceUtil.returnError(errMsg); } partyContactMech.set("thruDate", UtilDateTime.nowTimestamp()); try { partyContactMech.store(); } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_contact_info_write", locale); return ServiceUtil.returnError(errMsg); } result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); return result; } // ============================================================================ // ============================================================================ /** * Creates a PostalAddress * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_CREATE permission *@param ctx The DispatchContext that this service is operating in *@param context Map containing the input parameters *@return Map with the result of the service, the output parameters */ public static Map createPostalAddress(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); Security security = ctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Timestamp now = UtilDateTime.nowTimestamp(); List toBeStored = new LinkedList(); String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_CREATE"); String errMsg = null; Locale locale = (Locale) context.get("locale"); if (result.size() > 0) return result; String contactMechTypeId = "POSTAL_ADDRESS"; String newCmId = null; try { newCmId = delegator.getNextSeqId("ContactMech"); } catch (IllegalArgumentException e) { errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_contact_info_id_generation_failure", locale); return ServiceUtil.returnError(errMsg); } GenericValue tempContactMech = delegator.makeValue("ContactMech", UtilMisc.toMap("contactMechId", newCmId.toString(), "contactMechTypeId", contactMechTypeId)); toBeStored.add(tempContactMech); // don't create a PartyContactMech if there is no party; we define no party as sending _NA_ as partyId if (!partyId.equals("_NA_")) { toBeStored.add(delegator.makeValue("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", newCmId.toString(), "fromDate", now, "roleTypeId", context.get("roleTypeId"), "allowSolicitation", context.get("allowSolicitation"), "extension", context.get("extension")))); } GenericValue newAddr = delegator.makeValue("PostalAddress", null); newAddr.set("contactMechId", newCmId.toString()); newAddr.set("toName", context.get("toName")); newAddr.set("attnName", context.get("attnName")); newAddr.set("address1", context.get("address1")); newAddr.set("address2", context.get("address2")); newAddr.set("directions", context.get("directions")); newAddr.set("city", context.get("city")); newAddr.set("postalCode", context.get("postalCode")); newAddr.set("postalCodeExt", context.get("postalCodeExt")); newAddr.set("stateProvinceGeoId", context.get("stateProvinceGeoId")); newAddr.set("countryGeoId", context.get("countryGeoId")); newAddr.set("postalCodeGeoId", context.get("postalCodeGeoId")); toBeStored.add(newAddr); try { delegator.storeAll(toBeStored); } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_contact_info_write", messageMap, locale); return ServiceUtil.returnError(errMsg); } result.put("contactMechId", newCmId.toString()); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); return result; } /** * Updates a PostalAddress * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_UPDATE permission *@param ctx The DispatchContext that this service is operating in *@param context Map containing the input parameters *@return Map with the result of the service, the output parameters */ public static Map updatePostalAddress(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); Security security = ctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Timestamp now = UtilDateTime.nowTimestamp(); List toBeStored = new LinkedList(); boolean isModified = false; String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_UPDATE"); String errMsg = null; Locale locale = (Locale) context.get("locale"); if (result.size() > 0) { return result; } String newCmId = null; try { newCmId = delegator.getNextSeqId("ContactMech"); } catch (IllegalArgumentException e) { errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_id_generation_failure", locale); return ServiceUtil.returnError(errMsg); } String contactMechId = (String) context.get("contactMechId"); GenericValue contactMech = null; GenericValue partyContactMech = null; try { contactMech = delegator.findByPrimaryKey("ContactMech", UtilMisc.toMap("contactMechId", contactMechId)); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); contactMech = null; } if (!partyId.equals("_NA_")) { // try to find a PartyContactMech with a valid date range try { List partyContactMechs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId), UtilMisc.toList("fromDate")), true); partyContactMech = EntityUtil.getFirst(partyContactMechs); if (partyContactMech == null) { errMsg = UtilProperties.getMessage(resource,"contactmechservices.cannot_update_specified_contact_info_not_corresponds", locale); return ServiceUtil.returnError(errMsg); } else { toBeStored.add(partyContactMech); } } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); contactMech = null; } } if (contactMech == null) { errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_find_specified_contact_info_read", locale); return ServiceUtil.returnError(errMsg); } // never change a contact mech, just create a new one with the changes GenericValue newContactMech = GenericValue.create(contactMech); GenericValue newPartyContactMech = null; if (partyContactMech != null) newPartyContactMech = GenericValue.create(partyContactMech); GenericValue relatedEntityToSet = null; if ("POSTAL_ADDRESS".equals(contactMech.getString("contactMechTypeId"))) { GenericValue addr = null; try { addr = delegator.findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", contactMechId)); } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); addr = null; } relatedEntityToSet = GenericValue.create(addr); relatedEntityToSet.set("toName", context.get("toName")); relatedEntityToSet.set("attnName", context.get("attnName")); relatedEntityToSet.set("address1", context.get("address1")); relatedEntityToSet.set("address2", context.get("address2")); relatedEntityToSet.set("directions", context.get("directions")); relatedEntityToSet.set("city", context.get("city")); relatedEntityToSet.set("postalCode", context.get("postalCode")); relatedEntityToSet.set("postalCodeExt", context.get("postalCodeExt")); relatedEntityToSet.set("stateProvinceGeoId", context.get("stateProvinceGeoId")); relatedEntityToSet.set("countryGeoId", context.get("countryGeoId")); relatedEntityToSet.set("postalCodeGeoId", context.get("postalCodeGeoId")); if (addr == null || !relatedEntityToSet.equals(addr)) { isModified = true; } relatedEntityToSet.set("contactMechId", newCmId.toString()); } else { Map messageMap = UtilMisc.toMap("contactMechTypeId", contactMech.getString("contactMechTypeId")); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_update_contact_as_POSTAL_ADDRESS_specified", messageMap, locale); return ServiceUtil.returnError(errMsg); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -