mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
97425: Fix minor issues
This commit is contained in:
@@ -18,34 +18,35 @@ package org.dspace.alerts;
|
||||
* sessions.
|
||||
*/
|
||||
public enum AllowSessionsEnum {
|
||||
ALLOW_ALL_SESSIONS(0),
|
||||
ALLOW_CURRENT_SESSIONS_ONLY(1),
|
||||
ALLOW_ADMIN_SESSIONS_ONLY(2);
|
||||
ALLOW_ALL_SESSIONS("all"),
|
||||
ALLOW_CURRENT_SESSIONS_ONLY("current"),
|
||||
ALLOW_ADMIN_SESSIONS_ONLY("admin");
|
||||
|
||||
private int allowSessionsType;
|
||||
private String allowSessionsType;
|
||||
|
||||
AllowSessionsEnum(int allowSessionsType) {
|
||||
AllowSessionsEnum(String allowSessionsType) {
|
||||
this.allowSessionsType = allowSessionsType;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
public String getValue() {
|
||||
return allowSessionsType;
|
||||
}
|
||||
|
||||
public static AllowSessionsEnum fromInt(Integer alertAllowSessionType) {
|
||||
public static AllowSessionsEnum fromString(String alertAllowSessionType) {
|
||||
if (alertAllowSessionType == null) {
|
||||
return AllowSessionsEnum.ALLOW_ALL_SESSIONS;
|
||||
}
|
||||
|
||||
switch (alertAllowSessionType) {
|
||||
case 0:
|
||||
case "all":
|
||||
return AllowSessionsEnum.ALLOW_ALL_SESSIONS;
|
||||
case 1:
|
||||
case "current":
|
||||
return AllowSessionsEnum.ALLOW_CURRENT_SESSIONS_ONLY;
|
||||
case 2:
|
||||
case "admin" :
|
||||
return AllowSessionsEnum.ALLOW_ADMIN_SESSIONS_ONLY;
|
||||
default:
|
||||
throw new IllegalArgumentException("No corresponding enum value for integer");
|
||||
throw new IllegalArgumentException("No corresponding enum value for provided string: "
|
||||
+ alertAllowSessionType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,7 @@ public class SystemWideAlert implements ReloadableEntity<Integer> {
|
||||
private String message;
|
||||
|
||||
@Column(name = "allow_sessions")
|
||||
private int allowSessions;
|
||||
private String allowSessions;
|
||||
|
||||
@Column(name = "countdown_to")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@@ -97,8 +97,8 @@ public class SystemWideAlert implements ReloadableEntity<Integer> {
|
||||
*
|
||||
* @return what kind of sessions are allowed while the system-wide alert is active
|
||||
*/
|
||||
public int getAllowSessions() {
|
||||
return allowSessions;
|
||||
public AllowSessionsEnum getAllowSessions() {
|
||||
return AllowSessionsEnum.fromString(allowSessions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -112,7 +112,7 @@ public class SystemWideAlertServiceImpl implements SystemWideAlertService {
|
||||
if (active == null || active.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return active.get(0).getAllowSessions() == AllowSessionsEnum.ALLOW_ALL_SESSIONS.getValue();
|
||||
return active.get(0).getAllowSessions() == AllowSessionsEnum.ALLOW_ALL_SESSIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,6 +124,6 @@ public class SystemWideAlertServiceImpl implements SystemWideAlertService {
|
||||
if (active == null || active.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return active.get(0).getAllowSessions() != AllowSessionsEnum.ALLOW_ADMIN_SESSIONS_ONLY.getValue();
|
||||
return active.get(0).getAllowSessions() != AllowSessionsEnum.ALLOW_ADMIN_SESSIONS_ONLY;
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ CREATE TABLE systemwidealert
|
||||
(
|
||||
alert_id INTEGER NOT NULL PRIMARY KEY,
|
||||
message VARCHAR(512),
|
||||
allow_sessions INTEGER,
|
||||
allow_sessions VARCHAR(64),
|
||||
countdown_to TIMESTAMP,
|
||||
active BOOLEAN
|
||||
);
|
||||
|
@@ -16,7 +16,7 @@ CREATE TABLE systemwidealert
|
||||
(
|
||||
alert_id INTEGER NOT NULL PRIMARY KEY,
|
||||
message VARCHAR(512),
|
||||
allow_sessions INTEGER,
|
||||
allow_sessions VARCHAR(64),
|
||||
countdown_to TIMESTAMP,
|
||||
active BOOLEAN
|
||||
);
|
||||
|
@@ -16,7 +16,7 @@ CREATE TABLE systemwidealert
|
||||
(
|
||||
alert_id INTEGER NOT NULL PRIMARY KEY,
|
||||
message VARCHAR(512),
|
||||
allow_sessions INTEGER,
|
||||
allow_sessions VARCHAR(64),
|
||||
countdown_to TIMESTAMP,
|
||||
active BOOLEAN
|
||||
);
|
||||
|
@@ -133,7 +133,7 @@ public class SystemWideAlertServiceTest {
|
||||
@Test
|
||||
public void canNonAdminUserLoginTrueTest() throws Exception {
|
||||
// Mock the alert state
|
||||
when(systemWideAlert.getAllowSessions()).thenReturn(AllowSessionsEnum.ALLOW_ALL_SESSIONS.getValue());
|
||||
when(systemWideAlert.getAllowSessions()).thenReturn(AllowSessionsEnum.ALLOW_ALL_SESSIONS);
|
||||
|
||||
// Mock DAO to return our defined systemWideAlertList
|
||||
List<SystemWideAlert> systemWideAlertList = new ArrayList<>();
|
||||
@@ -147,7 +147,7 @@ public class SystemWideAlertServiceTest {
|
||||
@Test
|
||||
public void canNonAdminUserLoginFalseTest() throws Exception {
|
||||
// Mock the alert state
|
||||
when(systemWideAlert.getAllowSessions()).thenReturn(AllowSessionsEnum.ALLOW_ADMIN_SESSIONS_ONLY.getValue());
|
||||
when(systemWideAlert.getAllowSessions()).thenReturn(AllowSessionsEnum.ALLOW_ADMIN_SESSIONS_ONLY);
|
||||
|
||||
// Mock DAO to return our defined systemWideAlertList
|
||||
List<SystemWideAlert> systemWideAlertList = new ArrayList<>();
|
||||
@@ -169,7 +169,7 @@ public class SystemWideAlertServiceTest {
|
||||
when(authorizeService.isAdmin(context, eperson)).thenReturn(false);
|
||||
|
||||
// Mock the alert state
|
||||
when(systemWideAlert.getAllowSessions()).thenReturn(AllowSessionsEnum.ALLOW_CURRENT_SESSIONS_ONLY.getValue());
|
||||
when(systemWideAlert.getAllowSessions()).thenReturn(AllowSessionsEnum.ALLOW_CURRENT_SESSIONS_ONLY);
|
||||
|
||||
// Mock DAO to return our defined systemWideAlertList
|
||||
List<SystemWideAlert> systemWideAlertList = new ArrayList<>();
|
||||
@@ -186,7 +186,7 @@ public class SystemWideAlertServiceTest {
|
||||
when(authorizeService.isAdmin(context, eperson)).thenReturn(false);
|
||||
|
||||
// Mock the alert state
|
||||
when(systemWideAlert.getAllowSessions()).thenReturn(AllowSessionsEnum.ALLOW_ADMIN_SESSIONS_ONLY.getValue());
|
||||
when(systemWideAlert.getAllowSessions()).thenReturn(AllowSessionsEnum.ALLOW_ADMIN_SESSIONS_ONLY);
|
||||
|
||||
// Mock DAO to return our defined systemWideAlertList
|
||||
List<SystemWideAlert> systemWideAlertList = new ArrayList<>();
|
||||
|
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
package org.dspace.builder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -16,7 +15,6 @@ import org.dspace.alerts.SystemWideAlert;
|
||||
import org.dspace.alerts.service.SystemWideAlertService;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.scripts.Process;
|
||||
|
||||
public class SystemWideAlertBuilder extends AbstractBuilder<SystemWideAlert, SystemWideAlertService> {
|
||||
|
||||
@@ -93,20 +91,4 @@ public class SystemWideAlertBuilder extends AbstractBuilder<SystemWideAlert, Sys
|
||||
getService().delete(c, alert);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteProcess(Integer integer) throws SQLException, IOException {
|
||||
try (Context c = new Context()) {
|
||||
c.turnOffAuthorisationSystem();
|
||||
Process process = processService.find(c, integer);
|
||||
if (process != null) {
|
||||
try {
|
||||
processService.delete(c, process);
|
||||
} catch (AuthorizeException e) {
|
||||
// cannot occur, just wrap it to make the compiler happy
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
c.complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ public class SystemWideAlertConverter implements DSpaceConverter<SystemWideAlert
|
||||
systemWideAlertRest.setId(systemWideAlert.getID());
|
||||
systemWideAlertRest.setAlertId(systemWideAlert.getID());
|
||||
systemWideAlertRest.setMessage(systemWideAlert.getMessage());
|
||||
systemWideAlertRest.setAllowSessions(systemWideAlert.getAllowSessions());
|
||||
systemWideAlertRest.setAllowSessions(systemWideAlert.getAllowSessions().getValue());
|
||||
systemWideAlertRest.setCountdownTo(systemWideAlert.getCountdownTo());
|
||||
systemWideAlertRest.setActive(systemWideAlert.isActive());
|
||||
return systemWideAlertRest;
|
||||
|
@@ -36,7 +36,7 @@ public class SystemWideAlertRest extends BaseObjectRest<Integer> {
|
||||
|
||||
private Integer alertId;
|
||||
private String message;
|
||||
private Integer allowSessions;
|
||||
private String allowSessions;
|
||||
private Date countdownTo;
|
||||
private boolean active;
|
||||
|
||||
@@ -56,11 +56,11 @@ public class SystemWideAlertRest extends BaseObjectRest<Integer> {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Integer getAllowSessions() {
|
||||
public String getAllowSessions() {
|
||||
return allowSessions;
|
||||
}
|
||||
|
||||
public void setAllowSessions(final Integer allowSessions) {
|
||||
public void setAllowSessions(final String allowSessions) {
|
||||
this.allowSessions = allowSessions;
|
||||
}
|
||||
|
||||
|
@@ -80,7 +80,7 @@ public class SystemWideAlertRestRepository extends DSpaceRestRepository<SystemWi
|
||||
throw new ResourceNotFoundException(
|
||||
"systemWideAlert with id " + systemWideAlert.getID() + " was not found");
|
||||
}
|
||||
if (!authorizeService.isAdmin(context) && !systemWideAlert.isActive()) {
|
||||
if (!systemWideAlert.isActive() && !authorizeService.isAdmin(context)) {
|
||||
throw new AuthorizeException("Non admin users are not allowed to retrieve inactive alerts");
|
||||
}
|
||||
return converter.toRest(systemWideAlert, utils.obtainProjection());
|
||||
@@ -125,7 +125,7 @@ public class SystemWideAlertRestRepository extends DSpaceRestRepository<SystemWi
|
||||
}
|
||||
|
||||
systemWideAlert.setMessage(systemWideAlertRest.getMessage());
|
||||
systemWideAlert.setAllowSessions(AllowSessionsEnum.fromInt(systemWideAlertRest.getAllowSessions()));
|
||||
systemWideAlert.setAllowSessions(AllowSessionsEnum.fromString(systemWideAlertRest.getAllowSessions()));
|
||||
systemWideAlert.setCountdownTo(systemWideAlertRest.getCountdownTo());
|
||||
systemWideAlert.setActive(systemWideAlertRest.isActive());
|
||||
|
||||
@@ -166,7 +166,7 @@ public class SystemWideAlertRestRepository extends DSpaceRestRepository<SystemWi
|
||||
|
||||
try {
|
||||
systemWideAlert = systemWideAlertService.create(context, systemWideAlertRest.getMessage(),
|
||||
AllowSessionsEnum.fromInt(
|
||||
AllowSessionsEnum.fromString(
|
||||
systemWideAlertRest.getAllowSessions()),
|
||||
systemWideAlertRest.getCountdownTo(),
|
||||
systemWideAlertRest.isActive());
|
||||
|
@@ -68,7 +68,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
allOf(
|
||||
hasJsonPath("$.alertId", is(systemWideAlert1.getID())),
|
||||
hasJsonPath("$.message", is(systemWideAlert1.getMessage())),
|
||||
hasJsonPath("$.allowSessions", is(systemWideAlert1.getAllowSessions())),
|
||||
hasJsonPath("$.allowSessions", is(systemWideAlert1.getAllowSessions().getValue())),
|
||||
hasJsonPath("$.countdownTo",
|
||||
startsWith(sdf.format(systemWideAlert1.getCountdownTo()))),
|
||||
hasJsonPath("$.active", is(systemWideAlert1.isActive()))
|
||||
@@ -76,7 +76,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
allOf(
|
||||
hasJsonPath("$.alertId", is(systemWideAlert2.getID())),
|
||||
hasJsonPath("$.message", is(systemWideAlert2.getMessage())),
|
||||
hasJsonPath("$.allowSessions", is(systemWideAlert2.getAllowSessions())),
|
||||
hasJsonPath("$.allowSessions", is(systemWideAlert2.getAllowSessions().getValue())),
|
||||
hasJsonPath("$.countdownTo", is(systemWideAlert2.getCountdownTo())),
|
||||
hasJsonPath("$.active", is(systemWideAlert2.isActive()))
|
||||
)
|
||||
@@ -168,7 +168,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
hasJsonPath("$.alertId", is(systemWideAlert1.getID())),
|
||||
hasJsonPath("$.message", is(systemWideAlert1.getMessage())),
|
||||
hasJsonPath("$.allowSessions",
|
||||
is(systemWideAlert1.getAllowSessions())),
|
||||
is(systemWideAlert1.getAllowSessions().getValue())),
|
||||
hasJsonPath("$.countdownTo",
|
||||
startsWith(sdf.format(systemWideAlert1.getCountdownTo()))),
|
||||
hasJsonPath("$.active", is(systemWideAlert1.isActive()))
|
||||
@@ -209,7 +209,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
hasJsonPath("$.alertId", is(systemWideAlert1.getID())),
|
||||
hasJsonPath("$.message", is(systemWideAlert1.getMessage())),
|
||||
hasJsonPath("$.allowSessions",
|
||||
is(systemWideAlert1.getAllowSessions())),
|
||||
is(systemWideAlert1.getAllowSessions().getValue())),
|
||||
hasJsonPath("$.countdownTo",
|
||||
startsWith(sdf.format(systemWideAlert1.getCountdownTo()))),
|
||||
hasJsonPath("$.active", is(systemWideAlert1.isActive()))
|
||||
@@ -255,7 +255,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
hasJsonPath("$.alertId", is(systemWideAlert1.getID())),
|
||||
hasJsonPath("$.message", is(systemWideAlert1.getMessage())),
|
||||
hasJsonPath("$.allowSessions",
|
||||
is(systemWideAlert1.getAllowSessions())),
|
||||
is(systemWideAlert1.getAllowSessions().getValue())),
|
||||
hasJsonPath("$.countdownTo",
|
||||
startsWith(sdf.format(systemWideAlert1.getCountdownTo()))),
|
||||
hasJsonPath("$.active", is(systemWideAlert1.isActive()))
|
||||
@@ -305,7 +305,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
allOf(
|
||||
hasJsonPath("$.alertId", is(systemWideAlert1.getID())),
|
||||
hasJsonPath("$.message", is(systemWideAlert1.getMessage())),
|
||||
hasJsonPath("$.allowSessions", is(systemWideAlert1.getAllowSessions())),
|
||||
hasJsonPath("$.allowSessions", is(systemWideAlert1.getAllowSessions().getValue())),
|
||||
hasJsonPath("$.countdownTo",
|
||||
startsWith(sdf.format(systemWideAlert1.getCountdownTo()))),
|
||||
hasJsonPath("$.active", is(systemWideAlert1.isActive()))
|
||||
@@ -313,7 +313,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
allOf(
|
||||
hasJsonPath("$.alertId", is(systemWideAlert3.getID())),
|
||||
hasJsonPath("$.message", is(systemWideAlert3.getMessage())),
|
||||
hasJsonPath("$.allowSessions", is(systemWideAlert3.getAllowSessions())),
|
||||
hasJsonPath("$.allowSessions", is(systemWideAlert3.getAllowSessions().getValue())),
|
||||
hasJsonPath("$.countdownTo", is(systemWideAlert3.getCountdownTo())),
|
||||
hasJsonPath("$.active", is(systemWideAlert3.isActive()))
|
||||
)
|
||||
@@ -326,7 +326,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
SystemWideAlertRest systemWideAlertRest = new SystemWideAlertRest();
|
||||
systemWideAlertRest.setMessage("Alert test message");
|
||||
systemWideAlertRest.setCountdownTo(new Date());
|
||||
systemWideAlertRest.setAllowSessions(1);
|
||||
systemWideAlertRest.setAllowSessions(AllowSessionsEnum.ALLOW_CURRENT_SESSIONS_ONLY.getValue());
|
||||
systemWideAlertRest.setActive(true);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -376,7 +376,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
SystemWideAlertRest systemWideAlertRest = new SystemWideAlertRest();
|
||||
systemWideAlertRest.setMessage("Alert test message");
|
||||
systemWideAlertRest.setCountdownTo(new Date());
|
||||
systemWideAlertRest.setAllowSessions(1);
|
||||
systemWideAlertRest.setAllowSessions(AllowSessionsEnum.ALLOW_CURRENT_SESSIONS_ONLY.getValue());
|
||||
systemWideAlertRest.setActive(true);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -396,7 +396,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
SystemWideAlertRest systemWideAlertRest = new SystemWideAlertRest();
|
||||
systemWideAlertRest.setMessage("Alert test message");
|
||||
systemWideAlertRest.setCountdownTo(new Date());
|
||||
systemWideAlertRest.setAllowSessions(1);
|
||||
systemWideAlertRest.setAllowSessions(AllowSessionsEnum.ALLOW_CURRENT_SESSIONS_ONLY.getValue());
|
||||
systemWideAlertRest.setActive(true);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -425,7 +425,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
SystemWideAlertRest systemWideAlertRest = new SystemWideAlertRest();
|
||||
systemWideAlertRest.setMessage("Alert test message");
|
||||
systemWideAlertRest.setCountdownTo(new Date());
|
||||
systemWideAlertRest.setAllowSessions(1);
|
||||
systemWideAlertRest.setAllowSessions(AllowSessionsEnum.ALLOW_CURRENT_SESSIONS_ONLY.getValue());
|
||||
systemWideAlertRest.setActive(true);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -454,7 +454,7 @@ public class SystemWideAlertRestRepositoryIT extends AbstractControllerIntegrati
|
||||
systemWideAlertRest.setAlertId(systemWideAlert.getID());
|
||||
systemWideAlertRest.setMessage("Updated alert test message");
|
||||
systemWideAlertRest.setCountdownTo(new Date());
|
||||
systemWideAlertRest.setAllowSessions(1);
|
||||
systemWideAlertRest.setAllowSessions(AllowSessionsEnum.ALLOW_CURRENT_SESSIONS_ONLY.getValue());
|
||||
systemWideAlertRest.setActive(true);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
Reference in New Issue
Block a user