Document inDoc = null;
try { inDoc = initializeInput(messageNumber, aMessage); }
catch (JMSException jmse) {
// An error occurred creating the input document from the JMS message
// passed in. Log it and publish a sync error.
Error error = new Error();
error.setErrorNumber("OpenEAI-2101");
error.setErrorDescription("An error occurred creating the input " +
"document from the JMS message passed in. The exception is: " +
jmse.getMessage());
logger.fatal("[BasicPersonSyncCommand.execute]" +
error.getErrorDescription());
return;
}
// Get the message metadata.
Element eControlArea = getControlArea(inDoc.getRootElement());
String messageCategory = eControlArea.getAttribute("messageCategory")
.getValue();
String messageObject = eControlArea.getAttribute("messageObject")
.getValue();
String messageRelease = eControlArea.getAttribute("messageRelease")
.getValue();
String messageAction = eControlArea.getAttribute("messageAction")
.getValue();
String messageType = eControlArea.getAttribute("messageType").getValue();
logger.info("[BasicPersonSyncCommand.execute] Received a(n) " +
messageCategory + "." + messageObject + "." + messageAction + "-" +
messageType + " (release " + messageRelease + ") message.");
// Verify that this is a message we support.
ArrayList errors = new ArrayList();
if (messageObject.equalsIgnoreCase("BasicPerson") == false) {
Error error = new Error();
error.setType("application");
error.setErrorNumber("OpenEAI-1002");
error.setErrorDescription("Message object '" + messageObject +
"' is not supported.");
errors.add(error);
}
if (messageType.equalsIgnoreCase("Sync") == false) {
Error error = new Error();
error.setType("application");
error.setErrorNumber("OpenEAI-1002");
error.setErrorDescription("Message type '" + messageType + "' is not " +
"supported.");
errors.add(errors);
}
if (errors.size() > 0) {
ListIterator iterator = errors.listIterator();
while (iterator.hasNext()) {
Error error = (Error)iterator.next();
logger.fatal("[BasicPersonSyncCommand.execute] " +
error.getErrorDescription());
}
publishSyncError(eControlArea, errors);
return;
}
// Get two configured BasicPerson objects from AppConfig.
BasicPerson currentBasicPerson = null;
BasicPerson newBasicPerson = null;
try {
currentBasicPerson = (BasicPerson)getAppConfig().getObject("BasicPerson");
newBasicPerson = (BasicPerson)getAppConfig().getObject("BasicPerson");
}
catch (EnterpriseConfigurationObjectException ecoe) {
// An error occurred getting an object from AppConfig. Log it and
// publish a sync error message.
Error error = new Error();
error.setType("application");
error.setErrorNumber("OpenEAI-3001");
error.setErrorDescription("An error occurred getting an object from " +
"AppConfig. the exception is: " + ecoe.getMessage());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ecoe);
return;
}
// Handle a BasicPerson.Update-Sync
if (messageAction.equalsIgnoreCase("Update")) {
// Get the baseline state of the BasicPerson and build a BasicPerson
// object.
Element eBaselinePerson = inDoc.getRootElement().getChild("DataArea")
.getChild("BaselineData").getChild("BasicPerson");
try {
currentBasicPerson.buildObjectFromInput(eBaselinePerson);
}
catch (EnterpriseLayoutException ele) {
// An error occurred building the BasicPerson object from the
// BasicPerson element contained in the BaselineData element of the
// message. Log it and publish a sync error message.
Error error = new Error();
error.setType("system");
error.setErrorNumber("DirectoryServiceGateway-1001");
error.setErrorDescription("An error occurred building the BasicPerson "
+ "object from the BasicPerson element contained in the " +
"BaselineData element of the message. The exception is: " +
ele.getMessage());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ele);
return;
}
// Get the new state of the BasicPerson and build a BasicPerson
// object.
Element eNewPerson = inDoc.getRootElement().getChild("DataArea")
.getChild("NewData").getChild("BasicPerson");
try {
newBasicPerson.buildObjectFromInput(eNewPerson);
}
catch (EnterpriseLayoutException ele) {
// An error occurred building the BasicPerson object from thw
// BasicPerson element contained in the NewData element of
// the message. Log it and publish a sync error message.
Error error = new Error();
error.setType("system");
error.setErrorNumber("DirectoryServiceGateway-1002");
error.setErrorDescription("An error occurred building the " +
"BasicPerson object from the BasicPerson element contained in " +
"the NewData element of the message. The exception is: " +
ele.getMessage());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ele);
return;
}
// Determine whether the user exists in the portal database.
String instId = currentBasicPerson.getInstitutionalId();
PortalPerson portalPerson = null;
try { portalPerson = retrievePortalPerson(instId); }
catch (CommandException ce) {
// An error occurred querying the portal database to determine whether
// the user exists. Log it, publish a error message, and return.
String errMsg = "An error occurred querying the portal database to " +
"determine whether the user exists.";
logger.debug("[PasswordSyncCommand.execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("UportalGateway-2001");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ce);
return;
}
// If there are no matching entries and the publishErrorsForMissingEntries
// property is true, publish a error message indicating that the user does
// not exist. Otherwise, log the fact that the user does not exist and
// return.
if (portalPerson == null) {
if (getPublishErrorsForMissingEntries() == true) {
// --- Publish the sync error.
Error error = new Error();
error.setType("application");
error.setErrorNumber("UportalGateway-1005");
error.setErrorDescription("No user with user ID " + instId +
" exists in the portal. Cannot reset the password for this user.");
logger.fatal("[BasicPersonSyncCommand.execute] " +
error.getErrorDescription());
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors);
return;
}
else {
// --- Just log it.
logger.info("[BasicPersonSyncCommand.execute] No user with user ID " +
instId + " exists in the portal. Cannot reset the password for " +
"this user.");
return;
}
}
// Otherwise, the user already exists in the portal, so determine if their
// name and e-mail have changed and, if so, update them.
else {
// Get the new first name, last name, and e-mail address.
String newFirstName = newBasicPerson.getName().getFirstName();
String newLastName = newBasicPerson.getName().getLastName();
String email;
List emailAddresses = newBasicPerson.getEmail();
ListIterator li = emailAddresses.listIterator();
switch (emailAddresses.size()) {
// If there are no e-mail addresses in the list, set the value of the
// e-mail address to null.
case 0:
email = null;
break;
// If there is one e-mail address in the list, that will become the
// value of the e-mail address.
case 1:
Email emailAddress = (Email)li.next();
email = emailAddress.getEmailAddress();
break;
// If there are multiple e-mail addresses in the list, uPortal can
// store only one of them, so get any one that has the preferred
// indicator set or take the first e-mail address in the list if
// none are preferred.
default:
emailAddress = (Email)li.next();
email = emailAddress.getEmailAddress();
while (li.hasNext()) {
emailAddress = (Email)li.next();
if (emailAddress.getPreferred() != null &&
emailAddress.getPreferred().equalsIgnoreCase("Yes")) {
email = emailAddress.getEmailAddress();
}
}
break;
}
// Determine whether the name or e-mail address has changed.
PortalPerson newPortalPerson = new PortalPerson(portalPerson);
newPortalPerson.setFirstName(newFirstName);
newPortalPerson.setLastName(newLastName);
newPortalPerson.setEmailAddress(email);
// If there has been a change, update the person information. Otherwise
// log the fact that no update is required.
if (newPortalPerson.equals(portalPerson) == false) {
logger.info("[BasicPersonSyncCommand.execute] Updating portal " +
"person information for portal person " + portalPerson
.getFirstName() + " " + portalPerson.getLastName() + ".");
logger.debug("[BasicPersonSyncCommand.execute] current portal " +
"person: " + portalPerson);
logger.debug("[BasicPersonSyncCommand.execute] new portal " +
"person: " + newPortalPerson);
try { updatePortalPerson(portalPerson, newPortalPerson); }
catch (CommandException ce) {
// An error occurred accessing the portal database to update the
// the portal user information. Log it, publish a error message,
// and return.
String errMsg = "An error occurred accessing the portal database " +
"to update portal user information.";
logger.debug("[BasicPersonSyncCommand.execute] " + errMsg);
Error error = new Error();
error.setType("system");
error.setErrorNumber("UportalGateway-2001");
error.setErrorDescription(errMsg);
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors, ce);
return;
}
}
else {
logger.info("[BasicPersonSyncCommand.execute] No change in relevant "
+ "information. No portal person information update required for " +
"portal person " + portalPerson
.getFirstName() + " " + portalPerson.getLastName() + " (userId=" +
portalPerson.getUserId() + ", userName=" + portalPerson
.getUserName() + ").");
}
}
}
// Otherwise, the message is unsupported. Log it and publish a sync error.
else {
Error error = new Error();
error.setType("application");
error.setErrorNumber("OpenEAI-1002");
error.setErrorDescription("Unsupported message action. This command only "
+ "supports an action of 'update'");
errors = new ArrayList();
errors.add(error);
publishSyncError(eControlArea, errors);
return;