diff --git a/applications/party/minilang/party/PartyServices.xml b/applications/party/minilang/party/PartyServices.xml index 57b2621701..fcdebf7783 100644 --- a/applications/party/minilang/party/PartyServices.xml +++ b/applications/party/minilang/party/PartyServices.xml @@ -375,6 +375,27 @@ under the License. + + + + + + + + + + + + + + + + + + + + diff --git a/applications/party/servicedef/services_view.xml b/applications/party/servicedef/services_view.xml index e36dbf1aad..d0d2793519 100644 --- a/applications/party/servicedef/services_view.xml +++ b/applications/party/servicedef/services_view.xml @@ -126,6 +126,76 @@ under the License. + + Gets a collection of parties from an exact email address, uses SQL EQUALS + + + + + + Gets a collection of parties from a part of an email address, uses SQL LIKE + + + + + + Gets a collection of parties from a part of an UserloginId, uses SQL LIKE + + + + + + Gets a collection of parties from a first/last name, uses SQL LIKE + + + + + + + Gets a collection of parties from a group name, uses SQL LIKE + + + + + + Gets a list of parties from a party externalId + + + + + + Gets all parties related to partyIdFrom through the PartyRelationship entity + + + + + + + Get Parties Related to a Party + - The relatedPartyIdList coming out will include the original partyIdFrom + - The includeFromToSwitched and recurse attributes should by "Y" or "N" and default to N. + - The useCache attribute should be "true" or "false", defaults to "false" + + + + + + + + + + + + + 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 e2d171fd28..ea574ca9f2 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 @@ -26,6 +26,7 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -45,6 +46,8 @@ import org.apache.ofbiz.entity.GenericEntity; import org.apache.ofbiz.entity.GenericEntityException; import org.apache.ofbiz.entity.GenericValue; import org.apache.ofbiz.entity.condition.EntityCondition; +import org.apache.ofbiz.entity.condition.EntityConditionList; +import org.apache.ofbiz.entity.condition.EntityExpr; import org.apache.ofbiz.entity.condition.EntityFunction; import org.apache.ofbiz.entity.condition.EntityOperator; import org.apache.ofbiz.entity.model.DynamicViewEntity; @@ -702,6 +705,273 @@ public class PartyServices { return result; } + /** + * Get the party object(s) from an e-mail address + * @param dctx The DispatchContext that this service is operating in. + * @param context Map containing the input parameters. + * @return Map with the result of the service, the output parameters. + */ + public static Map getPartiesFromExactEmail(DispatchContext dctx, Map context) { + Map result = new HashMap<>(); + Delegator delegator = dctx.getDelegator(); + Collection> parties = new LinkedList<>(); + String email = (String) context.get("email"); + Locale locale = (Locale) context.get("locale"); + + if (email.length() == 0) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "partyservices.required_parameter_email_cannot_be_empty", locale)); + } + + try { + List 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(); + + if (Debug.verboseOn()) { + Debug.logVerbose("List: " + c, module); + } + if (Debug.infoOn()) { + 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"))); + + parties.add(UtilMisc.toMap("party", party)); + } + } + } catch (GenericEntityException e) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "partyservices.cannot_get_party_entities_read", + UtilMisc.toMap("errMessage", e.getMessage()), locale)); + } + if (parties.size() > 0) { + result.put("parties", parties); + } + return result; + } + + public static Map getPartiesFromPartOfEmail(DispatchContext dctx, Map context) { + Map result = new HashMap<>(); + Delegator delegator = dctx.getDelegator(); + Collection> parties = new LinkedList<>(); + String email = (String) context.get("email"); + Locale locale = (Locale) context.get("locale"); + + if (email.length() == 0) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "partyservices.required_parameter_email_cannot_be_empty", locale)); + } + + try { + List 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(); + + if (Debug.verboseOn()) { + Debug.logVerbose("List: " + c, module); + } + if (Debug.infoOn()) { + 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"))); + + parties.add(UtilMisc.toMap("party", party)); + } + } + } catch (GenericEntityException e) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "partyservices.cannot_get_party_entities_read", + UtilMisc.toMap("errMessage", e.getMessage()), locale)); + } + if (parties.size() > 0) { + result.put("parties", parties); + } + return result; + } + + /** + * Get the party object(s) from a user login ID + * @param dctx The DispatchContext that this service is operating in. + * @param context Map containing the input parameters. + * @return Map with the result of the service, the output parameters. + */ + public static Map getPartiesFromPartOfUserloginId(DispatchContext dctx, Map context) { + Debug.logWarning("Running the getPartiesFromPartOfUserloginId Service...", module); + Map result = new HashMap<>(); + Delegator delegator = dctx.getDelegator(); + Collection> 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, + "PartyCannotGetUserLoginFromParty", locale)); + } + + try { + Collection ulc = EntityQuery.use(delegator).from("PartyAndUserLogin") + .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); + } + if (Debug.infoOn()) { + 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"))); + + parties.add(UtilMisc.toMap("party", party)); + } + } + } catch (GenericEntityException e) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "partyservices.cannot_get_party_entities_read", + UtilMisc.toMap("errMessage", e.getMessage()), locale)); + } + if (UtilValidate.isNotEmpty(parties)) { + result.put("parties", parties); + } + return result; + } + + /** + * Get the party object(s) from person information + * @param dctx The DispatchContext that this service is operating in. + * @param context Map containing the input parameters. + * @return Map with the result of the service, the output parameters. + */ + public static Map getPartiesFromPerson(DispatchContext dctx, Map context) { + Map result = new HashMap<>(); + Delegator delegator = dctx.getDelegator(); + Collection> parties = new LinkedList<>(); + String firstName = (String) context.get("firstName"); + String lastName = (String) context.get("lastName"); + Locale locale = (Locale) context.get("locale"); + + if (firstName == null) { + firstName = ""; + } + if (lastName == null) { + lastName = ""; + } + if (firstName.length() == 0 && lastName.length() == 0) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "partyservices.both_names_cannot_be_empty", locale)); + } + + try { + EntityConditionList ecl = EntityCondition.makeCondition(EntityOperator.AND, + EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("firstName"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + firstName.toUpperCase(Locale.getDefault()) + "%")), + EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("lastName"), EntityOperator.LIKE, + EntityFunction.UPPER("%" + lastName.toUpperCase(Locale.getDefault()) + "%"))); + Collection pc = EntityQuery.use(delegator).from("Person").where(ecl).orderBy("lastName", "firstName", "partyId").queryList(); + + if (Debug.infoOn()) { + 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")); + + parties.add(UtilMisc.toMap("person", person, "party", party)); + } + } + } catch (GenericEntityException e) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "partyservices.cannot_get_party_entities_read", + UtilMisc.toMap("errMessage", e.getMessage()), locale)); + } + if (parties.size() > 0) { + result.put("parties", parties); + } + return result; + } + + /** + * Get the party object(s) from party group name. + * @param dctx The DispatchContext that this service is operating in. + * @param context Map containing the input parameters. + * @return Map with the result of the service, the output parameters. + */ + public static Map getPartiesFromPartyGroup(DispatchContext dctx, Map context) { + Map result = new HashMap<>(); + Delegator delegator = dctx.getDelegator(); + Collection> parties = new LinkedList<>(); + String groupName = (String) context.get("groupName"); + Locale locale = (Locale) context.get("locale"); + + if (groupName.length() == 0) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "PartyCannotgetPartiesFromPartyGroup", locale)); + } + + try { + Collection pc = EntityQuery.use(delegator).from("PartyGroup") + .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); + } + if (pc != null) { + for (GenericValue group: pc) { + GenericValue party = delegator.makeValue("Party", UtilMisc.toMap("partyId", group.get("partyId"), "partyTypeId", "PARTY_GROUP")); + + parties.add(UtilMisc.toMap("partyGroup", group, "party", party)); + } + } + } catch (GenericEntityException e) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "partyservices.cannot_get_party_entities_read", + UtilMisc.toMap("errMessage", e.getMessage()), locale)); + } + if (parties.size() > 0) { + result.put("parties", parties); + } + return result; + } + + /** + * Get the party object(s) from party externalId. + * @param dctx The DispatchContext that this service is operating in. + * @param context Map containing the input parameters. + * @return Map with the result of the service, the output parameters. + */ + public static Map getPartiesFromExternalId(DispatchContext dctx, Map context) { + Map result = ServiceUtil.returnSuccess(); + Delegator delegator = dctx.getDelegator(); + List parties; + String externalId = (String) context.get("externalId"); + Locale locale = (Locale) context.get("locale"); + + try { + parties = EntityQuery.use(delegator).from("Party") + .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, + "partyservices.cannot_get_party_entities_read", + UtilMisc.toMap("errMessage", e.getMessage()), locale)); + } + result.put("parties", parties); + return result; + } + public static Map getPerson(DispatchContext dctx, Map context) { Map result = new HashMap<>(); Delegator delegator = dctx.getDelegator();