Merge branch 'master' into update-funders-apis

This commit is contained in:
Michele Artini 2024-07-15 14:04:59 +02:00
commit b8b190070b
7 changed files with 46 additions and 21 deletions

View File

@ -19,6 +19,8 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.common.controller.AbstractDnetController;
import eu.dnetlib.organizations.importer.ImportExecutor;
import eu.dnetlib.organizations.importer.ImportStatus;
import eu.dnetlib.organizations.model.SystemConfiguration;
import eu.dnetlib.organizations.repository.SystemConfigurationRepository;
@ -28,6 +30,9 @@ public class HomeController extends AbstractDnetController {
@Autowired
private Environment env;
@Autowired
private ImportExecutor importExecutor;
@Autowired
private SystemConfigurationRepository systemConfigurationRepository;
@ -94,18 +99,23 @@ public class HomeController extends AbstractDnetController {
return systemConfigurationRepository.findById(SystemConfiguration.DEFAULT_ID).get();
}
@ModelAttribute("isImportRunning")
public boolean isImportRunning(final Authentication authentication) {
return importExecutor.getLastImportExecution().getStatus() == ImportStatus.RUNNING;
}
@ModelAttribute("supportPages")
public Map<String, String> supportPages(final Authentication authentication) throws JsonMappingException, JsonProcessingException {
if (supportPages == null) {
final ObjectMapper mapper = new ObjectMapper();
final TypeReference<LinkedHashMap<String, String>> typeRef = new TypeReference<LinkedHashMap<String, String>>() {};
this.supportPages = mapper.readValue(supportPagesJson, typeRef);
supportPages = mapper.readValue(supportPagesJson, typeRef);
}
return supportPages;
}
@GetMapping({
"apidoc", "api-doc", "/doc", "/swagger"
"apidoc", "api-doc", "/doc", "/swagger"
})
public String apiDoc() {
return "redirect:swagger-ui/index.html";

View File

@ -28,6 +28,9 @@ public class SystemConfiguration implements Serializable {
@Column(name = "homepage_msg")
private String homepageMessage;
@Column(name = "homepage_msg_import")
private String homepageMessageImport;
@Column(name = "readonly")
private Boolean readonly;
@ -85,6 +88,14 @@ public class SystemConfiguration implements Serializable {
this.homepageMessage = homepageMessage;
}
public String getHomepageMessageImport() {
return homepageMessageImport;
}
public void setHomepageMessageImport(final String homepageMessageImport) {
this.homepageMessageImport = homepageMessageImport;
}
public Boolean getReadonly() {
return readonly;
}

View File

@ -32,13 +32,14 @@ DROP TABLE IF EXISTS languages;
DROP SEQUENCE IF EXISTS organizations_id_seq;
CREATE TABLE sysconf (
id text PRIMARY KEY DEFAULT 'default',
title text NOT NULL,
homepage_msg text NOT NULL DEFAULT '',
readonly boolean NOT NULL DEFAULT false,
smtp_enabled boolean NOT NULL DEFAULT false,
smtp_host text NOT NULL DEFAULT 'localhost',
smtp_port int NOT NULL DEFAULT 587,
id text PRIMARY KEY DEFAULT 'default',
title text NOT NULL,
homepage_msg text NOT NULL DEFAULT '',
homepage_msg_import text NOT NULL DEFAULT '<p>The portal is temporarily in read-only mode because we are updating the suggestions.<br /><br />We apologize for the inconvenience.</p>',
readonly boolean NOT NULL DEFAULT false,
smtp_enabled boolean NOT NULL DEFAULT false,
smtp_host text NOT NULL DEFAULT 'localhost',
smtp_port int NOT NULL DEFAULT 587,
smtp_user text NOT NULL DEFAULT '',
smtp_password text NOT NULL DEFAULT '',
smtp_from_mail text NOT NULL DEFAULT 'no-reply@openaire.eu',

View File

@ -20,6 +20,12 @@
<textarea class="form-control" ng-model="sysconf.homepageMessage" placeholder="html message here" rows="5"></textarea>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Homepage message during the import of the dedup events</label>
<div class="col-sm-10">
<textarea class="form-control" ng-model="sysconf.homepageMessageImport" placeholder="html message here" rows="5"></textarea>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Read only</label>
<div class="col-sm-10">

View File

@ -52,10 +52,9 @@
<div class="card-body">
<div class="tab-content">
<div class="tab-pane active text-center p-3" id="tabLogin">
<div th:utext="${sysconf.homepageMessage}"></div>
<hr th:if="${sysconf.homepageMessage != '' and sysconf.homepageMessage != null}" />
<div th:if="${!isImportRunning}" th:utext="${sysconf.homepageMessage}"></div>
<div th:if="${isImportRunning}" th:utext="${sysconf.homepageMessageImport}"></div>
<a href="./main" class="btn btn-lg btn-primary">Access using OpenAIRE credentials</a>
</div>
<div class="tab-pane" id="tabRegister">

View File

@ -51,9 +51,8 @@
<div class="card-body">
<div class="tab-content">
<div class="tab-pane active" id="tabLogin">
<div th:utext="${sysconf.homepageMessage}"></div>
<hr th:if="${sysconf.homepageMessage != '' and sysconf.homepageMessage != null}" />
<div th:if="${!isImportRunning}" th:utext="${sysconf.homepageMessage}"></div>
<div th:if="${isImportRunning}" th:utext="${sysconf.homepageMessageImport}"></div>
<form th:action="@{/login}" method="post">
<div th:if="${param.error}">

View File

@ -150,9 +150,8 @@ fieldset > legend { font-size : 1.2rem !important; }
</nav>
<div class="alert alert-danger text-center" th:if="${sysconf.readonly}">The portal is running in READ-ONLY mode.</div>
<div class="alert alert-danger text-center" th:if="${sysconf.readonly} or ${isImportRunning}">The portal is running in READ-ONLY mode.</div>
<div class="container-fluid small mt-4" ng-view></div>
<script sec:authorize="hasRole('ROLE_OPENORGS_ADMIN')">
@ -243,7 +242,7 @@ fieldset > legend { font-size : 1.2rem !important; }
</script>
<script th:if="${sysconf.readonly}">
<script th:if="${sysconf.readonly} or ${isImportRunning}">
function call_http_post($http, url, obj, onSuccess) {
alert("Method not permitted in READ-ONLY mode !")
}
@ -254,7 +253,7 @@ fieldset > legend { font-size : 1.2rem !important; }
</script>
<script th:if="${!sysconf.readonly}">
<script th:if="${!sysconf.readonly} and ${!isImportRunning}">
function call_http_post($http, url, obj, onSuccess) {
showSpinner();
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";