📄 contactmechservices.java
字号:
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 EmailAddress * <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 createEmailAddress(DispatchContext ctx, Map context) { Map newContext = new HashMap(context); newContext.put("infoString", newContext.get("emailAddress")); newContext.remove("emailAddress"); newContext.put("contactMechTypeId", "EMAIL_ADDRESS"); return createContactMech(ctx, newContext); } /** * Updates a EmailAddress * <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 updateEmailAddress(DispatchContext ctx, Map context) { Map newContext = new HashMap(context); newContext.put("infoString", newContext.get("emailAddress")); newContext.remove("emailAddress"); return updateContactMech(ctx, newContext); } // ============================================================================ // ============================================================================ /** * Creates a PartyContactMechPurpose * <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 createPartyContactMechPurpose(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); Security security = ctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); 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; // required parameters String contactMechId = (String) context.get("contactMechId"); String contactMechPurposeTypeId = (String) context.get("contactMechPurposeTypeId"); GenericValue tempVal = null; try { List allPCMPs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId), null), true); tempVal = EntityUtil.getFirst(allPCMPs); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); tempVal = null; } Timestamp fromDate = UtilDateTime.nowTimestamp(); if (tempVal != null) { // exists already with valid date, show warning errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_new_purpose_already_exists", locale); return ServiceUtil.returnError(errMsg); } else { // no entry with a valid date range exists, create new with open thruDate GenericValue newPartyContactMechPurpose = delegator.makeValue("PartyContactMechPurpose", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId, "fromDate", fromDate)); try { delegator.create(newPartyContactMechPurpose); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_add_purpose_write", messageMap, locale); return ServiceUtil.returnError(errMsg); } } result.put("fromDate", fromDate); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); return result; } /** * Deletes the PartyContactMechPurpose corresponding to the parameters in the context * <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 deletePartyContactMechPurpose(DispatchContext ctx, Map context) { Map result = new HashMap(); GenericDelegator delegator = ctx.getDelegator(); Security security = ctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); 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; // required parameters String contactMechId = (String) context.get("contactMechId"); String contactMechPurposeTypeId = (String) context.get("contactMechPurposeTypeId"); Timestamp fromDate = (Timestamp) context.get("fromDate"); GenericValue pcmp = null; try { pcmp = delegator.findByPrimaryKey("PartyContactMechPurpose", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId, "fromDate", fromDate)); if (pcmp == null) { errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_purpose_from_contact_mechanism_not_found", locale); return ServiceUtil.returnError(errMsg); } } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_purpose_from_contact_mechanism_read", messageMap, locale); return ServiceUtil.returnError(errMsg); } pcmp.set("thruDate", UtilDateTime.nowTimestamp()); try { pcmp.store(); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_purpose_from_contact_mechanism_write", messageMap, locale); return ServiceUtil.returnError(errMsg); } result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); return result; } /** * Just wraps the ContactMechWorker method of the same name. * *@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 getPartyContactMechValueMaps(DispatchContext ctx, Map context) { Map result = ServiceUtil.returnSuccess(); GenericDelegator delegator = ctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); String partyId = (String)context.get("partyId"); if (UtilValidate.isEmpty(partyId) ) { if (userLogin != null) { partyId = userLogin.getString("partyId"); } else { return ServiceUtil.returnError("Both 'partyId' and 'userLogin' are empty."); } } Boolean bShowOld = (Boolean)context.get("showOld"); boolean showOld = (bShowOld != null && bShowOld.booleanValue()) ? true : false; String contactMechTypeId = (String)context.get("contactMechTypeId"); List valueMaps = ContactMechWorker.getPartyContactMechValueMaps(delegator, partyId, showOld, contactMechTypeId); result.put("valueMaps", valueMaps ); return result; } /** * Copies all contact mechs from one party to another. Does not delete or overwrite any contact mechs. */ public static Map copyPartyContactMechs(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 partyIdFrom = (String) context.get("partyIdFrom"); String partyIdTo = (String) context.get("partyIdTo"); try { // grab all of the non-expired contact mechs using this party worker method List valueMaps = ContactMechWorker.getPartyContactMechValueMaps(delegator, partyIdFrom, false); // loop through results for (Iterator iter = valueMaps.iterator(); iter.hasNext(); ) { Map thisMap = (Map) iter.next(); GenericValue contactMech = (GenericValue) thisMap.get("contactMech"); GenericValue partyContactMech = (GenericValue) thisMap.get("partyContactMech"); List partyContactMechPurposes = (List) thisMap.get("partyContactMechPurposes"); // get the contactMechId String contactMechId = contactMech.getString("contactMechId"); // create a new party contact mech for the partyIdTo Map serviceResults = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", partyIdTo, "userLogin", userLogin, "contactMechId", contactMechId, "fromDate", UtilDateTime.nowTimestamp(), "allowSolicitation", partyContactMech.getString("allowSolicitation"), "extension", partyContactMech.getString("extension"))); if (ServiceUtil.isError(serviceResults)) { return serviceResults; } // loop through purposes and copy each as a new purpose for the partyIdTo for (Iterator piter = partyContactMechPurposes.iterator(); piter.hasNext(); ) { GenericValue purpose = (GenericValue) piter.next(); Map input = UtilMisc.toMap("partyId", partyIdTo, "contactMechId", contactMechId, "userLogin", userLogin); input.put("contactMechPurposeTypeId", purpose.getString("contactMechPurposeTypeId")); serviceResults = dispatcher.runSync("createPartyContactMechPurpose", input); if (ServiceUtil.isError(serviceResults)) { return serviceResults; } } } } catch (GenericServiceException e) { Debug.logError(e, e.getMessage(), module); return ServiceUtil.returnError("Failed to copy contact mechs. Error: " + e.getMessage()); } return ServiceUtil.returnSuccess(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -