Package org.dspace.content

Examples of org.dspace.content.MetadataSchema


        Metadatum allMD[] = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);

        // For each field, we'll check if it exists. If not, we'll create it.
        for(Metadatum md : allMD)
        {
            MetadataSchema mdSchema = null;
            MetadataField mdField = null;
            try
            {
                //Try to access this Schema
                mdSchema = MetadataSchema.find(context, md.schema);
                //If Schema found, try to locate field from database
                if(mdSchema!=null)
                {
                    mdField = MetadataField.findByElement(context, mdSchema.getSchemaID(), md.element, md.qualifier);
                }
            }
            catch(SQLException se)
            {
                //If a SQLException error is thrown, then this field does NOT exist in DB
                //Set field to null, so we know we need to create it
                mdField = null;
            }

            // If our Schema was not found, we have a problem
            // We cannot easily create a Schema automatically -- as we don't know its Namespace
            if(mdSchema==null)
            {
                throw new PackageValidationException("Unknown Metadata Schema encountered (" + md.schema + ") when attempting to ingest an Item.  You will need to create this Metadata Schema in DSpace Schema Registry before the Item can be ingested.");
            }

            // If our Metadata Field is null, we will attempt to create it in the proper Schema
            if(mdField==null)
            {
                try
                {
                    //initialize field (but don't set a scope note) & create it
                    mdField = new MetadataField(mdSchema, md.element, md.qualifier, null);
                    // NOTE: Only Adminstrators can create Metadata Fields -- create() will throw an AuthorizationException for non-Admins
                    mdField.create(context);
                    //log that field was created
                    log.info("Located a missing metadata field (schema:'" + mdSchema.getName() +"', element:'"+ md.element +"', qualifier:'"+ md.qualifier +"') while ingesting Item.  This missing field has been created in the DSpace Metadata Field Registry.");
                }
                catch(NonUniqueMetadataException ne)
                {   // This exception should never happen, as we already checked to make sure the field doesn't exist.
                    // But, we'll catch it anyways so that the Java compiler doesn't get upset
                    throw new SQLException("Unable to create Metadata Field (element='" + md.element + "', qualifier='" + md.qualifier + "') in Schema "+ mdSchema.getName() +".", ne);
                }
            }
        }
    }
View Full Code Here


            if (elt.getName().equals("field") && elt.getNamespace().equals(DIM_NS))
            {
                String schema = elt.getAttributeValue("mdschema");
                String element = elt.getAttributeValue("element");
                String qualifier = elt.getAttributeValue("qualifier");
                MetadataSchema ms = MetadataSchema.find(context, schema);
                if (ms == null )
                {
                    System.err.println("DIM Error, Cannot find metadata schema for: schema=\""+schema+
                        "\" (... element=\""+element+"\", qualifier=\""+qualifier+"\")");
                }
                else
                {
                    if (qualifier != null && qualifier.equals(""))
                    {
                        System.err.println("DIM Warning, qualifier is empty string: "+
                              " schema=\""+schema+"\", element=\""+element+"\", qualifier=\""+qualifier+"\"");
                        qualifier = null;
                    }
                    MetadataField mf = MetadataField.findByElement(context,
                                  ms.getSchemaID(), element, qualifier);
                    if (mf == null)
                    {
                        System.err.println("DIM Error, Cannot find metadata field for: schema=\"" + schema +
                                "\", element=\"" + element + "\", qualifier=\"" + qualifier + "\"");
                    }
View Full Code Here

            try
            {
                if (id.equals(""))
                {
                    // Create a new metadata schema
                    MetadataSchema schema = new MetadataSchema();
                    schema.setNamespace(request.getParameter("namespace"));
                    schema.setName(request.getParameter("short_name"));
                    schema.create(context);
                    showSchemas(context, request, response);
                    context.complete();
                }
                else
                {
                    // Update an existing schema
                    MetadataSchema schema = MetadataSchema.find(context,
                            UIUtil.getIntParameter(request, "dc_schema_id"));
                    schema.setNamespace(request.getParameter("namespace"));
                    schema.setName(request.getParameter("short_name"));
                    schema.update(context);
                    showSchemas(context, request, response);
                    context.complete();
                }
            }
            catch (NonUniqueMetadataException e)
            {
                request.setAttribute("error",
                        "Please make the namespace and short name unique.");
                showSchemas(context, request, response);
                context.abort();
                return;
            }
        }
        else if (button.equals("submit_delete"))
        {
            // Start delete process - go through verification step
            MetadataSchema schema = MetadataSchema.find(context, UIUtil
                    .getIntParameter(request, "dc_schema_id"));
            request.setAttribute("schema", schema);
            JSPManager.showJSP(request, response,
                    "/dspace-admin/confirm-delete-mdschema.jsp");
        }
        else if (button.equals("submit_confirm_delete"))
        {
            // User confirms deletion of type
            MetadataSchema dc = MetadataSchema.find(context, UIUtil
                    .getIntParameter(request, "dc_schema_id"));
            dc.delete(context);
            showSchemas(context, request, response);
            context.complete();
        }
        else
        {
View Full Code Here

                    lang = null;
                }
            }

            MetadataField field = MetadataField.find(context, dcTypeID);
            MetadataSchema schema = MetadataSchema.find(context, field
                    .getSchemaID());
            item.addMetadata(schema.getName(), field.getElement(), field
                    .getQualifier(), lang, value);
        }

        item.update();
