public void addBody(Body body) throws WingException, SQLException, AuthorizeException {
    // Get all our parameters
    MetadataSchema[] schemas = MetadataSchema.findAll(context);
    String idsString = parameters.getParameter("fieldIDs", null);

    ArrayList<MetadataField> fields = new ArrayList<MetadataField>();
    for (String id : idsString.split(",")) {
      MetadataField field = MetadataField.find(context, Integer.valueOf(id));
      fields.add(field);
    }

    // DIVISION: metadata-field-move
    Division moved =
        body.addInteractiveDivision(
            "metadata-field-move",
            contextPath + "/admin/metadata-registry",
            Division.METHOD_POST,
            "primary administrative metadata-registry");
    moved.setHead(T_head1);
    moved.addPara(T_para1);

    Table table = moved.addTable("metadata-field-move", fields.size() + 1, 3);
    Row header = table.addRow(Row.ROLE_HEADER);
    header.addCell().addContent(T_column1);
    header.addCell().addContent(T_column2);
    header.addCell().addContent(T_column3);

    for (MetadataField field : fields) {
      String fieldID = String.valueOf(field.getID());
      String fieldEelement = field.getElement();
      String fieldQualifier = field.getQualifier();

      MetadataSchema schema = MetadataSchema.find(context, field.getSchemaID());
      String schemaName = schema.getName();

      String fieldName = schemaName + "." + fieldEelement;
      if (fieldQualifier != null && fieldQualifier.length() > 0) fieldName += "." + fieldQualifier;

      String fieldScopeNote = field.getScopeNote();

      Row row = table.addRow();
      row.addCell().addContent(fieldID);
      row.addCell().addContent(fieldName);
      row.addCell().addContent(fieldScopeNote);
    }

    Row row = table.addRow();
    Cell cell = row.addCell(1, 3);
    cell.addContent(T_para2);
    Select toSchema = cell.addSelect("to_schema");
    for (MetadataSchema schema : schemas) {
      toSchema.addOption(schema.getID(), schema.getNamespace());
    }

    Para buttons = moved.addPara();
    buttons.addButton("submit_move").setValue(T_submit_move);
    buttons.addButton("submit_cancel").setValue(T_submit_cancel);

    moved.addHidden("administrative-continue").setValue(knot.getId());
  }
