Package org.any_openeai_enterprise.services.i2s.commands

Source Code of org.any_openeai_enterprise.services.i2s.commands.InstitutionalIdentityRequestCommand

/*******************************************************************************
$Source: /cvs/repositories/openii3/project/java/examples/org/any_openeai_enterprise/services/i2s/commands/InstitutionalIdentityRequestCommand.java,v $
$Revision: 1.2 $
*******************************************************************************/

/**********************************************************************
This file is part of the OpenEAI sample, reference implementation,
and deployment management suite created by Tod Jackson
(tod@openeai.org) and Steve Wheat (steve@openeai.org).

Copyright (C) 2003 The OpenEAI Software Foundation

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

For specific licensing details and examples of how this software
can be used to implement integrations for your enterprise, visit
http://www.OpenEAI.org/licensing.
*/

package org.any_openeai_enterprise.services.i2s.commands;

// Core Java
import java.sql.SQLException;
import java.util.ArrayList;
import javax.jms.*;

// JDOM
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Attribute;

// General OpenEAI foundation
import org.openeai.config.CommandConfig;
import org.openeai.config.PropertyConfig;
import org.openeai.config.EnterpriseConfigurationObjectException;
import org.openeai.xml.XmlDocumentReader;
import org.openeai.xml.XmlDocumentReaderException;
import org.openeai.jms.consumer.commands.RequestCommand;
import org.openeai.jms.consumer.commands.CommandException;
import org.openeai.layouts.EnterpriseLayoutException;
import org.openeai.config.EnterpriseFieldException;
import org.openeai.moa.XmlEnterpriseObjectException;
import org.openeai.moa.objects.testsuite.TestId;

// OpenEAI I2S foundation
import org.any_openeai_enterprise.services.i2s.commands.I2sRequestCommand;
import org.any_openeai_enterprise.services.i2s.repository.*;

// Objects and message objects from OpenEAI implementations
import org.any_openeai_enterprise.moa.jmsobjects.coreapplication.v1_0.InstitutionalIdentity;
import org.any_openeai_enterprise.moa.objects.resources.v1_0.UnknownPerson;
import org.any_openeai_enterprise.moa.objects.resources.v1_0.Identifier;

