Package org.openeai.moa.objects.resources

Examples of org.openeai.moa.objects.resources.Error


    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;
View Full Code Here


   * @param errDescription - Detailed description of the error
   * @return ArrayList containing exactly one Error
   */
  protected ArrayList fillErrors (String errType, String errNumber, String errDescription) {
    ArrayList<Error> errors = new ArrayList<Error>();
    Error error = new Error();
    error.setType(errType);
    error.setErrorNumber(errNumber);
    error.setErrorDescription(errDescription);
    errors.add(error);
    return errors;
  }
View Full Code Here

    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("[PasswordSyncCommand.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("[PasswordSyncCommand.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("EnterpriseUserPassword") == 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("[PasswordSyncCommand.execute] " +
          error.getErrorDescription());
      }
      publishSyncError(eControlArea, errors);
      return;
    }

    // Get two configured EnterpriseUserPassword from AppConfig.
    EnterpriseUserPassword currentEntUserPassword = null;
    EnterpriseUserPassword newEntUserPassword = null;
    try {
      currentEntUserPassword = (EnterpriseUserPassword)getAppConfig()
        .getObject("EnterpriseUserPassword");
      newEntUserPassword = (EnterpriseUserPassword)getAppConfig()
        .getObject("EnterpriseUserPassword");
    }
    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 an EnterpriseUserPassword.CreateSync
    if (messageAction.equalsIgnoreCase("Create")) {
     
      // Get the new state of the EnterpriseUserPassword and build an
      // EnterpriseUserPassword object.
      Element eNewPassword = inDoc.getRootElement().getChild("DataArea")
        .getChild("NewData").getChild("EnterpriseUserPassword");
      try
        newEntUserPassword.buildObjectFromInput(eNewPassword);
      }
      catch (EnterpriseLayoutException ele) {
        // An error occurred building the EnterpriseUserPassword object from the
        // EnterpriseUserPassword 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("SakaiGateway-1002");
        error.setErrorDescription("An error occurred building the " +
          "EnterpriseUserPassword object from the EnterpriseUserPassword " +
          "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 database.
      String userId = getUserId(newEntUserPassword);
      String instId = newEntUserPassword.getEnterpriseUser()
        .getLightweightPerson().getInstitutionalId();
      BasicPerson bp=null;
      try {
        logger.info("[PasswordSyncCommand.execute] Querying for BasicPerson.");
        bp = getBasicPerson(instId);
        logger.info("[PasswordSyncCommand.execute] Queried for BasicPerson.");
    } catch (EnterpriseConfigurationObjectException e) {
        // Log it, publish a error message, and return.
        String errMsg = "EnterpriseConfigurationObjectException: " + e.getMessage();
        logger.error("[PasswordSyncCommand.execute] " + errMsg);
        Error error = new Error();
        error.setType("system");
        error.setErrorNumber("SakaiGateway-1014");
        error.setErrorDescription(errMsg);
        errors = new ArrayList();
        errors.add(error);
        logger.info("[PasswordSyncCommand.execute] Publishing Sync.Error-Sync.");
        publishSyncError(eControlArea, errors);
        return
     } catch (EnterpriseFieldException e) {
        // Log it, publish a error message, and return.
        String errMsg = "EnterpriseFieldException: " + e.getMessage();
        logger.error("[PasswordSyncCommand.execute] " + errMsg);
        Error error = new Error();
        error.setType("system");
        error.setErrorNumber("SakaiGateway-1014");
        error.setErrorDescription(errMsg);
        errors = new ArrayList();
        errors.add(error);
       logger.info("[PasswordSyncCommand.execute] Publishing Sync.Error-Sync.");
        publishSyncError(eControlArea, errors);
        return
     } catch (EnterpriseObjectQueryException e) {
        // Log it, publish a error message, and return.
        String errMsg = "EnterpriseObjectQueryException: " + e.getMessage();
        logger.error("[PasswordSyncCommand.execute] " + errMsg);
        Error error = new Error();
        error.setType("system");
        error.setErrorNumber("SakaiGateway-1014");
        error.setErrorDescription(errMsg);
        errors = new ArrayList();
        errors.add(error);
        logger.info("[PasswordSyncCommand.execute] Publishing Sync.Error-Sync.");
        publishSyncError(eControlArea, errors);
        return
     }
  if (bp==null) {
        // No BasicPerson exists for this instId.
        // Log it, publish a error message, and return.
        String errMsg = "No BasicPerson exists for " + instId;
        logger.debug("[PasswordSyncCommand.execute] " + errMsg);
        Error error = new Error();
        error.setType("application");
        error.setErrorNumber("SakaiGateway-1012");
        error.setErrorDescription(errMsg);
        errors = new ArrayList();
        errors.add(error);
        publishSyncError(eControlArea, errors);
        return
      }
      PortalPerson portalPerson = null
      try { portalPerson = retrievePortalPersonByUserId(userId); }
      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("SakaiGateway-2001");
        error.setErrorDescription(errMsg);
        errors = new ArrayList();
        errors.add(error);
        publishSyncError(eControlArea, errors, ce);
        return;
      }

      // If the user does exist, publish a error message indicating
      // that the user already exists.
      if (portalPerson != null) {
        Error error = new Error();
        error.setType("application");
        error.setErrorNumber("SakaiGateway-1011");
        error.setErrorDescription("User with user ID " + userId +
          ") exists in the portal. Cannot reset the password for this user.");
        logger.fatal("[PasswordSyncCommand.execute] " +
          error.getErrorDescription());
        errors = new ArrayList();
        errors.add(error);
        publishSyncError(eControlArea, errors);
        return;
      }

      // Create the portal user with info from BasicPerson and the
      // user's password to be the new value indicated in the message.
      else {
        logger.info("[PasswordSyncCommand.execute] BasicPerson="+bp);
        portalPerson = new PortalPerson();
        portalPerson.setEmailAddress(getEmailAddress(bp.getEmail()));
        portalPerson.setUserId(userId);
        portalPerson.setInstId(instId);
        portalPerson.setFirstName(bp.getName().getFirstName());
        portalPerson.setLastName(bp.getName().getLastName());
       
        // Encypt the password.
        String encryptedPassword=null;
        String cleartextPassword = newEntUserPassword.getPassword().getValue();
        try {
          encryptedPassword = hashPassword(cleartextPassword);
          logger.info("[PasswordSyncCommand.execute] cleartext password is: " +
                  cleartextPassword);
          logger.info("[PasswordSyncCommand.execute] excrypted password is: " +
                  encryptedPassword);
        } catch (NoSuchAlgorithmException nsae) {
          Error error = new Error();
          error.setType("application");
          error.setErrorNumber("SakaiGateway-1002");
          error.setErrorDescription("A NoSuchAlgorithmException occurred encrypting the user " +
            "password. The exception is: " + nsae.getMessage());
          logger.fatal("[PasswordSyncCommand.execute] " +
            error.getErrorDescription());
          errors = new ArrayList();
          errors.add(error);
          publishSyncError(eControlArea, errors, nsae);
          return;
        } catch (MessagingException nsae) {
            Error error = new Error();
            error.setType("application");
            error.setErrorNumber("SakaiGateway-1002");
            error.setErrorDescription("A MessagingException occurred encrypting the user " +
              "password. The exception is: " + nsae.getMessage());
            logger.fatal("[PasswordSyncCommand.execute] " +
              error.getErrorDescription());
            errors = new ArrayList();
            errors.add(error);
            publishSyncError(eControlArea, errors, nsae);
            return;
    } catch (IOException nsae) {
            Error error = new Error();
            error.setType("application");
            error.setErrorNumber("SakaiGateway-2022");
            error.setErrorDescription("An IOException occurred encrypting the user " +
              "password. The exception is: " + nsae.getMessage());
            logger.fatal("[PasswordSyncCommand.execute] " +
              error.getErrorDescription());
            errors = new ArrayList();
            errors.add(error);
            publishSyncError(eControlArea, errors, nsae);
            return;
    }       
       
        portalPerson.setPassword(encryptedPassword);
        try {
      createPortalPerson(portalPerson);
    } catch (CommandException e) {
          Error error = new Error();
          error.setType("system");
          error.setErrorNumber("SakaiGateway-1020");
          String errmsg = "An error occurred building the portal person. The exception is: " +
              e.getMessage();
          error.setErrorDescription(errmsg);
          errors = new ArrayList();
          errors.add(error);
          publishSyncError(eControlArea, errors, e);
          logger.error("[PasswordSyncCommand.execute] Can't create portal person. \n"+errmsg);
          return;
    }
      }
    }

   
    // Handle an EnterpriseUserPassword.Update-Sync.
    if (messageAction.equalsIgnoreCase("Update")) {
     
      // Get the new state of the EnterpriseUserPassword and build an
      // EnterpriseUserPassword object.
      Element eNewPassword = inDoc.getRootElement().getChild("DataArea")
        .getChild("NewData").getChild("EnterpriseUserPassword");
      try
        newEntUserPassword.buildObjectFromInput(eNewPassword);
      }
      catch (EnterpriseLayoutException ele) {
        // An error occurred building the EnterpriseUserPassword object from the
        // EnterpriseUserPassword 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("SakaiGateway-1002");
        error.setErrorDescription("An error occurred building the " +
          "EnterpriseUserPassword object from the EnterpriseUserPassword " +
          "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 database.
      String userId = getUserId(newEntUserPassword);
      PortalPerson portalPerson = null
      try {
        portalPerson = retrievePortalPersonByUserId(userId);
      }
      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("SakaiGateway-2001");
        error.setErrorDescription(errMsg);
        errors = new ArrayList();
        errors.add(error);
        publishSyncError(eControlArea, errors, ce);
        return;
      }

      // If the user does not exist, publish a error message indicating
      // that the user does not exist.
      if (portalPerson == null) {
        Error error = new Error();
        error.setType("application");
        error.setErrorNumber("SakaiGateway-1001");
        error.setErrorDescription("No user with user ID " + userId +
          ") exists in the portal. Cannot reset the password for this user.");
        logger.fatal("[PasswordSyncCommand.execute] " +
          error.getErrorDescription());
        errors = new ArrayList();
        errors.add(error);
        publishSyncError(eControlArea, errors);
        return;
      }

      // Otherwise, the user already exists in the portal, so reset the
      // user's password to be the new value indicated in the message.
      else {
        // Encypt the password.
        String encryptedPassword=null;
        String cleartextPassword = newEntUserPassword.getPassword().getValue();
        try {
          encryptedPassword = hashPassword(cleartextPassword);
          logger.info("[PasswordSyncCommand.execute] cleartext password is: " +
                  cleartextPassword);
          logger.info("[PasswordSyncCommand.execute] excrypted password is: " +
                  encryptedPassword);
        } catch (NoSuchAlgorithmException nsae) {
          Error error = new Error();
          error.setType("application");
          error.setErrorNumber("SakaiGateway-1002");
          error.setErrorDescription("A NoSuchAlgorithmException occurred encrypting the user " +
            "password. The exception is: " + nsae.getMessage());
          logger.fatal("[PasswordSyncCommand.execute] " +
            error.getErrorDescription());
          errors = new ArrayList();
          errors.add(error);
          publishSyncError(eControlArea, errors, nsae);
          return;
        } catch (MessagingException nsae) {
            Error error = new Error();
            error.setType("application");
            error.setErrorNumber("SakaiGateway-1002");
            error.setErrorDescription("A MessagingException occurred encrypting the user " +
              "password. The exception is: " + nsae.getMessage());
            logger.fatal("[PasswordSyncCommand.execute] " +
              error.getErrorDescription());
            errors = new ArrayList();
            errors.add(error);
            publishSyncError(eControlArea, errors, nsae);
            return;
    } catch (IOException nsae) {
            Error error = new Error();
            error.setType("application");
            error.setErrorNumber("SakaiGateway-1002");
            error.setErrorDescription("An IOException occurred encrypting the user " +
              "password. The exception is: " + nsae.getMessage());
            logger.fatal("[PasswordSyncCommand.execute] " +
              error.getErrorDescription());
            errors = new ArrayList();
            errors.add(error);
            publishSyncError(eControlArea, errors, nsae);
            return;
    }

        // Update the password in the database.
        try { updatePassword(userId, encryptedPassword); }
        catch (CommandException ce) {
          // An error occurred accessing the database to update the user
          // password. Log it, publish a error message, and return.
          String errMsg = "An error occurred accessing the database to " +
            "update the user password.";
          logger.debug("[PasswordSyncCommand.execute] " + errMsg);
          Error error = new Error();
          error.setType("system");
          error.setErrorNumber("SakaiGateway-2001");
          error.setErrorDescription(errMsg);
          errors = new ArrayList();
          errors.add(error);
          publishSyncError(eControlArea, errors, ce);
          return;
        }
       
        return
      }
    }

    // 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;
