// determine department number from responsible name
String depNoToLinkOrNull = getResponsibleNameDepartmentNumber();
// convert responsible id and type
String respIdTmpltElemName = getParameter("respIdTmpltElemName");
StandardFieldTextElement respIdElem = getStandardFieldTextElement(respIdTmpltElemName);
if (!respIdElem.isEmpty()) {
String newRespId = respIdElem.getText();
// 1. remove invalid parts (like @hlag.com)
String[] invalidSuffixes = StringHelper.split(getParameter("responsibleIdSuffixes2delete"), ",");
newRespId = StringHelper.removeSuffixes(newRespId, invalidSuffixes, true); // ignore case
// 2. replace group mailboxes with group mailbox ID (case insensitive)
newRespId = convertResponsibleId(newRespId);
// 3. update value
if (!respIdElem.getText().equals(newRespId)) {
addSetStandardFieldTextValue(respIdTmpltElemName, newRespId);
}
// set responsible type to nonPersonal for known group mailboxes
java.util.List<String> knownGroupMailboxIds = getKnownGroupMailboxIds();
if (knownGroupMailboxIds.contains(newRespId.toLowerCase())) {
// change type to nonPersonal
addSetOptionListValue(getParameter("responsibleIdTypeTmpltElemName"),
getParameter("responsibleIdTypeGroupMailboxValue"));
}
// determine department number for group mailboxes
Map<String, String> responsibleId2DepartmentNumberMap = getResponsibleId2DepartmentNumberMap();
String mapDepNo = responsibleId2DepartmentNumberMap.get(newRespId.toLowerCase());
if (mapDepNo != null) {
depNoToLinkOrNull = mapDepNo;
}
}
// try to link the department row for the determined department number, if no row linked
boolean linked = false;
if (!isResponsibleDepartmentLinked() && depNoToLinkOrNull != null) {
Page newRowPg = getResponsibleDepartments().findByHeadline(depNoToLinkOrNull);
if (newRowPg != null) {
linkResponsibleDepartment(newRowPg);
linked = true;
}
}
// try to remove department text from responsible_name field, if a department was linked
if (linked) {
String separator = " - ";
String respNameTmpltElemName = getParameter("respNameTmpltElemName");
StandardFieldTextElement respNameElem = getStandardFieldTextElement(respNameTmpltElemName);
if (!respNameElem.isEmpty()) {
String respName = respNameElem.getText();
int pos = respName.indexOf(separator);
if (pos >= 0) {
String newName = respName.substring(pos + separator.length());
addSetStandardFieldTextValue(respNameTmpltElemName, newName);
}