[CST-11887] refactoring

This commit is contained in:
eskander
2023-09-21 18:27:27 +03:00
parent 68609cc1fc
commit 224b94be95
10 changed files with 36 additions and 36 deletions

View File

@@ -53,8 +53,8 @@ public class NotifyServiceEntity implements ReloadableEntity<Integer> {
@OneToMany(mappedBy = "notifyService") @OneToMany(mappedBy = "notifyService")
private List<NotifyServiceOutboundPattern> outboundPatterns; private List<NotifyServiceOutboundPattern> outboundPatterns;
@Column(name = "status") @Column(name = "enabled")
private Boolean status = true; private Boolean enabled = true;
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
@@ -122,11 +122,11 @@ public class NotifyServiceEntity implements ReloadableEntity<Integer> {
return id; return id;
} }
public Boolean getStatus() { public Boolean isEnabled() {
return status; return enabled;
} }
public void setStatus(boolean status) { public void setEnabled(boolean enabled) {
this.status = status; this.enabled = enabled;
} }
} }

View File

@@ -7,7 +7,7 @@
-- --
----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------
-- edit notifyservice table add status column -- edit notifyservice table add enabled column
----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------
ALTER TABLE notifyservice ADD COLUMN status BOOLEAN DEFAULT TRUE NOT NULL; ALTER TABLE notifyservice ADD COLUMN enabled BOOLEAN DEFAULT TRUE NOT NULL;

View File

@@ -7,7 +7,7 @@
-- --
----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------
-- edit notifyservice table add status column -- edit notifyservice table add enabled column
----------------------------------------------------------------------------------- -----------------------------------------------------------------------------------
ALTER TABLE notifyservice ADD COLUMN status BOOLEAN DEFAULT TRUE NOT NULL; ALTER TABLE notifyservice ADD COLUMN enabled BOOLEAN DEFAULT TRUE NOT NULL;

View File

@@ -125,8 +125,8 @@ public class NotifyServiceBuilder extends AbstractBuilder<NotifyServiceEntity, N
return this; return this;
} }
public NotifyServiceBuilder withStatus(boolean status) { public NotifyServiceBuilder isEnabled(boolean enabled) {
notifyServiceEntity.setStatus(status); notifyServiceEntity.setEnabled(enabled);
return this; return this;
} }

View File

