mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Merge remote-tracking branch 'origin/coar-notify-7' into coar-notify-7_CST-11044
# Conflicts: # dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyServiceRestRepositoryIT.java
This commit is contained in:
@@ -87,7 +87,7 @@ public class LDNBusinessDelegate {
|
|||||||
String dspaceServerUrl = configurationService.getProperty("dspace.server.url");
|
String dspaceServerUrl = configurationService.getProperty("dspace.server.url");
|
||||||
String dspaceUIUrl = configurationService.getProperty("dspace.ui.url");
|
String dspaceUIUrl = configurationService.getProperty("dspace.ui.url");
|
||||||
String dspaceName = configurationService.getProperty("dspace.name");
|
String dspaceName = configurationService.getProperty("dspace.name");
|
||||||
String dspaceLdnInboxUrl = configurationService.getProperty("ldn.notify.local-inbox-endpoint");
|
String dspaceLdnInboxUrl = configurationService.getProperty("ldn.notify.inbox");
|
||||||
|
|
||||||
log.info("DSpace Server URL {}", dspaceServerUrl);
|
log.info("DSpace Server URL {}", dspaceServerUrl);
|
||||||
log.info("DSpace UI URL {}", dspaceUIUrl);
|
log.info("DSpace UI URL {}", dspaceUIUrl);
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.ldn;
|
package org.dspace.app.ldn;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@@ -56,6 +57,9 @@ public class NotifyServiceEntity implements ReloadableEntity<Integer> {
|
|||||||
@Column(name = "enabled")
|
@Column(name = "enabled")
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
|
|
||||||
|
@Column(name = "score")
|
||||||
|
private BigDecimal score;
|
||||||
|
|
||||||
public void setId(Integer id) {
|
public void setId(Integer id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
@@ -129,4 +133,12 @@ public class NotifyServiceEntity implements ReloadableEntity<Integer> {
|
|||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BigDecimal getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(BigDecimal score) {
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,13 @@
|
|||||||
|
--
|
||||||
|
-- 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/
|
||||||
|
--
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------------
|
||||||
|
-- edit notifyservice table add score column
|
||||||
|
-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ALTER TABLE notifyservice ADD COLUMN score NUMERIC(6, 5);
|
@@ -0,0 +1,13 @@
|
|||||||
|
--
|
||||||
|
-- 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/
|
||||||
|
--
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------------
|
||||||
|
-- edit notifyservice table add score column
|
||||||
|
-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ALTER TABLE notifyservice ADD COLUMN score NUMERIC(6, 5);
|
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.builder;
|
package org.dspace.builder;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@@ -125,6 +126,11 @@ public class NotifyServiceBuilder extends AbstractBuilder<NotifyServiceEntity, N
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NotifyServiceBuilder withScore(BigDecimal score) {
|
||||||
|
notifyServiceEntity.setScore(score);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public NotifyServiceBuilder isEnabled(boolean enabled) {
|
public NotifyServiceBuilder isEnabled(boolean enabled) {
|
||||||
notifyServiceEntity.setEnabled(enabled);
|
notifyServiceEntity.setEnabled(enabled);
|
||||||
return this;
|
return this;
|
||||||
|
@@ -38,6 +38,7 @@ public class NotifyServiceConverter implements DSpaceConverter<NotifyServiceEnti
|
|||||||
notifyServiceRest.setUrl(obj.getUrl());
|
notifyServiceRest.setUrl(obj.getUrl());
|
||||||
notifyServiceRest.setLdnUrl(obj.getLdnUrl());
|
notifyServiceRest.setLdnUrl(obj.getLdnUrl());
|
||||||
notifyServiceRest.setEnabled(obj.isEnabled());
|
notifyServiceRest.setEnabled(obj.isEnabled());
|
||||||
|
notifyServiceRest.setScore(obj.getScore());
|
||||||
|
|
||||||
if (obj.getInboundPatterns() != null) {
|
if (obj.getInboundPatterns() != null) {
|
||||||
notifyServiceRest.setNotifyServiceInboundPatterns(
|
notifyServiceRest.setNotifyServiceInboundPatterns(
|
||||||
|
@@ -7,11 +7,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.model;
|
package org.dspace.app.rest.model;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import org.dspace.app.rest.RestResourceController;
|
import org.dspace.app.rest.RestResourceController;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The NotifyServiceEntity REST Resource
|
* The NotifyServiceEntity REST Resource
|
||||||
*
|
*
|
||||||
@@ -27,6 +29,7 @@ public class NotifyServiceRest extends BaseObjectRest<Integer> {
|
|||||||
private String url;
|
private String url;
|
||||||
private String ldnUrl;
|
private String ldnUrl;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
private BigDecimal score;
|
||||||
|
|
||||||
private List<NotifyServiceInboundPatternRest> notifyServiceInboundPatterns;
|
private List<NotifyServiceInboundPatternRest> notifyServiceInboundPatterns;
|
||||||
private List<NotifyServiceOutboundPatternRest> notifyServiceOutboundPatterns;
|
private List<NotifyServiceOutboundPatternRest> notifyServiceOutboundPatterns;
|
||||||
@@ -102,4 +105,14 @@ public class NotifyServiceRest extends BaseObjectRest<Integer> {
|
|||||||
List<NotifyServiceOutboundPatternRest> notifyServiceOutboundPatterns) {
|
List<NotifyServiceOutboundPatternRest> notifyServiceOutboundPatterns) {
|
||||||
this.notifyServiceOutboundPatterns = notifyServiceOutboundPatterns;
|
this.notifyServiceOutboundPatterns = notifyServiceOutboundPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BigDecimal getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(BigDecimal score) {
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.repository;
|
package org.dspace.app.rest.repository;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -16,6 +18,7 @@ import javax.servlet.ServletInputStream;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||||
import org.dspace.app.ldn.NotifyServiceInboundPattern;
|
import org.dspace.app.ldn.NotifyServiceInboundPattern;
|
||||||
import org.dspace.app.ldn.NotifyServiceOutboundPattern;
|
import org.dspace.app.ldn.NotifyServiceOutboundPattern;
|
||||||
@@ -36,8 +39,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the repository responsible to manage NotifyService Rest object
|
* This is the repository responsible to manage NotifyService Rest object
|
||||||
@@ -97,12 +102,21 @@ public class NotifyServiceRestRepository extends DSpaceRestRepository<NotifyServ
|
|||||||
throw new UnprocessableEntityException("Error parsing request body", e1);
|
throw new UnprocessableEntityException("Error parsing request body", e1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(notifyServiceRest.getScore() != null) {
|
||||||
|
if(notifyServiceRest.getScore().compareTo(java.math.BigDecimal.ZERO) == -1 ||
|
||||||
|
notifyServiceRest.getScore().compareTo(java.math.BigDecimal.ONE) == 1) {
|
||||||
|
throw new UnprocessableEntityException(format("Score out of range [0, 1] %s",
|
||||||
|
notifyServiceRest.getScore().setScale(4).toPlainString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NotifyServiceEntity notifyServiceEntity = notifyService.create(context);
|
NotifyServiceEntity notifyServiceEntity = notifyService.create(context);
|
||||||
notifyServiceEntity.setName(notifyServiceRest.getName());
|
notifyServiceEntity.setName(notifyServiceRest.getName());
|
||||||
notifyServiceEntity.setDescription(notifyServiceRest.getDescription());
|
notifyServiceEntity.setDescription(notifyServiceRest.getDescription());
|
||||||
notifyServiceEntity.setUrl(notifyServiceRest.getUrl());
|
notifyServiceEntity.setUrl(notifyServiceRest.getUrl());
|
||||||
notifyServiceEntity.setLdnUrl(notifyServiceRest.getLdnUrl());
|
notifyServiceEntity.setLdnUrl(notifyServiceRest.getLdnUrl());
|
||||||
|
notifyServiceEntity.setEnabled(notifyServiceRest.isEnabled());
|
||||||
|
|
||||||
if (notifyServiceRest.getNotifyServiceInboundPatterns() != null) {
|
if (notifyServiceRest.getNotifyServiceInboundPatterns() != null) {
|
||||||
appendNotifyServiceInboundPatterns(context, notifyServiceEntity,
|
appendNotifyServiceInboundPatterns(context, notifyServiceEntity,
|
||||||
notifyServiceRest.getNotifyServiceInboundPatterns());
|
notifyServiceRest.getNotifyServiceInboundPatterns());
|
||||||
@@ -112,8 +126,8 @@ public class NotifyServiceRestRepository extends DSpaceRestRepository<NotifyServ
|
|||||||
appendNotifyServiceOutboundPatterns(context, notifyServiceEntity,
|
appendNotifyServiceOutboundPatterns(context, notifyServiceEntity,
|
||||||
notifyServiceRest.getNotifyServiceOutboundPatterns());
|
notifyServiceRest.getNotifyServiceOutboundPatterns());
|
||||||
}
|
}
|
||||||
|
notifyServiceEntity.setScore(notifyServiceRest.getScore());
|
||||||
|
|
||||||
notifyServiceEntity.setEnabled(notifyServiceRest.isEnabled());
|
|
||||||
notifyService.update(context, notifyServiceEntity);
|
notifyService.update(context, notifyServiceEntity);
|
||||||
|
|
||||||
return converter.toRest(notifyServiceEntity, utils.obtainProjection());
|
return converter.toRest(notifyServiceEntity, utils.obtainProjection());
|
||||||
|
@@ -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.app.rest.repository.patch.operation.ldn;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||||
|
import org.dspace.app.ldn.service.NotifyService;
|
||||||
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
|
import org.dspace.app.rest.model.patch.Operation;
|
||||||
|
import org.dspace.app.rest.repository.patch.operation.PatchOperation;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation for NotifyService Score Add patches.
|
||||||
|
*
|
||||||
|
* Example: <code>
|
||||||
|
* curl -X PATCH http://${dspace.server.url}/api/ldn/ldnservices/<:id-notifyService> -H "
|
||||||
|
* Content-Type: application/json" -d '
|
||||||
|
* [{
|
||||||
|
* "op": "add",
|
||||||
|
* "path": "/score",
|
||||||
|
* "value": "score value"
|
||||||
|
* }]'
|
||||||
|
* </code>
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class NotifyServiceScoreAddOperation extends PatchOperation<NotifyServiceEntity> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotifyService notifyService;
|
||||||
|
|
||||||
|
private static final String OPERATION_PATH = "/score";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotifyServiceEntity perform(Context context, NotifyServiceEntity notifyServiceEntity, Operation operation)
|
||||||
|
throws SQLException {
|
||||||
|
checkNonExistingScoreValue(notifyServiceEntity);
|
||||||
|
checkOperationValue(operation.getValue());
|
||||||
|
Object score = operation.getValue();
|
||||||
|
if (score == null) {
|
||||||
|
throw new DSpaceBadRequestException("The /score value must be a decimal number");
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal scoreBigDecimal = null;
|
||||||
|
try {
|
||||||
|
scoreBigDecimal = new BigDecimal(score.toString());
|
||||||
|
}catch(Exception e) {
|
||||||
|
throw new DSpaceBadRequestException(format("Score out of range [0, 1] %s", score.toString()));
|
||||||
|
}
|
||||||
|
if(scoreBigDecimal.compareTo(java.math.BigDecimal.ZERO) == -1 ||
|
||||||
|
scoreBigDecimal.compareTo(java.math.BigDecimal.ONE) == 1) {
|
||||||
|
throw new UnprocessableEntityException(format("Score out of range [0, 1] %s",
|
||||||
|
scoreBigDecimal.setScale(4).toPlainString()));
|
||||||
|
}
|
||||||
|
notifyServiceEntity.setScore(scoreBigDecimal);
|
||||||
|
notifyService.update(context, notifyServiceEntity);
|
||||||
|
return notifyServiceEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws PatchBadRequestException if a value is already set in the /score path.
|
||||||
|
*
|
||||||
|
* @param notifyServiceEntity the notifyServiceEntity to update
|
||||||
|
|
||||||
|
*/
|
||||||
|
void checkNonExistingScoreValue(NotifyServiceEntity notifyServiceEntity) {
|
||||||
|
if (notifyServiceEntity.getScore() != null) {
|
||||||
|
throw new DSpaceBadRequestException("Attempting to add a value to an already existing path.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(Object objectToMatch, Operation operation) {
|
||||||
|
return (objectToMatch instanceof NotifyServiceEntity &&
|
||||||
|
operation.getOp().trim().equalsIgnoreCase(OPERATION_ADD) &&
|
||||||
|
operation.getPath().trim().toLowerCase().equalsIgnoreCase(OPERATION_PATH));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* 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.patch.operation.ldn;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||||
|
import org.dspace.app.ldn.service.NotifyService;
|
||||||
|
import org.dspace.app.rest.model.patch.Operation;
|
||||||
|
import org.dspace.app.rest.repository.patch.operation.PatchOperation;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation for NotifyService Score Remove patches.
|
||||||
|
*
|
||||||
|
* Example: <code>
|
||||||
|
* curl -X PATCH http://${dspace.server.url}/api/ldn/ldnservices/<:id-notifyService> -H "
|
||||||
|
* Content-Type: application/json" -d '
|
||||||
|
* [{
|
||||||
|
* "op": "remove",
|
||||||
|
* "path": "/score"
|
||||||
|
* }]'
|
||||||
|
* </code>
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class NotifyServiceScoreRemoveOperation extends PatchOperation<NotifyServiceEntity> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotifyService notifyService;
|
||||||
|
|
||||||
|
private static final String OPERATION_PATH = "/score";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotifyServiceEntity perform(Context context, NotifyServiceEntity notifyServiceEntity, Operation operation)
|
||||||
|
throws SQLException {
|
||||||
|
notifyServiceEntity.setScore(null);
|
||||||
|
notifyService.update(context, notifyServiceEntity);
|
||||||
|
return notifyServiceEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(Object objectToMatch, Operation operation) {
|
||||||
|
return (objectToMatch instanceof NotifyServiceEntity &&
|
||||||
|
operation.getOp().trim().equalsIgnoreCase(OPERATION_REMOVE) &&
|
||||||
|
operation.getPath().trim().toLowerCase().equalsIgnoreCase(OPERATION_PATH));
|
||||||
|
}
|
||||||
|
}
|
@@ -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.repository.patch.operation.ldn;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||||
|
import org.dspace.app.ldn.service.NotifyService;
|
||||||
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
|
import org.dspace.app.rest.model.patch.Operation;
|
||||||
|
import org.dspace.app.rest.repository.patch.operation.PatchOperation;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation for NotifyService Score Replace patches.
|
||||||
|
*
|
||||||
|
* Example: <code>
|
||||||
|
* curl -X PATCH http://${dspace.server.url}/api/ldn/ldnservices/<:id-notifyService> -H "
|
||||||
|
* Content-Type: application/json" -d '
|
||||||
|
* [{
|
||||||
|
* "op": "replace",
|
||||||
|
* "path": "/score",
|
||||||
|
* "value": "score value"
|
||||||
|
* }]'
|
||||||
|
* </code>
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class NotifyServiceScoreReplaceOperation extends PatchOperation<NotifyServiceEntity> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NotifyService notifyService;
|
||||||
|
|
||||||
|
private static final String OPERATION_PATH = "/score";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotifyServiceEntity perform(Context context, NotifyServiceEntity notifyServiceEntity, Operation operation)
|
||||||
|
throws SQLException {
|
||||||
|
checkOperationValue(operation.getValue());
|
||||||
|
|
||||||
|
Object score = operation.getValue();
|
||||||
|
if (score == null) {
|
||||||
|
throw new DSpaceBadRequestException("The /score value must be a decimal number");
|
||||||
|
}
|
||||||
|
BigDecimal scoreBigDecimal = null;
|
||||||
|
try {
|
||||||
|
scoreBigDecimal = new BigDecimal(score.toString());
|
||||||
|
}catch(Exception e) {
|
||||||
|
throw new DSpaceBadRequestException(format("Score out of range [0, 1] %s", score.toString()));
|
||||||
|
}
|
||||||
|
if(scoreBigDecimal.compareTo(java.math.BigDecimal.ZERO) == -1 ||
|
||||||
|
scoreBigDecimal.compareTo(java.math.BigDecimal.ONE) == 1) {
|
||||||
|
throw new UnprocessableEntityException(format("Score out of range [0, 1]", (String)score));
|
||||||
|
}
|
||||||
|
|
||||||
|
checkModelForExistingValue(notifyServiceEntity);
|
||||||
|
notifyServiceEntity.setScore(new BigDecimal((String)score));
|
||||||
|
notifyService.update(context, notifyServiceEntity);
|
||||||
|
return notifyServiceEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the description of notifyServiceEntity has an existing value to replace
|
||||||
|
* @param notifyServiceEntity Object on which patch is being done
|
||||||
|
*/
|
||||||
|
private void checkModelForExistingValue(NotifyServiceEntity notifyServiceEntity) {
|
||||||
|
if (notifyServiceEntity.getDescription() == null) {
|
||||||
|
throw new DSpaceBadRequestException("Attempting to replace a non-existent value (description).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(Object objectToMatch, Operation operation) {
|
||||||
|
return (objectToMatch instanceof NotifyServiceEntity &&
|
||||||
|
operation.getOp().trim().equalsIgnoreCase(OPERATION_REPLACE) &&
|
||||||
|
operation.getPath().trim().toLowerCase().equalsIgnoreCase(OPERATION_PATH));
|
||||||
|
}
|
||||||
|
}
|
@@ -12,12 +12,14 @@ import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
|||||||
import static org.dspace.app.rest.matcher.NotifyServiceMatcher.matchNotifyService;
|
import static org.dspace.app.rest.matcher.NotifyServiceMatcher.matchNotifyService;
|
||||||
import static org.dspace.app.rest.matcher.NotifyServiceMatcher.matchNotifyServicePattern;
|
import static org.dspace.app.rest.matcher.NotifyServiceMatcher.matchNotifyServicePattern;
|
||||||
import static org.hamcrest.Matchers.allOf;
|
import static org.hamcrest.Matchers.allOf;
|
||||||
|
import static org.hamcrest.Matchers.closeTo;
|
||||||
import static org.hamcrest.Matchers.contains;
|
import static org.hamcrest.Matchers.contains;
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.empty;
|
||||||
import static org.hamcrest.Matchers.hasItem;
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||||
@@ -25,12 +27,13 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.apache.commons.lang3.RandomUtils;
|
import org.apache.commons.lang3.RandomUtils;
|
||||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||||
import org.dspace.app.rest.model.NotifyServiceInboundPatternRest;
|
import org.dspace.app.rest.model.NotifyServiceInboundPatternRest;
|
||||||
@@ -46,6 +49,8 @@ import org.dspace.builder.NotifyServiceBuilder;
|
|||||||
import org.dspace.builder.NotifyServiceInboundPatternBuilder;
|
import org.dspace.builder.NotifyServiceInboundPatternBuilder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test class for {@link NotifyServiceRestRepository}.
|
* Integration test class for {@link NotifyServiceRestRepository}.
|
||||||
*
|
*
|
||||||
@@ -148,6 +153,41 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration
|
|||||||
.andExpect(status().isForbidden());
|
.andExpect(status().isForbidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createTestScoreFail() throws Exception {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
NotifyServiceInboundPatternRest inboundPatternRestOne = new NotifyServiceInboundPatternRest();
|
||||||
|
inboundPatternRestOne.setPattern("patternA");
|
||||||
|
inboundPatternRestOne.setConstraint("itemFilterA");
|
||||||
|
inboundPatternRestOne.setAutomatic(true);
|
||||||
|
|
||||||
|
NotifyServiceInboundPatternRest inboundPatternRestTwo = new NotifyServiceInboundPatternRest();
|
||||||
|
inboundPatternRestTwo.setPattern("patternB");
|
||||||
|
inboundPatternRestTwo.setAutomatic(false);
|
||||||
|
|
||||||
|
NotifyServiceOutboundPatternRest outboundPatternRest = new NotifyServiceOutboundPatternRest();
|
||||||
|
outboundPatternRest.setPattern("patternC");
|
||||||
|
outboundPatternRest.setConstraint("itemFilterC");
|
||||||
|
|
||||||
|
NotifyServiceRest notifyServiceRest = new NotifyServiceRest();
|
||||||
|
notifyServiceRest.setName("service name");
|
||||||
|
notifyServiceRest.setDescription("service description");
|
||||||
|
notifyServiceRest.setUrl("service url");
|
||||||
|
notifyServiceRest.setLdnUrl("service ldn url");
|
||||||
|
notifyServiceRest.setScore(BigDecimal.TEN);
|
||||||
|
notifyServiceRest.setNotifyServiceInboundPatterns(List.of(inboundPatternRestOne, inboundPatternRestTwo));
|
||||||
|
notifyServiceRest.setNotifyServiceOutboundPatterns(List.of(outboundPatternRest));
|
||||||
|
notifyServiceRest.setEnabled(false);
|
||||||
|
|
||||||
|
AtomicReference<Integer> idRef = new AtomicReference<Integer>();
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken).perform(post("/api/ldn/ldnservices")
|
||||||
|
.content(mapper.writeValueAsBytes(notifyServiceRest))
|
||||||
|
.contentType(contentType))
|
||||||
|
.andExpect(status().isUnprocessableEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createTest() throws Exception {
|
public void createTest() throws Exception {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
@@ -3342,30 +3382,98 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void NotifyServiceStatusReplaceOperationTestBadRequestTest() throws Exception {
|
public void NotifyServiceScoreReplaceOperationTest() throws Exception {
|
||||||
|
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
NotifyServiceEntity notifyServiceEntity =
|
NotifyServiceEntity notifyServiceEntity =
|
||||||
NotifyServiceBuilder.createNotifyServiceBuilder(context)
|
NotifyServiceBuilder.createNotifyServiceBuilder(context)
|
||||||
.withName("service name")
|
.withName("service name")
|
||||||
.withDescription("service description")
|
.withDescription("service description")
|
||||||
|
.withUrl("service url")
|
||||||
|
.withLdnUrl("service ldn url")
|
||||||
|
.withScore(BigDecimal.ZERO)
|
||||||
.withUrl("https://service.ldn.org/about")
|
.withUrl("https://service.ldn.org/about")
|
||||||
.withLdnUrl("https://service.ldn.org/inbox")
|
.withLdnUrl("https://service.ldn.org/inbox")
|
||||||
.build();
|
.build();
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
List<Operation> ops = new ArrayList<Operation>();
|
List<Operation> ops = new ArrayList<Operation>();
|
||||||
ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/enabled", "test");
|
ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/score", "0.522");
|
||||||
ops.add(inboundReplaceOperation);
|
ops.add(inboundReplaceOperation);
|
||||||
String patchBody = getPatchContent(ops);
|
String patchBody = getPatchContent(ops);
|
||||||
|
|
||||||
String authToken = getAuthToken(admin.getEmail(), password);
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
// patch not boolean value
|
|
||||||
getClient(authToken)
|
getClient(authToken)
|
||||||
.perform(patch("/api/ldn/ldnservices/" + notifyServiceEntity.getID())
|
.perform(patch("/api/ldn/ldnservices/" + notifyServiceEntity.getID())
|
||||||
.content(patchBody)
|
.content(patchBody)
|
||||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||||
.andExpect(status().isBadRequest());
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$", matchNotifyService(notifyServiceEntity.getID(), "service name",
|
||||||
|
"service description", "service url", "service ldn url", false)))
|
||||||
|
.andExpect(jsonPath("$.score", notNullValue()))
|
||||||
|
.andExpect(jsonPath("$.score", closeTo(0.522d, 0.001d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void NotifyServiceScoreReplaceOperationTestUnprocessableTest() throws Exception {
|
||||||
|
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
NotifyServiceEntity notifyServiceEntity =
|
||||||
|
NotifyServiceBuilder.createNotifyServiceBuilder(context)
|
||||||
|
.withName("service name")
|
||||||
|
.withDescription("service description")
|
||||||
|
.withUrl("service url")
|
||||||
|
.withLdnUrl("service ldn url")
|
||||||
|
.withScore(BigDecimal.ZERO)
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
List<Operation> ops = new ArrayList<Operation>();
|
||||||
|
ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/score", "10");
|
||||||
|
ops.add(inboundReplaceOperation);
|
||||||
|
String patchBody = getPatchContent(ops);
|
||||||
|
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken)
|
||||||
|
.perform(patch("/api/ldn/ldnservices/" + notifyServiceEntity.getID())
|
||||||
|
.content(patchBody)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||||
|
.andExpect(status().isUnprocessableEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notifyServiceScoreAddOperationTest() throws Exception {
|
||||||
|
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
NotifyServiceEntity notifyServiceEntity =
|
||||||
|
NotifyServiceBuilder.createNotifyServiceBuilder(context)
|
||||||
|
.withName("service name")
|
||||||
|
.withDescription("service description")
|
||||||
|
.withUrl("service url")
|
||||||
|
.withLdnUrl("service ldn url")
|
||||||
|
.isEnabled(false)
|
||||||
|
.build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
List<Operation> ops = new ArrayList<Operation>();
|
||||||
|
AddOperation operation = new AddOperation("/score", "1");
|
||||||
|
ops.add(operation);
|
||||||
|
|
||||||
|
String patchBody = getPatchContent(ops);
|
||||||
|
|
||||||
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(authToken)
|
||||||
|
.perform(patch("/api/ldn/ldnservices/" + notifyServiceEntity.getID())
|
||||||
|
.content(patchBody)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$", matchNotifyService(notifyServiceEntity.getID(), "service name",
|
||||||
|
"service description", "service url", "service ldn url", false)))
|
||||||
|
.andExpect(jsonPath("$.score", notNullValue()))
|
||||||
|
.andExpect(jsonPath("$.score", closeTo(1d, 0.001d)))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -2,9 +2,8 @@
|
|||||||
# To enable the LDN service, set to true.
|
# To enable the LDN service, set to true.
|
||||||
ldn.enabled = true
|
ldn.enabled = true
|
||||||
|
|
||||||
|
#LDN message inbox endpoint
|
||||||
ldn.notify.local-inbox-endpoint = ${dspace.server.url}/ldn/inbox
|
ldn.notify.inbox = ${dspace.server.url}/ldn/inbox
|
||||||
|
|
||||||
|
|
||||||
# List the external services IDs for review/endorsement
|
# List the external services IDs for review/endorsement
|
||||||
# These IDs needs to be configured in the input-form.xml as well
|
# These IDs needs to be configured in the input-form.xml as well
|
||||||
|
@@ -53,6 +53,7 @@ rest.properties.exposed = cc.license.jurisdiction
|
|||||||
rest.properties.exposed = identifiers.item-status.register-doi
|
rest.properties.exposed = identifiers.item-status.register-doi
|
||||||
rest.properties.exposed = authentication-password.domain.valid
|
rest.properties.exposed = authentication-password.domain.valid
|
||||||
rest.properties.exposed = coar-notify.enabled
|
rest.properties.exposed = coar-notify.enabled
|
||||||
|
rest.properties.exposed = ldn.notify.inbox
|
||||||
|
|
||||||
#---------------------------------------------------------------#
|
#---------------------------------------------------------------#
|
||||||
# These configs are used by the deprecated REST (v4-6) module #
|
# These configs are used by the deprecated REST (v4-6) module #
|
||||||
|
Reference in New Issue
Block a user