Package edu.uga.galileo.voci.bo

Examples of edu.uga.galileo.voci.bo.MetadataElement


    // the delete action's being performed from the metadata list
    if (subCommand.equals("del")) {
      try {
        // we really disable, though we talk about deleting to the user
        MetadataElement element = manager
            .getMetadataElement(metadataId);
        if (element.isKeyField()) {
          errors.add("Key fields can not be deleted.");
        } else {
          manager.deleteMetadata(element);
          request.setAttribute("successMessage", "Metadata element ("
              + metadataId + ") successfully deleted.");
        }
      } catch (NumberFormatException e) {
        request.setAttribute("errorMessage",
            "The metadata ID requested (" + metadataId
                + ") couldn't be located to delete.");
      } catch (NoSuchMetadataException e) {
        request.setAttribute("errorMessage",
            "The metadata ID requested (" + metadataId
                + ") couldn't be located to delete: "
                + e.getMessage());
      }

      goToMetadataList = true;

    } else
    // ... and this one is for re-ordering from the metadata list
    if ((subCommand.equals("down")) || (subCommand.equals("up"))) {
      try {
        // "up" in the GUI means "down" in the ordering, so the
        // true/false here may look a little goofy
        manager.moveMetadata(manager.getMetadataElement(metadataId),
            subCommand.equals("down") ? true : false);
        request.setAttribute("successMessage", "Metadata element "
            + metadataId + " successfully moved.");
      } catch (NumberFormatException e) {
        request.setAttribute("errorMessage",
            "The metadata ID requested (" + metadataId
                + ") couldn't be located to move.");
      } catch (NoSuchMetadataException e) {
        request.setAttribute("errorMessage",
            "The metadata ID requested (" + metadataId
                + ") couldn't be located to move: "
                + e.getMessage());
      }

      goToMetadataList = true;
    } else
    // cancel the changes
    if (((cancel = request.getParameter("cancelChanges")) != null)
        && (cancel.equals("yes"))) {
      request.setAttribute("successMessages",
          "Your changes have been cancelled.");
      goToMetadataList = true;
    } else
    // all other commands (user is adding or updating an element, or
    // retrieving from history)
    if (metadataId != -2) {
      AuditLogManager alm = null;
      MetadataElement elem = null;
      try {
        if (metadataId == -1) {
          // -1 is for a blank form request from the list, asking
          // to add a new element
          elem = new MetadataElement();
          try {
            elem.setIndexMultiplier(1);
          } catch (ValidationException e) {
            // won't happen
          }
          elem.setMetadataId(-1);
          elem.setProjectId(((Project) ((HashMap) getServletContext()
              .getAttribute("projectMap")).get(command
              .getProject())).getProjectId());
          if (subCommand.equals("kf")) {
            elem.setIsKeyField(true);
          }
        } else if (subCommand.equals("history")) {
          alm = new AuditLogManager();
          String[] vals = command.getOther().get(2).split("\\|");
          try {
            AuditLog record = alm.getRecord(Integer
                .parseInt(vals[0]), ContentType.valueOf(Integer
                .parseInt(vals[1])), metadataId, Timestamp
                .valueOf(vals[2]));
            String data = record.getDataExport();
            elem = new MetadataElement();
            elem.fromString(data);
            request.setAttribute("isDirty", "t");
          } catch (NullPointerException e) {
            errors.add("Invalid history request format.");
          } catch (NumberFormatException e) {
            errors.add("Invalid history request format.");
          } catch (NoSuchAuditLogRecordException e) {
            errors
                .add("The history record requested couldn't be located.");
          } catch (DataTypeMismatchException e) {
            Logger.error("Data type mismatch occurred pulling "
                + command.getOther().get(0)
                + " from the audit log", e);
            errors
                .add("A system error was encountered (DataTypeMismatch). "
                    + "Please contact a system administrator.");
          }

          if (elem == null) {
            elem = manager.getMetadataElement(metadataId);
          }
        } else {
          elem = manager.getMetadataElement(metadataId);
        }
      } catch (NumberFormatException e) {
        request.setAttribute("errorMessage",
            "Invalid metadata ID requested.");
      } catch (NoSuchMetadataException e) {
        request.setAttribute("errorMessage",
            "The requested metadata element could not be found.");
      }

      if (request.getParameter("projectId") != null) {
        // this is an add/update from the form
        String oldContent = elem.toString();
        populateVBOFromRequest(elem, request, fieldMessages, true);
        if (oldContent.equals(elem.toString())) {
          errors.add("No changes detected.");
        }

        if ((fieldMessages.size() == 0) && (errors.size() == 0)) {
          try {
            elem
                .setContentType(ContentType.valueOf(
                    command.getModifier().toUpperCase())
                    .getValue());
            if (elem.getMetadataId() == -1) {
              manager.addMetadata(((User) request.getSession()
                  .getAttribute("user")), elem);
            } else {
              manager.updateMetadata(elem, oldContent,
                  ((User) request.getSession().getAttribute(
                      "user")));
            }

            request
                .setAttribute(
                    "successMessage",
                    "Your metadata element ("
                        + elem
                            .getFriendlyElementQualifierName()
                        + ") was successfully updated.");
            goToMetadataList = true;
          } catch (NoSuchMetadataException e) {
            errors
                .add("Couldn't find the metadata element for updating, or an ID for adding.");
          }
        }

        if (fieldMessages.size() != 0) {
          String plural = "";
          if (fieldMessages.size() > 1) {
            plural = "s";
          }
          errors.add("Form field" + plural
              + " failed validation (see below).");
        }
      }

      if ((elem != null) && (!goToMetadataList)) {
        request.setAttribute("metadata", elem);
        // put the project's history in the request scope (the project
        // itself is in the application scope)
        if (elem.getMetadataId() != -1) {
          if (alm == null) {
            alm = new AuditLogManager();
          }
          ArrayList<AuditLog> historyRecords = alm.getUpdateRecords(
              ((HashMap<String, Project>) getServletContext()
                  .getAttribute("projectMap")).get(
                  command.getProject()).getProjectId(),
              ContentType.METADATA, elem.getMetadataId());
          if ((historyRecords != null) && (historyRecords.size() > 0)) {
            request.setAttribute("history", historyRecords);
          }
        }
      } else if (elem == null) {
View Full Code Here


  public String getDisplayNameByElementAndQualifier(int projectId,
      int contentType, String element, String qualifier) {
    String key = projectId + "|" + contentType;
    if (typeToMetadataMap.containsKey(key)) {
      ArrayList<MetadataElement> elems = typeToMetadataMap.get(key);
      MetadataElement elem;
      for (int m = 0; m < elems.size(); m++) {
        elem = elems.get(m);
        if ((elem.getElement().equals(element))
            && (((qualifier == null) && (elem.getQualifier() == null)) || ((qualifier != null)
                && (elem.getQualifier() != null) && (elem
                .getQualifier().equals(qualifier))))) {
          return elem.getDisplayName();
        }
      }
    }

    return null;
View Full Code Here

   * @throws NoSuchMetadataException
   *             If no element matches the requested ID.
   */
  public MetadataElement getMetadataElement(int id)
      throws NoSuchMetadataException {
    MetadataElement elem = mdao.getMetadataElement(id);
    return elem;
  }
View Full Code Here

      // TODO: parse through the results, and do the special char
      // replacements and validation
      VociBusinessObject vbo;
      ArrayList<MetadataElement> metadataElements;
      MetadataElement metadataElement;
      String metadataValue;
      CommunityManager communityManager = new CommunityManager();
      CollectionManager collectionManager = new CollectionManager();
      BundleManager bundleManager = new BundleManager();
      ItemManager itemManager = new ItemManager();
      for (int m = 0; m < results.size(); m++) {
        vbo = results.get(m);
        Logger.debug("trying to import '" + vbo.getMetadataBasedTitle()
            + "' of type " + ContentType.valueOf(vbo.getType()));
        metadataElements = MetadataManager.getMetadataList(
            (new ProjectManager()).getProjectID(project), vbo
                .getType());
        for (int n = 0; n < metadataElements.size(); n++) {
          metadataElement = metadataElements.get(n);
          metadataValue = vbo.getMetadataData(metadataElement
              .getElement(), metadataElement.getQualifier());
          if (metadataValue == null) {
            metadataValue = "";
          }
          vbo.addToMetadataRegistry(metadataElement.getMetadataId(),
              metadataValue);
          try {
            vbo.validateMetadata(metadataElement, metadataValue);
          } catch (ValidationException e) {
            vbo.addToImportErrorHolder("Validation error on "
                + metadataElement
                    .getFriendlyElementQualifierName()
                + ": " + e.getMessage(), true);
          }
        }
View Full Code Here

TOP

Related Classes of edu.uga.galileo.voci.bo.MetadataElement

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.