@@ -37,7 +37,7 @@ public class NotifyServiceConverter implements DSpaceConverter<NotifyServiceEnti
notifyServiceRest.setDescription(obj.getDescription()); notifyServiceRest.setDescription(obj.getDescription());
notifyServiceRest.setUrl(obj.getUrl()); notifyServiceRest.setUrl(obj.getUrl());
notifyServiceRest.setLdnUrl(obj.getLdnUrl()); notifyServiceRest.setLdnUrl(obj.getLdnUrl());
notifyServiceRest.setStatus(obj.getStatus()); notifyServiceRest.setEnabled(obj.isEnabled());
if (obj.getInboundPatterns() != null) { if (obj.getInboundPatterns() != null) {
notifyServiceRest.setNotifyServiceInboundPatterns( notifyServiceRest.setNotifyServiceInboundPatterns(

View File

@@ -26,7 +26,7 @@ public class NotifyServiceRest extends BaseObjectRest<Integer> {
private String description; private String description;
private String url; private String url;
private String ldnUrl; private String ldnUrl;
private boolean status; private boolean enabled;
private List<NotifyServiceInboundPatternRest> notifyServiceInboundPatterns; private List<NotifyServiceInboundPatternRest> notifyServiceInboundPatterns;
private List<NotifyServiceOutboundPatternRest> notifyServiceOutboundPatterns; private List<NotifyServiceOutboundPatternRest> notifyServiceOutboundPatterns;
@@ -78,12 +78,12 @@ public class NotifyServiceRest extends BaseObjectRest<Integer> {
this.ldnUrl = ldnUrl; this.ldnUrl = ldnUrl;
} }
public boolean getStatus() { public boolean isEnabled() {
return status; return enabled;
} }
public void setStatus(boolean status) { public void setEnabled(boolean enabled) {
this.status = status; this.enabled = enabled;
} }
public List<NotifyServiceInboundPatternRest> getNotifyServiceInboundPatterns() { public List<NotifyServiceInboundPatternRest> getNotifyServiceInboundPatterns() {
return notifyServiceInboundPatterns; return notifyServiceInboundPatterns;

View File

@@ -87,7 +87,7 @@ public class NotifyServiceRestRepository extends DSpaceRestRepository<NotifyServ
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.setStatus(notifyServiceRest.getStatus()); notifyServiceEntity.setEnabled(notifyServiceRest.isEnabled());
notifyService.update(context, notifyServiceEntity); notifyService.update(context, notifyServiceEntity);
return converter.toRest(notifyServiceEntity, utils.obtainProjection()); return converter.toRest(notifyServiceEntity, utils.obtainProjection());

View File

@@ -19,19 +19,19 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* Implementation for NotifyService Status Replace patches. * Implementation for NotifyService Enabled Replace patches.
* *
* Example: <code> * Example: <code>
* curl -X PATCH http://${dspace.server.url}/api/ldn/ldnservices/<:id-notifyService> -H " * curl -X PATCH http://${dspace.server.url}/api/ldn/ldnservices/<:id-notifyService> -H "
* Content-Type: application/json" -d ' * Content-Type: application/json" -d '
* [{ * [{
* "op": "replace", * "op": "replace",
* "path": "/status" * "path": "/enabled"
* }]' * }]'
* </code> * </code>
*/ */
@Component @Component
public class NotifyServiceStatusReplaceOperation extends PatchOperation<NotifyServiceEntity> { public class NotifyServiceEnabledReplaceOperation extends PatchOperation<NotifyServiceEntity> {
@Autowired @Autowired
private NotifyService notifyService; private NotifyService notifyService;
@@ -39,21 +39,21 @@ public class NotifyServiceStatusReplaceOperation extends PatchOperation<NotifySe
@Autowired @Autowired
private NotifyServicePatchUtils notifyServicePatchUtils; private NotifyServicePatchUtils notifyServicePatchUtils;
private static final String OPERATION_PATH = "/status"; private static final String OPERATION_PATH = "/enabled";
@Override @Override
public NotifyServiceEntity perform(Context context, NotifyServiceEntity notifyServiceEntity, Operation operation) public NotifyServiceEntity perform(Context context, NotifyServiceEntity notifyServiceEntity, Operation operation)
throws SQLException { throws SQLException {
checkOperationValue(operation.getValue()); checkOperationValue(operation.getValue());
Boolean status = getBooleanOperationValue(operation.getValue()); Boolean enabled = getBooleanOperationValue(operation.getValue());
if (supports(notifyServiceEntity, operation)) { if (supports(notifyServiceEntity, operation)) {
notifyServiceEntity.setStatus(status); notifyServiceEntity.setEnabled(enabled);
notifyService.update(context, notifyServiceEntity); notifyService.update(context, notifyServiceEntity);
return notifyServiceEntity; return notifyServiceEntity;
} else { } else {
throw new DSpaceBadRequestException( throw new DSpaceBadRequestException(
"NotifyServiceStatusReplaceOperation does not support this operation"); "NotifyServiceEnabledReplaceOperation does not support this operation");
} }
} }

View File

@@ -153,7 +153,7 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration
notifyServiceRest.setDescription("service description"); notifyServiceRest.setDescription("service description");
notifyServiceRest.setUrl("service url"); notifyServiceRest.setUrl("service url");
notifyServiceRest.setLdnUrl("service ldn url"); notifyServiceRest.setLdnUrl("service ldn url");
notifyServiceRest.setStatus(false); notifyServiceRest.setEnabled(false);
AtomicReference<Integer> idRef = new AtomicReference<Integer>(); AtomicReference<Integer> idRef = new AtomicReference<Integer>();
String authToken = getAuthToken(admin.getEmail(), password); String authToken = getAuthToken(admin.getEmail(), password);
@@ -240,7 +240,7 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration
.withName("service name") .withName("service name")
.withUrl("service url") .withUrl("service url")
.withLdnUrl("service ldn url") .withLdnUrl("service ldn url")
.withStatus(false) .isEnabled(false)
.build(); .build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -330,7 +330,7 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration
.withDescription("service description") .withDescription("service description")
.withUrl("service url") .withUrl("service url")
.withLdnUrl("service ldn url") .withLdnUrl("service ldn url")
.withStatus(false) .isEnabled(false)
.build(); .build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -3199,12 +3199,12 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration
.withDescription("service description") .withDescription("service description")
.withUrl("service url") .withUrl("service url")
.withLdnUrl("service ldn url") .withLdnUrl("service ldn url")
.withStatus(true) .isEnabled(true)
.build(); .build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<Operation>();
ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/status", "false"); ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/enabled", "false");
ops.add(inboundReplaceOperation); ops.add(inboundReplaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -3234,7 +3234,7 @@ public class NotifyServiceRestRepositoryIT extends AbstractControllerIntegration
context.restoreAuthSystemState(); context.restoreAuthSystemState();
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<Operation>();
ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/status", "test"); ReplaceOperation inboundReplaceOperation = new ReplaceOperation("/enabled", "test");
ops.add(inboundReplaceOperation); ops.add(inboundReplaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);

View File

@@ -38,13 +38,13 @@ public class NotifyServiceMatcher {
} }
public static Matcher<? super Object> matchNotifyService(String name, String description, String url, public static Matcher<? super Object> matchNotifyService(String name, String description, String url,
String ldnUrl, boolean status) { String ldnUrl, boolean enabled) {
return allOf( return allOf(
hasJsonPath("$.name", is(name)), hasJsonPath("$.name", is(name)),
hasJsonPath("$.description", is(description)), hasJsonPath("$.description", is(description)),
hasJsonPath("$.url", is(url)), hasJsonPath("$.url", is(url)),
hasJsonPath("$.ldnUrl", is(ldnUrl)), hasJsonPath("$.ldnUrl", is(ldnUrl)),
hasJsonPath("$.status", is(status)), hasJsonPath("$.enabled", is(enabled)),
hasJsonPath("$._links.self.href", containsString("/api/ldn/ldnservices/")) hasJsonPath("$._links.self.href", containsString("/api/ldn/ldnservices/"))
); );
} }
@@ -60,10 +60,10 @@ public class NotifyServiceMatcher {
} }
public static Matcher<? super Object> matchNotifyService(int id, String name, String description, public static Matcher<? super Object> matchNotifyService(int id, String name, String description,
String url, String ldnUrl, boolean status) { String url, String ldnUrl, boolean enabled) {
return allOf( return allOf(
hasJsonPath("$.id", is(id)), hasJsonPath("$.id", is(id)),
matchNotifyService(name, description, url, ldnUrl, status), matchNotifyService(name, description, url, ldnUrl, enabled),
hasJsonPath("$._links.self.href", startsWith(REST_SERVER_URL)), hasJsonPath("$._links.self.href", startsWith(REST_SERVER_URL)),
hasJsonPath("$._links.self.href", endsWith("/api/ldn/ldnservices/" + id)) hasJsonPath("$._links.self.href", endsWith("/api/ldn/ldnservices/" + id))
); );