mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
Merge pull request #1719 from 4Science/DS-3577
DS-3577 Metadata Fields and Schemas READ-ONLY endpoints
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.converter;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.model.MetadataFieldRest;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the converter from/to the MetadataField in the DSpace API data model and
|
||||||
|
* the REST data model
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MetadataFieldConverter extends DSpaceConverter<org.dspace.content.MetadataField, MetadataFieldRest> {
|
||||||
|
@Autowired(required = true)
|
||||||
|
private MetadataSchemaConverter metadataSchemaConverter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetadataFieldRest fromModel(org.dspace.content.MetadataField obj) {
|
||||||
|
MetadataFieldRest field = new MetadataFieldRest();
|
||||||
|
field.setId(obj.getID());
|
||||||
|
field.setElement(obj.getElement());
|
||||||
|
field.setQualifier(obj.getQualifier());
|
||||||
|
field.setScopeNote(obj.getScopeNote());
|
||||||
|
field.setSchema(metadataSchemaConverter.convert(obj.getMetadataSchema()));
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.dspace.content.MetadataField toModel(MetadataFieldRest obj) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.converter;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.model.MetadataSchemaRest;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the converter from/to the MetadataSchema in the DSpace API data model and
|
||||||
|
* the REST data model
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MetadataSchemaConverter extends DSpaceConverter<org.dspace.content.MetadataSchema, MetadataSchemaRest> {
|
||||||
|
@Override
|
||||||
|
public MetadataSchemaRest fromModel(org.dspace.content.MetadataSchema obj) {
|
||||||
|
MetadataSchemaRest schema = new MetadataSchemaRest();
|
||||||
|
schema.setId(obj.getID());
|
||||||
|
schema.setNamespace(obj.getNamespace());
|
||||||
|
schema.setPrefix(obj.getName());
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.dspace.content.MetadataSchema toModel(MetadataSchemaRest obj) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.model;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.RestResourceController;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MetadataField REST Resource
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MetadataFieldRest extends BaseObjectRest<Integer> {
|
||||||
|
public static final String NAME = "metadatafield";
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private MetadataSchemaRest schema;
|
||||||
|
|
||||||
|
private String element;
|
||||||
|
|
||||||
|
private String qualifier;
|
||||||
|
|
||||||
|
private String scopeNote;
|
||||||
|
|
||||||
|
public MetadataSchemaRest getSchema() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchema(MetadataSchemaRest schema) {
|
||||||
|
this.schema = schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getElement() {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElement(String element) {
|
||||||
|
this.element = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQualifier() {
|
||||||
|
return qualifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQualifier(String qualifier) {
|
||||||
|
this.qualifier = qualifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScopeNote() {
|
||||||
|
return scopeNote;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScopeNote(String scopeNote) {
|
||||||
|
this.scopeNote = scopeNote;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JsonIgnore
|
||||||
|
public Class getController() {
|
||||||
|
return RestResourceController.class;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.RestResourceController;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MetadataSchema REST Resource
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MetadataSchemaRest extends BaseObjectRest<Integer> {
|
||||||
|
public static final String NAME = "metadataschema";
|
||||||
|
|
||||||
|
private String prefix;
|
||||||
|
|
||||||
|
private String namespace;
|
||||||
|
|
||||||
|
public String getPrefix() {
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrefix(String prefix) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNamespace() {
|
||||||
|
return namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNamespace(String namespace) {
|
||||||
|
this.namespace = namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JsonIgnore
|
||||||
|
public Class getController() {
|
||||||
|
return RestResourceController.class;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.model.hateoas;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.model.MetadataFieldRest;
|
||||||
|
import org.dspace.app.rest.utils.Utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MetadataField Rest HAL Resource. The HAL Resource wraps the REST Resource
|
||||||
|
* adding support for the links and embedded resources
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RelNameDSpaceResource(MetadataFieldRest.NAME)
|
||||||
|
public class MetadataFieldResource extends DSpaceResource<MetadataFieldRest> {
|
||||||
|
public MetadataFieldResource(MetadataFieldRest ms, Utils utils, String... rels) {
|
||||||
|
super(ms, utils, rels);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.model.hateoas;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.model.MetadataSchemaRest;
|
||||||
|
import org.dspace.app.rest.utils.Utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MetadataSchema Rest HAL Resource. The HAL Resource wraps the REST Resource
|
||||||
|
* adding support for the links and embedded resources
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RelNameDSpaceResource(MetadataSchemaRest.NAME)
|
||||||
|
public class MetadataSchemaResource extends DSpaceResource<MetadataSchemaRest> {
|
||||||
|
public MetadataSchemaResource(MetadataSchemaRest ms, Utils utils, String... rels) {
|
||||||
|
super(ms, utils, rels);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.repository;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.converter.MetadataFieldConverter;
|
||||||
|
import org.dspace.app.rest.model.MetadataFieldRest;
|
||||||
|
import org.dspace.app.rest.model.hateoas.MetadataFieldResource;
|
||||||
|
import org.dspace.content.MetadataField;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.MetadataFieldService;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the repository responsible to manage MetadataField Rest object
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Component(MetadataFieldRest.NAME)
|
||||||
|
public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFieldRest, Integer> {
|
||||||
|
MetadataFieldService metaFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
|
||||||
|
@Autowired
|
||||||
|
MetadataFieldConverter converter;
|
||||||
|
|
||||||
|
public MetadataFieldRestRepository() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetadataFieldRest findOne(Context context, Integer id) {
|
||||||
|
MetadataField metadataField = null;
|
||||||
|
try {
|
||||||
|
metadataField = metaFieldService.find(context, id);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
if (metadataField == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return converter.fromModel(metadataField);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<MetadataFieldRest> findAll(Context context, Pageable pageable) {
|
||||||
|
List<MetadataField> metadataField = null;
|
||||||
|
try {
|
||||||
|
metadataField = metaFieldService.findAll(context);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
Page<MetadataFieldRest> page = utils.getPage(metadataField, pageable).map(converter);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<MetadataFieldRest> getDomainClass() {
|
||||||
|
return MetadataFieldRest.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetadataFieldResource wrapResource(MetadataFieldRest bs, String... rels) {
|
||||||
|
return new MetadataFieldResource(bs, utils, rels);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.app.rest.repository;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.converter.MetadataSchemaConverter;
|
||||||
|
import org.dspace.app.rest.model.MetadataSchemaRest;
|
||||||
|
import org.dspace.app.rest.model.hateoas.MetadataSchemaResource;
|
||||||
|
import org.dspace.content.MetadataSchema;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.MetadataSchemaService;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the repository responsible to manage MetadataSchema Rest object
|
||||||
|
*
|
||||||
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Component(MetadataSchemaRest.NAME)
|
||||||
|
public class MetadataSchemaRestRepository extends DSpaceRestRepository<MetadataSchemaRest, Integer> {
|
||||||
|
MetadataSchemaService metaScemaService = ContentServiceFactory.getInstance().getMetadataSchemaService();
|
||||||
|
@Autowired
|
||||||
|
MetadataSchemaConverter converter;
|
||||||
|
|
||||||
|
public MetadataSchemaRestRepository() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetadataSchemaRest findOne(Context context, Integer id) {
|
||||||
|
MetadataSchema metadataSchema = null;
|
||||||
|
try {
|
||||||
|
metadataSchema = metaScemaService.find(context, id);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
if (metadataSchema == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return converter.fromModel(metadataSchema);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<MetadataSchemaRest> findAll(Context context, Pageable pageable) {
|
||||||
|
List<MetadataSchema> metadataSchema = null;
|
||||||
|
try {
|
||||||
|
metadataSchema = metaScemaService.findAll(context);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
Page<MetadataSchemaRest> page = utils.getPage(metadataSchema, pageable).map(converter);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<MetadataSchemaRest> getDomainClass() {
|
||||||
|
return MetadataSchemaRest.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MetadataSchemaResource wrapResource(MetadataSchemaRest bs, String... rels) {
|
||||||
|
return new MetadataSchemaResource(bs, utils, rels);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user