in applications/party/src/main/java/org/apache/ofbiz/party/contact/ContactMechWorker.java [281:495]
public static void getContactMechAndRelated(ServletRequest request, String partyId, Map<String, Object> target) {
Delegator delegator = (Delegator) request.getAttribute("delegator");
boolean tryEntity = true;
if (request.getAttribute("_ERROR_MESSAGE_") != null) {
tryEntity = false;
}
if ("true".equals(request.getParameter("tryEntity"))) {
tryEntity = true;
}
String donePage = request.getParameter("DONE_PAGE");
if (donePage == null) {
donePage = (String) request.getAttribute("DONE_PAGE");
}
if (UtilValidate.isEmpty(donePage)) {
donePage = "viewprofile";
}
target.put("donePage", donePage);
String contactMechTypeId = request.getParameter("preContactMechTypeId");
if (contactMechTypeId == null) {
contactMechTypeId = (String) request.getAttribute("preContactMechTypeId");
}
if (contactMechTypeId != null) {
tryEntity = false;
}
String contactMechId = request.getParameter("contactMechId");
if (request.getAttribute("contactMechId") != null) {
contactMechId = (String) request.getAttribute("contactMechId");
}
GenericValue contactMech = null;
if (contactMechId != null) {
target.put("contactMechId", contactMechId);
// try to find a PartyContactMech with a valid date range
List<GenericValue> partyContactMechs = null;
try {
partyContactMechs = EntityQuery.use(delegator).from("PartyContactMech")
.where("partyId", partyId, "contactMechId", contactMechId)
.filterByDate()
.queryList();
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
GenericValue partyContactMech = EntityUtil.getFirst(partyContactMechs);
if (partyContactMech != null) {
target.put("partyContactMech", partyContactMech);
Collection<GenericValue> partyContactMechPurposes = null;
try {
partyContactMechPurposes = EntityUtil.filterByDate(partyContactMech.getRelated("PartyContactMechPurpose", null,
null, false), true);
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
if (UtilValidate.isNotEmpty(partyContactMechPurposes)) {
target.put("partyContactMechPurposes", partyContactMechPurposes);
}
}
try {
contactMech = EntityQuery.use(delegator).from("ContactMech").where("contactMechId", contactMechId).queryOne();
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
if (contactMech != null) {
target.put("contactMech", contactMech);
contactMechTypeId = contactMech.getString("contactMechTypeId");
}
}
if (contactMechTypeId != null) {
target.put("contactMechTypeId", contactMechTypeId);
try {
GenericValue contactMechType = EntityQuery.use(delegator).from("ContactMechType").where("contactMechTypeId",
contactMechTypeId).queryOne();
if (contactMechType != null) {
target.put("contactMechType", contactMechType);
}
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
Collection<GenericValue> purposeTypes = new LinkedList<>();
Iterator<GenericValue> typePurposes = null;
try {
typePurposes = UtilMisc.toIterator(EntityQuery.use(delegator).from("ContactMechTypePurpose")
.where("contactMechTypeId", contactMechTypeId)
.queryList());
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
while (typePurposes != null && typePurposes.hasNext()) {
GenericValue contactMechTypePurpose = typePurposes.next();
GenericValue contactMechPurposeType = null;
try {
contactMechPurposeType = contactMechTypePurpose.getRelatedOne("ContactMechPurposeType", false);
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
if (contactMechPurposeType != null) {
purposeTypes.add(contactMechPurposeType);
}
}
if (!purposeTypes.isEmpty()) {
target.put("purposeTypes", purposeTypes);
}
}
String requestName;
if (contactMech == null) {
// create
if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
if (request.getParameter("contactMechPurposeTypeId") != null || request.getAttribute("contactMechPurposeTypeId") != null) {
requestName = "createPostalAddressAndPurpose";
} else {
requestName = "createPostalAddress";
}
} else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
requestName = "createTelecomNumber";
} else if ("EMAIL_ADDRESS".equals(contactMechTypeId)) {
requestName = "createEmailAddress";
} else if ("FTP_ADDRESS".equals(contactMechTypeId)) {
requestName = "createFtpAddress";
} else {
requestName = "createContactMech";
}
} else {
// update
if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
requestName = "updatePostalAddress";
} else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
requestName = "updateTelecomNumber";
} else if ("EMAIL_ADDRESS".equals(contactMechTypeId)) {
requestName = "updateEmailAddress";
} else if ("FTP_ADDRESS".equals(contactMechTypeId)) {
requestName = "updateFtpAddress";
} else {
requestName = "updateContactMech";
}
}
target.put("requestName", requestName);
if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
GenericValue postalAddress = null;
try {
if (contactMech != null) {
postalAddress = contactMech.getRelatedOne("PostalAddress", false);
}
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
if (postalAddress != null) {
target.put("postalAddress", postalAddress);
}
} else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
GenericValue telecomNumber = null;
try {
if (contactMech != null) {
telecomNumber = contactMech.getRelatedOne("TelecomNumber", false);
}
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
if (telecomNumber != null) {
target.put("telecomNumber", telecomNumber);
}
} else if ("FTP_ADDRESS".equals(contactMechTypeId)) {
GenericValue ftpAddress = null;
try {
if (contactMech != null) {
ftpAddress = contactMech.getRelatedOne("FtpAddress", false);
}
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
if (ftpAddress != null) {
target.put("ftpAddress", ftpAddress);
}
}
if ("true".equals(request.getParameter("useValues"))) {
tryEntity = true;
}
target.put("tryEntity", tryEntity);
try {
Collection<GenericValue> contactMechTypes = EntityQuery.use(delegator).from("ContactMechType").cache(true).queryList();
if (contactMechTypes != null) {
target.put("contactMechTypes", contactMechTypes);
}
} catch (GenericEntityException e) {
Debug.logWarning(e, MODULE);
}
}