mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #9405 from alexandrevryghem/w2p-112950_created-doi-builder_contribute-main
Created DOIBuilder
This commit is contained in:
@@ -57,6 +57,16 @@ public class DOIServiceImpl implements DOIService {
|
||||
return doiDAO.create(context, new DOI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Context context, DOI doi) throws SQLException {
|
||||
doiDAO.delete(context, doi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DOI> findAll(Context context) throws SQLException {
|
||||
return doiDAO.findAll(context, DOI.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DOI findByDoi(Context context, String doi) throws SQLException {
|
||||
return doiDAO.findByDoi(context, doi);
|
||||
|
@@ -43,6 +43,23 @@ public interface DOIService {
|
||||
*/
|
||||
public DOI create(Context context) throws SQLException;
|
||||
|
||||
/**
|
||||
* Deletes the given {@link DOI}.
|
||||
*
|
||||
* @param context current DSpace session.
|
||||
* @throws SQLException passed through.
|
||||
*/
|
||||
void delete(Context context, DOI doi) throws SQLException;
|
||||
|
||||
/**
|
||||
* Retrieves the full list of {@link DOI}s currently in storage.
|
||||
*
|
||||
* @param context current DSpace session.
|
||||
* @return The list of all DOIs currently in storage.
|
||||
* @throws SQLException passed through.
|
||||
*/
|
||||
List<DOI> findAll(Context context) throws SQLException;
|
||||
|
||||
/**
|
||||
* Find a specific DOI in storage.
|
||||
*
|
||||
|
@@ -51,6 +51,8 @@ import org.dspace.eperson.service.EPersonService;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.dspace.eperson.service.RegistrationDataService;
|
||||
import org.dspace.eperson.service.SubscribeService;
|
||||
import org.dspace.identifier.factory.IdentifierServiceFactory;
|
||||
import org.dspace.identifier.service.DOIService;
|
||||
import org.dspace.orcid.factory.OrcidServiceFactory;
|
||||
import org.dspace.orcid.service.OrcidHistoryService;
|
||||
import org.dspace.orcid.service.OrcidQueueService;
|
||||
@@ -114,6 +116,7 @@ public abstract class AbstractBuilder<T, S> {
|
||||
static ProcessService processService;
|
||||
static RequestItemService requestItemService;
|
||||
static VersioningService versioningService;
|
||||
static DOIService doiService;
|
||||
static OrcidHistoryService orcidHistoryService;
|
||||
static OrcidQueueService orcidQueueService;
|
||||
static OrcidTokenService orcidTokenService;
|
||||
@@ -178,6 +181,7 @@ public abstract class AbstractBuilder<T, S> {
|
||||
requestItemService = RequestItemServiceFactory.getInstance().getRequestItemService();
|
||||
versioningService = DSpaceServicesFactory.getInstance().getServiceManager()
|
||||
.getServiceByName(VersioningService.class.getName(), VersioningService.class);
|
||||
doiService = IdentifierServiceFactory.getInstance().getDOIService();
|
||||
|
||||
// Temporarily disabled
|
||||
claimedTaskService = XmlWorkflowServiceFactory.getInstance().getClaimedTaskService();
|
||||
@@ -234,6 +238,7 @@ public abstract class AbstractBuilder<T, S> {
|
||||
processService = null;
|
||||
requestItemService = null;
|
||||
versioningService = null;
|
||||
doiService = null;
|
||||
orcidTokenService = null;
|
||||
systemWideAlertService = null;
|
||||
submissionConfigService = null;
|
||||
|
@@ -183,17 +183,11 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
}
|
||||
|
||||
public BitstreamBuilder withFormat(String format) throws SQLException {
|
||||
|
||||
bitstreamService.addMetadata(context, bitstream, "dc", "format", null, null, format);
|
||||
|
||||
return this;
|
||||
return withMetadata("dc", "format", null, null, format);
|
||||
}
|
||||
|
||||
public BitstreamBuilder withProvenance(String provenance) throws SQLException {
|
||||
|
||||
bitstreamService.addMetadata(context, bitstream, "dc", "description", "provenance", null, provenance);
|
||||
|
||||
return this;
|
||||
return withMetadata("dc", "description", "provenance", null, provenance);
|
||||
}
|
||||
|
||||
|
||||
@@ -203,22 +197,24 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
|
||||
}
|
||||
|
||||
public BitstreamBuilder withIIIFLabel(String label) throws SQLException {
|
||||
bitstreamService.addMetadata(context, bitstream, "iiif", "label", null, null, label);
|
||||
return this;
|
||||
return withMetadata("iiif", "label", null, null, label);
|
||||
}
|
||||
|
||||
public BitstreamBuilder withIIIFCanvasWidth(int i) throws SQLException {
|
||||
bitstreamService.addMetadata(context, bitstream, "iiif", "image", "width", null, String.valueOf(i));
|
||||
return this;
|
||||
return withMetadata("iiif", "image", "width", null, String.valueOf(i));
|
||||
}
|
||||
|
||||
public BitstreamBuilder withIIIFCanvasHeight(int i) throws SQLException {
|
||||
bitstreamService.addMetadata(context, bitstream, "iiif", "image", "height", null, String.valueOf(i));
|
||||
return this;
|
||||
return withMetadata("iiif", "image", "height", null, String.valueOf(i));
|
||||
}
|
||||
|
||||
public BitstreamBuilder withIIIFToC(String toc) throws SQLException {
|
||||
bitstreamService.addMetadata(context, bitstream, "iiif", "toc", null, null, toc);
|
||||
return withMetadata("iiif", "toc", null, null, toc);
|
||||
}
|
||||
|
||||
public BitstreamBuilder withMetadata(String schema, String element, String qualifier, String lang, String value)
|
||||
throws SQLException {
|
||||
bitstreamService.addMetadata(context, bitstream, schema, element, qualifier, lang, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
90
dspace-api/src/test/java/org/dspace/builder/DOIBuilder.java
Normal file
90
dspace-api/src/test/java/org/dspace/builder/DOIBuilder.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* 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.builder;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.identifier.DOI;
|
||||
import org.dspace.identifier.service.DOIService;
|
||||
|
||||
/**
|
||||
* Builder for {@link DOI} entities.
|
||||
*/
|
||||
public class DOIBuilder extends AbstractBuilder<DOI, DOIService> {
|
||||
|
||||
private DOI doi;
|
||||
|
||||
protected DOIBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static DOIBuilder createDOI(final Context context) {
|
||||
DOIBuilder builder = new DOIBuilder(context);
|
||||
return builder.create(context);
|
||||
}
|
||||
|
||||
private DOIBuilder create(final Context context) {
|
||||
try {
|
||||
this.doi = doiService.create(context);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DOIBuilder withDoi(final String doi) {
|
||||
this.doi.setDoi(doi);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DOIBuilder withDSpaceObject(final DSpaceObject dSpaceObject) {
|
||||
this.doi.setDSpaceObject(dSpaceObject);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DOIBuilder withStatus(final Integer status) {
|
||||
this.doi.setStatus(status);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DOI build() throws SQLException, AuthorizeException {
|
||||
return this.doi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Context c, DOI doi) throws Exception {
|
||||
try {
|
||||
doiService.delete(c, doi);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() throws Exception {
|
||||
try (Context context = new Context()) {
|
||||
context.setDispatcher("noindex");
|
||||
context.turnOffAuthorisationSystem();
|
||||
this.doi = context.reloadEntity(this.doi);
|
||||
if (this.doi != null) {
|
||||
delete(context, this.doi);
|
||||
context.complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DOIService getService() {
|
||||
return doiService;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user