📄 contactmechservices.java
字号:
if (newPartyContactMech != null) { newPartyContactMech.set("roleTypeId", context.get("roleTypeId")); newPartyContactMech.set("allowSolicitation", context.get("allowSolicitation")); } if (!newContactMech.equals(contactMech)) isModified = true; if (newPartyContactMech != null && !newPartyContactMech.equals(partyContactMech)) isModified = true; toBeStored.add(newContactMech); if (newPartyContactMech != null) toBeStored.add(newPartyContactMech); if (isModified) { if (relatedEntityToSet != null) toBeStored.add(relatedEntityToSet); newContactMech.set("contactMechId", newCmId.toString()); if (newPartyContactMech != null) { newPartyContactMech.set("contactMechId", newCmId.toString()); newPartyContactMech.set("fromDate", now); newPartyContactMech.set("thruDate", null); try { Iterator partyContactMechPurposes = UtilMisc.toIterator(partyContactMech.getRelated("PartyContactMechPurpose")); while (partyContactMechPurposes != null && partyContactMechPurposes.hasNext()) { GenericValue tempVal = GenericValue.create((GenericValue) partyContactMechPurposes.next()); tempVal.set("contactMechId", newCmId.toString()); toBeStored.add(tempVal); } } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_read", messageMap, locale); return ServiceUtil.returnError(errMsg); } partyContactMech.set("thruDate", now); } 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_change_contact_info_write", messageMap, locale); return ServiceUtil.returnError(errMsg); } } 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; } // ============================================================================ // ============================================================================ /** * Creates a TelecomNumber * <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 createTelecomNumber(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 = "TELECOM_NUMBER"; 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); 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")))); toBeStored.add(delegator.makeValue("TelecomNumber", UtilMisc.toMap("contactMechId", newCmId.toString(), "countryCode", context.get("countryCode"), "areaCode", context.get("areaCode"), "contactNumber", context.get("contactNumber")))); 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 TelecomNumber * <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 updateTelecomNumber(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)); // 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.getMessage(), module); contactMech = null; partyContactMech = null; } if (contactMech == null) { errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_find_specified_contact_info_read", locale); return ServiceUtil.returnError(errMsg); } if (partyContactMech == null) { errMsg = UtilProperties.getMessage(resource,"contactmechservices.cannot_update_specified_contact_info_not_corresponds", locale); return ServiceUtil.returnError(errMsg); } toBeStored.add(partyContactMech); // never change a contact mech, just create a new one with the changes GenericValue newContactMech = GenericValue.create(contactMech); GenericValue newPartyContactMech = GenericValue.create(partyContactMech); GenericValue relatedEntityToSet = null; if ("TELECOM_NUMBER".equals(contactMech.getString("contactMechTypeId"))) { GenericValue telNum = null; try { telNum = delegator.findByPrimaryKey("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId)); } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); telNum = null; } relatedEntityToSet = GenericValue.create(telNum); relatedEntityToSet.set("countryCode", context.get("countryCode")); relatedEntityToSet.set("areaCode", context.get("areaCode")); relatedEntityToSet.set("contactNumber", context.get("contactNumber")); if (telNum == null || !relatedEntityToSet.equals(telNum)) { isModified = true; } relatedEntityToSet.set("contactMechId", newCmId.toString()); newPartyContactMech.set("extension", context.get("extension")); } else { Map messageMap = UtilMisc.toMap("contactMechTypeId", contactMech.getString("contactMechTypeId")); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_update_contact_as_TELECOM_NUMBER_specified", messageMap, locale); return ServiceUtil.returnError(errMsg); } newPartyContactMech.set("roleTypeId", context.get("roleTypeId")); newPartyContactMech.set("allowSolicitation", context.get("allowSolicitation")); if (!newContactMech.equals(contactMech)) isModified = true; if (!newPartyContactMech.equals(partyContactMech)) isModified = true; toBeStored.add(newContactMech); toBeStored.add(newPartyContactMech); if (isModified) { if (relatedEntityToSet != null) toBeStored.add(relatedEntityToSet); newContactMech.set("contactMechId", newCmId.toString()); newPartyContactMech.set("contactMechId", newCmId.toString()); newPartyContactMech.set("fromDate", now); newPartyContactMech.set("thruDate", null); try { Iterator partyContactMechPurposes = UtilMisc.toIterator(partyContactMech.getRelated("PartyContactMechPurpose")); while (partyContactMechPurposes != null && partyContactMechPurposes.hasNext()) { GenericValue tempVal = GenericValue.create((GenericValue) partyContactMechPurposes.next()); tempVal.set("contactMechId", newCmId.toString()); toBeStored.add(tempVal); } } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_read", messageMap, locale); return ServiceUtil.returnError(errMsg); } partyContactMech.set("thruDate", now); 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_change_contact_info_write", messageMap, locale); return ServiceUtil.returnError(errMsg); } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -