Package edu.uga.galileo.voci.model

Examples of edu.uga.galileo.voci.model.MetadataManager


   */
  private static HashMap<ContentType, ArrayList<String>> setUpMetadataBlurbFields(
      Command command) {
    HashMap<ContentType, ArrayList<String>> toReturn = new HashMap<ContentType, ArrayList<String>>();
    for (ContentType type : ContentType.documentValues()) {
      toReturn.put(type, (new MetadataManager()).getMetadataBlurbFields(
          command.getProject(), type));
    }

    return toReturn;
  }
View Full Code Here


          newFieldsToBlurbFrom[m] = newFieldsToBlurbFrom[m]
              .substring(2);
          // then fill in the rest of the info that the page expects
          newFieldsToBlurbFrom[m] = newFieldsToBlurbFrom[m]
              + " ("
              + (new MetadataManager())
                  .getDisplayNameByElementAndQualifier(
                      projectId, contentType.getValue(),
                      newFieldsToBlurbFrom[m]) + ")";
        }
      } catch (NoSuchProjectException e) {
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  protected void handleRequest(HttpServletRequest request,
      HttpServletResponse response) {
    Command command = (Command) request.getAttribute("command");
    MetadataManager manager = new MetadataManager();
    ArrayList<String> errors = new ArrayList<String>();
    HashMap<String, String> fieldMessages = new HashMap<String, String>();

    boolean goToMetadataList = false;
    String cancel;

    // parse the "other" data from the Command object into metadata ID
    // and sub-command
    int metadataId = -2;
    String subCommand = "";
    if ((command.getOther() != null) && (command.getOther().size() > 0)) {
      metadataId = Integer.parseInt((String) command.getOther().get(0));
      if (command.getOther().size() > 1) {
        subCommand = (String) command.getOther().get(1);
      }
    } else if (request.getParameter("metadataId") != null) {
      metadataId = Integer.parseInt(request.getParameter("metadataId"));
    }

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

          .getAttribute("user"), command.getProject(), command
          .getCommand(), -1))) {
        return "ERROR: You don't have permission to make this request.";
      }

      MetadataManager manager = new MetadataManager();
      try {
        manager.updateKeyField(projectHandle, contentType, metadataId);
      } catch (NoSuchMetadataException e) {
        return "ERROR: Requested metadata couldn't be located.";
      } catch (SQLException e) {
        return "ERROR: A database error occurred: " + e.toString();
      }
View Full Code Here

      }

      if ((element.isUnique())
          && (!element.getFieldType().startsWith(
              MetadataElement.CHECKBOX_FIELD))) {
        if (!((new MetadataManager()).isUniqueMetadataValue(element
            .getMetadataId(), getId(), getType(), value))) {
          throw new ValidationException(
              "This field's value must be unique, but another "
                  + ContentType.valueOf(getType()).toString()
                      .toLowerCase()
View Full Code Here

TOP

Related Classes of edu.uga.galileo.voci.model.MetadataManager

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.