diff --git a/dspace-api/src/main/java/org/dspace/content/Bitstream.java b/dspace-api/src/main/java/org/dspace/content/Bitstream.java index 451a3b75784d..15ebbd16a9d9 100644 --- a/dspace-api/src/main/java/org/dspace/content/Bitstream.java +++ b/dspace-api/src/main/java/org/dspace/content/Bitstream.java @@ -39,6 +39,7 @@ @Entity @Table(name = "bitstream") public class Bitstream extends DSpaceObject implements DSpaceObjectLegacySupport { + @Column(name = "bitstream_id", insertable = false, updatable = false) private Integer legacyId; @@ -79,7 +80,6 @@ public class Bitstream extends DSpaceObject implements DSpaceObjectLegacySupport @Transient private transient BitstreamService bitstreamService; - /** * Protected constructor, create object using: * {@link org.dspace.content.service.BitstreamService#create(Context, Bundle, InputStream)} @@ -434,5 +434,4 @@ public void setAcceptanceDate(Context context, DCDate acceptanceDate) throws SQL getBitstreamService() .setMetadataSingleValue(context, this, "dcterms", "accessRights", null, null, acceptanceDate.toString()); } - } diff --git a/dspace-api/src/main/java/org/dspace/content/BundleServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/BundleServiceImpl.java index aa32983362de..c6803d6d2c05 100644 --- a/dspace-api/src/main/java/org/dspace/content/BundleServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/BundleServiceImpl.java @@ -17,6 +17,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Objects; import java.util.UUID; import org.apache.commons.collections4.CollectionUtils; @@ -27,10 +28,13 @@ import org.dspace.authorize.ResourcePolicy; import org.dspace.authorize.service.AuthorizeService; import org.dspace.authorize.service.ResourcePolicyService; +import org.dspace.content.clarin.ClarinLicense; import org.dspace.content.dao.BundleDAO; import org.dspace.content.service.BitstreamService; import org.dspace.content.service.BundleService; import org.dspace.content.service.ItemService; +import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService; +import org.dspace.content.service.clarin.ClarinLicenseService; import org.dspace.core.Constants; import org.dspace.core.Context; import org.dspace.core.LogHelper; @@ -62,6 +66,10 @@ public class BundleServiceImpl extends DSpaceObjectServiceImpl implement protected AuthorizeService authorizeService; @Autowired(required = true) protected ResourcePolicyService resourcePolicyService; + @Autowired(required = true) + protected ClarinLicenseService clarinLicenseService; + @Autowired(required = true) + protected ClarinLicenseResourceMappingService clarinLicenseResourceMappingService; protected BundleServiceImpl() { super(); @@ -160,7 +168,6 @@ public void addBitstream(Context context, Bundle bundle, Bitstream bitstream) bundle.addBitstream(bitstream); bitstream.getBundles().add(bundle); - context.addEvent(new Event(Event.ADD, Constants.BUNDLE, bundle.getID(), Constants.BITSTREAM, bitstream.getID(), String.valueOf(bitstream.getSequenceID()), getIdentifiers(context, bundle))); @@ -169,6 +176,52 @@ public void addBitstream(Context context, Bundle bundle, Bitstream bitstream) // FIXME: multiple inclusion is affected by this... authorizeService.inheritPolicies(context, bundle, bitstream); bitstreamService.update(context, bitstream); + + // Add Clarin License to the bitstream + try { + if (!Objects.equals(bundle.getName(), Constants.CONTENT_BUNDLE_NAME)) { + return; + } + + if (Objects.isNull(owningItem)) { + return; + } + + List dcRights = + itemService.getMetadata(owningItem, "dc", "rights", null, Item.ANY); + List dcRightsUri = + itemService.getMetadata(owningItem, "dc", "rights", "uri", Item.ANY); + + String licenseUri = null; + if(CollectionUtils.isNotEmpty(dcRights)) { + if ( dcRights.size() != dcRightsUri.size() ) { + log.warn( String.format("Harvested bitstream [%s / %s] has different length of dc_rights and dc_rights_uri", + bitstream.getName(), bitstream.getHandle())); + licenseUri = "unknown"; + }else { + licenseUri = Objects.requireNonNull(dcRightsUri.get(0)).getValue(); + } + } + + ClarinLicense clarinLicense = this.clarinLicenseService.findByDefinition(context, licenseUri); + if (Objects.isNull(clarinLicense)) { + log.info("Cannot find clarin license with definition: " + licenseUri); + } + + List bundles = owningItem.getBundles(Constants.CONTENT_BUNDLE_NAME); + for (Bundle clarinBundle : bundles) { + List bitstreamList = clarinBundle.getBitstreams(); + for (Bitstream bundleBitstream : bitstreamList) { + // in case bitstream ID exists in license table for some reason .. just remove it + this.clarinLicenseResourceMappingService.detachLicenses(context, bitstream); + } + // add the license to bitstream + this.clarinLicenseResourceMappingService.attachLicense(context, clarinLicense, bitstream); + } + } catch (SQLException e) { + log.error("Something went wrong in the maintenance of clarin license in the bitstream bundle: " + + e.getSQLState()); + } } @Override diff --git a/dspace-api/src/main/java/org/dspace/content/WorkspaceItemServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/WorkspaceItemServiceImpl.java index d891dcf638e4..4284f6f09890 100644 --- a/dspace-api/src/main/java/org/dspace/content/WorkspaceItemServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/WorkspaceItemServiceImpl.java @@ -36,6 +36,7 @@ import org.dspace.workflow.WorkflowService; import org.springframework.beans.factory.annotation.Autowired; +/** /** * Service implementation for the WorkspaceItem object. * This class is responsible for all business logic calls for the WorkspaceItem object and is autowired by spring. diff --git a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicense.java b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicense.java index 9a773a8e0413..90c38c895f05 100644 --- a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicense.java +++ b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicense.java @@ -7,6 +7,7 @@ */ package org.dspace.content.clarin; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -21,9 +22,11 @@ import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; import javax.persistence.Table; +import org.dspace.authorize.ResourcePolicy; import org.dspace.core.ReloadableEntity; /** @@ -50,7 +53,10 @@ public class ClarinLicense implements ReloadableEntity { name = "license_label_extended_mapping", joinColumns = @JoinColumn(name = "license_id"), inverseJoinColumns = @JoinColumn(name = "label_id")) - Set clarinLicenseLabels = new HashSet<>();; + Set clarinLicenseLabels = new HashSet<>(); + + @OneToMany(fetch = FetchType.LAZY, mappedBy = "license", cascade = CascadeType.PERSIST) + private final List clarinLicenseResourceMappings = new ArrayList<>(); // @Column(name = "eperson_id") // private Integer epersonId; @@ -115,6 +121,19 @@ public void setLicenseLabels(Set clarinLicenseLabels) { this.clarinLicenseLabels = clarinLicenseLabels; } + public List getClarinLicenseResourceMappings() { + return clarinLicenseResourceMappings; + } + + public ClarinLicenseLabel getNonExtendedClarinLicenseLabel() { + for (ClarinLicenseLabel cll : getLicenseLabels()) { + if (!cll.isExtended()) { + return cll; + } + } + return null; + } + @Override public Integer getID() { return id; diff --git a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceMapping.java b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceMapping.java new file mode 100644 index 000000000000..9c89108ad676 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceMapping.java @@ -0,0 +1,52 @@ +package org.dspace.content.clarin; + +import org.dspace.content.Bitstream; +import org.dspace.core.ReloadableEntity; + +import javax.persistence.*; +import java.util.UUID; + +@Entity +@Table(name = "license_resource_mapping") +public class ClarinLicenseResourceMapping implements ReloadableEntity { + + @Id + @Column(name="mapping_id") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "license_resource_mapping_mapping_id_seq") + @SequenceGenerator(name = "license_resource_mapping_mapping_id_seq", sequenceName = "license_resource_mapping_mapping_id_seq", + allocationSize = 1) + private Integer id; + + @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST}) + @JoinColumn(name = "license_id") + private ClarinLicense license; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "bitstream_uuid", referencedColumnName = "uuid") + private Bitstream bitstream; + + @Override + public Integer getID() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Bitstream getBitstream() { + return bitstream; + } + + public void setBitstream(Bitstream bitstream) { + this.bitstream = bitstream; + } + + public ClarinLicense getLicense() { + return license; + } + + public void setLicense(ClarinLicense license) { + this.license = license; + } +} diff --git a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceMappingServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceMappingServiceImpl.java new file mode 100644 index 000000000000..ebd77e9fb276 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseResourceMappingServiceImpl.java @@ -0,0 +1,149 @@ +package org.dspace.content.clarin; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang.NullArgumentException; +import org.dspace.authorize.AuthorizeException; +import org.dspace.authorize.service.AuthorizeService; +import org.dspace.content.Bitstream; +import org.dspace.content.dao.clarin.ClarinLicenseResourceMappingDAO; +import org.dspace.content.service.BitstreamService; +import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService; +import org.dspace.content.service.clarin.ClarinLicenseService; +import org.dspace.core.Context; +import org.dspace.core.LogHelper; +import org.hibernate.ObjectNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.ws.rs.NotFoundException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; + +public class ClarinLicenseResourceMappingServiceImpl implements ClarinLicenseResourceMappingService { + + private static final Logger log = LoggerFactory.getLogger(ClarinLicenseServiceImpl.class); + + @Autowired + ClarinLicenseResourceMappingDAO clarinLicenseResourceMappingDAO; + + @Autowired + ClarinLicenseService clarinLicenseService; + + @Autowired + BitstreamService bitstreamService; + + @Autowired + AuthorizeService authorizeService; + + @Override + public ClarinLicenseResourceMapping create(Context context) throws SQLException { + // Create a table row + ClarinLicenseResourceMapping clarinLicenseResourceMapping = clarinLicenseResourceMappingDAO.create(context, new ClarinLicenseResourceMapping()); + + log.info(LogHelper.getHeader(context, "create_clarin_license_resource_mapping", "clarin_license_resource_mapping_id=" + + clarinLicenseResourceMapping.getID())); + + return clarinLicenseResourceMapping; + } + + @Override + public ClarinLicenseResourceMapping create(Context context, ClarinLicenseResourceMapping clarinLicenseResourceMapping) throws SQLException { + return clarinLicenseResourceMappingDAO.create(context, clarinLicenseResourceMapping); + } + + @Override + public ClarinLicenseResourceMapping create(Context context, Integer licenseId, UUID bitstreamUuid) throws SQLException { + ClarinLicenseResourceMapping clarinLicenseResourceMapping = new ClarinLicenseResourceMapping(); + ClarinLicense clarinLicense = clarinLicenseService.find(context, licenseId); + if (Objects.isNull(clarinLicense)) { + throw new NotFoundException("Cannot find the license with id: " + licenseId); + } + + Bitstream bitstream = bitstreamService.find(context, bitstreamUuid); + if (Objects.isNull(bitstream)) { + throw new NotFoundException("Cannot find the bitstream with id: " + bitstreamUuid); + } + clarinLicenseResourceMapping.setLicense(clarinLicense); + clarinLicenseResourceMapping.setBitstream(bitstream); + + return clarinLicenseResourceMappingDAO.create(context, clarinLicenseResourceMapping); + } + + @Override + public ClarinLicenseResourceMapping find(Context context, int valueId) throws SQLException { + return clarinLicenseResourceMappingDAO.findByID(context, ClarinLicenseResourceMapping.class, valueId); + } + + @Override + public List findAllByLicenseId(Context context, Integer licenseId) throws SQLException { + List mappings = clarinLicenseResourceMappingDAO.findAll(context, ClarinLicenseResourceMapping.class); + List mappingsByLicenseId = new ArrayList<>(); + for (ClarinLicenseResourceMapping mapping: mappings) { + if (Objects.equals(mapping.getLicense().getID(), licenseId)) { + mappingsByLicenseId.add(mapping); + } + } + return mappingsByLicenseId; + } + + @Override + public void update(Context context, ClarinLicenseResourceMapping newClarinLicenseResourceMapping) throws SQLException { + if (Objects.isNull(newClarinLicenseResourceMapping)) { + throw new NullArgumentException("Cannot update clarin license resource mapping because the new clarin license resource mapping is null"); + } + + ClarinLicenseResourceMapping foundClarinLicenseResourceMapping = find(context, newClarinLicenseResourceMapping.getID()); + if (Objects.isNull(foundClarinLicenseResourceMapping)) { + throw new ObjectNotFoundException(newClarinLicenseResourceMapping.getID(), "Cannot update the license resource mapping because" + + " the clarin license resource mapping wasn't found " + + "in the database."); + } + + clarinLicenseResourceMappingDAO.save(context, newClarinLicenseResourceMapping); + } + + @Override + public void delete(Context context, ClarinLicenseResourceMapping clarinLicenseResourceMapping) throws SQLException { + clarinLicenseResourceMappingDAO.delete(context, clarinLicenseResourceMapping); + } + + @Override + public void detachLicenses(Context context, Bitstream bitstream) throws SQLException { + List clarinLicenseResourceMappings = + clarinLicenseResourceMappingDAO.findByBitstreamUUID(context, bitstream.getID()); + + if (CollectionUtils.isEmpty(clarinLicenseResourceMappings)) { + log.info("Cannot detach licenses because bitstream with id: " + bitstream.getID() + " is not " + + "attached to any license."); + return; + } + + clarinLicenseResourceMappings.forEach(clarinLicenseResourceMapping -> { + try { + this.delete(context, clarinLicenseResourceMapping); + } catch (SQLException e) { + log.error(e.getMessage()); + } + }); + } + + @Override + public void attachLicense(Context context, ClarinLicense clarinLicense, Bitstream bitstream) throws SQLException { + ClarinLicenseResourceMapping clarinLicenseResourceMapping = this.create(context); + if (Objects.isNull(clarinLicenseResourceMapping)) { + throw new NotFoundException("Cannot create the ClarinLicenseResourceMapping."); + } + if (Objects.isNull(clarinLicense) || Objects.isNull(bitstream)) { + throw new NullArgumentException("Clarin License or Bitstream cannot be null."); + } + + clarinLicenseResourceMapping.setBitstream(bitstream); + clarinLicenseResourceMapping.setLicense(clarinLicense); + + clarinLicenseResourceMappingDAO.save(context, clarinLicenseResourceMapping); + } +} diff --git a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java index f33e190b0f10..c686b5e520a7 100644 --- a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java @@ -64,6 +64,11 @@ public ClarinLicense find(Context context, int valueId) throws SQLException { return clarinLicenseDAO.findByID(context, ClarinLicense.class, valueId); } + @Override + public ClarinLicense findByDefinition(Context context, String definition) throws SQLException { + return clarinLicenseDAO.findByDefinition(context, definition); + } + @Override public List findAll(Context context) throws SQLException, AuthorizeException { if (!authorizeService.isAdmin(context)) { diff --git a/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java b/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java index f9e2b0a18c7a..0fafb6fc22b7 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java @@ -8,8 +8,11 @@ package org.dspace.content.dao.clarin; import org.dspace.content.clarin.ClarinLicense; +import org.dspace.core.Context; import org.dspace.core.GenericDAO; +import java.sql.SQLException; + /** * Database Access Object interface class for the Clarin License object. * The implementation of this class is responsible for all database calls for the Clarin License object @@ -19,4 +22,7 @@ * @author Milan Majchrak (milan.majchrak at dataquest.sk) */ public interface ClarinLicenseDAO extends GenericDAO { + + ClarinLicense findByDefinition(Context context, String definition) throws SQLException; + } diff --git a/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseResourceMappingDAO.java b/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseResourceMappingDAO.java new file mode 100644 index 000000000000..6781a90d3c34 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseResourceMappingDAO.java @@ -0,0 +1,14 @@ +package org.dspace.content.dao.clarin; + +import org.dspace.content.clarin.ClarinLicenseResourceMapping; +import org.dspace.core.Context; +import org.dspace.core.GenericDAO; + +import java.sql.SQLException; +import java.util.List; +import java.util.UUID; + +public interface ClarinLicenseResourceMappingDAO extends GenericDAO { + + List findByBitstreamUUID(Context context, UUID bitstreamUUID) throws SQLException; +} diff --git a/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java b/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java index 56e7b8e14715..ef38d964096b 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java @@ -10,6 +10,10 @@ import org.dspace.content.clarin.ClarinLicense; import org.dspace.content.dao.clarin.ClarinLicenseDAO; import org.dspace.core.AbstractHibernateDAO; +import org.dspace.core.Context; + +import javax.persistence.Query; +import java.sql.SQLException; /** * Hibernate implementation of the Database Access Object interface class for the Clarin License object. @@ -22,4 +26,16 @@ public class ClarinLicenseDAOImpl extends AbstractHibernateDAO im protected ClarinLicenseDAOImpl() { super(); } + + @Override + public ClarinLicense findByDefinition(Context context, String definition) throws SQLException { + Query query = createQuery(context, "SELECT cl " + + "FROM ClarinLicense cl " + + "WHERE cl.definition = :definition"); + + query.setParameter("definition", definition); + query.setHint("org.hibernate.cacheable", Boolean.TRUE); + + return singleResult(query); + } } diff --git a/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseResourceMappingDAOImpl.java b/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseResourceMappingDAOImpl.java new file mode 100644 index 000000000000..edcaeb58789a --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseResourceMappingDAOImpl.java @@ -0,0 +1,31 @@ +package org.dspace.content.dao.impl.clarin; + +import org.dspace.content.Bitstream; +import org.dspace.content.clarin.ClarinLicense; +import org.dspace.content.clarin.ClarinLicenseResourceMapping; +import org.dspace.content.dao.clarin.ClarinLicenseResourceMappingDAO; +import org.dspace.core.AbstractHibernateDAO; +import org.dspace.core.Context; + +import javax.persistence.Query; +import java.sql.SQLException; +import java.util.List; +import java.util.UUID; + +public class ClarinLicenseResourceMappingDAOImpl extends AbstractHibernateDAO implements ClarinLicenseResourceMappingDAO { + protected ClarinLicenseResourceMappingDAOImpl() { + super(); + } + + @Override + public List findByBitstreamUUID(Context context, UUID bitstreamUUID) throws SQLException { + Query query = createQuery(context, "SELECT clrm " + + "FROM ClarinLicenseResourceMapping clrm " + + "WHERE clrm.bitstream.id = :bitstreamUUID"); + + query.setParameter("bitstreamUUID", bitstreamUUID); + query.setHint("org.hibernate.cacheable", Boolean.TRUE); + + return list(query); + } +} diff --git a/dspace-api/src/main/java/org/dspace/content/factory/ClarinServiceFactory.java b/dspace-api/src/main/java/org/dspace/content/factory/ClarinServiceFactory.java index f3d8df014a2f..e4a54ecb8d70 100644 --- a/dspace-api/src/main/java/org/dspace/content/factory/ClarinServiceFactory.java +++ b/dspace-api/src/main/java/org/dspace/content/factory/ClarinServiceFactory.java @@ -8,6 +8,7 @@ package org.dspace.content.factory; import org.dspace.content.service.clarin.ClarinLicenseLabelService; +import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService; import org.dspace.content.service.clarin.ClarinLicenseService; import org.dspace.services.factory.DSpaceServicesFactory; @@ -23,6 +24,8 @@ public abstract class ClarinServiceFactory { public abstract ClarinLicenseLabelService getClarinLicenseLabelService(); + public abstract ClarinLicenseResourceMappingService getClarinLicenseResourceMappingService(); + public static ClarinServiceFactory getInstance() { return DSpaceServicesFactory.getInstance().getServiceManager() .getServiceByName("clarinServiceFactory", ClarinServiceFactory.class); diff --git a/dspace-api/src/main/java/org/dspace/content/factory/ClarinServiceFactoryImpl.java b/dspace-api/src/main/java/org/dspace/content/factory/ClarinServiceFactoryImpl.java index 346aabada4b8..af42bc5f0607 100644 --- a/dspace-api/src/main/java/org/dspace/content/factory/ClarinServiceFactoryImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/factory/ClarinServiceFactoryImpl.java @@ -8,6 +8,7 @@ package org.dspace.content.factory; import org.dspace.content.service.clarin.ClarinLicenseLabelService; +import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService; import org.dspace.content.service.clarin.ClarinLicenseService; import org.springframework.beans.factory.annotation.Autowired; @@ -25,6 +26,9 @@ public class ClarinServiceFactoryImpl extends ClarinServiceFactory { @Autowired(required = true) private ClarinLicenseLabelService clarinLicenseLabelService; + @Autowired(required = true) + private ClarinLicenseResourceMappingService clarinLicenseResourceMappingService; + @Override public ClarinLicenseService getClarinLicenseService() { return clarinLicenseService; @@ -34,4 +38,9 @@ public ClarinLicenseService getClarinLicenseService() { public ClarinLicenseLabelService getClarinLicenseLabelService() { return clarinLicenseLabelService; } + + @Override + public ClarinLicenseResourceMappingService getClarinLicenseResourceMappingService() { + return clarinLicenseResourceMappingService; + } } diff --git a/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseResourceMappingService.java b/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseResourceMappingService.java new file mode 100644 index 000000000000..eaa791ae6e9c --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseResourceMappingService.java @@ -0,0 +1,30 @@ +package org.dspace.content.service.clarin; + +import org.dspace.authorize.AuthorizeException; +import org.dspace.content.Bitstream; +import org.dspace.content.clarin.ClarinLicense; +import org.dspace.content.clarin.ClarinLicenseLabel; +import org.dspace.content.clarin.ClarinLicenseResourceMapping; +import org.dspace.core.Context; + +import java.sql.SQLException; +import java.util.List; +import java.util.UUID; + +public interface ClarinLicenseResourceMappingService { + + ClarinLicenseResourceMapping create(Context context) throws SQLException, AuthorizeException; + ClarinLicenseResourceMapping create(Context context, ClarinLicenseResourceMapping clarinLicenseResourceMapping) throws SQLException, AuthorizeException; + ClarinLicenseResourceMapping create(Context context, Integer licenseId, UUID bitstreamUuid) throws SQLException, AuthorizeException; + + ClarinLicenseResourceMapping find(Context context, int valueId) throws SQLException; + List findAllByLicenseId(Context context, Integer licenseId) throws SQLException; + + void update(Context context, ClarinLicenseResourceMapping newClarinLicenseResourceMapping) throws SQLException; + + void delete(Context context, ClarinLicenseResourceMapping clarinLicenseResourceMapping) throws SQLException; + + void detachLicenses(Context context, Bitstream bitstream) throws SQLException; + + void attachLicense(Context context, ClarinLicense clarinLicense, Bitstream bitstream) throws SQLException, AuthorizeException; +} diff --git a/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java b/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java index f67be3f972de..a7ba90e4a4e2 100644 --- a/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java +++ b/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java @@ -53,6 +53,8 @@ public interface ClarinLicenseService { * @throws SQLException if database error */ ClarinLicense find(Context context, int valueId) throws SQLException; + + ClarinLicense findByDefinition(Context context, String definition) throws SQLException; /** * Find all clarin license objects diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql index d0402db1900c..3801277501f8 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql @@ -112,9 +112,8 @@ CREATE SEQUENCE license_label_label_id_seq CREATE TABLE license_resource_mapping ( mapping_id integer NOT NULL, - bitstream_id integer, - license_id integer, - active boolean DEFAULT true + bitstream_uuid uuid, + license_id integer ); @@ -263,6 +262,9 @@ ALTER TABLE license_resource_mapping ADD CONSTRAINT license_definition_license_resource_mapping_fk FOREIGN KEY (license_id) REFERENCES license_definition(license_id) ON DELETE CASCADE; +ALTER TABLE license_resource_mapping + ADD CONSTRAINT bitstream_license_resource_mapping_fk FOREIGN KEY (bitstream_uuid) REFERENCES bitstream(uuid) ON DELETE CASCADE; + -- -- Name: license_label_license_definition_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace -- diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql index 9356c82282b6..1deb1c6445e2 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql @@ -136,9 +136,8 @@ SELECT pg_catalog.setval('license_label_label_id_seq', 19, true); CREATE TABLE license_resource_mapping ( mapping_id integer NOT NULL, - bitstream_id integer, - license_id integer, - active boolean DEFAULT true + bitstream_uuid uuid, + license_id integer ); @@ -305,6 +304,8 @@ ALTER TABLE ONLY license_label_extended_mapping ALTER TABLE ONLY license_resource_mapping ADD CONSTRAINT license_definition_license_resource_mapping_fk FOREIGN KEY (license_id) REFERENCES license_definition(license_id) ON DELETE CASCADE; +ALTER TABLE ONLY license_resource_mapping + ADD CONSTRAINT bitstream_license_resource_mapping_fk FOREIGN KEY (bitstream_uuid) REFERENCES bitstream(uuid) ON DELETE CASCADE; -- -- Name: license_label_license_definition_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace diff --git a/dspace-api/src/test/java/org/dspace/builder/AbstractBuilder.java b/dspace-api/src/test/java/org/dspace/builder/AbstractBuilder.java index 319ee7537f48..427f2690d316 100644 --- a/dspace-api/src/test/java/org/dspace/builder/AbstractBuilder.java +++ b/dspace-api/src/test/java/org/dspace/builder/AbstractBuilder.java @@ -38,6 +38,7 @@ import org.dspace.content.service.SiteService; import org.dspace.content.service.WorkspaceItemService; import org.dspace.content.service.clarin.ClarinLicenseLabelService; +import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService; import org.dspace.content.service.clarin.ClarinLicenseService; import org.dspace.core.Context; import org.dspace.discovery.IndexingService; @@ -100,6 +101,7 @@ public abstract class AbstractBuilder { static VersioningService versioningService; static ClarinLicenseService clarinLicenseService; static ClarinLicenseLabelService clarinLicenseLabelService; + static ClarinLicenseResourceMappingService clarinLicenseResourceMappingService; protected Context context; @@ -158,6 +160,7 @@ public static void init() { workflowItemRoleService = XmlWorkflowServiceFactory.getInstance().getWorkflowItemRoleService(); clarinLicenseService = ClarinServiceFactory.getInstance().getClarinLicenseService(); clarinLicenseLabelService = ClarinServiceFactory.getInstance().getClarinLicenseLabelService(); + clarinLicenseResourceMappingService = ClarinServiceFactory.getInstance().getClarinLicenseResourceMappingService(); } @@ -192,6 +195,7 @@ public static void destroy() { versioningService = null; clarinLicenseService = null; clarinLicenseLabelService = null; + clarinLicenseResourceMappingService = null; } diff --git a/dspace-api/src/test/java/org/dspace/builder/ClarinLicenseResourceMappingBuilder.java b/dspace-api/src/test/java/org/dspace/builder/ClarinLicenseResourceMappingBuilder.java new file mode 100644 index 000000000000..71726fb0a614 --- /dev/null +++ b/dspace-api/src/test/java/org/dspace/builder/ClarinLicenseResourceMappingBuilder.java @@ -0,0 +1,67 @@ +package org.dspace.builder; + +import org.dspace.authorize.AuthorizeException; +import org.dspace.content.clarin.ClarinLicenseResourceMapping; +import org.dspace.content.factory.ClarinServiceFactory; +import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService; +import org.dspace.core.Context; + +import java.sql.SQLException; + +public class ClarinLicenseResourceMappingBuilder extends AbstractBuilder { + private ClarinLicenseResourceMapping clarinLicenseResourceMapping; + + protected ClarinLicenseResourceMappingBuilder(Context context) { + super(context); + } + + public static ClarinLicenseResourceMappingBuilder createClarinLicenseResourceMapping(final Context context) { + ClarinLicenseResourceMappingBuilder builder = new ClarinLicenseResourceMappingBuilder(context); + return builder.create(context); + } + + private ClarinLicenseResourceMappingBuilder create(final Context context) { + this.context = context; + try { + clarinLicenseResourceMapping = clarinLicenseResourceMappingService.create(context); + } catch (Exception e) { + return handleException(e); + } + return this; + } + + @Override + public void cleanup() throws Exception { + try (Context c = new Context()) { + c.turnOffAuthorisationSystem(); + // Ensure object and any related objects are reloaded before checking to see what needs cleanup + clarinLicenseResourceMapping = c.reloadEntity(clarinLicenseResourceMapping); + delete(c, clarinLicenseResourceMapping); + c.complete(); + indexingService.commit(); + } + } + + @Override + public ClarinLicenseResourceMapping build() throws SQLException, AuthorizeException { + try { + context.dispatchEvents(); + indexingService.commit(); + return clarinLicenseResourceMapping; + } catch (Exception e) { + return handleException(e); + } + } + + @Override + public void delete(Context c, ClarinLicenseResourceMapping dso) throws Exception { + if (dso != null) { + getService().delete(c, dso); + } + } + + @Override + protected ClarinLicenseResourceMappingService getService() { + return clarinLicenseResourceMappingService; + } +} diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseRestRepositoryIT.java index aa0795a0b9e5..a6ceb8b33bbf 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseRestRepositoryIT.java @@ -8,6 +8,11 @@ package org.dspace.app.rest; import static com.jayway.jsonpath.JsonPath.read; +import static org.apache.commons.codec.CharEncoding.UTF_8; +import static org.apache.commons.io.IOUtils.toInputStream; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.hamcrest.Matchers.is; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -17,6 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.io.InputStream; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -31,11 +37,15 @@ import org.dspace.app.rest.model.ClarinLicenseRest; import org.dspace.app.rest.projection.Projection; import org.dspace.app.rest.test.AbstractControllerIntegrationTest; -import org.dspace.builder.ClarinLicenseBuilder; -import org.dspace.builder.ClarinLicenseLabelBuilder; +import org.dspace.builder.*; +import org.dspace.content.Bitstream; +import org.dspace.content.Collection; +import org.dspace.content.Item; import org.dspace.content.clarin.ClarinLicense; import org.dspace.content.clarin.ClarinLicenseLabel; +import org.dspace.content.clarin.ClarinLicenseResourceMapping; import org.dspace.content.service.clarin.ClarinLicenseLabelService; +import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService; import org.dspace.content.service.clarin.ClarinLicenseService; import org.hamcrest.Matchers; import org.junit.Assert; @@ -59,6 +69,8 @@ public class ClarinLicenseRestRepositoryIT extends AbstractControllerIntegration @Autowired ClarinLicenseConverter clarinLicenseConverter; + @Autowired + ClarinLicenseResourceMappingService clarinLicenseResourceMappingService; ClarinLicense firstCLicense; ClarinLicense secondCLicense; @@ -66,6 +78,11 @@ public class ClarinLicenseRestRepositoryIT extends AbstractControllerIntegration ClarinLicenseLabel secondCLicenseLabel; ClarinLicenseLabel thirdCLicenseLabel; + Item publicItem1; + + Item publicItem2; + Item publicItem3; + @Before public void setup() throws Exception { context.turnOffAuthorisationSystem(); @@ -112,7 +129,45 @@ public void setup() throws Exception { secondCLicense.setLicenseLabels(secondClarinLicenseLabels); clarinLicenseService.update(context, secondCLicense); + //create collection for items + parentCommunity = CommunityBuilder.createCommunity(context) + .withName("Parent Community") + .build(); + Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection1").build(); + Collection col2 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection2").build(); + Collection col3 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection3").build(); + + // create two items with the first license + // the publicItem1 has license information added to the metadata + publicItem1 = ItemBuilder.createItem(context, col1) + .withTitle("Public item 1") + .withIssueDate("2022-10-17") + .withAuthor("Smith, Donald").withAuthor("Doe, John") + .withSubject("ExtraEntry") + .withMetadata("dc", "rights", null, firstCLicense.getName()) + .withMetadata("dc", "rights", "uri", firstCLicense.getDefinition()) +// .withMetadata("dc", "rights", "label", +// Objects.requireNonNull(firstCLicense.getNonExtendedClarinLicenseLabel()).getLabel()) + .build(); + + publicItem2 = ItemBuilder.createItem(context, col2) + .withTitle("Public item 2") + .withIssueDate("2016-02-13") + .withAuthor("Smith, Maria").withAuthor("Doe, Jane") + .withSubject("TestingForMore").withSubject("ExtraEntry") + .build(); + + // create item with the second license + publicItem3 = ItemBuilder.createItem(context, col3) + .withTitle("Public item 3") + .withIssueDate("2016-02-13") + .withAuthor("Smith, Maria").withAuthor("Doe, Jane") + .withSubject("AnotherTest").withSubject("TestingForMore") + .withSubject("ExtraEntry") + .build(); + context.restoreAuthSystemState(); + } @Test @@ -149,9 +204,259 @@ public void findAll() throws Exception { firstCLicense.getLicenseLabels()))) ))) .andExpect(jsonPath("$._links.self.href", - Matchers.containsString("/api/core/clarinlicenses"))) + Matchers.containsString("/api/core/clarinlicenses"))); + } + + @Test + public void create() throws Exception { + ClarinLicenseRest clarinLicenseRest = new ClarinLicenseRest(); + clarinLicenseRest.setName("name"); + clarinLicenseRest.setBitstreams(0); + clarinLicenseRest.setConfirmation(4); + clarinLicenseRest.setRequiredInfo("Not required"); + clarinLicenseRest.setDefinition("definition"); + clarinLicenseConverter.setExtendedClarinLicenseLabels(clarinLicenseRest, firstCLicense.getLicenseLabels(), + Projection.DEFAULT); + clarinLicenseConverter.setClarinLicenseLabel(clarinLicenseRest, firstCLicense.getLicenseLabels(), + Projection.DEFAULT); + + // id of created clarin license + AtomicReference idRef = new AtomicReference<>(); + String authTokenAdmin = getAuthToken(admin.getEmail(), password); + try { + getClient(authTokenAdmin).perform(post("/api/core/clarinlicenses") + .content(new ObjectMapper().writeValueAsBytes(clarinLicenseRest)) + .contentType(org.springframework.http.MediaType.APPLICATION_JSON)) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.name", is(clarinLicenseRest.getName()))) + .andExpect(jsonPath("$.definition", + is(clarinLicenseRest.getDefinition()))) + .andExpect(jsonPath("$.confirmation", + is(clarinLicenseRest.getConfirmation()))) + .andExpect(jsonPath("$.requiredInfo", + is(clarinLicenseRest.getRequiredInfo()))) + .andExpect(jsonPath("$.bitstreams", + is(clarinLicenseRest.getBitstreams()))) + .andExpect(jsonPath("$.type", + is(ClarinLicenseRest.NAME))) + + .andExpect(jsonPath("$.clarinLicenseLabel.label", + is(clarinLicenseRest.getClarinLicenseLabel().getLabel()))) + .andExpect(jsonPath("$.clarinLicenseLabel.title", + is(clarinLicenseRest.getClarinLicenseLabel().getTitle()))) + .andExpect(jsonPath("$.clarinLicenseLabel.extended", + is(clarinLicenseRest.getClarinLicenseLabel().isExtended()))) + .andExpect(jsonPath("$.clarinLicenseLabel.type", + is(ClarinLicenseLabelRest.NAME))) + + .andExpect(jsonPath("$.extendedClarinLicenseLabels[0].label", + is(clarinLicenseRest.getExtendedClarinLicenseLabels().get(0).getLabel()))) + .andExpect(jsonPath("$.extendedClarinLicenseLabels[0].title", + is(clarinLicenseRest.getExtendedClarinLicenseLabels().get(0).getTitle()))) + .andExpect(jsonPath("$.extendedClarinLicenseLabels[0].extended", + is(clarinLicenseRest.getExtendedClarinLicenseLabels().get(0).isExtended()))) + .andExpect(jsonPath("$.extendedClarinLicenseLabels[0].type", + is(ClarinLicenseLabelRest.NAME))) + .andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), + "$.id"))); + } finally { + if (Objects.nonNull(idRef.get())) { + // remove created clarin license + ClarinLicenseBuilder.deleteClarinLicense(idRef.get()); + } + } + } + + // Edit + @Test + public void update() throws Exception { + context.turnOffAuthorisationSystem(); + // clarin license to update + ClarinLicense clarinLicense = ClarinLicenseBuilder.createClarinLicense(context).build(); + clarinLicense.setName("default name"); + clarinLicense.setDefinition("default definition"); + clarinLicense.setConfirmation(0); + clarinLicense.setRequiredInfo("default info"); + + Set clarinLicenseLabels = new HashSet<>(); + clarinLicenseLabels.add(firstCLicenseLabel); + clarinLicenseLabels.add(secondCLicenseLabel); + clarinLicense.setLicenseLabels(clarinLicenseLabels); + + // clarin license with updated values + ClarinLicense clarinLicenseUpdated = ClarinLicenseBuilder.createClarinLicense(context).build(); + clarinLicenseUpdated.setName("updated name"); + clarinLicenseUpdated.setDefinition("updated definition"); + clarinLicenseUpdated.setConfirmation(4); + clarinLicenseUpdated.setRequiredInfo("updated info"); + + Set clarinLicenseLabelUpdated = new HashSet<>(); + clarinLicenseLabelUpdated.add(firstCLicenseLabel); + clarinLicenseLabelUpdated.add(thirdCLicenseLabel); + clarinLicenseUpdated.setLicenseLabels(clarinLicenseLabelUpdated); + context.restoreAuthSystemState(); + + ClarinLicenseRest clarinLicenseRest = clarinLicenseConverter.convert(clarinLicenseUpdated, Projection.DEFAULT); + + String authTokenAdmin = getAuthToken(admin.getEmail(), password); + getClient(authTokenAdmin).perform(get("/api/core/clarinlicenses/" + clarinLicense.getID())) + .andExpect(status().isOk()); + + getClient(authTokenAdmin).perform(put("/api/core/clarinlicenses/" + clarinLicense.getID()) + .content(new ObjectMapper().writeValueAsBytes(clarinLicenseRest)) + .contentType(org.springframework.http.MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + + getClient(authTokenAdmin).perform(get("/api/core/clarinlicenses/" + clarinLicense.getID())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", Matchers.is( + ClarinLicenseMatcher.matchClarinLicenseWithoutId(clarinLicenseUpdated)) + )); + } + + // 403 + @Test + public void forbiddenUpdateClarinLicense() throws Exception { + context.turnOffAuthorisationSystem(); + // clarin license to update + ClarinLicense clarinLicense = ClarinLicenseBuilder.createClarinLicense(context).build(); + + clarinLicense.setName("default name"); + clarinLicense.setDefinition("default definition"); + clarinLicense.setConfirmation(0); + clarinLicense.setRequiredInfo("default info"); + + Set clarinLicenseLabels = new HashSet<>(); + clarinLicenseLabels.add(firstCLicenseLabel); + clarinLicenseLabels.add(thirdCLicenseLabel); + clarinLicense.setLicenseLabels(clarinLicenseLabels); + context.restoreAuthSystemState(); + + ClarinLicenseRest clarinLicenseRest = clarinLicenseConverter.convert(clarinLicense, Projection.DEFAULT); + String authTokenUser = getAuthToken(eperson.getEmail(), password); + getClient(authTokenUser).perform(delete("/api/core/clarinlicenses/" + clarinLicense.getID()) + .content(new ObjectMapper().writeValueAsBytes(clarinLicenseRest)) + .contentType(org.springframework.http.MediaType.APPLICATION_JSON)) + .andExpect(status().isForbidden()) ; } + // 404 + @Test + public void notFoundUpdateClarinLicense() throws Exception { + context.turnOffAuthorisationSystem(); + // clarin license to update + ClarinLicense clarinLicense = ClarinLicenseBuilder.createClarinLicense(context).build(); + + clarinLicense.setName("default name"); + clarinLicense.setDefinition("default definition"); + clarinLicense.setConfirmation(0); + clarinLicense.setRequiredInfo("default info"); + + Set clarinLicenseLabels = new HashSet<>(); + clarinLicenseLabels.add(firstCLicenseLabel); + clarinLicenseLabels.add(thirdCLicenseLabel); + clarinLicense.setLicenseLabels(clarinLicenseLabels); + context.restoreAuthSystemState(); + + ClarinLicenseRest clarinLicenseRest = clarinLicenseConverter.convert(clarinLicense, Projection.DEFAULT); + + String authTokenAdmin = getAuthToken(admin.getEmail(), password); + getClient(authTokenAdmin).perform(put("/api/core/clarinlicenses/" + clarinLicense.getID() + "124679") + .content(new ObjectMapper().writeValueAsBytes(clarinLicenseRest)) + .contentType(org.springframework.http.MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()) + ; + } + + // 204 + @Test + public void deleteClarinLicense() throws Exception { + context.turnOffAuthorisationSystem(); + ClarinLicense clarinLicense = ClarinLicenseBuilder.createClarinLicense(context).build(); + context.restoreAuthSystemState(); + + String authTokenAdmin = getAuthToken(admin.getEmail(), password); + getClient(authTokenAdmin).perform(get("/api/core/clarinlicenses/" + clarinLicense.getID())) + .andExpect(status().isOk()); + + getClient(authTokenAdmin).perform(delete("/api/core/clarinlicenses/" + clarinLicense.getID())) + .andExpect(status().isNoContent()); + + getClient(authTokenAdmin).perform(get("/api/core/clarinlicenses/" + clarinLicense.getID())) + .andExpect(status().isNotFound()); + } + + // 401 + @Test + public void unauthorizedDeleteClarinLicense() throws Exception { + context.turnOffAuthorisationSystem(); + ClarinLicense clarinLicense = ClarinLicenseBuilder.createClarinLicense(context).build(); + context.restoreAuthSystemState(); + + getClient().perform(delete("/api/core/clarinlicenses/" + clarinLicense.getID())) + .andExpect(status().isUnauthorized()) + ; + } + + // 403 + @Test + public void forbiddenDeleteClarinLicense() throws Exception { + context.turnOffAuthorisationSystem(); + ClarinLicense clarinLicense = ClarinLicenseBuilder.createClarinLicense(context).build(); + context.restoreAuthSystemState(); + + String authTokenUser = getAuthToken(eperson.getEmail(), password); + getClient(authTokenUser).perform(delete("/api/core/clarinlicenses/" + clarinLicense.getID())) + .andExpect(status().isForbidden()) + ; + } + // 404 + @Test + public void notFoundDeleteClarinLicense() throws Exception { + String authTokenAdmin = getAuthToken(admin.getEmail(), password); + getClient(authTokenAdmin).perform(delete("/api/core/clarinlicenses/" + 1239990)) + .andExpect(status().isNotFound()) + ; + } + + private ClarinLicenseLabel getNonExtendedLicenseLabel(List clarinLicenseLabelList) { + for (ClarinLicenseLabel clarinLicenseLabel : clarinLicenseLabelList) { + if (clarinLicenseLabel.isExtended()) { + continue; + } + return clarinLicenseLabel; + } + return null; + } + + private ClarinLicenseLabel getExtendedLicenseLabels(List clarinLicenseLabelList) { + for (ClarinLicenseLabel clarinLicenseLabel : clarinLicenseLabelList) { + if (!clarinLicenseLabel.isExtended()) { + continue; + } + return clarinLicenseLabel; + } + return null; + } + + @Test + public void findAllBitstreamsAttachedToLicense() throws Exception { + context.turnOffAuthorisationSystem(); + // create bitstreams and add them with licenses to the clarin license resource mapping + BitstreamBuilder.createBitstream(context, publicItem1, toInputStream("test 1", UTF_8)) + .withFormat("test format") + .build(); + + BitstreamBuilder.createBitstream(context, publicItem1, toInputStream("test 2", UTF_8)) + .withFormat("test format") + .build(); + context.restoreAuthSystemState(); + // without commit the clarin license resource mappings aren't mapped into th clarin license object + context.commit(); + + ClarinLicense cl = clarinLicenseService.find(context, firstCLicense.getID()); + assertEquals(cl.getClarinLicenseResourceMappings().size(),2); + } @Test public void create() throws Exception { diff --git a/dspace/config/hibernate.cfg.xml b/dspace/config/hibernate.cfg.xml index 57dce8c84df6..03ad78b13ccf 100644 --- a/dspace/config/hibernate.cfg.xml +++ b/dspace/config/hibernate.cfg.xml @@ -66,6 +66,7 @@ + diff --git a/dspace/config/registries/dublin-core-types.xml b/dspace/config/registries/dublin-core-types.xml index 50e79b0d6151..d1107eea1c19 100644 --- a/dspace/config/registries/dublin-core-types.xml +++ b/dspace/config/registries/dublin-core-types.xml @@ -486,6 +486,13 @@ References terms governing use and reproduction. + + dc + rights + label + Rights label should be one of PUB, RES, ACA. + + dc source diff --git a/dspace/config/spring/api/core-dao-services.xml b/dspace/config/spring/api/core-dao-services.xml index 4c44103361a0..0f653cd85dce 100644 --- a/dspace/config/spring/api/core-dao-services.xml +++ b/dspace/config/spring/api/core-dao-services.xml @@ -45,6 +45,7 @@ + diff --git a/dspace/config/spring/api/core-services.xml b/dspace/config/spring/api/core-services.xml index 2152acf85627..3841cd0cb302 100644 --- a/dspace/config/spring/api/core-services.xml +++ b/dspace/config/spring/api/core-services.xml @@ -75,6 +75,7 @@ +