Skip to content

Commit

Permalink
Add license file rest objects to data license
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Jan 19, 2024
1 parent 5fe27c2 commit 8eb9875
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
*/
package org.dspace.app.rest.model.step;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.fasterxml.jackson.annotation.JsonUnwrapped;

/**
* TAMU Customization - Customized DTO to expose the section license during in progress submission.
Expand All @@ -23,9 +27,14 @@ public class DataLicense implements SectionData {
@JsonProperty(access = Access.READ_ONLY)
private String acceptanceDate;

private boolean granted = false;

// TAMU Cusomtization - selected license
private String selected;

private boolean granted = false;
// TAMU Cusomtization - proxy license
@JsonUnwrapped
private List<UploadBitstreamRest> files;

public String getUrl() {
return url;
Expand All @@ -43,6 +52,14 @@ public void setAcceptanceDate(String acceptanceDate) {
this.acceptanceDate = acceptanceDate;
}

public boolean isGranted() {
return granted;
}

public void setGranted(boolean granted) {
this.granted = granted;
}

public String getSelected() {
return selected;
}
Expand All @@ -51,12 +68,12 @@ public void setSelected(String selected) {
this.selected = selected;
}

public boolean isGranted() {
return granted;
public List<UploadBitstreamRest> getFiles() {
return files;
}

public void setGranted(boolean granted) {
this.granted = granted;
public void setFiles(List<UploadBitstreamRest> files) {
this.files = files;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

Expand All @@ -12,6 +13,7 @@
import org.dspace.app.rest.model.ErrorRest;
import org.dspace.app.rest.model.patch.Operation;
import org.dspace.app.rest.model.step.DataLicense;
import org.dspace.app.rest.model.step.UploadBitstreamRest;
import org.dspace.app.rest.repository.WorkspaceItemRestRepository;
import org.dspace.app.rest.submit.SubmissionService;
import org.dspace.app.rest.submit.UploadableStep;
Expand All @@ -34,6 +36,8 @@ public class ProxyLicenseStep extends LicenseStep implements UploadableStep {

private static final String LICENSE_STEP_SELECTED_OPERATION_ENTRY = "selected";

private static final String PROXY_LICENSE_NAME = "PERMISSION";

private static final String DCTERMS_RIGHTSDATE = "dcterms.accessRights";
private static final String DCTERMS_ALTERNATIVE = "dcterms.alternative";

Expand All @@ -49,14 +53,28 @@ public DataLicense getData(SubmissionService submissionService, InProgressSubmis

DataLicense result = new DataLicense();

Bitstream bitstream = bitstreamService
.getBitstreamByName(obj.getItem(), Constants.LICENSE_BUNDLE_NAME, Constants.LICENSE_BITSTREAM_NAME);
List<Bundle> bundles = itemService.getBundles(obj.getItem(), Constants.LICENSE_BUNDLE_NAME);

Bitstream licenseBitstream = null;
Bitstream proxyBitstream = null;

for (Bundle bundle : bundles) {
for (Bitstream bitstream : bundle.getBitstreams()) {
if (bitstream.getName().equals(Constants.LICENSE_BITSTREAM_NAME)) {
licenseBitstream = bitstream;
} else if (bitstream.getName().startsWith(PROXY_LICENSE_NAME)) {
proxyBitstream = bitstream;
}
}
}

List<UploadBitstreamRest> files = new ArrayList<>();

if (bitstream != null) {
String selected = bitstreamService.getMetadata(bitstream, DCTERMS_ALTERNATIVE);
if (licenseBitstream != null) {
String selected = bitstreamService.getMetadata(licenseBitstream, DCTERMS_ALTERNATIVE);
result.setSelected(selected);

String acceptanceDate = bitstreamService.getMetadata(bitstream, DCTERMS_RIGHTSDATE);
String acceptanceDate = bitstreamService.getMetadata(licenseBitstream, DCTERMS_RIGHTSDATE);

if (StringUtils.isNotBlank(acceptanceDate)) {
result.setAcceptanceDate(acceptanceDate);
Expand All @@ -67,9 +85,17 @@ public DataLicense getData(SubmissionService submissionService, InProgressSubmis

result.setUrl(
configurationService.getProperty("dspace.server.url") + "/api/" + BitstreamRest.CATEGORY + "/" + English
.plural(BitstreamRest.NAME) + "/" + bitstream.getID() + "/content");
.plural(BitstreamRest.NAME) + "/" + licenseBitstream.getID() + "/content");

files.add(submissionService.buildUploadBitstream(configurationService, licenseBitstream));
}

if (proxyBitstream != null) {
files.add(submissionService.buildUploadBitstream(configurationService, proxyBitstream));
}

result.setFiles(files);

System.out.println("\nProxyLicenseStep.getData\n");
System.out.println("\tselected: " + result.getSelected());
System.out.println("\tacceptance date: " + result.getAcceptanceDate());
Expand Down Expand Up @@ -111,7 +137,7 @@ public ErrorRest upload(Context context, SubmissionService submissionService, Su
if (licenseBundles.size() > 0) {
licenseBundle = licenseBundles.get(0);
for (Bitstream bitstream: licenseBundle.getBitstreams()) {
if (bitstream.getName().startsWith("PERMISSION")) {
if (bitstream.getName().startsWith(PROXY_LICENSE_NAME)) {
System.out.println("\n\nremove bitstream: " + bitstream.getName() + "\n\n");
bundleService.removeBitstream(context, licenseBundle, bitstream);
break;
Expand All @@ -128,8 +154,8 @@ public ErrorRest upload(Context context, SubmissionService submissionService, Su
System.out.println("\t\tfilename: " + filename);
String[] parts = filename.split("\\.");
String permissionLicenseName = parts.length == 1
? "PERMISSION.license"
: String.join(".", "PERMISSION", parts[parts.length - 1]);
? String.join(".", PROXY_LICENSE_NAME, "license")
: String.join(".", PROXY_LICENSE_NAME, parts[parts.length - 1]);

System.out.println("\t\tset proxy bitstream name: " + permissionLicenseName);
proxyBitstream.setName(context, permissionLicenseName);
Expand Down

0 comments on commit 8eb9875

Please sign in to comment.