if ("Y".equals(lookupFlag)) {
String showAll = (context.get("showAll") != null ? (String) context.get("showAll") : "N");
paramList = paramList + "&lookupFlag=" + lookupFlag + "&showAll=" + showAll + "&extInfo=" + extInfo;
// create the dynamic view entity
DynamicViewEntity dynamicView = new DynamicViewEntity();
// default view settings
dynamicView.addMemberEntity("PT", "Party");
dynamicView.addAlias("PT", "partyId");
dynamicView.addAlias("PT", "statusId");
dynamicView.addAlias("PT", "partyTypeId");
dynamicView.addRelation("one-nofk", "", "PartyType", ModelKeyMap.makeKeyMapList("partyTypeId"));
dynamicView.addRelation("many", "", "UserLogin", ModelKeyMap.makeKeyMapList("partyId"));
// define the main condition & expression list
List<EntityCondition> andExprs = FastList.newInstance();
EntityCondition mainCond = null;
List<String> orderBy = FastList.newInstance();
List<String> fieldsToSelect = FastList.newInstance();
// fields we need to select; will be used to set distinct
fieldsToSelect.add("partyId");
fieldsToSelect.add("statusId");
fieldsToSelect.add("partyTypeId");
// filter on parties that have relationship with logged in user
String partyRelationshipTypeId = (String) context.get("partyRelationshipTypeId");
if (UtilValidate.isNotEmpty(partyRelationshipTypeId)) {
// add relation to view
dynamicView.addMemberEntity("PRSHP", "PartyRelationship");
dynamicView.addAlias("PRSHP", "partyIdTo");
dynamicView.addAlias("PRSHP", "partyRelationshipTypeId");
dynamicView.addViewLink("PT", "PRSHP", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId", "partyIdTo"));
List<String> ownerPartyIds = UtilGenerics.cast(context.get("ownerPartyIds"));
EntityCondition relationshipCond = null;
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));
} else {
relationshipCond = EntityCondition.makeCondition("partyIdFrom", EntityOperator.IN, ownerPartyIds);
}
dynamicView.addAlias("PRSHP", "partyIdFrom");
// add the expr
andExprs.add(EntityCondition.makeCondition(
relationshipCond, EntityOperator.AND,
EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("partyRelationshipTypeId"), EntityOperator.EQUALS, EntityFunction.UPPER(partyRelationshipTypeId))));
fieldsToSelect.add("partyIdTo");
}
// get the params
String partyId = (String) context.get("partyId");
String statusId = (String) context.get("statusId");
String userLoginId = (String) context.get("userLoginId");
String firstName = (String) context.get("firstName");
String lastName = (String) context.get("lastName");
String groupName = (String) context.get("groupName");
if (!"Y".equals(showAll)) {
// 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+"%")));
}
// now the statusId - send ANY for all statuses; leave null for just enabled; or pass a specific status
if (statusId != null) {
paramList = paramList + "&statusId=" + statusId;
if (!"ANY".equalsIgnoreCase(statusId)) {
andExprs.add(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, 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", 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+"%")));
}
// ----
// UserLogin Fields
// ----
// filter on user login
if (UtilValidate.isNotEmpty(userLoginId)) {
paramList = paramList + "&userLoginId=" + userLoginId;
// modify the dynamic view
dynamicView.addMemberEntity("UL", "UserLogin");
dynamicView.addAlias("UL", "userLoginId");
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+"%")));
fieldsToSelect.add("userLoginId");
}
// ----
// PartyGroup Fields
// ----
// filter on groupName
if (UtilValidate.isNotEmpty(groupName)) {
paramList = paramList + "&groupName=" + groupName;
// modify the dynamic view
dynamicView.addMemberEntity("PG", "PartyGroup");
dynamicView.addAlias("PG", "groupName");
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+"%")));
fieldsToSelect.add("groupName");
}
// ----
// Person Fields
// ----
// modify the dynamic view
if (UtilValidate.isNotEmpty(firstName) || UtilValidate.isNotEmpty(lastName)) {
dynamicView.addMemberEntity("PE", "Person");
dynamicView.addAlias("PE", "firstName");
dynamicView.addAlias("PE", "lastName");
dynamicView.addViewLink("PT", "PE", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));
fieldsToSelect.add("firstName");
fieldsToSelect.add("lastName");
orderBy.add("lastName");
orderBy.add("firstName");
}
// filter on firstName
if (UtilValidate.isNotEmpty(firstName)) {
paramList = paramList + "&firstName=" + 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+"%")));
}
// ----
// RoleType Fields
// ----
// filter on role member
if (roleTypeId != null && !"ANY".equals(roleTypeId)) {
paramList = paramList + "&roleTypeId=" + roleTypeId;
// add role to view
dynamicView.addMemberEntity("PR", "PartyRole");
dynamicView.addAlias("PR", "roleTypeId");
dynamicView.addViewLink("PT", "PR", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));
// add the expr
andExprs.add(EntityCondition.makeCondition("roleTypeId", EntityOperator.EQUALS, roleTypeId));
fieldsToSelect.add("roleTypeId");
}
// ----
// InventoryItem Fields
// ----
// filter on inventory item's fields
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)) {
// add role to view
dynamicView.addMemberEntity("II", "InventoryItem");
dynamicView.addAlias("II", "ownerPartyId");
dynamicView.addViewLink("PT", "II", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId", "ownerPartyId"));
}
if (UtilValidate.isNotEmpty(inventoryItemId)) {
paramList = paramList + "&inventoryItemId=" + inventoryItemId;
dynamicView.addAlias("II", "inventoryItemId");
// add the expr
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 + "%")));
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 + "%")));
fieldsToSelect.add("softIdentifier");
}
// ----
// PostalAddress fields
// ----
if ("P".equals(extInfo)) {
// add address to dynamic view
dynamicView.addMemberEntity("PC", "PartyContactMech");
dynamicView.addMemberEntity("PA", "PostalAddress");
dynamicView.addAlias("PC", "contactMechId");
dynamicView.addAlias("PA", "address1");
dynamicView.addAlias("PA", "address2");
dynamicView.addAlias("PA", "city");
dynamicView.addAlias("PA", "stateProvinceGeoId");
dynamicView.addAlias("PA", "countryGeoId");
dynamicView.addAlias("PA", "postalCode");
dynamicView.addViewLink("PT", "PC", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));
dynamicView.addViewLink("PC", "PA", Boolean.FALSE, ModelKeyMap.makeKeyMapList("contactMechId"));
// filter on address1
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 + "%")));
}
// 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 + "%")));
}
// 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 + "%")));
}
// filter on state geo
if (stateProvinceGeoId != null && !"ANY".equals(stateProvinceGeoId)) {
paramList = paramList + "&stateProvinceGeoId=" + stateProvinceGeoId;
andExprs.add(EntityCondition.makeCondition("stateProvinceGeoId", EntityOperator.EQUALS, stateProvinceGeoId));
}
// filter on postal code
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 + "%")));
}
fieldsToSelect.add("postalCode");
fieldsToSelect.add("city");
fieldsToSelect.add("stateProvinceGeoId");
}
// ----
// Generic CM Fields
// ----
if ("O".equals(extInfo)) {
// add info to dynamic view
dynamicView.addMemberEntity("PC", "PartyContactMech");
dynamicView.addMemberEntity("CM", "ContactMech");
dynamicView.addAlias("PC", "contactMechId");
dynamicView.addAlias("CM", "infoString");
dynamicView.addViewLink("PT", "PC", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));
dynamicView.addViewLink("PC", "CM", Boolean.FALSE, ModelKeyMap.makeKeyMapList("contactMechId"));
// filter on infoString
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+"%")));
fieldsToSelect.add("infoString");
}
}
// ----
// TelecomNumber Fields
// ----
if ("T".equals(extInfo)) {
// add telecom to dynamic view
dynamicView.addMemberEntity("PC", "PartyContactMech");
dynamicView.addMemberEntity("TM", "TelecomNumber");
dynamicView.addAlias("PC", "contactMechId");
dynamicView.addAlias("TM", "countryCode");
dynamicView.addAlias("TM", "areaCode");
dynamicView.addAlias("TM", "contactNumber");
dynamicView.addViewLink("PT", "PC", Boolean.FALSE, ModelKeyMap.makeKeyMapList("partyId"));
dynamicView.addViewLink("PC", "TM", Boolean.FALSE, ModelKeyMap.makeKeyMapList("contactMechId"));
// filter on countryCode
String countryCode = (String) context.get("countryCode");
if (UtilValidate.isNotEmpty(countryCode)) {
paramList = paramList + "&countryCode=" + countryCode;