Exemple #2
0
    List<DCValue> get(Context c, int resourceId, int resourceTypeId, Logger log)
        throws SQLException {
      if (metadata == null) {
        metadata = new ArrayList<DCValue>();

        // Get Dublin Core metadata
        TableRowIterator tri = retrieveMetadata(resourceId, resourceTypeId);

        if (tri != null) {
          try {
            while (tri.hasNext()) {
              TableRow resultRow = tri.next();

              // Get the associated metadata field and schema information
              int fieldID = resultRow.getIntColumn("metadata_field_id");
              MetadataField field = MetadataField.find(c, fieldID);

              if (field == null) {
                log.error("Loading item - cannot find metadata field " + fieldID);
              } else {
                MetadataSchema schema = MetadataSchema.find(c, field.getSchemaID());
                if (schema == null) {
                  log.error(
                      "Loading item - cannot find metadata schema "
                          + field.getSchemaID()
                          + ", field "
                          + fieldID);
                } else {
                  // Make a DCValue object
                  DCValue dcv = new DCValue();
                  dcv.element = field.getElement();
                  dcv.qualifier = field.getQualifier();
                  dcv.value = resultRow.getStringColumn("text_value");
                  dcv.language = resultRow.getStringColumn("text_lang");
                  // dcv.namespace = schema.getNamespace();
                  dcv.schema = schema.getName();
                  dcv.authority = resultRow.getStringColumn("authority");
                  dcv.confidence = resultRow.getIntColumn("confidence");

                  // Add it to the list
                  metadata.add(dcv);
                }
              }
            }
          } finally {
            // close the TableRowIterator to free up resources
            if (tri != null) {
              tri.close();
            }
          }
        }
      }

      return metadata;
    }
  /**
   * Utility method for pattern-matching metadata elements. This method will return <code>true
   * </code> if the given schema, element, qualifier and language match the schema, element,
   * qualifier and language of the <code>DCValue</code> object passed in. Any or all of the element,
   * qualifier and language passed in can be the <code>Item.ANY</code> wildcard.
   *
   * @param schema the schema for the metadata field. <em>Must</em> match the <code>name</code> of
   *     an existing metadata schema.
   * @param element the element to match, or <code>Item.ANY</code>
   * @param qualifier the qualifier to match, or <code>Item.ANY</code>
   * @param language the language to match, or <code>Item.ANY</code>
   * @param metadataValue the Dublin Core value
   * @return <code>true</code> if there is a match
   */
  protected boolean match(
      String schema,
      String element,
      String qualifier,
      String language,
      MetadataValue metadataValue) {

    MetadataField metadataField = metadataValue.getMetadataField();
    MetadataSchema metadataSchema = metadataField.getMetadataSchema();
    // We will attempt to disprove a match - if we can't we have a match
    if (!element.equals(Item.ANY) && !element.equals(metadataField.getElement())) {
      // Elements do not match, no wildcard
      return false;
    }

    if (qualifier == null) {
      // Value must be unqualified
      if (metadataField.getQualifier() != null) {
        // Value is qualified, so no match
        return false;
      }
    } else if (!qualifier.equals(Item.ANY)) {
      // Not a wildcard, so qualifier must match exactly
      if (!qualifier.equals(metadataField.getQualifier())) {
        return false;
      }
    }

    if (language == null) {
      // Value must be null language to match
      if (metadataValue.getLanguage() != null) {
        // Value is qualified, so no match
        return false;
      }
    } else if (!language.equals(Item.ANY)) {
      // Not a wildcard, so language must match exactly
      if (!language.equals(metadataValue.getLanguage())) {
        return false;
      }
    }

    if (!schema.equals(Item.ANY)) {
      if (metadataSchema != null && !metadataSchema.getName().equals(schema)) {
        // The namespace doesn't match
        return false;
      }
    }

    // If we get this far, we have a match
    return true;
  }
  /**
   * Serialize a single metadata field registry entry to xml
   *
   * @param context DSpace context
   * @param xmlSerializer xml serializer
   * @param mdField DSpace metadata field
   * @throws SAXException if XML error
   * @throws RegistryExportException if export error
   * @throws SQLException if database error
   * @throws IOException if IO error
   */
  private static void saveType(Context context, XMLSerializer xmlSerializer, MetadataField mdField)
      throws SAXException, RegistryExportException, SQLException, IOException {
    // If we haven't been given a field, it's an error
    if (mdField == null) {
      throw new RegistryExportException("no field to export");
    }

    // Get the data from the metadata field
    String schemaName = getSchemaName(context, mdField);
    String element = mdField.getElement();
    String qualifier = mdField.getQualifier();
    String scopeNote = mdField.getScopeNote();

    // We must have a schema and element
    if (schemaName == null || element == null) {
      throw new RegistryExportException("incomplete field information");
    }

    // Output the parent tag
    xmlSerializer.startElement("dc-type", null);

    // Output the schema name
    xmlSerializer.startElement("schema", null);
    xmlSerializer.characters(schemaName.toCharArray(), 0, schemaName.length());
    xmlSerializer.endElement("schema");

    // Output the element
    xmlSerializer.startElement("element", null);
    xmlSerializer.characters(element.toCharArray(), 0, element.length());
    xmlSerializer.endElement("element");

    // Output the qualifier, if present
    if (qualifier != null) {
      xmlSerializer.startElement("qualifier", null);
      xmlSerializer.characters(qualifier.toCharArray(), 0, qualifier.length());
      xmlSerializer.endElement("qualifier");
    } else {
      xmlSerializer.comment("unqualified");
    }

    // Output the scope note, if present
    if (scopeNote != null) {
      xmlSerializer.startElement("scope_note", null);
      xmlSerializer.characters(scopeNote.toCharArray(), 0, scopeNote.length());
      xmlSerializer.endElement("scope_note");
    } else {
      xmlSerializer.comment("no scope note");
    }

    xmlSerializer.endElement("dc-type");
  }
  @Override
  public void update(Context context, MetadataField metadataField)
      throws SQLException, AuthorizeException, NonUniqueMetadataException, IOException {
    // Check authorisation: Only admins may update the metadata registry
    if (!authorizeService.isAdmin(context)) {
      throw new AuthorizeException("Only administrators may modiffy the Dublin Core registry");
    }

    // Ensure the element and qualifier are unique within a given schema.
    if (hasElement(
        context,
        metadataField.getFieldID(),
        metadataField.getMetadataSchema(),
        metadataField.getElement(),
        metadataField.getQualifier())) {
      throw new NonUniqueMetadataException(
          "Please make "
              + metadataField.getMetadataSchema().getName()
              + "."
              + metadataField.getElement()
              + "."
              + metadataField.getQualifier());
    }

    metadataFieldDAO.save(context, metadataField);

    log.info(
        LogManager.getHeader(
            context,
            "update_metadatafieldregistry",
            "metadata_field_id="
                + metadataField.getFieldID()
                + "element="
                + metadataField.getElement()
                + "qualifier="
                + metadataField.getQualifier()));
  }
  @Override
  public void loadMetadata(Item item) {
    MetadataFieldDAO mfDAO = MetadataFieldDAOFactory.getInstance(context);
    MetadataSchemaDAO msDAO = MetadataSchemaDAOFactory.getInstance(context);

    try {
      TableRowIterator tri =
          DatabaseManager.queryTable(
              context,
              "metadatavalue",
              "SELECT * FROM MetadataValue "
                  + "WHERE item_id = ? "
                  + "ORDER BY metadata_field_id, place",
              item.getID());

      List<DCValue> metadata = new ArrayList<DCValue>();

      for (TableRow row : tri.toList()) {
        // Get the associated metadata field and schema information
        int fieldID = row.getIntColumn("metadata_field_id");
        MetadataField field = mfDAO.retrieve(fieldID);

        if (field == null) {
          log.error("Loading item - cannot find metadata field " + fieldID);
        } else {
          MetadataSchema schema = msDAO.retrieve(field.getSchemaID());

          // Make a DCValue object
          DCValue dcv = new DCValue();
          dcv.schema = schema.getName();
          dcv.element = field.getElement();
          dcv.qualifier = field.getQualifier();
          dcv.language = row.getStringColumn("text_lang");
          dcv.value = row.getStringColumn("text_value");

          // Add it to the item
          metadata.add(dcv);
        }
      }

      item.setMetadata(metadata);
    } catch (SQLException sqle) {
      throw new RuntimeException(sqle);
    }
  }
Exemple #7
0
  protected MetadataField getMetadataField(DCValue dcv) throws SQLException, AuthorizeException {
    if (allMetadataFields == null) {
      allMetadataFields = MetadataField.findAll(ourContext);
    }

    if (allMetadataFields != null) {
      int schemaID = getMetadataSchemaID(dcv);
      for (MetadataField field : allMetadataFields) {
        if (field.getSchemaID() == schemaID
            && StringUtils.equals(field.getElement(), dcv.element)
            && StringUtils.equals(field.getQualifier(), dcv.qualifier)) {
          return field;
        }
      }
    }

    return null;
  }