This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch release18.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 5193280424d5146fed4b1982240041a6b122f35a Author: bjugl <61057136+bj...@users.noreply.github.com> AuthorDate: Thu Apr 8 11:05:38 2021 +0200 Fixed: Service calls of "createPartyContactMech" now include the needed contactMechTypeId (OFBIZ-12175) (#292) This was broken by OFBIZ-8358 where, as well explained at OFBIZ-12175, "createPartyContactMech Service has been changed to expect an OUT contactMechTypeId paramter and the call on this end has not been modified." Conflicts handled by hand in PartyServices.java I let the changes coming from trunk, too much to revert by hand --- .../apache/ofbiz/party/party/PartyServices.java | 740 +++++++++++---------- 1 file changed, 376 insertions(+), 364 deletions(-) diff --git a/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java b/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java index def9d44..460a3bd 100644 --- a/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java +++ b/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java @@ -67,9 +67,9 @@ import org.apache.ofbiz.service.ServiceUtil; */ public class PartyServices { - public static final String module = PartyServices.class.getName(); - public static final String resource = "PartyUiLabels"; - public static final String resourceError = "PartyErrorUiLabels"; + private static final String MODULE = PartyServices.class.getName(); + private static final String RESOURCE = "PartyUiLabels"; + private static final String RES_ERROR = "PartyErrorUiLabels"; /** * Creates a Person. @@ -92,7 +92,7 @@ public class PartyServices { // if specified partyId starts with a number, return an error if (UtilValidate.isNotEmpty(partyId) && partyId.matches("\\d+")) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "party.id_is_digit", locale)); } @@ -101,7 +101,7 @@ public class PartyServices { try { partyId = delegator.getNextSeqId("Party"); } catch (IllegalArgumentException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "party.id_generation_failure", locale)); } } @@ -112,12 +112,12 @@ public class PartyServices { try { party = EntityQuery.use(delegator).from("Party").where("partyId", partyId).queryOne(); } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); + Debug.logWarning(e.getMessage(), MODULE); } if (party != null) { if (!"PERSON".equals(party.getString("partyTypeId"))) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "person.create.party_exists_not_person_type", locale)); } } else { @@ -126,7 +126,8 @@ public class PartyServices { if (statusId == null) { statusId = "PARTY_ENABLED"; } - Map<String, Object> newPartyMap = UtilMisc.toMap("partyId", partyId, "partyTypeId", "PERSON", "description", description, "createdDate", now, "lastModifiedDate", now, "statusId", statusId); + Map<String, Object> newPartyMap = UtilMisc.toMap("partyId", partyId, "partyTypeId", "PERSON", "description", description, + "createdDate", now, "lastModifiedDate", now, "statusId", statusId); String preferredCurrencyUomId = (String) context.get("preferredCurrencyUomId"); if (UtilValidate.isNotEmpty(preferredCurrencyUomId)) { newPartyMap.put("preferredCurrencyUomId", preferredCurrencyUomId); @@ -156,11 +157,11 @@ public class PartyServices { try { person = EntityQuery.use(delegator).from("Person").where("partyId", partyId).queryOne(); } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); + Debug.logWarning(e.getMessage(), MODULE); } if (person != null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "person.create.person_exists", locale)); } @@ -171,9 +172,9 @@ public class PartyServices { try { delegator.storeAll(toBeStored); } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, - "person.create.db_error", new Object[] { e.getMessage() }, locale)); + Debug.logWarning(e.getMessage(), MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, + "person.create.db_error", new Object[] {e.getMessage() }, locale)); } result.put("partyId", partyId); @@ -207,24 +208,22 @@ public class PartyServices { party.set("statusId", statusId); oldStatusId = party.getString("statusId"); } else { - - // check that status is defined as a valid change - GenericValue statusValidChange = EntityQuery.use(delegator).from("StatusValidChange").where("statusId", party.getString("statusId"), "statusIdTo", statusId).queryOne(); - if (statusValidChange == null) { - String errorMsg = "Cannot change party status from " + party.getString("statusId") + " to " + statusId; - Debug.logWarning(errorMsg, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "PartyStatusCannotBeChanged", - UtilMisc.toMap("partyFromStatusId", party.getString("statusId"), - "partyToStatusId", statusId), locale)); - } - - party.set("statusId", statusId); + // check that status is defined as a valid change + GenericValue statusValidChange = EntityQuery.use(delegator).from("StatusValidChange").where("statusId", + party.getString("statusId"), "statusIdTo", statusId).queryOne(); + if (statusValidChange == null) { + String errorMsg = "Cannot change party status from " + party.getString("statusId") + " to " + statusId; + Debug.logWarning(errorMsg, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyStatusCannotBeChanged", + UtilMisc.toMap("partyFromStatusId", party.getString("statusId"), "partyToStatusId", statusId), locale)); + } + party.set("statusId", statusId); } party.store(); // record this status change in PartyStatus table - GenericValue partyStatus = delegator.makeValue("PartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", statusId, "statusDate", statusDate)); + GenericValue partyStatus = delegator.makeValue("PartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", statusId, + "statusDate", statusDate)); if (loggedInUserLogin != null) { partyStatus.put("changeByUserLoginId", loggedInUserLogin.get("userLoginId")); } @@ -234,9 +233,8 @@ public class PartyServices { if (("PARTY_DISABLED").equals(statusId)) { EntityCondition cond = EntityCondition.makeCondition( EntityCondition.makeCondition("partyId", partyId), - EntityCondition.makeCondition("enabled", EntityOperator.NOT_EQUAL, "N") - ); - List <GenericValue> userLogins = EntityQuery.use(delegator).from("UserLogin").where(cond).queryList(); + EntityCondition.makeCondition("enabled", EntityOperator.NOT_EQUAL, "N")); + List<GenericValue> userLogins = EntityQuery.use(delegator).from("UserLogin").where(cond).queryList(); for (GenericValue userLogin : userLogins) { userLogin.set("enabled", "N"); userLogin.set("disabledDateTime", UtilDateTime.nowTimestamp()); @@ -249,9 +247,9 @@ public class PartyServices { results.put("oldStatusId", oldStatusId); return results; } catch (GenericEntityException e) { - Debug.logError(e, e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, - "person.update.write_failure", new Object[] { e.getMessage() }, locale)); + Debug.logError(e, e.getMessage(), MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, + "person.update.write_failure", new Object[] {e.getMessage() }, locale)); } } @@ -280,13 +278,13 @@ public class PartyServices { person = EntityQuery.use(delegator).from("Person").where("partyId", partyId).queryOne(); party = EntityQuery.use(delegator).from("Party").where("partyId", partyId).queryOne(); } catch (GenericEntityException e) { - Debug.logWarning(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, - "person.update.read_failure", new Object[] { e.getMessage() }, locale)); + Debug.logWarning(e, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, + "person.update.read_failure", new Object[] {e.getMessage() }, locale)); } if (person == null || party == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "person.update.not_found", locale)); } @@ -305,27 +303,28 @@ public class PartyServices { person.store(); party.store(); } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, - "person.update.write_failure", new Object[] { e.getMessage() }, locale)); + Debug.logWarning(e.getMessage(), MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, + "person.update.write_failure", new Object[] {e.getMessage() }, locale)); } if (UtilValidate.isNotEmpty(context.get("statusId")) && !context.get("statusId").equals(oldStatusId)) { try { - Map<String, Object> serviceResult = dispatcher.runSync("setPartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", context.get("statusId"), "userLogin", context.get("userLogin"))); + Map<String, Object> serviceResult = dispatcher.runSync("setPartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", + context.get("statusId"), "userLogin", context.get("userLogin"))); if (ServiceUtil.isError(serviceResult)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); } } catch (GenericServiceException e) { - Debug.logWarning(e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, - "person.update.write_failure", new Object[] { e.getMessage() }, locale)); + Debug.logWarning(e.getMessage(), MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, + "person.update.write_failure", new Object[] {e.getMessage() }, locale)); } } result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); result.put(ModelService.SUCCESS_MESSAGE, - UtilProperties.getMessage(resourceError, "person.update.success", locale)); + UtilProperties.getMessage(RES_ERROR, "person.update.success", locale)); return result; } @@ -350,13 +349,13 @@ public class PartyServices { try { partyId = delegator.getNextSeqId("Party"); } catch (IllegalArgumentException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_create_party_group_generation_failure", locale)); } } else { // if specified partyId starts with a number, return an error if (partyId.matches("\\d+")) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_create_party_ID_digit", locale)); } } @@ -367,7 +366,7 @@ public class PartyServices { GenericValue partyGroupPartyType = EntityQuery.use(delegator).from("PartyType").where("partyTypeId", "PARTY_GROUP").cache().queryOne(); if (partyGroupPartyType == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.partyservices.party_type_not_found_in_database_cannot_create_party_group", locale)); } @@ -375,7 +374,7 @@ public class PartyServices { GenericValue partyType = party.getRelatedOne("PartyType", true); if (!EntityTypeUtil.isType(partyType, partyGroupPartyType)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.partyservices.cannot_create_party_group_already_exists_not_PARTY_GROUP_type", locale)); } } else { @@ -383,16 +382,18 @@ public class PartyServices { String partyTypeId = "PARTY_GROUP"; if (UtilValidate.isNotEmpty(context.get("partyTypeId"))) { - GenericValue desiredPartyType = EntityQuery.use(delegator).from("PartyType").where("partyTypeId", context.get("partyTypeId")).cache().queryOne(); + GenericValue desiredPartyType = EntityQuery.use(delegator).from("PartyType").where("partyTypeId", context.get("partyTypeId")) + .cache().queryOne(); if (desiredPartyType != null && EntityTypeUtil.isType(desiredPartyType, partyGroupPartyType)) { partyTypeId = desiredPartyType.getString("partyTypeId"); } else { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyPartyTypeIdNotFound", UtilMisc.toMap("partyTypeId", context.get("partyTypeId")), locale)); } } - Map<String, Object> newPartyMap = UtilMisc.toMap("partyId", partyId, "partyTypeId", partyTypeId, "createdDate", now, "lastModifiedDate", now); + Map<String, Object> newPartyMap = UtilMisc.toMap("partyId", partyId, "partyTypeId", partyTypeId, "createdDate", now, + "lastModifiedDate", now); if (userLogin != null) { newPartyMap.put("createdByUserLogin", userLogin.get("userLoginId")); newPartyMap.put("lastModifiedByUserLogin", userLogin.get("userLoginId")); @@ -419,7 +420,7 @@ public class PartyServices { GenericValue partyGroup = EntityQuery.use(delegator).from("PartyGroup").where("partyId", partyId).queryOne(); if (partyGroup != null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_create_party_group_already_exists", locale)); } @@ -428,8 +429,8 @@ public class PartyServices { partyGroup.create(); } catch (GenericEntityException e) { - Debug.logWarning(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + Debug.logWarning(e, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.data_source_error_adding_party_group", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } @@ -464,14 +465,14 @@ public class PartyServices { partyGroup = EntityQuery.use(delegator).from("PartyGroup").where("partyId", partyId).queryOne(); party = EntityQuery.use(delegator).from("Party").where("partyId", partyId).queryOne(); } catch (GenericEntityException e) { - Debug.logWarning(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + Debug.logWarning(e, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_update_party_information_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } if (partyGroup == null || party == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_update_party_information_not_found", locale)); } @@ -486,22 +487,23 @@ public class PartyServices { partyGroup.store(); party.store(); } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + Debug.logWarning(e.getMessage(), MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_update_party_information_write", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } if (UtilValidate.isNotEmpty(context.get("statusId")) && !context.get("statusId").equals(oldStatusId)) { try { - Map<String, Object> serviceResult = dispatcher.runSync("setPartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", context.get("statusId"), "userLogin", context.get("userLogin"))); + Map<String, Object> serviceResult = dispatcher.runSync("setPartyStatus", UtilMisc.toMap("partyId", partyId, + "statusId", context.get("statusId"), "userLogin", context.get("userLogin"))); if (ServiceUtil.isError(serviceResult)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); } } catch (GenericServiceException e) { - Debug.logWarning(e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, - "person.update.write_failure", new Object[] { e.getMessage() }, locale)); + Debug.logWarning(e.getMessage(), MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, + "person.update.write_failure", new Object[] {e.getMessage() }, locale)); } } @@ -525,7 +527,7 @@ public class PartyServices { // if specified partyId starts with a number, return an error if (UtilValidate.isNotEmpty(partyId) && partyId.matches("\\d+")) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_create_affiliate_digit", locale)); } @@ -534,7 +536,7 @@ public class PartyServices { try { partyId = delegator.getNextSeqId("Party"); } catch (IllegalArgumentException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_create_affiliate_generation_failure", locale)); } } @@ -545,11 +547,11 @@ public class PartyServices { try { party = EntityQuery.use(delegator).from("Party").where("partyId", partyId).queryOne(); } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); + Debug.logWarning(e.getMessage(), MODULE); } if (party == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_create_affiliate_no_party_entity", locale)); } @@ -558,11 +560,11 @@ public class PartyServices { try { affiliate = EntityQuery.use(delegator).from("Affiliate").where("partyId", partyId).queryOne(); } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); + Debug.logWarning(e.getMessage(), MODULE); } if (affiliate != null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_create_affiliate_ID_already_exists", locale)); } @@ -573,8 +575,8 @@ public class PartyServices { try { delegator.create(affiliate); } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + Debug.logWarning(e.getMessage(), MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_add_affiliate_info_write", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } @@ -605,14 +607,14 @@ public class PartyServices { try { affiliate = EntityQuery.use(delegator).from("Affiliate").where("partyId", partyId).queryOne(); } catch (GenericEntityException e) { - Debug.logWarning(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + Debug.logWarning(e, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_update_affiliate_information_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } if (affiliate == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_update_affiliate_information_not_found", locale)); } @@ -621,7 +623,7 @@ public class PartyServices { try { affiliate.store(); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.could_not_update_affiliate_information_write", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } @@ -650,11 +652,11 @@ public class PartyServices { try { GenericValue value = EntityQuery.use(delegator).from("NoteData").where("noteId", noteId).queryOne(); if (value == null) { - Debug.logError("ERROR: Note id does not exist for : " + noteId + ", autogenerating." , module); + Debug.logError("ERROR: Note id does not exist for : " + noteId + ", autogenerating.", MODULE); noteId = null; } } catch (GenericEntityException e) { - Debug.logError(e, "ERROR: Note id does not exist for : " + noteId + ", autogenerating." , module); + Debug.logError(e, "ERROR: Note id does not exist for : " + noteId + ", autogenerating.", MODULE); noteId = null; } } @@ -669,8 +671,8 @@ public class PartyServices { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(noteRes)); } } catch (GenericServiceException e) { - Debug.logError(e, e.getMessage(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + Debug.logError(e, e.getMessage(), MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyNoteCreationError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } @@ -681,7 +683,7 @@ public class PartyServices { noteId = (String) noteRes.get("noteId"); if (UtilValidate.isEmpty(noteId)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.problem_creating_note_no_noteId_returned", locale)); } } @@ -694,14 +696,14 @@ public class PartyServices { delegator.create(v); } catch (GenericEntityException ee) { - Debug.logError(ee, module); + Debug.logError(ee, MODULE); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); - result.put(ModelService.ERROR_MESSAGE, UtilProperties.getMessage(resourceError, + result.put(ModelService.ERROR_MESSAGE, UtilProperties.getMessage(RES_ERROR, "partyservices.problem_associating_note_with_party", UtilMisc.toMap("errMessage", ee.getMessage()), locale)); } result.put(ModelService.SUCCESS_MESSAGE, - UtilProperties.getMessage(resource, "PartyNoteCreatedSuccessfully", locale)); + UtilProperties.getMessage(RESOURCE, "PartyNoteCreatedSuccessfully", locale)); return result; } @@ -718,37 +720,37 @@ public class PartyServices { String email = (String) context.get("email"); Locale locale = (Locale) context.get("locale"); - if (email.length() == 0) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + if (email.isEmpty()) { + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.required_parameter_email_cannot_be_empty", locale)); } try { List<GenericValue> c = EntityQuery.use(delegator).from("PartyAndContactMech") - .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("infoString"), EntityOperator.EQUALS, EntityFunction.UPPER(email.toUpperCase(Locale.getDefault())))) - .orderBy("infoString") - .filterByDate() - .queryList(); + .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("infoString"), + EntityOperator.EQUALS, EntityFunction.UPPER(email.toUpperCase(Locale.getDefault())))) + .orderBy("infoString").filterByDate().queryList(); if (Debug.verboseOn()) { - Debug.logVerbose("List: " + c, module); + Debug.logVerbose("List: " + c, MODULE); } if (Debug.infoOn()) { - Debug.logInfo("PartyFromEmail number found: " + c.size(), module); + Debug.logInfo("PartyFromEmail number found: " + c.size(), MODULE); } if (c != null) { for (GenericValue pacm: c) { - GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", pacm.get("partyId"), "partyTypeId", pacm.get("partyTypeId"))); + GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", pacm.get("partyId"), + "partyTypeId", pacm.get("partyTypeId"))); parties.add(UtilMisc.<String, GenericValue>toMap("party", party)); } } } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_get_party_entities_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } - if (parties.size() > 0) { + if (!parties.isEmpty()) { result.put("parties", parties); } return result; @@ -761,37 +763,37 @@ public class PartyServices { String email = (String) context.get("email"); Locale locale = (Locale) context.get("locale"); - if (email.length() == 0) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + if (email.isEmpty()) { + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.required_parameter_email_cannot_be_empty", locale)); } try { List<GenericValue> c = EntityQuery.use(delegator).from("PartyAndContactMech") - .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("infoString"), EntityOperator.LIKE, EntityFunction.UPPER(("%" + email.toUpperCase(Locale.getDefault())) + "%"))) - .orderBy("infoString") - .filterByDate() - .queryList(); + .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("infoString"), EntityOperator.LIKE, + EntityFunction.UPPER(("%" + email.toUpperCase(Locale.getDefault())) + "%"))) + .orderBy("infoString").filterByDate().queryList(); if (Debug.verboseOn()) { - Debug.logVerbose("List: " + c, module); + Debug.logVerbose("List: " + c, MODULE); } if (Debug.infoOn()) { - Debug.logInfo("PartyFromEmail number found: " + c.size(), module); + Debug.logInfo("PartyFromEmail number found: " + c.size(), MODULE); } if (c != null) { for (GenericValue pacm: c) { - GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", pacm.get("partyId"), "partyTypeId", pacm.get("partyTypeId"))); + GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", pacm.get("partyId"), + "partyTypeId", pacm.get("partyTypeId"))); parties.add(UtilMisc.<String, GenericValue>toMap("party", party)); } } } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_get_party_entities_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } - if (parties.size() > 0) { + if (!parties.isEmpty()) { result.put("parties", parties); } return result; @@ -804,39 +806,38 @@ public class PartyServices { * @return Map with the result of the service, the output parameters. */ public static Map<String, Object> getPartiesFromPartOfUserloginId(DispatchContext dctx, Map<String, ? extends Object> context) { - Debug.logWarning("Running the getPartiesFromPartOfUserloginId Service...", module); + Debug.logWarning("Running the getPartiesFromPartOfUserloginId Service...", MODULE); Map<String, Object> result = new HashMap<>(); Delegator delegator = dctx.getDelegator(); Collection<Map<String, GenericValue>> parties = new LinkedList<>(); String userLoginId = (String) context.get("userLoginId"); Locale locale = (Locale) context.get("locale"); - if (userLoginId.length() == 0) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + if (userLoginId.isEmpty()) { + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyCannotGetUserLoginFromParty", locale)); } try { Collection<GenericValue> ulc = EntityQuery.use(delegator).from("PartyAndUserLogin") - .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("userLoginId"), EntityOperator.LIKE, EntityFunction.UPPER("%" + userLoginId.toUpperCase(Locale.getDefault()) + "%"))) - .orderBy("userLoginId") - .queryList(); + .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("userLoginId"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + userLoginId.toUpperCase(Locale.getDefault()) + "%"))).orderBy("userLoginId").queryList(); if (Debug.verboseOn()) { - Debug.logVerbose("Collection: " + ulc, module); + Debug.logVerbose("Collection: " + ulc, MODULE); } if (Debug.infoOn()) { - Debug.logInfo("PartyFromUserLogin number found: " + ulc.size(), module); + Debug.logInfo("PartyFromUserLogin number found: " + ulc.size(), MODULE); } if (ulc != null) { for (GenericValue ul: ulc) { - GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", ul.get("partyId"), "partyTypeId", ul.get("partyTypeId"))); - + GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", ul.get("partyId"), + "partyTypeId", ul.get("partyTypeId"))); parties.add(UtilMisc.<String, GenericValue>toMap("party", party)); } } } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_get_party_entities_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } @@ -866,8 +867,8 @@ public class PartyServices { if (lastName == null) { lastName = ""; } - if (firstName.length() == 0 && lastName.length() == 0) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + if (firstName.isEmpty() && lastName.isEmpty()) { + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.both_names_cannot_be_empty", locale)); } @@ -877,24 +878,26 @@ public class PartyServices { EntityFunction.UPPER("%" + firstName.toUpperCase(Locale.getDefault()) + "%")), EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("lastName"), EntityOperator.LIKE, EntityFunction.UPPER("%" + lastName.toUpperCase(Locale.getDefault()) + "%"))); - Collection<GenericValue> pc = EntityQuery.use(delegator).from("Person").where(ecl).orderBy("lastName", "firstName", "partyId").queryList(); + Collection<GenericValue> pc = EntityQuery.use(delegator).from("Person").where(ecl).orderBy("lastName", "firstName", "partyId") + .queryList(); if (Debug.infoOn()) { - Debug.logInfo("PartyFromPerson number found: " + pc.size(), module); + Debug.logInfo("PartyFromPerson number found: " + pc.size(), MODULE); } if (pc != null) { for (GenericValue person: pc) { - GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", person.get("partyId"), "partyTypeId", "PERSON")); + GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", + person.get("partyId"), "partyTypeId", "PERSON")); parties.add(UtilMisc.<String, GenericValue>toMap("person", person, "party", party)); } } } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_get_party_entities_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } - if (parties.size() > 0) { + if (!parties.isEmpty()) { result.put("parties", parties); } return result; @@ -913,33 +916,35 @@ public class PartyServices { String groupName = (String) context.get("groupName"); Locale locale = (Locale) context.get("locale"); - if (groupName.length() == 0) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + if (groupName.isEmpty()) { + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyCannotgetPartiesFromPartyGroup", locale)); } try { Collection<GenericValue> pc = EntityQuery.use(delegator).from("PartyGroup") - .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("groupName"), EntityOperator.LIKE, EntityFunction.UPPER("%" + groupName.toUpperCase(Locale.getDefault()) + "%"))) + .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("groupName"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + groupName.toUpperCase(Locale.getDefault()) + "%"))) .orderBy("groupName", "partyId") .queryList(); if (Debug.infoOn()) { - Debug.logInfo("PartyFromGroup number found: " + pc.size(), module); + Debug.logInfo("PartyFromGroup number found: " + pc.size(), MODULE); } if (pc != null) { for (GenericValue group: pc) { - GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", group.get("partyId"), "partyTypeId", "PARTY_GROUP")); + GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", + group.get("partyId"), "partyTypeId", "PARTY_GROUP")); parties.add(UtilMisc.<String, GenericValue>toMap("partyGroup", group, "party", party)); } } } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_get_party_entities_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } - if (parties.size() > 0) { + if (!parties.isEmpty()) { result.put("parties", parties); } return result; @@ -960,11 +965,12 @@ public class PartyServices { try { parties = EntityQuery.use(delegator).from("Party") - .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("externalId"), EntityOperator.EQUALS, EntityFunction.UPPER(externalId))) + .where(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("externalId"), + EntityOperator.EQUALS, EntityFunction.UPPER(externalId))) .orderBy("externalId", "partyId") .queryList(); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_get_party_entities_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } @@ -982,7 +988,7 @@ public class PartyServices { try { person = EntityQuery.use(delegator).from("Person").where("partyId", partyId).cache().queryOne(); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, "partyservices.cannot_get_party_entities_read", UtilMisc.toMap("errMessage", e.getMessage()), locale)); } @@ -992,29 +998,6 @@ public class PartyServices { return result; } - public static Map<String, Object> createRoleType(DispatchContext dctx, Map<String, ? extends Object> context) { - Map<String, Object> result = new HashMap<>(); - Delegator delegator = dctx.getDelegator(); - Locale locale = (Locale) context.get("locale"); - GenericValue roleType = null; - - try { - roleType = delegator.makeValue("RoleType"); - roleType.setPKFields(context); - roleType.setNonPKFields(context); - roleType = delegator.create(roleType); - } catch (GenericEntityException e) { - Debug.logError(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "PartyCannotCreateRoleTypeEntity", - UtilMisc.toMap("errMessage", e.getMessage()), locale)); - } - if (roleType != null) { - result.put("roleType", roleType); - } - return result; - } - @Deprecated // migration from ftl to widget in process. public static Map<String, Object> findParty(DispatchContext dctx, Map<String, ? extends Object> context) { Map<String, Object> result = ServiceUtil.returnSuccess(); @@ -1030,8 +1013,8 @@ public class PartyServices { result.put("roleTypes", roleTypes); } catch (GenericEntityException e) { String errMsg = "Error looking up RoleTypes: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + Debug.logError(e, errMsg, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyLookupRoleTypeError", UtilMisc.toMap("errMessage", e.toString()), locale)); } @@ -1046,8 +1029,8 @@ public class PartyServices { } } catch (GenericEntityException e) { String errMsg = "Error looking up current RoleType: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + Debug.logError(e, errMsg, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyLookupRoleTypeError", UtilMisc.toMap("errMessage", e.toString()), locale)); } @@ -1058,8 +1041,8 @@ public class PartyServices { result.put("partyTypes", partyTypes); } catch (GenericEntityException e) { String errMsg = "Error looking up PartyTypes: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + Debug.logError(e, errMsg, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyLookupPartyTypeError", UtilMisc.toMap("errMessage", e.toString()), locale)); } @@ -1074,8 +1057,8 @@ public class PartyServices { } } catch (GenericEntityException e) { String errMsg = "Error looking up current PartyType: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + Debug.logError(e, errMsg, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyLookupPartyTypeError", UtilMisc.toMap("errMessage", e.toString()), locale)); } @@ -1090,8 +1073,8 @@ public class PartyServices { } } catch (GenericEntityException e) { String errMsg = "Error looking up current stateProvinceGeo: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + Debug.logError(e, errMsg, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyLookupStateProvinceGeoError", UtilMisc.toMap("errMessage", e.toString()), locale)); } @@ -1167,7 +1150,8 @@ public class PartyServices { if (UtilValidate.isEmpty(ownerPartyIds)) { String partyIdFrom = userLogin.getString("partyId"); paramList = paramList + "&partyIdFrom=" + partyIdFrom; - relationshipCond = EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyIdFrom"), EntityOperator.EQUALS, EntityFunction.UPPER(partyIdFrom)); + relationshipCond = EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyIdFrom"), + EntityOperator.EQUALS, EntityFunction.UPPER(partyIdFrom)); } else { relationshipCond = EntityCondition.makeCondition("partyIdFrom", EntityOperator.IN, ownerPartyIds); } @@ -1175,7 +1159,8 @@ public class PartyServices { // add the expr andExprs.add(EntityCondition.makeCondition( relationshipCond, EntityOperator.AND, - EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyRelationshipTypeId"), EntityOperator.EQUALS, EntityFunction.UPPER(partyRelationshipTypeId)))); + EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyRelationshipTypeId"), + EntityOperator.EQUALS, EntityFunction.UPPER(partyRelationshipTypeId)))); fieldsToSelect.add("partyIdTo"); } @@ -1191,7 +1176,8 @@ public class PartyServices { // check for a partyId if (UtilValidate.isNotEmpty(partyId)) { paramList = paramList + "&partyId=" + partyId; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyId"), EntityOperator.LIKE, EntityFunction.UPPER("%"+partyId+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyId"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + partyId + "%"))); } // now the statusId - send ANY for all statuses; leave null for just enabled; or pass a specific status @@ -1202,12 +1188,14 @@ public class PartyServices { } } else { // NOTE: _must_ explicitly allow null as it is not included in a not equal in many databases... odd but true - andExprs.add(EntityCondition.makeCondition(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PARTY_DISABLED"))); + andExprs.add(EntityCondition.makeCondition(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, null), + EntityOperator.OR, EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PARTY_DISABLED"))); } // check for partyTypeId if (partyTypeId != null && !"ANY".equals(partyTypeId)) { paramList = paramList + "&partyTypeId=" + partyTypeId; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyTypeId"), EntityOperator.LIKE, EntityFunction.UPPER("%"+partyTypeId+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyTypeId"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + partyTypeId + "%"))); } // ---- @@ -1224,7 +1212,8 @@ public class PartyServices { dynamicView.addViewLink("PT", "UL", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId")); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("userLoginId"), EntityOperator.LIKE, EntityFunction.UPPER("%"+userLoginId+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("userLoginId"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + userLoginId + "%"))); fieldsToSelect.add("userLoginId"); } @@ -1243,7 +1232,8 @@ public class PartyServices { dynamicView.addViewLink("PT", "PG", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId")); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("groupName"), EntityOperator.LIKE, EntityFunction.UPPER("%"+groupName+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("groupName"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + groupName + "%"))); fieldsToSelect.add("groupName"); } @@ -1268,13 +1258,15 @@ public class PartyServices { // filter on firstName if (UtilValidate.isNotEmpty(firstName)) { paramList = paramList + "&firstName=" + firstName; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("firstName"), EntityOperator.LIKE, EntityFunction.UPPER("%"+firstName+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("firstName"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + firstName + "%"))); } // filter on lastName if (UtilValidate.isNotEmpty(lastName)) { paramList = paramList + "&lastName=" + lastName; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("lastName"), EntityOperator.LIKE, EntityFunction.UPPER("%"+lastName+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("lastName"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + lastName + "%"))); } // ---- @@ -1304,10 +1296,7 @@ public class PartyServices { String inventoryItemId = (String) context.get("inventoryItemId"); String serialNumber = (String) context.get("serialNumber"); String softIdentifier = (String) context.get("softIdentifier"); - if (UtilValidate.isNotEmpty(inventoryItemId) || - UtilValidate.isNotEmpty(serialNumber) || - UtilValidate.isNotEmpty(softIdentifier)) { - + if (UtilValidate.isNotEmpty(inventoryItemId) || UtilValidate.isNotEmpty(serialNumber) || UtilValidate.isNotEmpty(softIdentifier)) { // add role to view dynamicView.addMemberEntity("II", "InventoryItem"); dynamicView.addAlias("II", "ownerPartyId"); @@ -1317,21 +1306,24 @@ public class PartyServices { paramList = paramList + "&inventoryItemId=" + inventoryItemId; dynamicView.addAlias("II", "inventoryItemId"); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("inventoryItemId"), EntityOperator.LIKE, EntityFunction.UPPER("%" + inventoryItemId + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("inventoryItemId"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + inventoryItemId + "%"))); fieldsToSelect.add("inventoryItemId"); } if (UtilValidate.isNotEmpty(serialNumber)) { paramList = paramList + "&serialNumber=" + serialNumber; dynamicView.addAlias("II", "serialNumber"); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("serialNumber"), EntityOperator.LIKE, EntityFunction.UPPER("%" + serialNumber + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("serialNumber"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + serialNumber + "%"))); fieldsToSelect.add("serialNumber"); } if (UtilValidate.isNotEmpty(softIdentifier)) { paramList = paramList + "&softIdentifier=" + softIdentifier; dynamicView.addAlias("II", "softIdentifier"); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("softIdentifier"), EntityOperator.LIKE, EntityFunction.UPPER("%" + softIdentifier + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("softIdentifier"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + softIdentifier + "%"))); fieldsToSelect.add("softIdentifier"); } @@ -1356,21 +1348,24 @@ public class PartyServices { String address1 = (String) context.get("address1"); if (UtilValidate.isNotEmpty(address1)) { paramList = paramList + "&address1=" + address1; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("address1"), EntityOperator.LIKE, EntityFunction.UPPER("%" + address1 + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("address1"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + address1 + "%"))); } // filter on address2 String address2 = (String) context.get("address2"); if (UtilValidate.isNotEmpty(address2)) { paramList = paramList + "&address2=" + address2; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("address2"), EntityOperator.LIKE, EntityFunction.UPPER("%" + address2 + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("address2"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + address2 + "%"))); } // filter on city String city = (String) context.get("city"); if (UtilValidate.isNotEmpty(city)) { paramList = paramList + "&city=" + city; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("city"), EntityOperator.LIKE, EntityFunction.UPPER("%" + city + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("city"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + city + "%"))); } // filter on state geo @@ -1383,7 +1378,8 @@ public class PartyServices { String postalCode = (String) context.get("postalCode"); if (UtilValidate.isNotEmpty(postalCode)) { paramList = paramList + "&postalCode=" + postalCode; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("postalCode"), EntityOperator.LIKE, EntityFunction.UPPER("%" + postalCode + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("postalCode"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + postalCode + "%"))); } fieldsToSelect.add("postalCode"); @@ -1407,7 +1403,8 @@ public class PartyServices { String infoString = (String) context.get("infoString"); if (UtilValidate.isNotEmpty(infoString)) { paramList = paramList + "&infoString=" + infoString; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("infoString"), EntityOperator.LIKE, EntityFunction.UPPER("%"+infoString+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("infoString"), + EntityOperator.LIKE, EntityFunction.UPPER("%" + infoString + "%"))); fieldsToSelect.add("infoString"); } @@ -1431,21 +1428,24 @@ public class PartyServices { String countryCode = (String) context.get("countryCode"); if (UtilValidate.isNotEmpty(countryCode)) { paramList = paramList + "&countryCode=" + countryCode; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("countryCode"), EntityOperator.EQUALS, EntityFunction.UPPER(countryCode))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("countryCode"), + EntityOperator.EQUALS, EntityFunction.UPPER(countryCode))); } // filter on areaCode String areaCode = (String) context.get("areaCode"); if (UtilValidate.isNotEmpty(areaCode)) { paramList = paramList + "&areaCode=" + areaCode; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("areaCode"), EntityOperator.EQUALS, EntityFunction.UPPER(areaCode))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("areaCode"), + EntityOperator.EQUALS, EntityFunction.UPPER(areaCode))); } // filter on contact number String contactNumber = (String) context.get("contactNumber"); if (UtilValidate.isNotEmpty(contactNumber)) { paramList = paramList + "&contactNumber=" + contactNumber; - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("contactNumber"), EntityOperator.EQUALS, EntityFunction.UPPER(contactNumber))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("contactNumber"), + EntityOperator.EQUALS, EntityFunction.UPPER(contactNumber))); } fieldsToSelect.add("contactNumber"); @@ -1455,15 +1455,15 @@ public class PartyServices { // ---- End of Dynamic View Creation // build the main condition - if (andExprs.size() > 0) { + if (!andExprs.isEmpty()) { mainCond = EntityCondition.makeCondition(andExprs, EntityOperator.AND); } } - Debug.logInfo("In findParty mainCond=" + mainCond, module); + Debug.logInfo("In findParty mainCond=" + mainCond, MODULE); String sortField = (String) context.get("sortField"); - if(UtilValidate.isNotEmpty(sortField)){ + if (UtilValidate.isNotEmpty(sortField)) { orderBy.add(sortField); } @@ -1494,8 +1494,8 @@ public class PartyServices { } catch (GenericEntityException e) { String errMsg = "Failure in party find operation, rolling back transaction: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + Debug.logError(e, errMsg, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyLookupPartyError", UtilMisc.toMap("errMessage", e.toString()), locale)); } @@ -1548,7 +1548,7 @@ public class PartyServices { List<String> orderBy = new ArrayList<>(); String sortField = (String) context.get("sortField"); - if(UtilValidate.isNotEmpty(sortField)){ + if (UtilValidate.isNotEmpty(sortField)) { orderBy.add(sortField); } List<String> fieldsToSelect = new ArrayList<>(); @@ -1572,7 +1572,8 @@ public class PartyServices { EntityCondition relationshipCond = null; if (UtilValidate.isEmpty(ownerPartyIds)) { String partyIdFrom = userLogin.getString("partyId"); - relationshipCond = EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyIdFrom"), EntityOperator.EQUALS, EntityFunction.UPPER(partyIdFrom)); + relationshipCond = EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyIdFrom"), + EntityOperator.EQUALS, EntityFunction.UPPER(partyIdFrom)); } else { relationshipCond = EntityCondition.makeCondition("partyIdFrom", EntityOperator.IN, ownerPartyIds); } @@ -1580,7 +1581,8 @@ public class PartyServices { // add the expr andExprs.add(EntityCondition.makeCondition( relationshipCond, EntityOperator.AND, - EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyRelationshipTypeId"), EntityOperator.EQUALS, EntityFunction.UPPER(partyRelationshipTypeId)))); + EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyRelationshipTypeId"), EntityOperator.EQUALS, + EntityFunction.UPPER(partyRelationshipTypeId)))); fieldsToSelect.add("partyIdTo"); } @@ -1597,7 +1599,8 @@ public class PartyServices { // check for a partyId if (UtilValidate.isNotEmpty(partyId)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyId"), EntityOperator.LIKE, EntityFunction.UPPER("%"+partyId+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyId"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + partyId + "%"))); } // now the statusId - send ANY for all statuses; leave null for just enabled; or pass a specific status @@ -1605,7 +1608,8 @@ public class PartyServices { andExprs.add(EntityCondition.makeCondition("statusId", statusId)); } else { // NOTE: _must_ explicitly allow null as it is not included in a not equal in many databases... odd but true - andExprs.add(EntityCondition.makeCondition(EntityCondition.makeCondition("statusId", GenericEntity.NULL_FIELD), EntityOperator.OR, EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PARTY_DISABLED"))); + andExprs.add(EntityCondition.makeCondition(EntityCondition.makeCondition("statusId", GenericEntity.NULL_FIELD), + EntityOperator.OR, EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PARTY_DISABLED"))); } // check for partyTypeId if (UtilValidate.isNotEmpty(partyTypeId)) { @@ -1628,7 +1632,8 @@ public class PartyServices { dynamicView.addViewLink("PT", "UL", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId")); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("userLoginId"), EntityOperator.LIKE, EntityFunction.UPPER("%"+userLoginId+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("userLoginId"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + userLoginId + "%"))); fieldsToSelect.add("userLoginId"); } @@ -1645,7 +1650,8 @@ public class PartyServices { dynamicView.addViewLink("PT", "PG", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId")); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("groupName"), EntityOperator.LIKE, EntityFunction.UPPER("%"+groupName+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("groupName"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + groupName + "%"))); fieldsToSelect.add("groupName"); } @@ -1668,12 +1674,14 @@ public class PartyServices { // filter on firstName if (UtilValidate.isNotEmpty(firstName)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("firstName"), EntityOperator.LIKE, EntityFunction.UPPER("%"+firstName+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("firstName"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + firstName + "%"))); } // filter on lastName if (UtilValidate.isNotEmpty(lastName)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("lastName"), EntityOperator.LIKE, EntityFunction.UPPER("%"+lastName+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("lastName"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + lastName + "%"))); } // ---- @@ -1715,10 +1723,7 @@ public class PartyServices { String idValue = (String) context.get("idValue"); String partyIdentificationTypeId = (String) context.get("partyIdentificationTypeId"); - if ("I".equals(extInfo) || - UtilValidate.isNotEmpty(idValue) || - UtilValidate.isNotEmpty(partyIdentificationTypeId)) { - + if ("I".equals(extInfo) || UtilValidate.isNotEmpty(idValue) || UtilValidate.isNotEmpty(partyIdentificationTypeId)) { // add role to view dynamicView.addMemberEntity("PAI", "PartyIdentification"); dynamicView.addAlias("PAI", "idValue"); @@ -1727,7 +1732,8 @@ public class PartyServices { fieldsToSelect.add("idValue"); fieldsToSelect.add("partyIdentificationTypeId"); if (UtilValidate.isNotEmpty(idValue)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("idValue"), EntityOperator.LIKE, EntityFunction.UPPER("%".concat(idValue).concat("%")))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("idValue"), EntityOperator.LIKE, + EntityFunction.UPPER("%".concat(idValue).concat("%")))); } if (UtilValidate.isNotEmpty(partyIdentificationTypeId)) { andExprs.add(EntityCondition.makeCondition("partyIdentificationTypeId", partyIdentificationTypeId)); @@ -1742,9 +1748,9 @@ public class PartyServices { String inventoryItemId = (String) context.get("inventoryItemId"); String serialNumber = (String) context.get("serialNumber"); String softIdentifier = (String) context.get("softIdentifier"); - if (UtilValidate.isNotEmpty(inventoryItemId) || - UtilValidate.isNotEmpty(serialNumber) || - UtilValidate.isNotEmpty(softIdentifier)) { + if (UtilValidate.isNotEmpty(inventoryItemId) + || UtilValidate.isNotEmpty(serialNumber) + || UtilValidate.isNotEmpty(softIdentifier)) { // add role to view dynamicView.addMemberEntity("II", "InventoryItem"); @@ -1754,19 +1760,22 @@ public class PartyServices { if (UtilValidate.isNotEmpty(inventoryItemId)) { dynamicView.addAlias("II", "inventoryItemId"); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("inventoryItemId"), EntityOperator.LIKE, EntityFunction.UPPER("%" + inventoryItemId + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("inventoryItemId"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + inventoryItemId + "%"))); fieldsToSelect.add("inventoryItemId"); } if (UtilValidate.isNotEmpty(serialNumber)) { dynamicView.addAlias("II", "serialNumber"); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("serialNumber"), EntityOperator.LIKE, EntityFunction.UPPER("%" + serialNumber + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("serialNumber"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + serialNumber + "%"))); fieldsToSelect.add("serialNumber"); } if (UtilValidate.isNotEmpty(softIdentifier)) { dynamicView.addAlias("II", "softIdentifier"); // add the expr - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("softIdentifier"), EntityOperator.LIKE, EntityFunction.UPPER("%" + softIdentifier + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("softIdentifier"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + softIdentifier + "%"))); fieldsToSelect.add("softIdentifier"); } @@ -1774,10 +1783,10 @@ public class PartyServices { // PostalAddress fields // ---- String stateProvinceGeoId = (String) context.get("stateProvinceGeoId"); - if ( "P".equals(extInfo) || - UtilValidate.isNotEmpty(context.get("address1"))|| UtilValidate.isNotEmpty(context.get("address2"))|| - UtilValidate.isNotEmpty(context.get("city"))|| UtilValidate.isNotEmpty(context.get("postalCode"))|| - UtilValidate.isNotEmpty(context.get("countryGeoId"))|| (UtilValidate.isNotEmpty(stateProvinceGeoId))) { + if ("P".equals(extInfo) + || UtilValidate.isNotEmpty(context.get("address1")) || UtilValidate.isNotEmpty(context.get("address2")) + || UtilValidate.isNotEmpty(context.get("city")) || UtilValidate.isNotEmpty(context.get("postalCode")) + || UtilValidate.isNotEmpty(context.get("countryGeoId")) || (UtilValidate.isNotEmpty(stateProvinceGeoId))) { // add address to dynamic view dynamicView.addMemberEntity("PC", "PartyContactMech"); dynamicView.addMemberEntity("PA", "PostalAddress"); @@ -1794,19 +1803,22 @@ public class PartyServices { // filter on address1 String address1 = (String) context.get("address1"); if (UtilValidate.isNotEmpty(address1)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("address1"), EntityOperator.LIKE, EntityFunction.UPPER("%" + address1 + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("address1"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + address1 + "%"))); } // filter on address2 String address2 = (String) context.get("address2"); if (UtilValidate.isNotEmpty(address2)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("address2"), EntityOperator.LIKE, EntityFunction.UPPER("%" + address2 + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("address2"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + address2 + "%"))); } // filter on city String city = (String) context.get("city"); if (UtilValidate.isNotEmpty(city)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("city"), EntityOperator.LIKE, EntityFunction.UPPER("%" + city + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("city"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + city + "%"))); } // filter on state geo @@ -1817,7 +1829,8 @@ public class PartyServices { // filter on postal code String postalCode = (String) context.get("postalCode"); if (UtilValidate.isNotEmpty(postalCode)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("postalCode"), EntityOperator.LIKE, EntityFunction.UPPER("%" + postalCode + "%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("postalCode"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + postalCode + "%"))); } fieldsToSelect.add("postalCode"); @@ -1840,7 +1853,8 @@ public class PartyServices { // filter on infoString String infoString = (String) context.get("infoString"); if (UtilValidate.isNotEmpty(infoString)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("infoString"), EntityOperator.LIKE, EntityFunction.UPPER("%"+infoString+"%"))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("infoString"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + infoString + "%"))); fieldsToSelect.add("infoString"); } } @@ -1865,19 +1879,22 @@ public class PartyServices { // filter on countryCode String countryCode = (String) context.get("countryCode"); if (UtilValidate.isNotEmpty(countryCode)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("countryCode"), EntityOperator.EQUALS, EntityFunction.UPPER(countryCode))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("countryCode"), + EntityOperator.EQUALS, EntityFunction.UPPER(countryCode))); } // filter on areaCode String areaCode = (String) context.get("areaCode"); if (UtilValidate.isNotEmpty(areaCode)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("areaCode"), EntityOperator.EQUALS, EntityFunction.UPPER(areaCode))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("areaCode"), + EntityOperator.EQUALS, EntityFunction.UPPER(areaCode))); } // filter on contact number String contactNumber = (String) context.get("contactNumber"); if (UtilValidate.isNotEmpty(contactNumber)) { - andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("contactNumber"), EntityOperator.EQUALS, EntityFunction.UPPER(contactNumber))); + andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("contactNumber"), + EntityOperator.EQUALS, EntityFunction.UPPER(contactNumber))); } fieldsToSelect.add("contactNumber"); fieldsToSelect.add("areaCode"); @@ -1892,12 +1909,12 @@ public class PartyServices { mainCond = EntityCondition.makeCondition(andExprs, EntityOperator.AND); } if (Debug.infoOn()) { - Debug.logInfo("In findParty mainCond=" + mainCond, module); + Debug.logInfo("In findParty mainCond=" + mainCond, MODULE); } // do the lookup - if (UtilValidate.isNotEmpty(noConditionFind) && - ("Y".equals(noConditionFind) || andExprs.size()>1)) { //exclude on condition the status expr + if (UtilValidate.isNotEmpty(noConditionFind) && ("Y".equals(noConditionFind) || andExprs.size() > 1)) { + //exclude on condition the status expr try { // set distinct on so we only get one row per party // using list iterator @@ -1910,8 +1927,8 @@ public class PartyServices { .queryIterator(); } catch (GenericEntityException e) { String errMsg = "Failure in party find operation, rolling back transaction: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + Debug.logError(e, errMsg, MODULE); + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyLookupPartyError", UtilMisc.toMap("errMessage", e.toString()), locale)); } @@ -1924,14 +1941,12 @@ public class PartyServices { * Changes the association of contact mechs, purposes, notes, orders and attributes from * one party to another for the purpose of merging records together. Flags the from party * as disabled so it no longer appears in a search. - * * @param dctx the dispatch context * @param context the context * @return the result of the service execution */ public static Map<String, Object> linkParty(DispatchContext dctx, Map<String, ? extends Object> context) { - Delegator _delegator = dctx.getDelegator(); - Delegator delegator = _delegator.cloneDelegator(); + Delegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); delegator.setEntityEcaHandler(null); @@ -1940,7 +1955,7 @@ public class PartyServices { Timestamp now = UtilDateTime.nowTimestamp(); if (partyIdTo.equals(partyId)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyCannotLinkPartyToItSelf", locale)); } @@ -1949,15 +1964,15 @@ public class PartyServices { try { partyTo = EntityQuery.use(delegator).from("Party").where("partyId", partyIdTo).queryOne(); } catch (GenericEntityException e) { - Debug.logInfo(e, module); + Debug.logInfo(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } if (partyTo == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyPartyToDoesNotExists", locale)); } if ("PARTY_DISABLED".equals(partyTo.get("statusId"))) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyCannotMergeDisabledParty", locale)); } @@ -1965,11 +1980,11 @@ public class PartyServices { try { party = EntityQuery.use(delegator).from("Party").where("partyId", partyId).queryOne(); } catch (GenericEntityException e) { - Debug.logInfo(e, module); + Debug.logInfo(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } if (party == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyPartyFromDoesNotExists", locale)); } @@ -1978,7 +1993,7 @@ public class PartyServices { delegator.storeByCondition("PartyContactMech", UtilMisc.<String, Object>toMap("partyId", partyIdTo, "thruDate", now), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -1987,7 +2002,7 @@ public class PartyServices { delegator.storeByCondition("PartyContactMechPurpose", UtilMisc.<String, Object>toMap("partyId", partyIdTo, "thruDate", now), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -1996,7 +2011,7 @@ public class PartyServices { delegator.storeByCondition("PartyNote", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2005,7 +2020,7 @@ public class PartyServices { delegator.storeByCondition("InventoryItem", UtilMisc.toMap("ownerPartyId", partyIdTo), EntityCondition.makeCondition("ownerPartyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2014,7 +2029,7 @@ public class PartyServices { delegator.storeByCondition("Subscription", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2023,7 +2038,7 @@ public class PartyServices { delegator.storeByCondition("UserLogin", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2032,7 +2047,7 @@ public class PartyServices { try { rolesToMove = EntityQuery.use(delegator).from("PartyRole").where("partyId", partyId).queryList(); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2043,7 +2058,7 @@ public class PartyServices { attr.create(); } } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } } @@ -2053,7 +2068,7 @@ public class PartyServices { delegator.storeByCondition("OrderRole", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2062,16 +2077,16 @@ public class PartyServices { delegator.storeByCondition("InvoiceRole", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } - // data resource role + // data RESOURCE role try { delegator.storeByCondition("DataResourceRole", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2080,7 +2095,7 @@ public class PartyServices { delegator.storeByCondition("ContentRole", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2089,7 +2104,7 @@ public class PartyServices { delegator.storeByCondition("FinAccountRole", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2098,7 +2113,7 @@ public class PartyServices { delegator.storeByCondition("ProductStoreRole", UtilMisc.<String, Object>toMap("partyId", partyIdTo, "thruDate", now), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2107,7 +2122,7 @@ public class PartyServices { delegator.storeByCondition("CommunicationEventRole", UtilMisc.toMap("partyId", partyIdTo), EntityCondition.makeCondition("partyId", EntityOperator.EQUALS, partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2115,7 +2130,7 @@ public class PartyServices { try { delegator.removeByAnd("PartyRole", UtilMisc.toMap("partyId", partyId)); } catch (GenericEntityException e) { - Debug.logWarning(e, module); + Debug.logWarning(e, MODULE); // if this fails no problem } @@ -2124,7 +2139,7 @@ public class PartyServices { try { attrsToMove = EntityQuery.use(delegator).from("PartyAttribute").where("partyId", partyId).queryList(); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2135,14 +2150,14 @@ public class PartyServices { attr.create(); } } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } } try { delegator.removeByAnd("PartyAttribute", UtilMisc.toMap("partyId", partyId)); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2154,7 +2169,7 @@ public class PartyServices { try { delegator.create(linkAttr); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2166,7 +2181,7 @@ public class PartyServices { try { party.store(); } catch (GenericEntityException e) { - Debug.logError(e, "Error setting disable mode on partyId: " + partyId, module); + Debug.logError(e, "Error setting disable mode on partyId: " + partyId, MODULE); return ServiceUtil.returnError(e.getMessage()); } } @@ -2190,7 +2205,7 @@ public class PartyServices { String str = records[i].trim(); String[] map = str.split(","); if (map.length != 2 && map.length != 3) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyImportInvalidCsvFile", locale)); } GenericValue addrMap = delegator.makeValue("AddressMatchMap"); @@ -2209,21 +2224,21 @@ public class PartyServices { try { seq = Integer.parseInt(map[2]); } catch (Throwable t) { - Debug.logWarning(t, "Unable to parse number", module); + Debug.logWarning(t, "Unable to parse number", MODULE); } } } addrMap.put("sequenceNum", (long) seq); - Debug.logInfo("Creating map entry: " + addrMap, module); + Debug.logInfo("Creating map entry: " + addrMap, MODULE); try { delegator.create(addrMap); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } } else { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "PartyImportNoRecordsFoundInFile", locale)); } } @@ -2241,8 +2256,6 @@ public class PartyServices { } return partyId; } - - /** * Finds partyId(s) corresponding to a party reference, partyId or a GoodIdentification idValue * @param ctx the dispatch context @@ -2257,14 +2270,14 @@ public class PartyServices { String searchAllIdContext = (String) context.get("searchAllId"); boolean searchPartyFirst = UtilValidate.isNotEmpty(searchPartyFirstContext) && "N".equals(searchPartyFirstContext) ? false : true; - boolean searchAllId = UtilValidate.isNotEmpty(searchAllIdContext)&& "Y".equals(searchAllIdContext) ? true : false; + boolean searchAllId = UtilValidate.isNotEmpty(searchAllIdContext) && "Y".equals(searchAllIdContext) ? true : false; GenericValue party = null; List<GenericValue> partiesFound = null; try { partiesFound = PartyWorker.findPartiesById(delegator, idToFind, partyIdentificationTypeId, searchPartyFirst, searchAllId); } catch (GenericEntityException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } @@ -2316,13 +2329,13 @@ public class PartyServices { String lastContactMechPurposeTypeId = null; String currentContactMechPurposeTypeId = null; - Boolean addParty = false; // when modify party, contact mech not added again + boolean addParty = false; // when modify party, contact mech not added again try (BufferedReader csvReader = new BufferedReader(new StringReader(csvString))) { for (final CSVRecord rec : fmt.parse(csvReader)) { if (UtilValidate.isNotEmpty(rec.get("partyId"))) { - currentPartyId = rec.get("partyId"); + currentPartyId = rec.get("partyId"); } if (lastPartyId == null || !currentPartyId.equals(lastPartyId)) { newPartyId = null; @@ -2339,38 +2352,46 @@ public class PartyServices { lastContactNumber = null; // party validation - List <GenericValue> currencyCheck = EntityQuery.use(delegator).from("Uom") + List<GenericValue> currencyCheck = EntityQuery.use(delegator).from("Uom") .where("abbreviation", rec.get("preferredCurrencyUomId"), "uomTypeId", "CURRENCY_MEASURE") .queryList(); - if (UtilValidate.isNotEmpty(rec.get("preferredCurrencyUomId")) && currencyCheck.size() == 0) { - newErrMsgs.add("Line number " + rec.getRecordNumber() + ": partyId: " + currentPartyId + "Currency code not found for: " + rec.get("preferredCurrencyUomId")); + if (UtilValidate.isNotEmpty(rec.get("preferredCurrencyUomId")) && currencyCheck.isEmpty()) { + newErrMsgs.add("Line number " + rec.getRecordNumber() + ": partyId: " + currentPartyId + "Currency code not found for: " + + rec.get("preferredCurrencyUomId")); } if (UtilValidate.isEmpty(rec.get("roleTypeId"))) { - newErrMsgs.add("Line number " + rec.getRecordNumber() + ": Mandatory roletype is missing, possible values: CUSTOMER, SUPPLIER, EMPLOYEE and more...."); + newErrMsgs.add("Line number " + rec.getRecordNumber() + + ": Mandatory roletype is missing, possible values: CUSTOMER, SUPPLIER, EMPLOYEE and more...."); } else if (EntityQuery.use(delegator).from("RoleType").where("roleTypeId", rec.get("roleTypeId")).queryOne() == null) { - newErrMsgs.add("Line number " + rec.getRecordNumber() + ": RoletypeId is not valid: " + rec.get("roleTypeId") ); + newErrMsgs.add("Line number " + rec.getRecordNumber() + ": RoletypeId is not valid: " + rec.get("roleTypeId")); } - if (UtilValidate.isNotEmpty(rec.get("contactMechTypeId")) && - EntityQuery.use(delegator).from("ContactMechType").where("contactMechTypeId", rec.get("contactMechTypeId")).cache().queryOne() == null) { - newErrMsgs.add("Line number " + rec.getRecordNumber() + ": partyId: " + currentPartyId + " contactMechTypeId code not found for: " + rec.get("contactMechTypeId")); + if (UtilValidate.isNotEmpty(rec.get("contactMechTypeId")) + && EntityQuery.use(delegator).from("ContactMechType").where("contactMechTypeId", rec.get("contactMechTypeId")) + .cache().queryOne() == null) { + newErrMsgs.add("Line number " + rec.getRecordNumber() + ": partyId: " + currentPartyId + + " contactMechTypeId code not found for: " + + rec.get("contactMechTypeId")); } - if (UtilValidate.isNotEmpty(rec.get("contactMechPurposeTypeId")) && - EntityQuery.use(delegator).from("ContactMechPurposeType").where("contactMechPurposeTypeId", rec.get("contactMechPurposeTypeId")).cache().queryOne() == null) { - newErrMsgs.add("Line number " + rec.getRecordNumber() + ": partyId: " + currentPartyId + "contactMechPurposeTypeId code not found for: " + rec.get("contactMechPurposeTypeId")); + if (UtilValidate.isNotEmpty(rec.get("contactMechPurposeTypeId")) + && EntityQuery.use(delegator).from("ContactMechPurposeType").where("contactMechPurposeTypeId", + rec.get("contactMechPurposeTypeId")).cache().queryOne() == null) { + newErrMsgs.add("Line number " + rec.getRecordNumber() + ": partyId: " + currentPartyId + + "contactMechPurposeTypeId code not found for: " + rec.get("contactMechPurposeTypeId")); } if (UtilValidate.isNotEmpty(rec.get("contactMechTypeId")) && "POSTAL_ADDRESS".equals(rec.get("contactMechTypeId"))) { if (UtilValidate.isEmpty(rec.get("countryGeoId"))) { newErrMsgs.add("Line number " + rec.getRecordNumber() + ": partyId: " + currentPartyId + "Country code missing"); } else { - List <GenericValue> countryCheck = EntityQuery.use(delegator).from("Geo") + List<GenericValue> countryCheck = EntityQuery.use(delegator).from("Geo") .where("geoTypeId", "COUNTRY", "abbreviation", rec.get("countryGeoId")) .queryList(); - if (countryCheck.size() == 0) { - newErrMsgs.add("Line number " + rec.getRecordNumber() + " partyId: " + currentPartyId + " Invalid Country code: " + rec.get("countryGeoId")); + if (countryCheck.isEmpty()) { + newErrMsgs.add("Line number " + rec.getRecordNumber() + " partyId: " + currentPartyId + " Invalid Country code: " + + rec.get("countryGeoId")); } } @@ -2379,11 +2400,12 @@ public class PartyServices { } if (UtilValidate.isNotEmpty(rec.get("stateProvinceGeoId"))) { - List <GenericValue> stateCheck = EntityQuery.use(delegator).from("Geo") + List<GenericValue> stateCheck = EntityQuery.use(delegator).from("Geo") .where("geoTypeId", "STATE", "abbreviation", rec.get("stateProvinceGeoId")) .queryList(); - if (stateCheck.size() == 0) { - newErrMsgs.add("Line number " + rec.getRecordNumber() + " partyId: " + currentPartyId + " Invalid stateProvinceGeoId code: " + rec.get("countryGeoId")); + if (stateCheck.isEmpty()) { + newErrMsgs.add("Line number " + rec.getRecordNumber() + " partyId: " + currentPartyId + + " Invalid stateProvinceGeoId code: " + rec.get("countryGeoId")); } } } @@ -2400,11 +2422,11 @@ public class PartyServices { } } - if (errMsgs.size() == 0) { - List <GenericValue> partyCheck = EntityQuery.use(delegator).from("PartyIdentification") + if (errMsgs.isEmpty()) { + List<GenericValue> partyCheck = EntityQuery.use(delegator).from("PartyIdentification") .where("partyIdentificationTypeId", "PARTY_IMPORT", "idValue", rec.get("partyId")) .queryList(); - addParty = partyCheck.size() == 0; + addParty = partyCheck.isEmpty(); if (!addParty) { // update party newPartyId = EntityUtil.getFirst(partyCheck).getString("partyId"); @@ -2413,8 +2435,7 @@ public class PartyServices { "partyId", newPartyId, "preferredCurrencyUomId", rec.get("preferredCurrencyUomId"), "groupName", rec.get("groupName"), - "userLogin", userLogin - ); + "userLogin", userLogin); result = dispatcher.runSync("updatePartyGroup", partyGroup); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); @@ -2426,8 +2447,7 @@ public class PartyServices { "middleName", rec.get("middleName"), "lastName", rec.get("lastName"), "preferredCurrencyUomId", rec.get("preferredCurrencyUomId"), - "userLogin", userLogin - ); + "userLogin", userLogin); result = dispatcher.runSync("updatePerson", person); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); @@ -2440,8 +2460,7 @@ public class PartyServices { "preferredCurrencyUomId", rec.get("preferredCurrencyUomId"), "groupName", rec.get("groupName"), "userLogin", userLogin, - "statusId", "PARTY_ENABLED" - ); + "statusId", "PARTY_ENABLED"); result = dispatcher.runSync("createPartyGroup", partyGroup); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); @@ -2453,8 +2472,7 @@ public class PartyServices { "lastName", rec.get("lastName"), "preferredCurrencyUomId", rec.get("preferredCurrencyUomId"), "statusId", "PARTY_ENABLED", - "userLogin", userLogin - ); + "userLogin", userLogin); result = dispatcher.runSync("createPerson", person); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); @@ -2462,39 +2480,29 @@ public class PartyServices { } newPartyId = (String) result.get("partyId"); - Map<String, Object> partyIdentification = UtilMisc.toMap( - "partyId", newPartyId, - "partyIdentificationTypeId", "PARTY_IMPORT", - "idValue", rec.get("partyId"), - "userLogin", userLogin - ); + Map<String, Object> partyIdentification = UtilMisc.toMap("partyId", newPartyId, + "partyIdentificationTypeId", "PARTY_IMPORT", "idValue", rec.get("partyId"), "userLogin", userLogin); result = dispatcher.runSync("createPartyIdentification", partyIdentification); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } - Map<String, Object> partyRole = UtilMisc.toMap( - "partyId", newPartyId, - "roleTypeId", rec.get("roleTypeId"), - "userLogin", userLogin - ); + Map<String, Object> partyRole = UtilMisc.toMap("partyId", newPartyId, "roleTypeId", rec.get("roleTypeId"), + "userLogin", userLogin); dispatcher.runSync("createPartyRole", partyRole); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } if (UtilValidate.isNotEmpty(rec.get("companyPartyId"))) { - List <GenericValue> companyCheck = EntityQuery.use(delegator).from("PartyIdentification") + List<GenericValue> companyCheck = EntityQuery.use(delegator).from("PartyIdentification") .where("partyIdentificationTypeId", "PARTY_IMPORT", "idValue", rec.get("partyId")) .queryList(); - if (companyCheck.size() == 0) { // update party group + if (companyCheck.isEmpty()) { // update party group // company does not exist so create Map<String, Object> companyPartyGroup = UtilMisc.toMap( - "partyId", newCompanyPartyId, - "statusId", "PARTY_ENABLED", - "userLogin", userLogin - ); + "partyId", newCompanyPartyId, "statusId", "PARTY_ENABLED", "userLogin", userLogin); result = dispatcher.runSync("createPartyGroup", companyPartyGroup); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); @@ -2505,30 +2513,22 @@ public class PartyServices { } Map<String, Object> companyRole = UtilMisc.toMap( - "partyId", newCompanyPartyId, - "roleTypeId", "ACCOUNT", - "userLogin", userLogin - ); + "partyId", newCompanyPartyId, "roleTypeId", "ACCOUNT", "userLogin", userLogin); Map<String, Object> serviceResult = dispatcher.runSync("createPartyRole", companyRole); if (ServiceUtil.isError(serviceResult)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); } // company exist, so create link - Map<String, Object> partyRelationship = UtilMisc.toMap( - "partyIdTo", newPartyId, - "partyIdFrom", newCompanyPartyId, - "roleTypeIdFrom", "ACCOUNT", - "partyRelationshipTypeId", "EMPLOYMENT", - "userLogin", userLogin - ); + Map<String, Object> partyRelationship = UtilMisc.toMap("partyIdTo", newPartyId, "partyIdFrom", newCompanyPartyId, + "roleTypeIdFrom", "ACCOUNT", "partyRelationshipTypeId", "EMPLOYMENT", "userLogin", userLogin); result = dispatcher.runSync("createPartyRelationship", partyRelationship); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } } } - Debug.logInfo(" =========================================================party created id: " + newPartyId, module); + Debug.logInfo(" New party created with id: " + newPartyId, MODULE); partiesCreated++; } else { errMsgs.addAll(newErrMsgs); @@ -2542,77 +2542,84 @@ public class PartyServices { if (newPartyId != null && addParty && UtilValidate.isNotEmpty(currentContactMechTypeId)) { // fill maps and check changes - Map<String, Object> emailAddress = UtilMisc.toMap( - "contactMechTypeId", "EMAIL_ADDRESS", - "userLogin", userLogin - ); - Boolean emailAddressChanged = false; + Map<String, Object> emailAddress = UtilMisc.toMap("contactMechTypeId", "EMAIL_ADDRESS", "userLogin", userLogin); + boolean emailAddressChanged = false; if ("EMAIL_ADDRESS".equals(currentContactMechTypeId)) { emailAddress.put("infoString", rec.get("emailAddress")); emailAddressChanged = lastEmailAddress == null || !lastEmailAddress.equals(rec.get("emailAddress")); lastEmailAddress = rec.get("emailAddress"); } - Map<String, Object> postalAddress = UtilMisc.toMap("userLogin", (Object) userLogin); // casting is here necessary for some compiler versions + Map<String, Object> postalAddress = UtilMisc.toMap("userLogin", (Object) userLogin); + // casting is here necessary for some compiler versions - Boolean postalAddressChanged = false; + boolean postalAddressChanged = false; if ("POSTAL_ADDRESS".equals(currentContactMechTypeId)) { postalAddress.put("address1", rec.get("address1")); postalAddress.put("address2", rec.get("address2")); - postalAddress.put("city", rec.get("city")); + postalAddress.put("city", rec.get("city")); postalAddress.put("stateProvinceGeoId", rec.get("stateProvinceGeoId")); postalAddress.put("countryGeoId", rec.get("countryGeoId")); postalAddress.put("postalCode", rec.get("postalCode")); postalAddressChanged = - lastAddress1 == null || !lastAddress1.equals(postalAddress.get("address1")) || - lastAddress2 == null || !lastAddress2.equals(postalAddress.get("address2")) || - lastCity == null || !lastCity.equals(postalAddress.get("city")) || - lastCountryGeoId == null || !lastCountryGeoId.equals(postalAddress.get("countryGeoId")); + lastAddress1 == null || !lastAddress1.equals(postalAddress.get("address1")) + || lastAddress2 == null || !lastAddress2.equals(postalAddress.get("address2")) + || lastCity == null || !lastCity.equals(postalAddress.get("city")) + || lastCountryGeoId == null || !lastCountryGeoId.equals(postalAddress.get("countryGeoId")); lastAddress1 = (String) postalAddress.get("address1"); lastAddress2 = (String) postalAddress.get("address2"); lastCity = (String) postalAddress.get("city"); lastCountryGeoId = (String) postalAddress.get("countryGeoId"); } - Map<String, Object> telecomNumber = UtilMisc.toMap("userLogin", (Object) userLogin); // casting is here necessary for some compiler versions + Map<String, Object> telecomNumber = UtilMisc.toMap("userLogin", (Object) userLogin); + // casting is here necessary for some compiler versions - Boolean telecomNumberChanged = false; + boolean telecomNumberChanged = false; if ("TELECOM_NUMBER".equals(currentContactMechTypeId)) { telecomNumber.put("countryCode", rec.get("telCountryCode")); telecomNumber.put("areaCode", rec.get("telAreaCode")); telecomNumber.put("contactNumber", rec.get("telContactNumber")); telecomNumberChanged = - lastCountryCode == null || !lastCountryCode.equals(telecomNumber.get("countryCode")) || - lastAreaCode == null || !lastAreaCode.equals(telecomNumber.get("areaCode")) || - lastContactNumber == null || !lastContactNumber.equals(telecomNumber.get("contactNumber")); + lastCountryCode == null || !lastCountryCode.equals(telecomNumber.get("countryCode")) + || lastAreaCode == null || !lastAreaCode.equals(telecomNumber.get("areaCode")) + || lastContactNumber == null || !lastContactNumber.equals(telecomNumber.get("contactNumber")); lastCountryCode = (String) telecomNumber.get("countryCode"); lastAreaCode = (String) telecomNumber.get("areaCode"); lastContactNumber = (String) telecomNumber.get("contactNumber"); } Map<String, Object> partyContactMechPurpose = UtilMisc.toMap("partyId", newPartyId, "userLogin", userLogin); - Boolean partyContactMechPurposeChanged = false; + boolean partyContactMechPurposeChanged = false; currentContactMechPurposeTypeId = rec.get("contactMechPurposeTypeId"); - if (currentContactMechPurposeTypeId != null && ("TELECOM_NUMBER".equals(currentContactMechTypeId) || "POSTAL_ADDRESS".equals(currentContactMechTypeId) ||"EMAIL_ADDRESS".equals(currentContactMechTypeId))) { + if (currentContactMechPurposeTypeId != null && ("TELECOM_NUMBER".equals(currentContactMechTypeId) + || "POSTAL_ADDRESS".equals(currentContactMechTypeId) || "EMAIL_ADDRESS".equals(currentContactMechTypeId))) { partyContactMechPurpose.put("contactMechPurposeTypeId", currentContactMechPurposeTypeId); - partyContactMechPurposeChanged = (lastContactMechPurposeTypeId == null || !lastContactMechPurposeTypeId.equals(currentContactMechPurposeTypeId)) && !telecomNumberChanged && !postalAddressChanged && !emailAddressChanged; - Debug.logInfo("===================================last:" + lastContactMechPurposeTypeId + " current: " + currentContactMechPurposeTypeId + " t :" + telecomNumberChanged + " p: " + postalAddressChanged + " e: " + emailAddressChanged + " result: " + partyContactMechPurposeChanged, module); + partyContactMechPurpose.put("contactMechTypeId", currentContactMechTypeId); + partyContactMechPurposeChanged = (lastContactMechPurposeTypeId == null + || !lastContactMechPurposeTypeId.equals(currentContactMechPurposeTypeId)) && !telecomNumberChanged + && !postalAddressChanged && !emailAddressChanged; + Debug.logInfo("Last:" + lastContactMechPurposeTypeId + " current: " + currentContactMechPurposeTypeId + " t :" + + telecomNumberChanged + " p: " + postalAddressChanged + " e: " + emailAddressChanged + " result: " + + partyContactMechPurposeChanged, MODULE); } lastContactMechPurposeTypeId = currentContactMechPurposeTypeId; // update - if (errMsgs.size() == 0) { + if (errMsgs.isEmpty()) { if (postalAddressChanged) { result = dispatcher.runSync("createPostalAddress", postalAddress); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } - newContactMechId = (String) result.get("contactMechId"); + newContactMechId = (String) result.get("contactMechId"); if (currentContactMechPurposeTypeId == null) { currentContactMechPurposeTypeId = "GENERAL_LOCATION"; } - Map<String, Object> serviceResult = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", newPartyId, "contactMechId", newContactMechId, "contactMechPurposeTypeId", currentContactMechPurposeTypeId, "userLogin", userLogin)); + Map<String, Object> serviceResult = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", newPartyId, + "contactMechId", newContactMechId, "contactMechTypeId", currentContactMechTypeId, "contactMechPurposeTypeId", currentContactMechPurposeTypeId, + "userLogin", userLogin)); if (ServiceUtil.isError(serviceResult)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); } @@ -2623,11 +2630,13 @@ public class PartyServices { if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } - newContactMechId = (String) result.get("contactMechId"); + newContactMechId = (String) result.get("contactMechId"); if (currentContactMechPurposeTypeId == null) { - currentContactMechPurposeTypeId= "PHONE_WORK"; + currentContactMechPurposeTypeId = "PHONE_WORK"; } - Map<String, Object> resultMap = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", newPartyId, "contactMechId", newContactMechId, "contactMechPurposeTypeId", currentContactMechPurposeTypeId, "userLogin", userLogin)); + Map<String, Object> resultMap = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", newPartyId, + "contactMechId", newContactMechId, "contactMechTypeId", currentContactMechTypeId, "contactMechPurposeTypeId", currentContactMechPurposeTypeId, + "userLogin", userLogin)); if (ServiceUtil.isError(resultMap)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } @@ -2638,11 +2647,13 @@ public class PartyServices { if (ServiceUtil.isError(result)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } - newContactMechId = (String) result.get("contactMechId"); + newContactMechId = (String) result.get("contactMechId"); if (currentContactMechPurposeTypeId == null) { currentContactMechPurposeTypeId = "PRIMARY_EMAIL"; } - Map<String, Object> resultMap = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", newPartyId, "contactMechId", newContactMechId, "contactMechPurposeTypeId", currentContactMechPurposeTypeId, "userLogin", userLogin)); + Map<String, Object> resultMap = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", newPartyId, + "contactMechId", newContactMechId, "contactMechTypeId", currentContactMechTypeId, "contactMechPurposeTypeId", currentContactMechPurposeTypeId, "userLogin", + userLogin)); if (ServiceUtil.isError(resultMap)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } @@ -2662,15 +2673,16 @@ public class PartyServices { } } } catch (GenericServiceException | GenericEntityException | IOException e) { - Debug.logError(e, module); + Debug.logError(e, MODULE); return ServiceUtil.returnError(e.getMessage()); } - if (errMsgs.size() > 0) { + if (!errMsgs.isEmpty()) { return ServiceUtil.returnError(errMsgs); } - result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "PartyNewPartiesCreated", UtilMisc.toMap("partiesCreated", partiesCreated), locale)); + result = ServiceUtil.returnSuccess(UtilProperties.getMessage(RESOURCE, "PartyNewPartiesCreated", + UtilMisc.toMap("partiesCreated", partiesCreated), locale)); return result; } }