From eea9750e3d2b5adeebd7a0631093b7f07c261f3a Mon Sep 17 00:00:00 2001 From: frabacche Date: Fri, 13 Oct 2023 17:33:45 +0200 Subject: [PATCH 1/6] CST-12178 notifyService score attribute, consistency inside controller to be reviewed --- .../dspace/app/ldn/NotifyServiceEntity.java | 12 ++++++ ..._add_score_column_notifyservices_table.sql | 13 +++++++ ..._add_score_column_notifyservices_table.sql | 13 +++++++ .../app/rest/model/NotifyServiceRest.java | 15 +++++++- .../NotifyServiceRestRepository.java | 13 +++++++ .../rest/NotifyServiceRestRepositoryIT.java | 37 +++++++++++++++++++ 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V8.0_2023.10.13__add_score_column_notifyservices_table.sql create mode 100644 dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V8.0_2023.10.13__add_score_column_notifyservices_table.sql diff --git a/dspace-api/src/main/java/org/dspace/app/ldn/NotifyServiceEntity.java b/dspace-api/src/main/java/org/dspace/app/ldn/NotifyServiceEntity.java index 9a7e9c7caf..e15267b480 100644 --- a/dspace-api/src/main/java/org/dspace/app/ldn/NotifyServiceEntity.java +++ b/dspace-api/src/main/java/org/dspace/app/ldn/NotifyServiceEntity.java @@ -7,6 +7,7 @@ */ package org.dspace.app.ldn; +import java.math.BigDecimal; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; @@ -56,6 +57,9 @@ public class NotifyServiceEntity implements ReloadableEntity { @Column(name = "enabled") private boolean enabled = false; + @Column(name = "score") + private BigDecimal score; + public void setId(Integer id) { this.id = id; } @@ -129,4 +133,12 @@ public class NotifyServiceEntity implements ReloadableEntity { public void setEnabled(boolean enabled) { this.enabled = enabled; } + + public BigDecimal getScore() { + return score; + } + + public void setScore(BigDecimal score) { + this.score = score; + } } diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V8.0_2023.10.13__add_score_column_notifyservices_table.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V8.0_2023.10.13__add_score_column_notifyservices_table.sql new file mode 100644 index 0000000000..418be81dcd --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V8.0_2023.10.13__add_score_column_notifyservices_table.sql @@ -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) DEFAULT NULL CHECK (score >= 0 AND score <= 1); \ No newline at end of file diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V8.0_2023.10.13__add_score_column_notifyservices_table.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V8.0_2023.10.13__add_score_column_notifyservices_table.sql new file mode 100644 index 0000000000..418be81dcd --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V8.0_2023.10.13__add_score_column_notifyservices_table.sql @@ -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) DEFAULT NULL CHECK (score >= 0 AND score <= 1); \ No newline at end of file diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/NotifyServiceRest.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/NotifyServiceRest.java index 2af0bbbe2f..7e23ba8c84 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/NotifyServiceRest.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/NotifyServiceRest.java @@ -7,11 +7,13 @@ */ package org.dspace.app.rest.model; +import java.math.BigDecimal; import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; import org.dspace.app.rest.RestResourceController; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * The NotifyServiceEntity REST Resource * @@ -27,6 +29,7 @@ public class NotifyServiceRest extends BaseObjectRest { private String url; private String ldnUrl; private boolean enabled; + private BigDecimal score; private List notifyServiceInboundPatterns; private List notifyServiceOutboundPatterns; @@ -102,4 +105,14 @@ public class NotifyServiceRest extends BaseObjectRest { List notifyServiceOutboundPatterns) { this.notifyServiceOutboundPatterns = notifyServiceOutboundPatterns; } + + public BigDecimal getScore() { + return score; + } + + public void setScore(BigDecimal score) { + this.score = score; + } + + } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/NotifyServiceRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/NotifyServiceRestRepository.java index 76a8d54877..7aeec574fa 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/NotifyServiceRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/NotifyServiceRestRepository.java @@ -7,6 +7,8 @@ */ package org.dspace.app.rest.repository; +import static java.lang.String.format; + import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; @@ -15,6 +17,7 @@ import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import com.fasterxml.jackson.databind.ObjectMapper; + import org.dspace.app.ldn.NotifyServiceEntity; import org.dspace.app.ldn.NotifyServiceInboundPattern; import org.dspace.app.ldn.NotifyServiceOutboundPattern; @@ -35,8 +38,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.rest.webmvc.ResourceNotFoundException; +import org.springframework.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Component; +import org.springframework.web.server.ResponseStatusException; /** * This is the repository responsible to manage NotifyService Rest object @@ -113,6 +118,14 @@ public class NotifyServiceRestRepository extends DSpaceRestRepository idRef = new AtomicReference(); + String authToken = getAuthToken(admin.getEmail(), password); + getClient(authToken).perform(post("/api/ldn/ldnservices") + .content(mapper.writeValueAsBytes(notifyServiceRest)) + .contentType(contentType)) + .andExpect(status().isUnprocessableEntity()); + } @Test public void createTest() throws Exception { From ae611ca9fd603ecdb221d126d393cbf5d14578f2 Mon Sep 17 00:00:00 2001 From: frabacche Date: Mon, 16 Oct 2023 14:57:20 +0200 Subject: [PATCH 2/6] CST-12178 move score check before creating the NotifyServiceEntity --- .../NotifyServiceRestRepository.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/NotifyServiceRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/NotifyServiceRestRepository.java index 7aeec574fa..a7a3eba307 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/NotifyServiceRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/NotifyServiceRestRepository.java @@ -101,12 +101,20 @@ public class NotifyServiceRestRepository extends DSpaceRestRepository Date: Mon, 16 Oct 2023 17:29:32 +0200 Subject: [PATCH 3/6] CST-12178 Patch first implementation (tests still broken) --- .../dspace/builder/NotifyServiceBuilder.java | 6 ++ .../NotifyServiceRestRepository.java | 3 +- .../ldn/NotifyServiceScoreAddOperation.java | 90 +++++++++++++++++++ .../NotifyServiceScoreRemoveOperation.java | 54 +++++++++++ .../NotifyServiceScoreReplaceOperation.java | 87 ++++++++++++++++++ .../rest/NotifyServiceRestRepositoryIT.java | 71 ++++++++++++++- 6 files changed, 307 insertions(+), 4 deletions(-) create mode 100644 dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreAddOperation.java create mode 100644 dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreRemoveOperation.java create mode 100644 dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreReplaceOperation.java diff --git a/dspace-api/src/test/java/org/dspace/builder/NotifyServiceBuilder.java b/dspace-api/src/test/java/org/dspace/builder/NotifyServiceBuilder.java index c9e1b4825f..a7886ebe51 100644 --- a/dspace-api/src/test/java/org/dspace/builder/NotifyServiceBuilder.java +++ b/dspace-api/src/test/java/org/dspace/builder/NotifyServiceBuilder.java @@ -7,6 +7,7 @@ */ package org.dspace.builder; +import java.math.BigDecimal; import java.sql.SQLException; import org.apache.logging.log4j.LogManager; @@ -125,6 +126,11 @@ public class NotifyServiceBuilder extends AbstractBuilder + * 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" + * }]' + * + */ +@Component +public class NotifyServiceScoreAddOperation extends PatchOperation { + + @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"); + } + try { + BigDecimal scoreBigDecimal = new BigDecimal((String)score); + 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())); + } + }catch(Exception e) { + throw new DSpaceBadRequestException(format("Score out of range [0, 1] %s", (String)score)); + } + checkNonExistingScoreValue(notifyServiceEntity); + notifyServiceEntity.setScore((BigDecimal) score); + 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)); + } +} diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreRemoveOperation.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreRemoveOperation.java new file mode 100644 index 0000000000..e26d888e9f --- /dev/null +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreRemoveOperation.java @@ -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: + * curl -X PATCH http://${dspace.server.url}/api/ldn/ldnservices/<:id-notifyService> -H " + * Content-Type: application/json" -d ' + * [{ + * "op": "remove", + * "path": "/score" + * }]' + * + */ +@Component +public class NotifyServiceScoreRemoveOperation extends PatchOperation { + + @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)); + } +} diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreReplaceOperation.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreReplaceOperation.java new file mode 100644 index 0000000000..31523252aa --- /dev/null +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/patch/operation/ldn/NotifyServiceScoreReplaceOperation.java @@ -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.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: + * 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" + * }]' + * + */ +@Component +public class NotifyServiceScoreReplaceOperation extends PatchOperation { + + @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"); + } + try { + BigDecimal scoreBigDecimal = new BigDecimal((String)score); + 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)); + } + }catch(Exception e) { + throw new DSpaceBadRequestException(format("Score out of range [0, 1] %s", (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)); + } +} diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyServiceRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyServiceRestRepositoryIT.java index 742b455e39..8f361c7238 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyServiceRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyServiceRestRepositoryIT.java @@ -3286,7 +3286,7 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration } @Test - public void NotifyServiceStatusReplaceOperationTestBadRequestTest() throws Exception { + public void NotifyServiceScoreReplaceOperationTest() throws Exception { context.turnOffAuthorisationSystem(); NotifyServiceEntity notifyServiceEntity = @@ -3295,11 +3295,12 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration .withDescription("service description") .withUrl("service url") .withLdnUrl("service ldn url") + .withScore(BigDecimal.ZERO) .build(); context.restoreAuthSystemState(); List ops = new ArrayList(); - ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/enabled", "test"); + ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/score", "0.5"); ops.add(inboundReplaceOperation); String patchBody = getPatchContent(ops); @@ -3309,7 +3310,71 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration .perform(patch("/api/ldn/ldnservices/" + notifyServiceEntity.getID()) .content(patchBody) .contentType(MediaType.APPLICATION_JSON_PATCH_JSON)) - .andExpect(status().isBadRequest()); + .andExpect(status().isOk()) + .andExpect(jsonPath("$", matchNotifyService(notifyServiceEntity.getID(), "service name", + "add service description", "service url", "service ldn url", false)) + ); } + @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 ops = new ArrayList(); + ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/score", BigDecimal.TEN); + ops.add(inboundReplaceOperation); + String patchBody = getPatchContent(ops); + + String authToken = getAuthToken(admin.getEmail(), password); + // patch not boolean value + 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") + .withUrl("service url") + .withLdnUrl("service ldn url") + .isEnabled(false) + .build(); + context.restoreAuthSystemState(); + + List ops = new ArrayList(); + AddOperation operation = new AddOperation("/score", BigDecimal.ONE); + 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", + "add service description", "service url", "service ldn url", false)) + ); + } + + } \ No newline at end of file From 8b67c77ce834e671fa51015f18fce5f423dc1a02 Mon Sep 17 00:00:00 2001 From: frabacche Date: Tue, 17 Oct 2023 10:06:50 +0200 Subject: [PATCH 4/6] CST-12178 default score value as null, checks about its value has to be delegated to the services, not as db constraints --- .../V8.0_2023.10.13__add_score_column_notifyservices_table.sql | 2 +- .../V8.0_2023.10.13__add_score_column_notifyservices_table.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V8.0_2023.10.13__add_score_column_notifyservices_table.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V8.0_2023.10.13__add_score_column_notifyservices_table.sql index 418be81dcd..2be6684f9c 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V8.0_2023.10.13__add_score_column_notifyservices_table.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V8.0_2023.10.13__add_score_column_notifyservices_table.sql @@ -10,4 +10,4 @@ -- edit notifyservice table add score column ----------------------------------------------------------------------------------- -ALTER TABLE notifyservice ADD COLUMN score NUMERIC(6, 5) DEFAULT NULL CHECK (score >= 0 AND score <= 1); \ No newline at end of file +ALTER TABLE notifyservice ADD COLUMN score NUMERIC(6, 5); \ No newline at end of file diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V8.0_2023.10.13__add_score_column_notifyservices_table.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V8.0_2023.10.13__add_score_column_notifyservices_table.sql index 418be81dcd..2be6684f9c 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V8.0_2023.10.13__add_score_column_notifyservices_table.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V8.0_2023.10.13__add_score_column_notifyservices_table.sql @@ -10,4 +10,4 @@ -- edit notifyservice table add score column ----------------------------------------------------------------------------------- -ALTER TABLE notifyservice ADD COLUMN score NUMERIC(6, 5) DEFAULT NULL CHECK (score >= 0 AND score <= 1); \ No newline at end of file +ALTER TABLE notifyservice ADD COLUMN score NUMERIC(6, 5); \ No newline at end of file From 06611e9158341cce3ecb645d4f5acf81441957f0 Mon Sep 17 00:00:00 2001 From: frabacche Date: Tue, 17 Oct 2023 14:37:44 +0200 Subject: [PATCH 5/6] CST-12178 notifyservice entity score attribute Patch + tests --- .../converter/NotifyServiceConverter.java | 1 + .../ldn/NotifyServiceScoreAddOperation.java | 22 +++++++-------- .../NotifyServiceScoreReplaceOperation.java | 13 +++++---- .../rest/NotifyServiceRestRepositoryIT.java | 28 +++++++++++-------- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/NotifyServiceConverter.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/NotifyServiceConverter.java index 720e60c873..f454f8a0f4 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/NotifyServiceConverter.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/NotifyServiceConverter.java @@ -38,6 +38,7 @@ public class NotifyServiceConverter implements DSpaceConverter ops = new ArrayList(); - ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/score", "0.5"); + ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/score", "0.522"); ops.add(inboundReplaceOperation); String patchBody = getPatchContent(ops); String authToken = getAuthToken(admin.getEmail(), password); - // patch not boolean value 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", - "add service description", "service url", "service ldn url", false)) - ); + "service description", "service url", "service ldn url", false))) + .andExpect(jsonPath("$.score", notNullValue())) + .andExpect(jsonPath("$.score", closeTo(0.522d, 0.001d))); } @Test @@ -3331,12 +3333,11 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration context.restoreAuthSystemState(); List ops = new ArrayList(); - ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/score", BigDecimal.TEN); + ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/score", "10"); ops.add(inboundReplaceOperation); String patchBody = getPatchContent(ops); String authToken = getAuthToken(admin.getEmail(), password); - // patch not boolean value getClient(authToken) .perform(patch("/api/ldn/ldnservices/" + notifyServiceEntity.getID()) .content(patchBody) @@ -3353,6 +3354,7 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration NotifyServiceEntity notifyServiceEntity = NotifyServiceBuilder.createNotifyServiceBuilder(context) .withName("service name") + .withDescription("service description") .withUrl("service url") .withLdnUrl("service ldn url") .isEnabled(false) @@ -3360,7 +3362,7 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration context.restoreAuthSystemState(); List ops = new ArrayList(); - AddOperation operation = new AddOperation("/score", BigDecimal.ONE); + AddOperation operation = new AddOperation("/score", "1"); ops.add(operation); String patchBody = getPatchContent(ops); @@ -3372,8 +3374,10 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration .contentType(MediaType.APPLICATION_JSON_PATCH_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$", matchNotifyService(notifyServiceEntity.getID(), "service name", - "add service description", "service url", "service ldn url", false)) - ); + "service description", "service url", "service ldn url", false))) + .andExpect(jsonPath("$.score", notNullValue())) + .andExpect(jsonPath("$.score", closeTo(1d, 0.001d))) + ; } From b143d1b3c35198db9b3c928f5e7f723bf3541fed Mon Sep 17 00:00:00 2001 From: frabacche Date: Thu, 26 Oct 2023 16:16:27 +0200 Subject: [PATCH 6/6] CST-12236 rename and expose ldn inbox endpoint --- .../main/java/org/dspace/app/ldn/LDNBusinessDelegate.java | 2 +- dspace/config/modules/ldn.cfg | 5 ++--- dspace/config/modules/rest.cfg | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/app/ldn/LDNBusinessDelegate.java b/dspace-api/src/main/java/org/dspace/app/ldn/LDNBusinessDelegate.java index 6890d8b0fb..8fa38645b9 100644 --- a/dspace-api/src/main/java/org/dspace/app/ldn/LDNBusinessDelegate.java +++ b/dspace-api/src/main/java/org/dspace/app/ldn/LDNBusinessDelegate.java @@ -87,7 +87,7 @@ public class LDNBusinessDelegate { String dspaceServerUrl = configurationService.getProperty("dspace.server.url"); String dspaceUIUrl = configurationService.getProperty("dspace.ui.url"); 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 UI URL {}", dspaceUIUrl); diff --git a/dspace/config/modules/ldn.cfg b/dspace/config/modules/ldn.cfg index a58ba4a0b7..688a337edf 100644 --- a/dspace/config/modules/ldn.cfg +++ b/dspace/config/modules/ldn.cfg @@ -2,9 +2,8 @@ # To enable the LDN service, set to true. ldn.enabled = true - -ldn.notify.local-inbox-endpoint = ${dspace.server.url}/ldn/inbox - +#LDN message inbox endpoint +ldn.notify.inbox = ${dspace.server.url}/ldn/inbox # List the external services IDs for review/endorsement # These IDs needs to be configured in the input-form.xml as well diff --git a/dspace/config/modules/rest.cfg b/dspace/config/modules/rest.cfg index 846d587b31..f349c40e7b 100644 --- a/dspace/config/modules/rest.cfg +++ b/dspace/config/modules/rest.cfg @@ -53,6 +53,7 @@ rest.properties.exposed = cc.license.jurisdiction rest.properties.exposed = identifiers.item-status.register-doi rest.properties.exposed = authentication-password.domain.valid rest.properties.exposed = coar-notify.enabled +rest.properties.exposed = ldn.notify.inbox #---------------------------------------------------------------# # These configs are used by the deprecated REST (v4-6) module #