/**
* This class implements message support for the InstitutionalIdentityService.
* <P>
* Specifically, this command handles request messages for the
* org.any-openeai-enterprise.CoreApplication.InstitutionalIdentity message
* object.  The command handles Query-Request messages and replies with Provide-
* Reply messages. It also handles Generate-Request, Update-Request, and
* Delete-Request messages and replies with Response-Reply messages.
* <P>
* <B>1. org.any-openeai-enterprise.CoreApplication.InstitutionalIdentity.Query-Request</B>
* <P>
* When processing a Query-Request message, this command first gets the query
* element from the message, verifies that this element is an UnknownPerson
* (the appropriate query element for an InstitutionalIdentity), and verifies
* that this UnknownPerson element is not null. If the the query element is not
* an UnknownPerson, the command replies with an error to the requesting client.
* If the query object is an UnknownPerson, the command gets a pre-configured
* UnknownPerson object from AppConfig and tries to build an UnknownPerson
* object from the UnknownPerson element in the Query-Request. If an error
* occurs building the UnknownPerson object from the XML element, the command
* replies with an error to the requesting client. If the command successfully
* builds the UnknownPerson object, then it attempts to retrieve an
* InstitutionalIdentity from the I2sRepository it is configured to use with
* the UnknownPerson object it has just built. For details on how the
* I2sRepository retrieves the InsitutionalIdentity, see the documentation for
* the specific I2sRepository implementation you have configured this command
* to use. If an InstitutionalIdentity was found in the repository for the
* UnknownPerson, the InstitutionalIdentity object returned from the repository
* will not be null. If no InstitutionalIdentity was found for the UnknownPerson,
* the InstitutionalIdentity will be null. If the InstitutionalIdentity is not
* null, the command serializes it and places it into the DataArea of the
* Provide-Reply message. If the InstitutionalIdentity returned from the
* repository is null, the command clears the DataArea of the Provide-Reply
* message to return a reply with an empty DataArea as prescribed by the OpenEAI
* Message Protocol. If an error occurs serializing the InstitutionalIdentity
* element from the InstitutionalIdentity object returned from the I2sRepository,
* the command replies with an error to the requesting client. Finally, the
* command builds the reply message and returns it to be sent to the requesting
* client.     
* <P>
* <B>2. org.any-openeai-enterprise.CoreApplication.InstitutionalIdentity.Generate-Request</B>
* <P>
* When processing a Generate-Request message, this command first gets the
* generate element from the message, verifies that this element is an
* UnknownPerson (the appropriate generate element for an InstitutionalIdentity),
* and verifies that this UnknownPerson element is not null. If the the generate
* element is not an UnknownPerson, the command replies with an error to the
* requesting client. If the generate object is an UnknownPerson, the command
* gets a pre-configured UnknownPerson object from AppConfig and tries to build
* an UnknownPerson object from the UnknownPerson element in the Generate-
* Request. If an error occurs building the UnknownPerson object from the XML
* element, the command replies with an error to the requesting client. If the
* command successfully builds the UnknownPerson object, then it attempts to
* generate an InstitutionalIdentity using the I2sRepository it is configured to
* use with the UnknownPerson object it has just built. If the I2sRepository
* successfully generates an InsitutionalIdentity using the UnknownPerson
* provided, the repository returns the InstitutionalIdentity object it
* generated. If the I2sRepository encounters a problem or error when attempting
* to generate an InstitutionalIdentity, it throws an exception. If the
* I2sRepository successfully generates an InstitutionalIdentity, the command
* places the InstitutionalIdentity returned into the DataArea of an
* InstitutionalIdentity.Response-Reply and returns it to reply with success.
* If the InstitutionalIdentity is not generated successfully, the command
* replies to the requesting client with an error.
* <P>
* <B>3. org.any-openeai-enterprise.CoreApplication.InstitutionalIdentity.Update-Request</B>
* <P>
* When processing a Update-Request message, this command first gets the
* generate elements (the baseline and new InstitutionalIdentity elements) from
* the message, verifies that these elements are InstitutionalIdentities and
* that they are not null. If either of the generate elements is not an
* InstitutionalIdentity, the command replies with an error to the requesting
* client. If the generate elements are InstitutionalIdentities, the command
* gets two pre-configured InstitutionalIdenity objects from AppConfig and tries
* to build an baseline InstitutionalIdentity object from the baseline
* InstitutionalIdentity element and a new InsitutionalIdentity object from the
* new InstitutionalIdentity element.  If an error occurs building the
* baseline or new InstitutionalIdentity object from the appropriate XML
* element, the command replies with an error to the requesting client. If the
* command successfully builds both the baseline InstitutionalIdentity object
* and the new InstitutionalIdentity object, then it attempts to update the
* InstitutionalIdentity using the I2sRepository it is configured to
* use with both the baseline InstitutionalIdentity and the new
* InstitutionalIdentity object it has just built. If the I2sRepository
* encounters a problem or error when attempting to update an
* InstitutionalIdentity, it throws an exception. If the I2sRepository
* successfully updates an InstitutionalIdentity, the command and returns an
* InstitutionalIdentity.Response-Reply to reply with success. If the
* InstitutionalIdentity is not generated successfully, the command
* replies to the requesting client with the same message, containing details
* of the errors it encountered.
* <P>
* <B>4. org.openeai.CoreApplication.InstitutionalIdentity.Delete-Request</B>
* <P>
* When processing a Delete-Request message, this command first gets the
* delete element from the message, verifies that this element is an
* InstitutionalIdentity and that it is not null. If the the delete element is
* null or is not an InstitutionalIdentity, the command replies with an error to
* the requesting client. The command then verifies that the delete action has
* a valid value. If the delete action is not valid, it replies with an error
* to the requesting client. If the delete action specified in the message is
* 'Purge', the command verifies that purge functionality is configured to be
* enable. If purge functionality is disabled, the command replies to the
* requesting client with an error. If the delete object is an
* InstitutionalIdentity and the specified delete action is valid and enabled,
* the command gets a pre-configured InstitutionalIdentity object from AppConfig
* and tries to build an InstitutionalIdentity object from the
* InstitutionalIdentity element in the Delete-Request. If an error occurs
* building the InstitutionalIdentity object from the XML element, the command
* replies with an error to the requesting client. If the command successfully
* builds the InstitutionalIdentity object, then it attempts to delete the
* InstitutionalIdentity using the I2sRepository it is configured to
* use with the InstitutionalIdentity object it has just built. If the
* I2sRepository encounters a problem or error when attempting to delete the
* InstitutionalIdentity, it throws an exception. If the I2sRepository
* successfully deletes an InstitutionalIdentity, the command returns an
* InstitutionalIdentity.Response-Reply to reply with success. If the
* InstitutionalIdentity is not generated successfully, the command replies to
* he requesting client with an error.
* <P>
* <B>Configuration Parameters:</B>
* <P>
* This command extends I2sRequestCommand and must be configured as an
* I2sRequestCommand. See the configuration information for I2sRequestCommand.
* <P>
* In addition to the configuration parameters specified by I2sRequestCommand,
* the InstitutionalIdentityRequestCommand specifies one additional
* configuration paramater that must be found in the I2sRequestCommandProperties
* object.
* <P>
* <TABLE BORDER=2 CELLPADDING=5 CELLSPACING=2>
* <TR>
* <TH>Name</TH>
* <TH>Required</TH>
* <TH>Description</TH>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD>provideDocumentUri</TD>
* <TD>yes</TD>
* <TD>URI for retrieving the primed 
* org.openeai.CoreApplication/EnterpriseSession/Provide-Reply document</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TR HALIGN="left" VALIGN="top">
* <TD>allowPurge</TD>
* <TD>yes</TD>
* <TD>If allowPurge has a value of 'true' then Delete-Request messages with a
* delete action type of purge will be processed. Support for purges can be
* useful in testing such as running test suites with the OpenEAI
* TestSuiteApplication using tear-down test steps. If allowPurge has a value of
* 'false' then Delete-Request messages with a delete action of type purge are
* not supported. If such a message is received, the command replies with an
* org.openeai.CoreApplication.Generic.Response-Reply containing an error
* message.</TD>
* </TR>
* </TABLE>
* <P>
* <B>Error Messages:</B>
* <P>
* <TABLE BORDER=2 CELLPADDING=5 CELLSPACING=2>
* <TR>
* <TH>Code</TH>
* <TH>Type</TH>
* <TH>Description</TH>
* <TH>Explanation</TH>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1001</NOBR></TD>
* <TD>application</TD>
* <TD>Unsupported message object: [unsupported message object name]. This
* command expects '[supported message object name(s)]'. (in this case
* 'InstitutionalIdentity')</TD>
* <TD>Somehow the wrong message object name is getting placed into the
* message by the sending application or it is sending the wrong message
* entirely.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1002</NOBR></TD>
* <TD>application</TD>
* <TD>Unsupported message action: [unsupported message action name]. This
* command only supports '[supported message action name(s)]'. (in this case
* 'query', 'generate', 'update', and 'delete')</TD>
* <TD>Somehow the wrong message action name is getting placed into the
* message by the sending application or it is sending the wrong message
* entirely. This command supports Query-Request, Generate-Request,
* Update-Request, and Delete-Request messages.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1003</NOBR></TD>
* <TD>application</TD>
* <TD>Invalid query element found in the Query-Request message. This command
* expects '[name of the expected query object(s)]'. (in this case
* 'UnknownPerson')</TD>
* <TD>A null or inappropriate query object is getting placed into the
* message by the sending application or it is sending the wrong message
* entirely. This command only supports InstitutionalIdentity.Query-Request,
* which expects an UnknownPerson as the query object.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1008</NOBR></TD>
* <TD>application</TD>
* <TD>Invalid delete action type. Only delete actions of type 'delete' and
* 'purge' are allowed.
* </TD>
* <TD>Somehow an invalid delete action type is being set. Check the sending
* application or the appropriate EnterpriseObjects document to figure out
* how this could be and prevent it from happening.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1009</NOBR></TD>
* <TD>application</TD>
* <TD>Purge disabled. The delete action type of purge is supported by this
* implementation, but it is presently disabled.
* </TD>
* <TD>This command apparently supports a delete action of type purge, but
* this support is configurable, because there are conditions under which
* a purge should be allowed (such as test and development use) and should
* not be allowed (such as production use). Presently, this purge support
* is toggled off presumably by an appropriate command configuration or runtime
* configuration property called something like 'allowPurge'.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1010</NOBR></TD>
* <TD>application</TD>
* <TD>Invalid delete element found in the Delete-Request message. This command
* expects an [delete element name(s)] (in this case 'InstitutionalIdentity.').
* </TD>
* <TD>Somehow there is an unsupported delete element in the message processed
* by this command. Verify that the sending application is sending the
* appropriate message and that it contains the appropriate delete element.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1011</NOBR></TD>
* <TD>application</TD>
* <TD>Invalid update element found in the NewData element of the Update-Request
* message. This command expects an [update element name(s)] (in this case
* 'InstitutionalIdentity.').
* </TD>
* <TD>Somehow there is an unsupported update element in the NewData element of
* the message processed by this command. Verify that the sending application is
* sending the appropriate message and that it contains the appropriate update
* elements in the NewData and Baseline data elements.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1012</NOBR></TD>
* <TD>application</TD>
* <TD>Invalid update element found in the BaselineData element of the
* Update-Request message. This command expects an [update element name(s)]
* (in this case 'InstitutionalIdentity.').
* </TD>
* <TD>Somehow there is an unsupported update element in the BaselineData
* element of the message processed by this command. Verify that the sending
* application is sending the appropriate message and that it contains the
* appropriate update elements in the NewData and Baseline data elements.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1014</NOBR></TD>
* <TD>application</TD>
* <TD>Baseline is stale.
* </TD>
* <TD>The baseline state of the InstitutionalIdentity in the message does not
* match the current state of the InstitutionalIdentity in the I2sRepository.
* Most likely, the InstitutionalIdentity has been updated by another client
* since the client making the current request queried for a baseline.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>OpenEAI-1015</NOBR></TD>
* <TD>application</TD>
* <TD>Invalid generate element found in the Generate-Request message. This
* command expects an [update element name(s)]
* (in this case 'UnknownPerson.').
* </TD>
* <TD>Somehow there is an unsupported generate element in the message being
* processed by this command. Verify that the sending application is sending the
* appropriate message and that it contains the appropriate generate element in
* the DataArea element.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1001</NOBR></TD>
* <TD>application</TD>
* <TD>Error building the UnknownPerson object from the UnknownPerson element
* in the Query-Request message.  The exception is: [EnterpriseLayoutException
* message].
* </TD>
* <TD>There was an error building an UnknownPerson XmlEnterpriseObject from
* the UnknownPerson element used as the query object in the incoming Query-
* Request message. There is most likely bad data in this UnknownPerson element
* or its children or the element (and therefore the entire message) is not
* well-formed and valid.  Verify that the message is well-formed and valid and
* consult the appropriate EnterpriseObjects document for the UnknownPerson
* object to verify that the data being passed is allowable.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1002</NOBR></TD>
* <TD>system</TD>
* <TD>Error accessing the I2sRepository to retrieve the InstitutionalIdentity.
* The exception is: [I2sRepositoryException message].
* </TD>
* <TD>An error occurred while accessing the I2sRepository to retrieve an
* InstitutionalIdentity. The I2sRepositoryException message should contain
* details about the error and its cause. These potential problems will vary
* depending on the I2sRepository implementation you have configured this
* command to use. See the documentation for the I2sRepository implementation
* you are using for an explanation of its errors. The implementer of the
* I2sRepoistory you are using should provide documentation with an explanation
* of common errors.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1003</NOBR></TD>
* <TD>application</TD>
* <TD>An error occurred building the InstitutionalIdentity element from the
* InstitutionalIdentity object returned from the I2sRepository. The exception
* is: [I2sRepositoryException message].
* </TD>
* <TD>There was an error serializing the InstitutionalIdentity object returned
* from the I2sRepository to place it into the reply message. There is most
* likely bad data in this InstitutionalIdentity element or its children.
* Consult the appropriate EnterpriseObjects document for the
* InstitutionalIdentiy object to verify that the data values found for this
* InstitutionalIdentity in the I2sRepoistory is (still) allowable.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1004</NOBR></TD>
* <TD>application</TD>
* <TD>Error building the UnknownPerson object from the UnknownPerson element
* in the Generate-Request message.  The exception is:
* [EnterpriseLayoutException message].
* </TD>
* <TD>There was an error building an UnknownPerson XmlEnterpriseObject from
* the UnknownPerson element used as the generate object in the incoming
* Generate-Request message. There is most likely bad data in this UnknownPerson
* element or its children or the element (and therefore the entire message) is
* not well-formed and valid.  Verify that the message is well-formed and valid
* and consult the appropriate EnterpriseObjects document for the UnknownPerson
* object to verify that the data being passed is allowable.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1005</NOBR></TD>
* <TD>system</TD>
* <TD>Error accessing the I2sRepository to generate the InstitutionalIdentity.
* The exception is: [I2sRepositoryException message].
* </TD>
* <TD>An error occurred while accessing the I2sRepository to generate an
* InstitutionalIdentity. The I2sRepositoryException message should contain
* details about the error and its cause. These potential problems will vary
* depending on the I2sRepository implementation you have configured this
* command to use. See the documentation for the I2sRepository implementation
* you are using for an explanation of its errors. The implementer of the
* I2sRepoistory you are using should provide documentation with an explanation
* of common errors.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1006</NOBR></TD>
* <TD>application</TD>
* <TD>Error building the InstitutionalIdentity object from the
* InstitutionalIdentity element found in the the NewData element in the
* Update-Request message.  The exception is: [EnterpriseLayoutException
* message].
* </TD>
* <TD>There was an error building an InstitutionalIdentity XmlEnterpriseObject
* from the InstitutionalIdentity element used as the NewData element in the
* incoming Update-Request message. There is most likely bad data in this
* InstitutionalIdentity element or its children or the element (and therefore
* the entire message) is not well-formed and valid.  Verify that the message is
* well-formed and valid and consult the appropriate EnterpriseObjects document
* for the InstitutionalIdentity object to verify that the data being passed is
* allowable.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1007</NOBR></TD>
* <TD>application</TD>
* <TD>Error building the InstitutionalIdentity object from the
* InstitutionalIdentity element found in the the BaselineData element in the
* Update-Request message.  The exception is: [EnterpriseLayoutException
* message].
* </TD>
* <TD>There was an error building an InstitutionalIdentity XmlEnterpriseObject
* from the InstitutionalIdentity element used as the BaselineData element in
* the incoming Update-Request message. There is most likely bad data in this
* InstitutionalIdentity element or its children or the element (and therefore
* the entire message) is not well-formed and valid.  Verify that the message is
* well-formed and valid and consult the appropriate EnterpriseObjects document
* for the InstitutionalIdentity object to verify that the data being passed is
* allowable.</TD>
* </TR>         
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1008</NOBR></TD>
* <TD>system</TD>
* <TD>Error accessing the I2sRepository to update the InstitutionalIdentity.
* The exception is: [I2sRepositoryException message].
* </TD>
* <TD>An error occurred while accessing the I2sRepository to update an
* InstitutionalIdentity. The I2sRepositoryException message should contain
* details about the error and its cause. These potential problems will vary
* depending on the I2sRepository implementation you have configured this
* command to use. See the documentation for the I2sRepository implementation
* you are using for an explanation of its errors. The implementer of the
* I2sRepoistory you are using should provide documentation with an explanation
* of common errors.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1009</NOBR></TD>
* <TD>application</TD>
* <TD>Error building the InstitutionalIdentity object from the
* InstitutionalIdentity element in the Delete-Request message.  The exception
* is: [EnterpriseLayoutException message].
* </TD>
* <TD>There was an error building an InstitutionalIdentity XmlEnterpriseObject
* from the InstitutionalIdentity element used as the delete object in the
* incoming Delete-Request message. There is most likely bad data in this
* InstitutionalIdentity element or its children or the element (and therefore
* the entire message) is not well-formed and valid.  Verify that the message is
* well-formed and valid and consult the appropriate EnterpriseObjects document
* for the InstitutionalIdentity object to verify that the data being passed is
* allowable.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1010</NOBR></TD>
* <TD>application</TD>
* <TD>Error accessing the I2sRepository to perform a delete action of type
* [action name] for the InstitutionalIdentity. The exception is:
* [I2sRepositoryException message].
* </TD>
* <TD>An error occurred while accessing the I2sRepository to delete an
* InstitutionalIdentity. The I2sRepositoryException message should contain
* details about the error and its cause. These potential problems will vary
* depending on the I2sRepository implementation you have configured this
* command to use. See the documentation for the I2sRepository implementation
* you are using for an explanation of its errors. The implementer of the
* I2sRepoistory you are using should provide documentation with an explanation
* of common errors.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1011</NOBR></TD>
* <TD>application</TD>
* <TD>Error occurred setting field values for the identifier to use in
* retrieving the current state of the InstitutionalIdentity. The exception is:
* [EnterpriseFieldException message].
* </TD>
* <TD>An error occurred while setting the type and value fields for the
* identifier to us to retrieve the current state of the
* InstitutionalIdentity. A possible cause for this error is invalid data.
* consult the application or application data and the EnterpriseObject
* document for the object Identifier to verify that valid data is being
* used to populate the type and value fields of the Identifier object.</TD>
* </TR>
* <TR HALIGN="left" VALIGN="top">
* <TD><NOBR>InstitutionalIdentityService-1012</NOBR></TD>
* <TD>application</TD>
* <TD>An error occurred comparing the baseline InstitutionalIdentity with the
* current state of the InstitutionalIdentity. The exception is: 
* [XmlEnterpriseObjectException message].
* </TD>
* <TD>An error occurred while comparing the baseline and current value of the
* InstitutionalIdentity at an XmlEnterpriseObject level.</TD>
* </TR>
* </TABLE>
* <P>
* @author      Steve Wheat (steve@openeai.org)
* @version     1.0 beta - 24 July 2003
*/
public class InstitutionalIdentityRequestCommand
  extends I2sRequestCommand
  implements RequestCommand {

  /**
   * @param CommandConfig, the command configuration object for this command.
   * @throws InstantiationException, with details of instantiation or
   * initialization errors.
   *
   * This is the constructor for the command. It calls the constructor of the
   * superclass I2sRequestCommand, which sets some properties common to
   * all I2sRequestCommands and then also sets the allowPurge property,
   * which is specific to this implementation.
   */
  public InstitutionalIdentityRequestCommand(CommandConfig cConfig) throws
    InstantiationException {
    super(cConfig);
    // Set the allowPurge property.
    String sAllowPurge = getProperties().getProperty("allowPurge");
    if (sAllowPurge.equalsIgnoreCase("true") ||
        sAllowPurge.equalsIgnoreCase("false")) {
      m_allowPurge = Boolean.valueOf(sAllowPurge).booleanValue();
      logger.info("[InstitutionalIdentityRequestCommand] allowPurge " +
                  "is " + m_allowPurge + ".");
    }
    else {
      throw new InstantiationException("'allowPurge' property must be " +
        "present in the deployment descriptor, and it must have a value of " +
        "'true' or 'false'.  Can't continue.");
    }

    logger.info("[InstitutionalIdentityRequestCommand] instantiated " +
      "successfully.");
  }

  /**
   * @param int, the number of the message processed by the consumer.
   * @param Message, the message for the command to process.
   * @throws CommandException, with details of the error processing the message.
   *
   * This method makes a local copy of the response and provide documents to
   * use in the reply to the request. Then it coverts the JMS message to an XML
   * document, retrieves the text portion of the message, clears the message
   * body in preparation for the reply, gets the ControlArea from the XML
   * document, and verifies that message object of the message is an
   * InstitutionalIdentity. If the message object is not an
   * InstitutionalIdentity, the command replies with an error to the client.
   * If the message object is an InstitutionalIdentity, it processes the
   * message. The comments above contain a detailed description of the
   * processing logic for supported message actions. That logic is implemented
   * in this method.
   */
  public final Message execute(int messageNumber, Message aMessage) throws
    CommandException {
    // Make a local copy of the response and provide documents to use in
    // replies.
    Document localProvideDoc = (Document)m_provideDoc.clone();
    Document localResponseDoc = (Document)m_responseDoc.clone();
   
    // Convert the JMS Message to a Document etc.
    Document inDoc = null;
    try { inDoc = initializeInput(messageNumber, aMessage); }
    catch (Exception e) {
      String errMsg = "An exception occurred processing input message in " +
        "org.openeai.jms.consumer.commands.Command.  The exception is: " +
        e.getMessage();
      logger.fatal("[InstitutionalIdentityRequestCommand] " + errMsg);
      throw new CommandException(errMsg);
    }

    // Retrieve text portion of the message.
    TextMessage msg = (TextMessage)aMessage;
    try {
      // Clear the message body for the reply, so we do not
      // have to do it later.
      msg.clearBody();
    }
    catch (Exception e) {
      String errMsg = "Error clearing the message body. The exception is: " +
        e.getMessage();
      logger.fatal("[InstitutionalIdentityRequestCommand] " + errMsg);
      throw new CommandException(errMsg);
    }

    // Get the ControlArea from the XML document.
    Element eControlArea = getControlArea(inDoc.getRootElement());

    // Get the TestId if it exists.
    TestId testId = extractTestId("TestId", eControlArea);

    // Get the messageAction, messageObject, and SenderAppId from the
    // ControlArea.
    String msgAction = eControlArea.getAttribute("messageAction").getValue();
    String msgObject = eControlArea.getAttribute("messageObject").getValue();
    String senderAppId = eControlArea.getChild("Sender").getChild("MessageId").
      getChild("SenderAppId").getText();

    // Verify that the message object we are dealing with is an
    // InstitutionalIdentity; if not, reply with an error.
    if (msgObject.equalsIgnoreCase("InstitutionalIdentity") == false) {
      String errType = "application";
      String errCode = "OpenEAI-1001";
      String errDesc = "Unsupported message object: " + msgObject +
        ". This command expects 'InstitutionalIdentity'.";
      logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
      logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
        "is: \n" + getMessageBody(inDoc));
      ArrayList errors = new ArrayList();
      errors.add(buildError(errType, errCode, errDesc));
      String replyContents =
        buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
      return getMessage(msg, replyContents);
    }

    // Process a Query-Request message.
    if (msgAction.equalsIgnoreCase("Query")) {   
      logger.info("[InstitutionalIdentityRequestCommand] Handling an " +
        "org.any-openeai-enterprise.CoreApplication.InstitutionalIdentity." +
        "Query-Request message.");
      // Get the query element.
      Element queryElement = inDoc.getRootElement().getChild("DataArea").
        getChild("UnknownPerson");

      // Verify that the query element is an UnknownPerson (and is not null).
      // If it is null, reply with an error.
      if (queryElement == null) {
        String errType = "application";
        String errCode = "OpenEAI-1003";
        String errDesc = "Invalid query element found in the Query-Request " +
          "message. This command expects an UnknownPerson.";
        logger.fatal("[ApplicationSessionRequestCommand] " + errDesc);
        logger.fatal("[ApplicationSessionRequestCommand] Message sent in is: \n"
          + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localProvideDoc,
          errors);
        return getMessage(msg, replyContents);
      }
    
      else {
        // Get a primed UnknownPerson object from AppConfig.
        UnknownPerson uPerson = new UnknownPerson();
        try {
          uPerson = (UnknownPerson)getAppConfig().
            getObject("UnknownPerson");
        }
        catch (EnterpriseConfigurationObjectException eoce) {
        logger.fatal("[InstitutionalIdentityRequestCommand] Error retrieving " +
          "an UnknownPerson object from AppConfig. The exception is: " +
          eoce.getMessage());
        }
     
        // Try to build the UnknownPerson object from the query element.
        try {
          uPerson.buildObjectFromInput(queryElement);
        }
        catch (EnterpriseLayoutException ele) {
          // There was an error building the UnknownPerson object from the
          // query element.
          String errType = "application";
          String errCode = "InstitutionalIdentityService-1001";
          String errDesc = "Error building the UnknownPerson object from the" +
            "UnknownPerson element in the Query-Request message. The " +
            "exception is: " + ele.getMessage();
          logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
          logger.fatal("Message sent in is: \n" + getMessageBody(inDoc));
          ArrayList errors = new ArrayList();
          errors.add(buildError(errType, errCode, errDesc));
          String replyContents =
            buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
          return getMessage(msg, replyContents);       
        }
     
        // Retrieve the InstitutionalIdentity.
        InstitutionalIdentity instIdent = new InstitutionalIdentity();
        try {
          instIdent = m_i2sRepository.retrieveInstitutionalIdentity(uPerson)
        }
        catch (I2sRepositoryException i2sre) {
          String errType = "system";
          String errCode = "InstitutionalIdentityService-1002";
          String errDesc = "Error accessing the I2sRepository to retrieve the "
            + "InstitutionalIdentity. The exception is: " + i2sre.getMessage();
          logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
          logger.fatal("[InstitutionalIdentityRequestCommand] Message sent " +
            "in is: \n" + getMessageBody(inDoc));
          ArrayList errors = new ArrayList();
          errors.add(buildError(errType, errCode, errDesc));
          String replyContents =
            buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
          return getMessage(msg, replyContents);
        }

        // If an InstitutionalIdentity was found in the repository for the
        // UnknownPerson, the InstitutionalIdentity object will not be null. If
        // no InstitutionalIdentity was found for the UnknownPerson, the
        // InstitutionalIdentity will be null. If the InstitutionalIdentity is
        // not null, serialize it and place it into the DataArea of the
        // Provide-Reply. If it is null, clear the DataArea of the Provide-Reply
        // to return an empty DataArea as prescribed by the OpenEAI Message
        // Protocol.     
        try {
          if (instIdent != null) {  
            localProvideDoc.getRootElement().getChild("DataArea").
              removeContent();
            localProvideDoc.getRootElement().getChild("DataArea").
              addContent((Element)instIdent.buildOutputFromObject());
          }
          else {
            localProvideDoc.getRootElement().getChild("DataArea").
              removeContent();
          }
        }
        catch (EnterpriseLayoutException ele) {
          // An error occurred building the InstitutionalIdentity element from
          // the InstitutionalIdentity object returned from the I2sRepository.
          // Log it an reply with an error.
          String errType = "application";
          String errCode = "InstitutionalIdentityService-1003";
          String errDesc = "An error occurred building the Institutional" +
            "Identity element from the InstitutionalIdentity object returned " +
            "from the I2sRepository.  The exception is: " + ele.getMessage();
          logger.fatal("[InstitutionalIdentityRequestCommand " + errDesc);
          ArrayList errors = new ArrayList();
          errors.add(buildError(errType, errCode, errDesc));
          String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
          return getMessage(msg, replyContents);
        }

        // Build the reply message and return it.
        String replyContents =
          buildReplyDocument(eControlArea, localProvideDoc);
        return getMessage(msg, replyContents);
      }
    }

    // Process a Generate-Request message.
    if (msgAction.equalsIgnoreCase("Generate")) { 
      logger.info("[InstitutionalIdentityRequestCommand] Handling an " +
        "org.any-openeai-enterprise.CoreApplication.InstitutionalIdentity." +
        "Generate-Request message.");
      // Get the generate element.
      Element generateElement = inDoc.getRootElement().getChild("DataArea")
        .getChild("UnknownPerson");

      // Verify that the generate element is an UnknownPerson and that it is
      // not null. If it is null, reply with an error.
      if (generateElement == null) {
        String errType = "application";
        String errCode = "OpenEAI-1015";
        String errDesc = "Invalid generate element found in the Generate-" +
          "Request message. This command expects an UnknownPerson.";
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
          "is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }

      // Get a primed UnknownPerson object from AppConfig.
      UnknownPerson uPerson = new UnknownPerson();
      try {
        uPerson = (UnknownPerson)getAppConfig().
          getObject("UnknownPerson");
      }
      catch (EnterpriseConfigurationObjectException eoce) {
      logger.fatal("[InstitutionalIdentityRequestCommand] Error retrieving " +
        "an UnknownPerson object from AppConfig. The exception is: " +
        eoce.getMessage());
      }
     
      // Try to build the UnknownPerson object from the generate element.
      try {
        uPerson.buildObjectFromInput(generateElement);
      }
      catch (EnterpriseLayoutException ele) {
        // There was an error building the UnknownPerson object from the
        // generate element.
        String errType = "application";
        String errCode = "InstitutionalIdentityService-1004";
        String errDesc = "Error building the UnknownPerson object from the" +
          "UnknownPerson element in the Generate-Request message. The " +
          "exception is: " + ele.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("Message sent in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);       
      }

      // Set the TestId.
      uPerson.setTestId(testId);

      // Generate the InstitutionalIdentity and reply.
      InstitutionalIdentity instIdent = new InstitutionalIdentity();
      try {
        instIdent = m_i2sRepository.generateInstitutionalIdentity(uPerson);       
      }
      catch (I2sRepositoryException i2sre) {
        String errType = "system";
        String errCode = "InstitutionalIdentityService-1005";
        String errDesc = "Error accessing the I2sRepository to generate the " +
          "InstitutionalIdentiy. The exception is: " + i2sre.getMessage();      
        logger.fatal("[InstitutionalIdentityRequestCommand]" + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
          "is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }

      try {
        localResponseDoc.getRootElement().getChild("DataArea").
          removeContent();
        localResponseDoc.getRootElement().getChild("DataArea").
          addContent((Element)instIdent.buildOutputFromObject());
        String replyContents = buildReplyDocument(eControlArea, localResponseDoc);
        return getMessage(msg, replyContents);
      }
      catch (EnterpriseLayoutException ele) {
        // An error occurred building the InstitutionalIdentity element from
        // the InstitutionalIdentity object returned from the I2sRepository.
        // Log it an reply with an error.
        String errType = "application";
        String errCode = "InstitutionalIdentityService-1003";
        String errDesc = "An error occurred building the Institutional" +
          "Identity element from the InstitutionalIdentity object returned " +
          "from the I2sRepository.  The exception is: " + ele.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand " + errDesc);
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
        buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
        return getMessage(msg, replyContents);
      }
    }

    // Process an Update-Request message.
    if (msgAction.equalsIgnoreCase("Update")) {
      logger.info("[InstitutionalIdentityRequestCommand] Handling an " +
        "org.any-openeai-enterprise.CoreApplication.InstitutionalIdentity." +
        "Update-Request message.");
      // Get the update elements.
      Element newUpdateElement = inDoc.getRootElement().getChild("DataArea").
        getChild("NewData").getChild("InstitutionalIdentity");
      Element baselineUpdateElement = inDoc.getRootElement()
        .getChild("DataArea").getChild("BaselineData")
        .getChild("InstitutionalIdentity");

      // Verify that the NewData element is an InstitutionalIdentity and that it
      // is not null. If it is null, reply with an error.
      if (newUpdateElement == null) {
        String errType = "application";
        String errCode = "OpenEAI-1011";
        String errDesc = "Invalid update element found in the NewData " +
          "element of the Update-Request message. This command expects an " +
          "InstitutionalIdentity.";
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
          "is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }

      // Verify that the BaselineData element is an InstitutionalIdentity and
      // that it is not null. If it is null, reply with an error.
      if (baselineUpdateElement == null) {
        String errType = "application";
        String errCode = "OpenEAI-1012";
        String errDesc = "Invalid update element found in the BaselineData " +
          "element of the Update-Request message. This command expects an " +
          "InstitutionalIdentity.";
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
          "is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }

      // Get two primed InstitutionalIdentity objects out of AppConfig.
      InstitutionalIdentity newInstIdent = new InstitutionalIdentity();
      InstitutionalIdentity baselineInstIdent = new InstitutionalIdentity();
      try {
        newInstIdent = (InstitutionalIdentity)getAppConfig().
          getObject("InstitutionalIdentity");
        baselineInstIdent = (InstitutionalIdentity)getAppConfig().
          getObject("InstitutionalIdentity");
      }
      catch (EnterpriseConfigurationObjectException eoce) {
      logger.fatal("[InstitutionalIdentityRequestCommand] Error retrieving an" +
        " InstitutionalIdentity object from AppConfig. The exception is: " +
        eoce.getMessage());
      }
     
      // Try to build an InstitutionalIdentity object from the NewData element.
      try {
        newInstIdent.buildObjectFromInput(newUpdateElement);
      }
      catch (EnterpriseLayoutException ele) {
        // An error occurred building the InstitutionalIdentity object from the
        // InstitutionalIdentity NewData element.
        String errType = "application";
        String errCode = "InstitutionalIdentityService-1006";
        String errDesc = "Error building the InstitutionalIdentity object " +
          "from the InstitutionalIdentity element found in the NewData " +
          "element in the Update-Request message. The exception is: " +
          ele.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("Message sent in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);       
      }
     
      // Try to build an InstitutionalIdentity object from the BaselineData
      // element.
      try {
        baselineInstIdent.buildObjectFromInput(baselineUpdateElement);
      }
      catch (EnterpriseLayoutException ele) {
        // There was an error building the InstitutionalIdentity object from the
        // baseline update element.
        String errType = "application";
        String errCode = "InstitutionalIdentityService-1007";
        String errDesc = "Error building the InstitutionalIdentity object " +
          "from the InstitutionalIdentity element found in the BaselineData " +
          "element in the Update-Request message. The exception is: " +
          ele.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("Message sent in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);       
      }

      // Verify that the baseline matches the current state of the
      // InstitutionalIdentity. Otherwise reply with a baseline stale error.

      // --- Retrieve the current state of the InstitutionalIdentity.
      Identifier id = new Identifier();
      try {
        id.setType("InstitutionalId");
        id.setValue(baselineInstIdent.getInstitutionalId());
      }
      catch (EnterpriseFieldException efe) {
        // An error occurred setting the values of the identifier to use to
        // retrieve the current state of the InstitutionalIdentity. Log it
        // and throw an exception.
        String errType = "application";
        String errCode = "InstitutionalIdentityService-1011";
        String errDesc = "Error occurred setting field values for the " +
          "identifier to use in retrieving the current state of the " +
          "InstitutionalIdentity. The exception is:  " + efe.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent " +
          "in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
        return getMessage(msg, replyContents);
      }
      InstitutionalIdentity currentInstIdent = new InstitutionalIdentity();
      try {
        currentInstIdent = m_i2sRepository.retrieveInstitutionalIdentity(id);
      }
      catch (I2sRepositoryException i2sre) {
        String errType = "system";
        String errCode = "InstitutionalIdentityService-1002";
        String errDesc = "Error accessing the I2sRepository to retrieve the "
          + "InstitutionalIdentity. The exception is: " + i2sre.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent " +
          "in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
        return getMessage(msg, replyContents);
      }

      // --- If the InstitutionalIdentity to update does not exist, reply with
      //     an error.
      if (currentInstIdent == null) {
        String errType = "application";
        String errCode = "OpenEAI-1016";
        String errDesc = "The object for which an update was requested does " +
          "not exist. An object must be created before it can be updated.";
        logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
          errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent " +
        "in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
        return getMessage(msg, replyContents);
      }
     
      // --- If the InstitutionalIdentity to update does exists, compare the
      //     baseline to the current state of the InstitutionalIdentity. If they
      //     do not match, reply with an error.
      try
        if (baselineInstIdent.equals(currentInstIdent) == false) {
          // The baseline does not match the current state of the
          // InstitutionalIdentity. Log it and reply with an error.
          String errType = "application";
          String errCode = "OpenEAI-1014";
          String errDesc = "The baseline is stale. This InstitutionalIdentity " +
            "has been updated since you queried for the baseline. You must " +
            "query for the InstitutionalIdentity to retrieve a current baseline"
            + " before an update can be performed.";
          logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
            errDesc);
          logger.fatal("[InstitutionalIdentityRequestCommand] Message sent " +
          "in is: \n" + getMessageBody(inDoc));
          ArrayList errors = new ArrayList();
          errors.add(buildError(errType, errCode, errDesc));
          String replyContents =
            buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
          return getMessage(msg, replyContents);
        }
      }
      catch (XmlEnterpriseObjectException xeoe) {
        // An error occurred comparing the baseline InstitutionalIdentity and
        // the current state of the InstitutionalIdentity. Log it, and throw an
        // exception.
        String errType = "application";
        String errCode = "InstitutionalIdentityService-1012";
        String errDesc = "An error occurred comparing the baseline " +
          "InstitutionalIdentity with the current state of the " +
          "InstitutionalIdentity. The exception is: " + xeoe.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent " +
          "in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localProvideDoc, errors);
        return getMessage(msg, replyContents);
      }

      // Set the TestId.
      baselineInstIdent.setTestId(testId);
      newInstIdent.setTestId(testId);

      // Update the InstitutionalIdentity and reply.
      try {
        m_i2sRepository.updateInstitutionalIdentity(baselineInstIdent,
          newInstIdent);       
      }
      catch (I2sRepositoryException i2sre) {
        String errType = "system";
        String errCode = "InstitutionalIdentityService-1008";
        String errDesc = "Error accessing the I2Repository to update the " +
          "InstitutionalIdentity. The exception is: " + i2sre.getMessage();      
        logger.fatal("[InstitutionalIdentityRequestCommand]" + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
          "is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }

      // Reply with a success.
      String replyContents = buildReplyDocument(eControlArea, localResponseDoc);
      return getMessage(msg, replyContents);
   
   
    // Process a Delete-Request.
    if (msgAction.equalsIgnoreCase("Delete")) {
      logger.info("[InstitutionalIdentityRequestCommand] Handling an " +
        "org.any-openeai-enterprise.CoreApplication.InstitutionalIdentity." +
        "Delete-Request message.");
      // Get the delete action type.
      Attribute aDeleteType = inDoc.getRootElement().getChild("DataArea").
        getChild("DeleteData").getChild("DeleteAction").getAttribute("type");                
      String deleteAction = aDeleteType.getValue();

      // Verify that the delete action is valid. If it is not, reply with an
      // error.
      if (deleteAction.equalsIgnoreCase("delete") == false &&
        deleteAction.equalsIgnoreCase("purge") == false) {
        String errType = "application";
        String errCode = "OpenEAI-1008";
        String errDesc = "Invalid delete action type. Only delete actions of " +
          "type 'delete' and 'purge' are allowed.";
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
          "is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }

      // If the delete action is of type purge and purge support is presently
      // disabled, reply with an error.
      if (deleteAction.equalsIgnoreCase("purge") &&
        m_allowPurge == false) {
        String errType = "application";
        String errCode = "OpenEAI-1009";
        String errDesc = "Purge disabled. The delete action type of purge is " +
          "supported by this implementation, but it is presently disabled.";
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent " +
          "in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }
     
      // Get the delete element.
      Element deleteElement = inDoc.getRootElement().getChild("DataArea").
        getChild("DeleteData").getChild("InstitutionalIdentity");

      // Verify that the delete element is an InstitutionalIdentity and that it
      // is not null. If it is null, reply with an error.
      if (deleteElement == null) {
        String errType = "application";
        String errCode = "OpenEAI-1010";
        String errDesc = "Invalid delete element found in the Delete-Request " +
          "message. This command expects an ApplicationSession.";
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
          "is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }

      // Get a configured InstitutionalIdentity object out of AppConfig.
      InstitutionalIdentity instIdent = new InstitutionalIdentity();
      try {
        instIdent = (InstitutionalIdentity)getAppConfig().
          getObject("InstitutionalIdentity");
      }
      catch (EnterpriseConfigurationObjectException eoce) {
        // An error occurred retrieving an InstitutionalIdentity object from
        // AppConfig. Log it and throw an exception.
        String errMsg = "An error occurred retrieving an Institutional" +
          "Identity object from AppConfig. The exception is: " +
          eoce.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errMsg);
      }
     
      // Try to build the InstitutionalIdentity object from the delete Element.
      try {
        instIdent.buildObjectFromInput(deleteElement);
      }
      catch (EnterpriseLayoutException ele) {
        // There was an error building the InstitutionalIdentity object from the
        // delete element.
        String errType = "application";
        String errCode = "InstitutionalIdentityService-1009";
        String errDesc = "Error building the InstitutionalIdentity object " +
          "from the InstitutionalIdentity element in the Delete-Request " +
          "message. The exception is: " + ele.getMessage();
        logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
        logger.fatal("Message sent in is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);     
      }

      // Set the TestId.
      instIdent.setTestId(testId);

      // Delete the InstitutionalIdentity.
      try {
        m_i2sRepository.deleteInstitutionalIdentity(deleteAction, instIdent);       
      }
      catch (I2sRepositoryException i2sre) {
        String errType = "system";
        String errCode = "InstitutionalIdentityService-1010";
        String errDesc = "Error accessing the I2sRepository to perform a " +
          "delete action of type '" + deleteAction + "' for the " +
          "InstitutionalIdentity. The exception is: " + i2sre.getMessage();      
        logger.fatal("[InstitutionalIdentityRequestCommand]" + errDesc);
        logger.fatal("[InstitutionalIdentityRequestCommand] Message sent in " +
          "is: \n" + getMessageBody(inDoc));
        ArrayList errors = new ArrayList();
        errors.add(buildError(errType, errCode, errDesc));
        String replyContents =
          buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
        return getMessage(msg, replyContents);
      }

      // Reply with a success.
      String replyContents = buildReplyDocument(eControlArea, localResponseDoc);
      return getMessage(msg, replyContents);
    }

    else {
      // The messageAction is invalid; it is not a query, generate, update, or
      // delete.
      String errType = "application";
      String errCode = "OpenEAI-1002";
      String errDesc = "Unsupported message action: " + msgAction + ". " +
        "This command only supports 'query', 'generate', 'update', and 'delete'.";
      logger.fatal("[InstitutionalIdentityRequestCommand] " + errDesc);
      logger.fatal("Message sent in is: \n" + getMessageBody(inDoc));
      ArrayList errors = new ArrayList();
      errors.add(buildError(errType, errCode, errDesc));
      String replyContents =
        buildReplyDocumentWithErrors(eControlArea, localResponseDoc, errors);
      return getMessage(msg, replyContents);
    }
  }
}
TOP

Related Classes of org.any_openeai_enterprise.services.i2s.commands.InstitutionalIdentityRequestCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.