View Full Code Here

    {
        try
        {
            context.turnOffAuthorisationSystem();
            boolean create = false;
            MetadataSchema mdschema = MetadataSchema.find(context, schema);
            MetadataField mdfield = null;
            if (mdschema == null)
            {
                mdschema = new MetadataSchema(
                        SubmissionLookupService.SL_NAMESPACE_PREFIX + schema,
                        schema);
                mdschema.create(context);
                create = true;
            }
            else
            {
                mdfield = MetadataField.findByElement(context,
                        mdschema.getSchemaID(), element, qualifier);
            }

            if (mdfield == null)
            {
                mdfield = new MetadataField(mdschema, element, qualifier,
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

            String lang = request.getParameter("lang_" + i);

            if ((dcTypeID != -1) && (value != null) && !value.equals(""))
            {
                MetadataField field = MetadataField.find(context,dcTypeID);
                MetadataSchema schema = MetadataSchema.find(context,field.getSchemaID());
                item.addMetadata(schema.getName(),field.getElement(), field.getQualifier(), lang, value);
            }
        }

        item.update();
View Full Code Here

        MetadataField[] types = MetadataField
                .findAllInSchema(context, schemaID);
        request.setAttribute("types", types);

        // Pull the metadata schema object as well
        MetadataSchema schema = MetadataSchema.find(context, schemaID);
        request.setAttribute("schema", schema);

        // Pull all metadata schemas for the pulldown
        MetadataSchema[] schemas = MetadataSchema.findAll(context);
        request.setAttribute("schemas", schemas);
View Full Code Here

      {
        String fieldID = String.valueOf(field.getFieldID());
      String fieldEelement = field.getElement();
      String fieldQualifier = field.getQualifier();
     
      MetadataSchema schema = MetadataSchema.find(context, field.getSchemaID());
      String schemaName = schema.getName();
     
      StringBuilder fieldName = new StringBuilder()
                                            .append(schemaName)
                                            .append(".")
                                            .append(fieldEelement);

      if (fieldQualifier != null && fieldQualifier.length() > 0)
            {
        fieldName.append(".").append(fieldQualifier);
            }
       
      String fieldScopeNote = field.getScopeNote();
       
        Row row = table.addRow();
        row.addCell().addContent(fieldID);
          row.addCell().addContent(fieldName.toString());
          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.getSchemaID(), schema.getNamespace());
      }
     
      Para buttons = moved.addPara();
      buttons.addButton("submit_move").setValue(T_submit_move);
      buttons.addButton("submit_cancel").setValue(T_submit_cancel);
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.