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 andExprs = FastList.newInstance();
EntityCondition mainCond = null;
List orderBy = FastList.newInstance();
List fieldsToSelect = FastList.newInstance();
// fields we need to select; will be used to set distinct
fieldsToSelect.add("partyId");
fieldsToSelect.add("statusId");
fieldsToSelect.add("partyTypeId");
// 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 (partyId != null && partyId.length() > 0) {
paramList = paramList + "&partyId=" + partyId;
andExprs.add(new EntityExpr("partyId", true, EntityOperator.LIKE, "%"+partyId+"%", true));
}
// 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(new EntityExpr("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(new EntityExpr(new EntityExpr("statusId", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "PARTY_DISABLED")));
}
// ----
// UserLogin Fields
// ----
// filter on user login
if (userLoginId != null && userLoginId.length() > 0) {
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(new EntityExpr("userLoginId", true, EntityOperator.LIKE, "%"+userLoginId+"%", true));
fieldsToSelect.add("userLoginId");
}
// ----
// PartyGroup Fields
// ----
// filter on groupName
if (groupName != null && groupName.length() > 0) {
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(new EntityExpr("groupName", true, EntityOperator.LIKE, "%"+groupName+"%", true));
fieldsToSelect.add("groupName");
}
// ----
// Person Fields
// ----
// modify the dynamic view
if ((firstName != null && firstName.length() > 0) || (lastName != null && lastName.length() > 0)) {
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 (firstName != null && firstName.length() > 0) {
paramList = paramList + "&firstName=" + firstName;
andExprs.add(new EntityExpr("firstName", true, EntityOperator.LIKE, "%"+firstName+"%", true));
}
// filter on lastName
if (lastName != null && lastName.length() > 0) {
paramList = paramList + "&lastName=" + lastName;
andExprs.add(new EntityExpr("lastName", true, EntityOperator.LIKE, "%"+lastName+"%", true));
}
// ----
// 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(new EntityExpr("roleTypeId", EntityOperator.EQUALS, roleTypeId));
fieldsToSelect.add("roleTypeId");
}
// ----
// 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 (address1 != null && address1.length() > 0) {
paramList = paramList + "&address1=" + address1;
andExprs.add(new EntityExpr("address1", true, EntityOperator.LIKE, "%" + address1 + "%", true));
}
// filter on address2
String address2 = (String) context.get("address2");
if (address2 != null && address2.length() > 0) {
paramList = paramList + "&address2=" + address2;
andExprs.add(new EntityExpr("address2", true, EntityOperator.LIKE, "%" + address2 + "%", true));
}
// filter on city
String city = (String) context.get("city");
if (city != null && city.length() > 0) {
paramList = paramList + "&city=" + city;
andExprs.add(new EntityExpr("city", true, EntityOperator.EQUALS, city, true));
}
// filter on state geo
if (stateProvinceGeoId != null && !"ANY".equals(stateProvinceGeoId)) {
paramList = paramList + "&stateProvinceGeoId=" + stateProvinceGeoId;
andExprs.add(new EntityExpr("stateProvinceGeoId", EntityOperator.EQUALS, stateProvinceGeoId));
}
// filter on postal code
String postalCode = (String) context.get("postalCode");
if (postalCode != null && postalCode.length() > 0) {
paramList = paramList + "&postalCode=" + postalCode;
andExprs.add(new EntityExpr("postalCode", true, EntityOperator.LIKE, "%" + postalCode + "%", true));
}
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 (infoString != null && infoString.length() > 0) {
paramList = paramList + "&infoString=" + infoString;
andExprs.add(new EntityExpr("infoString", true, EntityOperator.LIKE, "%"+infoString+"%", true));
}
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 (countryCode != null && countryCode.length() > 0) {
paramList = paramList + "&countryCode=" + countryCode;