Package org.dspace.content

Examples of org.dspace.content.MetadataSchema


    FlowResult result = new FlowResult();
   
    int count = 0;
    for (String id : schemaIDs)
      {
      MetadataSchema schema = MetadataSchema.find(context, Integer.valueOf(id));
     
      // First remove and fields in the schema
      MetadataField[] fields = MetadataField.findAllInSchema(context, schema.getSchemaID());
      for (MetadataField field : fields)
        field.delete(context);
     
      // Once all the fields are gone, then delete the schema.
          schema.delete(context);
          count++;
      }
   
    if (count > 0)
    {
View Full Code Here


            if (isTest)
            {
              ItemUpdate.pr("Metadata to add: " + dtom.toString());
                 //validity tests that would occur in actual processing
                        // If we're just test the import, let's check that the actual metadata field exists.
                      MetadataSchema foundSchema = MetadataSchema.find(context, dtom.schema);
                     
                      if (foundSchema == null)
                      {
                        ItemUpdate.pr("ERROR: schema '"
                          + dtom.schema + "' was not found in the registry; found on item " + dirname);
                      }
                      else
                      {
                        int schemaID = foundSchema.getSchemaID();
                        MetadataField foundField = MetadataField.findByElement(context, schemaID, dtom.element, dtom.qualifier);
                       
                        if (foundField == null)
                        {
                          ItemUpdate.pr("ERROR: Metadata field: '" + dtom.schema + "." + dtom.element + "."
View Full Code Here

    String fieldID = request.getParameter("field");
    String value = request.getParameter("value");
    String language = request.getParameter("language");
   
    MetadataField field = MetadataField.find(context,Integer.valueOf(fieldID));
    MetadataSchema schema = MetadataSchema.find(context,field.getSchemaID());
   
    item.addMetadata(schema.getName(), field.getElement(), field.getQualifier(), language, value);
   
    item.update();
    context.commit();
   
    result.setContinue(true);
View Full Code Here

                addName.setLabel(T_name_label);
                MetadataField[] fields = MetadataField.findAll(context);
                for (MetadataField field : fields)
                {
                        int fieldID = field.getFieldID();
                        MetadataSchema schema = MetadataSchema.find(context, field.getSchemaID());
                        String name = schema.getName() +"."+field.getElement();
                        if (field.getQualifier() != null)
                                name += "."+field.getQualifier();

                        addName.addOption(fieldID, name);
                }
View Full Code Here

      Metadatum[] values = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
      for (Metadatum value : values)
      {
        // Verify that the schema exists
        MetadataSchema mdSchema = MetadataSchema.find(ourContext, value.schema);
        if (mdSchema == null && !clearList.contains(value.schema)) {
          // add a new schema, giving it a namespace of "unknown". Possibly a very bad idea.
          if (schemaChoice.equals("add")) {
            mdSchema = new MetadataSchema(value.schema,String.valueOf(new Date().getTime()));
            try {
            mdSchema.create(ourContext);
            mdSchema.setName(value.schema);
            mdSchema.setNamespace("unknown"+mdSchema.getSchemaID());
              mdSchema.update(ourContext);
          } catch (NonUniqueMetadataException e) {
            // This case should not be possible
            e.printStackTrace();
          }
          clearList.add(value.schema);
          }
          // ignore the offending schema, quietly dropping all of its metadata elements before they clog our gears
          else if (schemaChoice.equals("ignore")) {
            item.clearMetadata(value.schema, Item.ANY, Item.ANY, Item.ANY);
            continue;
          }
          // otherwise, go ahead and generate the error
          else {
            throw new HarvestingException("The '" + value.schema + "' schema has not been defined in this DSpace instance. ");
          }
        }

            if (mdSchema != null) {
                // Verify that the element exists; this part is reachable only if the metadata schema is valid
                MetadataField mdField = MetadataField.findByElement(ourContext, mdSchema.getSchemaID(), value.element, value.qualifier);
                if (mdField == null) {
                    if (fieldChoice.equals("add")) {
                        mdField = new MetadataField(mdSchema, value.element, value.qualifier, null);
                        try {
                            mdField.create(ourContext);
View Full Code Here

        // If a single schema has been specified
        if (schema != null && !"".equals(schema))
        {
            // Get the id of that schema
            MetadataSchema mdSchema = MetadataSchema.find(context, schema);
            if (mdSchema == null)
            {
                throw new RegistryExportException("no schema to export");
            }
           
            // Get the metadata fields only for the specified schema
            mdFields = MetadataField.findAllInSchema(context, mdSchema.getSchemaID());
        }
        else
        {
            // Get the metadata fields for all the schemas
            mdFields = MetadataField.findAll(context);
View Full Code Here

    public static void saveSchema(Context context, XMLSerializer xmlSerializer, String schema) throws SQLException, SAXException, RegistryExportException
    {
        if (schema != null && !"".equals(schema))
        {
            // Find a single named schema
            MetadataSchema mdSchema = MetadataSchema.find(context, schema);
           
            saveSchema(xmlSerializer, mdSchema);
        }
        else
        {
View Full Code Here

        String name = schemaMap.get(Integer.valueOf(mdField.getSchemaID()));

        if (name == null)
        {
            // Name not retrieved before, so get the schema now
            MetadataSchema mdSchema = MetadataSchema.find(context, mdField.getSchemaID());
            if (mdSchema != null)
            {
                name = mdSchema.getName();
                schemaMap.put(Integer.valueOf(mdSchema.getSchemaID()), name);
            }
            else
            {
                // Can't find the schema
                throw new RegistryExportException("Can't get schema name for field");
View Full Code Here

        {
            throw new RegistryImportException("Namespace of schema must be supplied");
        }

        // check to see if the schema already exists
        MetadataSchema s = MetadataSchema.find(context, name);
       
        if (s == null)
        {
            // Schema does not exist - create
            log.info("Registering Schema " + name + " (" + namespace + ")");
            MetadataSchema schema = new MetadataSchema(namespace, name);
            schema.create(context);
        }
        else
        {
            // Schema exists - if it's the same namespace, allow the type imports to continue
            if (s.getNamespace().equals(namespace))
View Full Code Here

            schema = MetadataSchema.DC_SCHEMA;
        }

       
        // Find the matching schema object
        MetadataSchema schemaObj = MetadataSchema.find(context, schema);
       
        if (schemaObj == null)
        {
            throw new RegistryImportException("Schema '" + schema + "' is not registered and does not exist.");
        }
       
        MetadataField mf = MetadataField.findByElement(context, schemaObj.getSchemaID(), element, qualifier);
        if (mf != null)
        {
            // Metadata field already exists, skipping it
            return;
        }
       
        // Actually create this metadata field as it doesn't yet exist
        String fieldName = schema + "." + element + "." + qualifier;
        if(qualifier==null)
            fieldName = schema + "." + element;
        log.info("Registering metadata field " + fieldName);
        MetadataField field = new MetadataField();
        field.setSchemaID(schemaObj.getSchemaID());
        field.setElement(element);
        field.setQualifier(qualifier);
        field.setScopeNote(scopeNote);
        field.create(context);
    }
View Full Code Here

TOP

Related Classes of org.dspace.content.MetadataSchema

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.