forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in task/dspace-cris-2023_02_x/DSC-1997 (pull request DSpace#2962)
Task/dspace cris 2023 02 x/DSC-1997 Approved-by: Vincenzo Mecca
- Loading branch information
Showing
11 changed files
with
393 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...e-server-webapp/src/main/java/org/dspace/app/rest/health/EPersonGroupHealthIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* 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.health; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Map; | ||
|
||
import org.dspace.core.Context; | ||
import org.dspace.eperson.Group; | ||
import org.dspace.eperson.service.GroupService; | ||
import org.dspace.web.ContextUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.actuate.health.AbstractHealthIndicator; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
|
||
/** | ||
* Implementation of {@link HealthIndicator} to verify the presence of essential | ||
* groups in the system, specifically "Anonymous" and "Administrators" in the | ||
* `epersongroups` table. | ||
* Marks the status as "UP" if both groups are present, otherwise "DOWN" with | ||
* details about the missing group(s). | ||
* | ||
* @author Adamo Fapohunda (adamo.fapohunda at 4science.com) | ||
*/ | ||
public class EPersonGroupHealthIndicator extends AbstractHealthIndicator { | ||
|
||
private static final Map<Map<Boolean, Boolean>, String> ERROR_MESSAGES = Map.of( | ||
Map.of(false, false), "Both 'Anonymous' and 'Administrators' groups are missing", | ||
Map.of(true, false), "The 'Administrators' group is missing", | ||
Map.of(false, true), "The 'Anonymous' group is missing" | ||
); | ||
@Autowired | ||
private GroupService groupService; | ||
|
||
@Override | ||
protected void doHealthCheck(Health.Builder builder) throws Exception { | ||
Context context = ContextUtil.obtainCurrentRequestContext(); | ||
try { | ||
boolean hasAnonymous = groupService.findByName(context, Group.ANONYMOUS) != null; | ||
boolean hasAdministrators = groupService.findByName(context, Group.ADMIN) != null; | ||
|
||
if (hasAnonymous && hasAdministrators) { | ||
builder.up(); | ||
} else { | ||
builder.down() | ||
.withDetail("error", ERROR_MESSAGES.get(Map.of(hasAnonymous, hasAdministrators))); | ||
} | ||
} catch (SQLException e) { | ||
builder.down(e); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
dspace-server-webapp/src/main/java/org/dspace/app/rest/health/SiteHealthIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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.health; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import org.dspace.content.Site; | ||
import org.dspace.content.service.SiteService; | ||
import org.dspace.core.Context; | ||
import org.dspace.web.ContextUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.actuate.health.AbstractHealthIndicator; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
|
||
|
||
/** | ||
* Implementation of {@link HealthIndicator} that verifies if the table sites | ||
* has exactly one row. | ||
* | ||
* @author Adamo Fapohunda (adamo.fapohunda at 4science.com) | ||
*/ | ||
public class SiteHealthIndicator extends AbstractHealthIndicator { | ||
|
||
@Autowired | ||
private SiteService siteService; | ||
|
||
@Override | ||
protected void doHealthCheck(Health.Builder builder) throws Exception { | ||
Context context = ContextUtil.obtainCurrentRequestContext(); | ||
try { | ||
List<Site> sites = siteService.findAll(context); | ||
if (sites != null && sites.size() != 1) { | ||
builder.down().withDetail("error", "`sites` table must contain exactly one row"); | ||
} else { | ||
builder.up(); | ||
} | ||
} catch (SQLException e) { | ||
builder.down(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.