@Override public int hashCode() { int hash = 7; hash = 47 * hash + getID(); hash = 47 * hash + getMetadataSchema().getID(); return hash; }
/** * Helper method to retrieve a schema name for the field. * Caches the name after looking up the id. * * @param context DSpace Context * @param mdField DSpace metadata field * @return name of schema * @throws SQLException if database error * @throws RegistryExportException if export error */ private static String getSchemaName(Context context, MetadataField mdField) throws SQLException, RegistryExportException { // Get name from cache String name = schemaMap.get(mdField.getMetadataSchema().getID()); if (name == null) { // Name not retrieved before, so get the schema now MetadataSchema mdSchema = metadataSchemaService.find(context, mdField.getMetadataSchema().getID()); if (mdSchema != null) { name = mdSchema.getName(); schemaMap.put(mdSchema.getID(), name); } else { // Can't find the schema throw new RegistryExportException("Can't get schema name for field"); } } return name; }
private void setup(org.dspace.content.MetadataSchema schema, String expand, Context context) throws SQLException { List<String> expandFields = new ArrayList<String>(); if (expand != null) { expandFields = Arrays.asList(expand.split(",")); } this.setSchemaID(schema.getID()); this.setPrefix(schema.getName()); this.setNamespace(schema.getNamespace()); if (expandFields.contains("fields") || expandFields.contains("all")) { List<org.dspace.content.MetadataField> fields = metadataFieldService.findAllInSchema(context, schema); this.addExpand("fields"); for (org.dspace.content.MetadataField field : fields) { this.fields.add(new MetadataField(schema, field, "", context)); } } }
@Override public void delete(Context context, MetadataSchema metadataSchema) throws SQLException, AuthorizeException { // Check authorisation: Only admins may create DC types if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only administrators may modify the metadata registry"); } log.info(LogManager.getHeader(context, "delete_metadata_schema", "metadata_schema_id=" + metadataSchema.getID())); metadataSchemaDAO.delete(context, metadataSchema); }
@Override public void update(Context context, MetadataSchema metadataSchema) throws SQLException, AuthorizeException, NonUniqueMetadataException { // Check authorisation: Only admins may update the metadata registry if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only administrators may modify the metadata registry"); } // Ensure the schema name is unique if (!uniqueShortName(context, metadataSchema.getID(), metadataSchema.getName())) { throw new NonUniqueMetadataException("Please make the name " + metadataSchema.getName() + " unique"); } // Ensure the schema namespace is unique if (!uniqueNamespace(context, metadataSchema.getID(), metadataSchema.getNamespace())) { throw new NonUniqueMetadataException("Please make the namespace " + metadataSchema.getNamespace() + " unique"); } metadataSchemaDAO.save(context, metadataSchema); log.info(LogManager.getHeader(context, "update_metadata_schema", "metadata_schema_id=" + metadataSchema.getID() + "namespace=" + metadataSchema.getNamespace() + "name=" + metadataSchema.getName())); }
try { mdSchema = metadataSchemaService.create(context, schema, String.valueOf(new Date().getTime())); mdSchema.setNamespace("unknown" + mdSchema.getID()); metadataSchemaService.update(context, mdSchema); } catch (NonUniqueMetadataException e) {
@Override public MetadataSchema create(Context context, String name, String namespace) throws SQLException, AuthorizeException, NonUniqueMetadataException { // Check authorisation: Only admins may create metadata schemas if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only administrators may modify the metadata registry"); } // Ensure the schema name is unique if (!uniqueShortName(context, -1, name)) { throw new NonUniqueMetadataException("Please make the name " + name + " unique"); } // Ensure the schema namespace is unique if (!uniqueNamespace(context, -1, namespace)) { throw new NonUniqueMetadataException("Please make the namespace " + namespace + " unique"); } // Create a table row and update it with the values MetadataSchema metadataSchema = metadataSchemaDAO.create(context, new MetadataSchema()); metadataSchema.setNamespace(namespace); metadataSchema.setName(name); metadataSchemaDAO.save(context, metadataSchema); log.info(LogManager.getHeader(context, "create_metadata_schema", "metadata_schema_id=" + metadataSchema.getID())); return metadataSchema; }
@Override public MetadataField create(Context context, MetadataSchema metadataSchema, String element, String qualifier, String scopeNote) throws AuthorizeException, SQLException, NonUniqueMetadataException { // Check authorisation: Only admins may create DC types if (!authorizeService.isAdmin(context)) { throw new AuthorizeException( "Only administrators may modify the metadata registry"); } // Ensure the element and qualifier are unique within a given schema. if (hasElement(context, -1, metadataSchema, element, qualifier)) { throw new NonUniqueMetadataException("Please make " + element + "." + qualifier + " unique within schema #" + metadataSchema.getID()); } // Create a table row and update it with the values MetadataField metadataField = new MetadataField(); metadataField.setElement(element); metadataField.setQualifier(qualifier); metadataField.setScopeNote(scopeNote); metadataField.setMetadataSchema(metadataSchema); metadataField = metadataFieldDAO.create(context, metadataField); metadataFieldDAO.save(context, metadataField); log.info(LogManager.getHeader(context, "create_metadata_field", "metadata_field_id=" + metadataField.getID())); return metadataField; }