View Full Code Here

    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("[PasswordSyncCommand.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("[PasswordSyncCommand.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("EnterpriseUserPassword") == 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("[PasswordSyncCommand.execute] " +
          error.getErrorDescription());
      }
      publishSyncError(eControlArea, errors);
      return;
    }

    // Get two configured EnterpriseUserPassword from AppConfig.
    EnterpriseUserPassword currentEntUserPassword = null;
    EnterpriseUserPassword newEntUserPassword = null;
    try {
      currentEntUserPassword = (EnterpriseUserPassword)getAppConfig()
        .getObject("EnterpriseUserPassword");
      newEntUserPassword = (EnterpriseUserPassword)getAppConfig()
        .getObject("EnterpriseUserPassword");
    }
    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 an EnterpriseUserPassword.CreateSync or an
    // EnterpriseUserPassword.Update-Sync.
    if (messageAction.equalsIgnoreCase("Create") ||
        messageAction.equalsIgnoreCase("Update")) {
     
      // Get the new state of the EnterpriseUserPassword and build an
      // EnterpriseUserPassword object.
      Element eNewPassword = inDoc.getRootElement().getChild("DataArea")
        .getChild("NewData").getChild("EnterpriseUserPassword");
      try
        newEntUserPassword.buildObjectFromInput(eNewPassword);
      }
      catch (EnterpriseLayoutException ele) {
        // An error occurred building the EnterpriseUserPassword object from the
        // EnterpriseUserPassword 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("UportalGateway-1002");
        error.setErrorDescription("An error occurred building the " +
          "EnterpriseUserPassword object from the EnterpriseUserPassword " +
          "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 database.
      String instId = newEntUserPassword.getEnterpriseUser()
        .getLightweightPerson().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 the user does not exist, publish a error message indicating
      // that the user does not exist.
      if (portalPerson == null) {
        Error error = new Error();
        error.setType("application");
        error.setErrorNumber("UportalGateway-1001");
        error.setErrorDescription("No user with user ID " + instId +
          ") exists in the portal. Cannot reset the password for this user.");
        logger.fatal("[PasswordSyncCommand.execute] " +
          error.getErrorDescription());
        errors = new ArrayList();
        errors.add(error);
        publishSyncError(eControlArea, errors);
        return;
      }

      // Otherwise, the user already exists in the portal, so reset the
      // user's password to be the new value indicated in the message.
      else {
        // Encypt the password.
        String cleartextPassword = newEntUserPassword.getPassword().getValue();
        byte[] hash, rnd = new byte[8], fin = new byte[24];
        Long date = new Long((new java.util.Date()).getTime());
        SecureRandom r = new SecureRandom((date.toString()).getBytes());
        MessageDigest md = null;
        try { md = MessageDigest.getInstance("MD5"); }
        catch (NoSuchAlgorithmException nsae) {
          Error error = new Error();
          error.setType("application");
          error.setErrorNumber("UportalGateway-1002");
          error.setErrorDescription("An error occurred encrypting the user " +
            "password. The exception is: " + nsae.getMessage());
          logger.fatal("[PasswordSyncCommand.execute] " +
            error.getErrorDescription());
          errors = new ArrayList();
          errors.add(error);
          publishSyncError(eControlArea, errors, nsae);
          return;
        }
        r.nextBytes(rnd);
        md.update(rnd);
        hash = md.digest(cleartextPassword.getBytes());
        System.arraycopy(rnd, 0, fin, 0, 8);
        System.arraycopy(hash, 0, fin, 8, 16);
        String encryptedPassword = "(MD5)"+encode(fin);
        logger.debug("[PasswordSyncCommand.execute] cleartext password is: " +
          cleartextPassword);
        logger.debug("[PasswordSyncCommand.execute] excrypted password is: " +
          encryptedPassword);

        // Update the password in the database.
        try { updatePassword(instId, encryptedPassword); }
        catch (CommandException ce) {
          // An error occurred accessing the database to update the user
          // password. Log it, publish a error message, and return.
          String errMsg = "An error occurred accessing the database to " +
            "update the user password.";
          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;
        }
       
        return
      }
    }

    // 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;
View Full Code Here

    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("[" + getServiceName() + ".execute]" +
        error.getErrorDescription());
      return;
    }

    // Get the message metadata.
    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("[" + getServiceName() + ".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("EnterpriseUserPassword") == 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("[" + getServiceName() + ".execute] " +
          error.getErrorDescription());
      }
      publishSyncError(eControlArea, errors);
      return;
    }

    // Get two configured EnterpriseUserPassword from AppConfig.
    EnterpriseUserPassword currentEntUserPassword = null;
    EnterpriseUserPassword newEntUserPassword = null;
    try {
      currentEntUserPassword = (EnterpriseUserPassword)getAppConfig()
        .getObject("EnterpriseUserPassword");
      newEntUserPassword = (EnterpriseUserPassword)getAppConfig()
        .getObject("EnterpriseUserPassword");
    }
    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 an EnterpriseUserPassword.Create-Sync
    if (messageAction.equalsIgnoreCase("Create")) {
      logger.info("[" + getServiceName() + ".execute] Handling an " +
        "EnterpriseUserPassword.Create-Sync message.");
       
      // Get the new state of the EnterpriseUserPassword and build an
      // EnterpriseUserPassword object.
      Element eNewPassword = inDoc.getRootElement().getChild("DataArea")
        .getChild("NewData").getChild("EnterpriseUserPassword");
      try { newEntUserPassword.buildObjectFromInput(eNewPassword); }
      catch (EnterpriseLayoutException ele) {
        // An error occurred building the EnterpriseUserPassword object from the
        // EnterpriseUserPassword 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 " +
          "EnterpriseUserPassword object from the EnterpriseUserPassword " +
          "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 is the directory server.
      LightweightPerson lPerson = newEntUserPassword.getEnterpriseUser()
        .getLightweightPerson();
      String userName = "";
      if (lPerson.getName() != null) userName = lPerson.getName().getFirstName()
        + " " + lPerson.getName().getLastName();

      logger.debug("[" + getServiceName() + ".execute] Querying the directory to " +
        "determine if the user whose password has changed already exists " +
        "in the directory.");

      // Specify the search filter for the directory service query using
      // the employeeNumber.
      String filter = "employeeNumber=" + lPerson.getInstitutionalId();
      logger.debug("[" + getServiceName() + ".execute] Search filter is: " + filter);

      // Specify the providerUrl.
      String providerUrl = getUserDirectoryTreeBase();
      logger.debug("[" + getServiceName() + ".execute] providerUrl is: " +
        providerUrl);

      // Specify search controls that set the scope of the search.
      SearchControls cons = new SearchControls();
      cons.setSearchScope(SearchControls.ONELEVEL_SCOPE);
      String[] attrs = new String[1];
      attrs[0] = "uid";
      cons.setReturningAttributes(attrs);

      // Search for user entries that match the employeeNumber, retrieving
      // the uid.
      NamingEnumeration results = null;
      boolean userExists = false;
      try {
        logger.debug("[" + getServiceName() + ".execute] Querying the directory " +
          "server.");
        results = getDirContext().search(providerUrl, filter, cons);
        if (results != null && results.hasMore() == true) userExists = true;  
      }
      catch (NamingException ne) {
        // An error occurred querying the directory server to determine whether
        // the user exists. Log it, publich a error message, and return.
        String errMsg = "An error occurred querying the directory server to " +
          "determine whether the user exists.";
        logger.debug("[" + getServiceName() + ".execute] " + errMsg);
        Error error = new Error();
        error.setType("system");
        error.setErrorNumber("DirectoryServiceGateway-2002");
        error.setErrorDescription(errMsg);
        errors = new ArrayList();
        errors.add(error);
        publishSyncError(eControlArea, errors, ne);
        return;
      }

      // If there are no matching entries, the user does not exist. If the
      // createMissingUsers property is true, create the user with attribute
      // and password indicated in the new data of the message. If the
      // createMissingUsers property is false, publish a Sync.Error-Sync
      // indicating that the password cannot be set for this user, because
      // the user does not exist.
      if (userExists == false) {
        logger.info("[" + getServiceName() + ".execute] The user " + userName +
          "(" + lPerson.getInstitutionalId() +
          ") does not exist in the directory.");

        if (getCreateMissingUsers() == true) {
          // Create the user.
          // -- Build the attributes for the new directory entry.
          BasicAttributes attributes = buildDirectoryUser(newEntUserPassword);

          // -- Create the new subcontext for the entry.
          String dn = "uid=" + getEnterpriseId(newEntUserPassword
            .getEnterpriseUser()).getPrincipal() + "," +
            getUserDirectoryTreeBase();
          logger.debug("[" + getServiceName() + ".execute] dn for the new " +
            "directory context is: " + dn);
          try {
            logger.debug("[" + getServiceName() + ".execute] Creating directory " +
              "user with attributes: " + attributes.toString());
            Context result = getDirContext().createSubcontext(dn, attributes);
            logger.info("[" + getServiceName() + ".execute] Created directory " +
              "user.");
          }
          catch (NamingException ne) {
            // An error occurred creating the entry for the user in the
            // directory server. Log it, publich a error message, and return.
            String errMsg = "An error occurred creating the entry for the " +
              "user in the directory server.";
            logger.debug("[" + getServiceName() + ".execute] " + errMsg);
            Error error = new Error();
            error.setType("system");
            error.setErrorNumber("DirectoryServiceGateway-2002");
            error.setErrorDescription(errMsg);
            errors = new ArrayList();
            errors.add(error);
            publishSyncError(eControlArea, errors, ne);
            return;
          }
          return;
        }
        else {
          // The createMissingUsers property is false, so we will not create
          // the missing user.
          logger.info("[" + getServiceName() + ".execute] createMissingUsers is " +
            "false, so the missing user will not be created and the " +
            "cannot be set.");
          return;
        }
      }
      else {
        // Otherwise, the user already exists, so the user does not have to be
        // created. Log it and return.
        logger.info("[" + getServiceName() + ".execute] The directory user already "
            + "exists, so the user does not need to be created.");
        return;
      }
    }

    // Handle an EnterpriseUserPassword.Update-Sync
    if (messageAction.equalsIgnoreCase("Update")) {
      // Get the baseline state of the EnterpriseUserPassword and build an
      // EnterpriseUserPassword object.
      Element eBaselinePassword = inDoc.getRootElement().getChild("DataArea")
        .getChild("BaselineData").getChild("EnterpriseUserPassword");
      try
        currentEntUserPassword.buildObjectFromInput(eBaselinePassword);
      }
      catch (EnterpriseLayoutException ele) {
        // An error occurred building the EnterpriseUserPassword object from the
        // EnterpriseUserPassword 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 " +
          "EnterpriseUserPassword object from the EnterpriseUserPassword " +
          "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 EnterpriseUserPassword and build an
      // EnterpriseUserPassword object.
      Element eNewPassword = inDoc.getRootElement().getChild("DataArea")
        .getChild("NewData").getChild("EnterpriseUserPassword");
      try
        newEntUserPassword.buildObjectFromInput(eNewPassword);
      }
      catch (EnterpriseLayoutException ele) {
        // An error occurred building the EnterpriseUserPassword object from the
        // EnterpriseUserPassword 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 " +
          "EnterpriseUserPassword object from the EnterpriseUserPassword " +
          "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 is the directory server.
      LightweightPerson lPerson = newEntUserPassword.getEnterpriseUser()
        .getLightweightPerson();
      String userName = "";
      if (lPerson.getName() != null) userName = lPerson.getName().getFirstName()
        + " " + lPerson.getName().getLastName();

      logger.debug("[" + getServiceName() + ".execute] Querying the directory to " +
        "see if the user whose password has changed already exists in the " +
        "directory.");

      // Specify the search filter for the directory service query using
      // the uniqueMember and the uniquePermission built above.
      String filter = "employeeNumber=" + lPerson.getInstitutionalId();
      logger.debug("[" + getServiceName() + ".execute] Search filter is: " + filter);

      // Specify the providerUrl.
      String providerUrl = getUserDirectoryTreeBase();
      logger.debug("[" + getServiceName() + ".execute] providerUrl is: " +
        providerUrl);

      // Specify search controls that set the scope of the search.
      SearchControls cons = new SearchControls();
      cons.setSearchScope(SearchControls.ONELEVEL_SCOPE);
      String[] attrs = new String[1];
      attrs[0] = "uid";
      cons.setReturningAttributes(attrs);

      // Search for user entries that match the employeeNumber, retrieving
      // the uid.
      try {
        logger.debug("[" + getServiceName() + ".execute] Querying the directory " +
          "server.");
        NamingEnumeration results = getDirContext().search(providerUrl, filter,
          cons);

        // If there are no matching entries, publish a error message indicating
        // that the user does not exist.
        if (results == null || results.hasMore() == false) {
          Error error = new Error();
          error.setType("application");
          error.setErrorNumber("DirectoryServiceGateway-1005");
          error.setErrorDescription("No user " + userName + "(" +
            lPerson.getInstitutionalId() + ") exists in the directory. " +
            "Cannot reset the password for this user.");
          logger.fatal("[" + getServiceName() + ".execute] " +
            error.getErrorDescription());
          errors = new ArrayList();
          errors.add(error);
          publishSyncError(eControlArea, errors);
          return;
        }

        // Otherwise, the user already exists in the directory, so reset the
        // user's password to be the new value indicated in the message.
        else {
          // -- Get the dn for the EnterpriseUser.
          NetId enterpriseId = new NetId();
          enterpriseId = getEnterpriseId(newEntUserPassword.getEnterpriseUser());
          String dn = "uid=" + enterpriseId.getPrincipal() + "," + getUserDirectoryTreeBase();

          // Specify the modification.
          String newPassword = newEntUserPassword.getPassword().getValue();
          // SHA algorithm is assumed here.  Maybe this should be made configurable.
          String shaPw = makeSHA(newPassword);
          Attribute userPassword = new BasicAttribute("userPassword");
          userPassword.add(shaPw);
          ModificationItem[] mods = new ModificationItem[1];
          mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, userPassword);
      
          // Perform the modification.
          try {
            logger.debug("[" + getServiceName() + ".execute] Modifying the "
              + "userPassword attribute for user " + dn + " to be '" +
              newPassword + "'...");

            getDirContext().modifyAttributes(dn, mods);

            logger.info("[" + getServiceName() + ".execute] Modified the " +
              "userPassword attribute for user " + dn + ".");
          }
          catch (NamingException ne) {
            // An error occurred resetting the user's password. Log it and
            // publish a sync error message.
            Error error = new Error();
            error.setType("system");
            error.setErrorNumber("DirectoryServiceGateway-1003");
            error.setErrorDescription("An error occurred resetting the user's " +
              "password. The exception is: " + ne.getMessage());
            logger.fatal("[" + getServiceName() + ".execute] " +
              error.getErrorDescription());
            errors = new ArrayList();
            errors.add(error);
            publishSyncError(eControlArea, errors, ne);
            return;
          }
          return
        }
      }
      catch (NamingException ne) {
        // An error occurred determining whether the user exists in the
        // directory. Log it and publish a sync error message.
        Error error = new Error();
        error.setType("system");
        error.setErrorNumber("DirectoryServiceGateway-1004");
        error.setErrorDescription("An error occurred determining whether the " +
          "user exists in the directory. The exception is: " + ne.getMessage());
        logger.fatal("[" + getServiceName() + ".execute] " +
          error.getErrorDescription());
        errors = new ArrayList();
        errors.add(error);
        publishSyncError(eControlArea, errors, ne);
        return;
      }
    }

    // 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;
