forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coar-notify-7 merge conflicts fixes, ldn configuration fixes
- Loading branch information
Showing
18 changed files
with
891 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
.../main/java/org/dspace/app/rest/submit/factory/impl/PrimaryBitstreamAddPatchOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* 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.submit.factory.impl; | ||
|
||
import static org.dspace.core.Constants.CONTENT_BUNDLE_NAME; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.dspace.app.rest.exception.UnprocessableEntityException; | ||
import org.dspace.content.Bitstream; | ||
import org.dspace.content.Bundle; | ||
import org.dspace.content.InProgressSubmission; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.service.ItemService; | ||
import org.dspace.core.Context; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* Submission "add" operation to set primary bitstream. | ||
* | ||
* @author Mykhaylo Boychuk ([email protected]) | ||
*/ | ||
public class PrimaryBitstreamAddPatchOperation extends AddPatchOperation<String> { | ||
|
||
@Autowired | ||
private ItemService itemService; | ||
|
||
@Override | ||
void add(Context context, HttpServletRequest currentRequest, InProgressSubmission source, String path, Object value) | ||
throws Exception { | ||
Item item = source.getItem(); | ||
UUID primaryUUID = parseValue(value); | ||
List<Bundle> bundles = itemService.getBundles(item, CONTENT_BUNDLE_NAME); | ||
Optional<Bundle> currentPrimaryBundle = bundles.stream() | ||
.filter(bundle -> Objects.nonNull(bundle.getPrimaryBitstream())) | ||
.findFirst(); | ||
|
||
Optional<Bitstream> primaryBitstreamToAdd = null; | ||
for (Bundle bundle : bundles) { | ||
primaryBitstreamToAdd = bundle.getBitstreams().stream() | ||
.filter(b -> b.getID().equals(primaryUUID)) | ||
.findFirst(); | ||
if (primaryBitstreamToAdd.isPresent()) { | ||
if (currentPrimaryBundle.isPresent()) { | ||
currentPrimaryBundle.get().setPrimaryBitstreamID(null); | ||
} | ||
bundle.setPrimaryBitstreamID(primaryBitstreamToAdd.get()); | ||
break; | ||
} | ||
} | ||
|
||
if (primaryBitstreamToAdd.isEmpty()) { | ||
throw new UnprocessableEntityException("The provided uuid: " + primaryUUID + | ||
" of bitstream to set as primary doesn't match any bitstream!"); | ||
} | ||
} | ||
|
||
private UUID parseValue(Object value) { | ||
UUID primaryBitstreamUUID; | ||
try { | ||
primaryBitstreamUUID = UUID.fromString((String) value); | ||
} catch (Exception e) { | ||
throw new UnprocessableEntityException("The provided value is invalid!", e); | ||
} | ||
return primaryBitstreamUUID; | ||
} | ||
|
||
@Override | ||
protected Class<String[]> getArrayClassForEvaluation() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Class<String> getClassForEvaluation() { | ||
return null; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...in/java/org/dspace/app/rest/submit/factory/impl/PrimaryBitstreamRemovePatchOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* 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.submit.factory.impl; | ||
|
||
import static org.dspace.core.Constants.CONTENT_BUNDLE_NAME; | ||
|
||
import java.util.List; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.dspace.content.Bundle; | ||
import org.dspace.content.InProgressSubmission; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.service.ItemService; | ||
import org.dspace.core.Context; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* Submission "remove" operation to remove primary bitstream. | ||
* | ||
* @author Mykhaylo Boychuk ([email protected]) | ||
*/ | ||
public class PrimaryBitstreamRemovePatchOperation extends RemovePatchOperation<String> { | ||
|
||
@Autowired | ||
private ItemService itemService; | ||
|
||
@Override | ||
void remove(Context context, HttpServletRequest request, InProgressSubmission source, String path, Object value) | ||
throws Exception { | ||
Item item = source.getItem(); | ||
List<Bundle> bundles = itemService.getBundles(item, CONTENT_BUNDLE_NAME); | ||
bundles.forEach(b -> b.setPrimaryBitstreamID(null)); | ||
} | ||
|
||
@Override | ||
protected Class<String[]> getArrayClassForEvaluation() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Class<String> getClassForEvaluation() { | ||
return null; | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
...n/java/org/dspace/app/rest/submit/factory/impl/PrimaryBitstreamReplacePatchOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* 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.submit.factory.impl; | ||
|
||
import static org.dspace.core.Constants.CONTENT_BUNDLE_NAME; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.dspace.app.rest.exception.UnprocessableEntityException; | ||
import org.dspace.content.Bitstream; | ||
import org.dspace.content.Bundle; | ||
import org.dspace.content.InProgressSubmission; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.service.ItemService; | ||
import org.dspace.core.Context; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* Submission "replace" operation to replace primary bitstream. | ||
* | ||
* @author Mykhaylo Boychuk ([email protected]) | ||
*/ | ||
public class PrimaryBitstreamReplacePatchOperation extends ReplacePatchOperation<String> { | ||
|
||
private final String EX_MESSAGE = "It is impossible to replace primary bitstrem if it wasn't set!"; | ||
|
||
@Autowired | ||
private ItemService itemService; | ||
|
||
@Override | ||
void replace(Context context, HttpServletRequest request, InProgressSubmission source, String path, Object value) | ||
throws Exception { | ||
Item item = source.getItem(); | ||
UUID primaryUUID = parseValue(value); | ||
List<Bundle> bundles = itemService.getBundles(item, CONTENT_BUNDLE_NAME); | ||
Bundle currentPrimaryBundle = bundles.stream() | ||
.filter(bundle -> Objects.nonNull(bundle.getPrimaryBitstream())) | ||
.findFirst() | ||
.orElseThrow(() -> new UnprocessableEntityException(EX_MESSAGE)); | ||
|
||
Optional<Bitstream> primaryBitstream = null; | ||
for (Bundle bundle : bundles) { | ||
primaryBitstream = bundle.getBitstreams().stream() | ||
.filter(b -> b.getID().equals(primaryUUID)) | ||
.findFirst(); | ||
if (primaryBitstream.isPresent()) { | ||
currentPrimaryBundle.setPrimaryBitstreamID(null); | ||
bundle.setPrimaryBitstreamID(primaryBitstream.get()); | ||
break; | ||
} | ||
} | ||
|
||
if (primaryBitstream.isEmpty()) { | ||
throw new UnprocessableEntityException("The provided uuid: " + primaryUUID + | ||
" of bitstream to set as primary doesn't match any bitstream!"); | ||
} | ||
} | ||
|
||
private UUID parseValue(Object value) { | ||
UUID primaryBitstreamUUID; | ||
try { | ||
primaryBitstreamUUID = UUID.fromString((String) value); | ||
} catch (Exception e) { | ||
throw new UnprocessableEntityException("The provided value is invalid!", e); | ||
} | ||
return primaryBitstreamUUID; | ||
} | ||
|
||
@Override | ||
protected Class<String[]> getArrayClassForEvaluation() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Class<String> getClassForEvaluation() { | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.