View Full Code Here

    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;
    }
   
    logger.info("[BasicPersonSyncCommand.execute] "+messageAction+" is the requested action.");
   
    // Handle a BasicPerson.Delete-Sync
    if (messageAction.equalsIgnoreCase("Delete")) {
      logger.info("[BasicPersonSyncCommand.execute] Ignoring BasicPerson.Delete-Sync...");
    }

    // Do not handle a BasicPerson.Create-Sync
    if (messageAction.equalsIgnoreCase("Create")) {
      logger.info("[BasicPersonSyncCommand.execute] Ignoring BasicPerson.Create-Sync...");
    }

    // 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("SakaiGateway-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 = retrievePortalPersonByInstId(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("[BasicPersonSyncCommand.execute] " + errMsg);
        Error error = new Error();
        error.setType("system");
        error.setErrorNumber("SakaiGateway-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("SakaiGateway-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=getEmailAddress(newBasicPerson.getEmail());


        // 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("SakaiGateway-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
            .getInstId() + ").");
        }
      }     
    }

    // 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;
View Full Code Here

    logger.info("[" + getServiceName() + ".execute] Received a(n) " + messageCategory  + "." + messageObject + "." + messageAction + "-" +
        messageType + " (release " + messageRelease + ") message.");
   
    // Verify that this is a message we support.
    if (messageObject.equalsIgnoreCase("EnterpriseUser") == 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(error);
    }
    if (errors.size() > 0) {
      ListIterator iterator = errors.listIterator();
      while (iterator.hasNext()) {
        Error error = (Error)iterator.next();
        logger.fatal("[" + getServiceName() + ".execute] " + error.getErrorDescription());
      }
      publishSyncError(getControlArea(null), errors);
      return;
    }
   
View Full Code Here

        messageCategory  + "." + messageObject + "." + messageAction + "-" +
        messageType + " (release " + messageRelease + ") message.");
   
    // Verify that this is a message we support.
    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(error);
    }
    if (errors.size() > 0) {
      ListIterator iterator = errors.listIterator();
      while (iterator.hasNext()) {
        Error error = (Error)iterator.next();
        logger.fatal("[" + getServiceName() + ".execute] " +
            error.getErrorDescription());
      }
      publishSyncError(eControlArea, errors);
      return;
    }
   
View Full Code Here

TOP

Related Classes of org.openeai.moa.objects.resources.Error

Copyright © 2018 www.massapicom. 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.