Skip to content

Commit

Permalink
Merge branch 'system-warning' into test-system
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Oct 12, 2023
2 parents 4917092 + 225b5cf commit 2cbe9d1
Show file tree
Hide file tree
Showing 19 changed files with 490 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--
-- (c) Kitodo. Key to digital objects e. V. <[email protected]>
--
-- This file is part of the Kitodo project.
--
-- It is licensed under GNU General Public License version 3 or later.
--
-- For the full copyright and license information, please read the
-- GPL3-License.txt file that was distributed with this source code.
--

-- Insert authority to broadcast messages

INSERT IGNORE INTO authority (title) VALUES ('broadcastMessage_globalAssignable');

INSERT IGNORE INTO role_x_authority (role_id, authority_id)
SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'broadcastMessage_globalAssignable';
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.production.channel;

import java.util.HashMap;
import java.util.Set;

import javax.enterprise.context.ApplicationScoped;
import javax.faces.push.Push;
import javax.faces.push.PushContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.kitodo.data.database.beans.User;
import org.kitodo.production.security.SecuritySession;
import org.kitodo.production.services.ServiceManager;

@Named("SystemMessageChannel")
@ApplicationScoped
public class SystemMessageChannel {

@Inject
@Push
PushContext messageChannel;

private static final String SHOW_MESSAGE = "showMessage";
private static final String UPDATE_USER_TABLE = "updateUserTable";

private String userName = "";
private String message = "";
private HashMap<String, Boolean> currentUsers;

private String staticSystemMessage = "";
private Boolean showSystemMessage = false;

/**
* Inform connected websocket clients to show message.
*/
public void showMessage() {
messageChannel.send(SHOW_MESSAGE);
}

/**
* Inform connected websocket clients to update user table.
*/
public void updateUserTable() {
messageChannel.send(UPDATE_USER_TABLE);
}

/**
* Set message String.
*
* @param messageText message String
*/
public void setMessage(String messageText) {
this.message = messageText;
}

/**
* Get message String.
*
* @return message String
*/
public String getMessage() {
return this.message;
}

/**
* Acknowledge system message.
*
* @param user User that acknowledges system message
*/
public void acknowledge(User user) {
this.currentUsers.put(user.getLogin(), true);
this.updateUserTable();
}

/**
* Load list of current users.
*/
public void loadCurrentUsers() {
this.currentUsers = new HashMap<>();
for (SecuritySession session : ServiceManager.getSessionService().getActiveSessions()) {
this.currentUsers.put(session.getUserName(), null);
}
}

/**
* Reset status of current users.
*/
public void resetCurrentUsersStatus() {
this.currentUsers.replaceAll((n, v) -> false);
}

/**
* Get list of current users.
*
* @return list of current users
*/
public Set<String> getCurrentUsers() {
return this.currentUsers.keySet();
}

/**
* Return whether User with user name 'userName' acknowledged system message or not.
*
* @param userName user name of user to check
* @return whether user acknowledged system message or not
*/
public Boolean acknowledged(String userName) {
return this.currentUsers.get(userName);
}

/**
* Get user name of broadcaster.
*
* @return user name
*/
public String getUserName() {
return this.userName;
}

/**
* Set user name of broadcaster.
*
* @param name user name
*/
public void setUserName(String name) {
this.userName = name;
}

/**
* Send message String to connected clients.
*/
public void sendMessage() {
this.resetCurrentUsersStatus();
this.showMessage();
}

/**
* Get staticSystemMessage.
*
* @return value of staticSystemMessage
*/
public String getStaticSystemMessage() {
return staticSystemMessage;
}

/**
* Set staticSystemMessage.
*
* @param staticSystemMessage as java.lang.String
*/
public void setStaticSystemMessage(String staticSystemMessage) {
this.staticSystemMessage = staticSystemMessage;
}

/**
* Get showSystemMessage.
*
* @return value of showSystemMessage
*/
public boolean isShowSystemMessage() {
return showSystemMessage;
}

/**
* Set showSystemMessage.
*
* @param showSystemMessage as boolean
*/
public void setShowSystemMessage(boolean showSystemMessage) {
this.showSystemMessage = showSystemMessage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ public boolean hasAuthorityToViewSystemPage() {
return securityAccessService.hasAuthorityToViewIndexPage()
|| securityAccessService.hasAuthorityToViewTaskManagerPage()
|| securityAccessService.hasAuthorityToViewTermsPage()
|| securityAccessService.hasAuthorityToViewMigrationPage();
|| securityAccessService.hasAuthorityToViewMigrationPage()
|| securityAccessService.hasAuthorityToViewMessagePage();
}

/**
Expand Down Expand Up @@ -753,6 +754,15 @@ public boolean hasAuthorityToViewMigrationPage() {
return securityAccessService.hasAuthorityToViewMigrationPage();
}

/**
* Check if current user has authority to view message tab of system page.
*
* @return true if user has authority to view message tab of system page
*/
public boolean hasAuthorityToViewMessagePage() {
return securityAccessService.hasAuthorityToViewMessagePage();
}

/**
* Check if current user has authority to view task page. It returns true if
* user has "viewAllTasks" authority for client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
Expand Down Expand Up @@ -85,7 +87,8 @@ public void setSelectedProjectId(int projectId) {
public List<Project> getTemplateProjects() {
try {
Template template = ServiceManager.getTemplateService().getById(this.templateDTO.getId());
return template.getProjects();
return template.getProjects().stream().sorted(Comparator.comparing(Project::getTitle))
.collect(Collectors.toList());
} catch (DAOException e) {
Helper.setErrorMessage(ERROR_LOADING_ONE, new Object[] {ObjectType.TEMPLATE.getTranslationSingular(),
this.templateDTO.getId()}, logger, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ public List<Project> getAllNotIndexed() {

@Override
public List<Project> getAllForSelectedClient() {
return dao.getByQuery("SELECT p FROM Project AS p INNER JOIN p.client AS c WITH c.id = :clientId",
Collections.singletonMap("clientId", ServiceManager.getUserService().getSessionClientId()));
return dao.getByQuery(
"SELECT p FROM Project AS p INNER JOIN p.client AS c WITH c.id = :clientId ORDER BY title",
Collections.singletonMap("clientId", ServiceManager.getUserService().getSessionClientId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -41,6 +43,7 @@
import org.kitodo.data.elasticsearch.search.Searcher;
import org.kitodo.data.exceptions.DataException;
import org.kitodo.exceptions.ProcessGenerationException;
import org.kitodo.production.dto.ProjectDTO;
import org.kitodo.production.dto.TaskDTO;
import org.kitodo.production.dto.TemplateDTO;
import org.kitodo.production.dto.WorkflowDTO;
Expand Down Expand Up @@ -204,7 +207,8 @@ public TemplateDTO convertJSONObjectToDTO(Map<String, Object> jsonObject, boolea
private void convertRelatedJSONObjects(Map<String, Object> jsonObject, TemplateDTO templateDTO)
throws DataException {
templateDTO.setProjects(convertRelatedJSONObjectToDTO(jsonObject, TemplateTypeField.PROJECTS.getKey(),
ServiceManager.getProjectService()));
ServiceManager.getProjectService()).stream().sorted(Comparator.comparing(ProjectDTO::getTitle))
.collect(Collectors.toList()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,15 @@ public boolean hasAuthorityToViewMigrationPage() {
return hasAnyAuthorityGlobal("viewMigration");
}

/**
* Check if the current user has the authority to view the message tab of the system page.
*
* @return true if the current user has the authority to view the message tab of the system page
*/
public boolean hasAuthorityToViewMessagePage() {
return hasAnyAuthorityGlobal("broadcastMessage");
}


private boolean hasAuthorityForTask(int taskId) throws DataException {
Integer processId = ServiceManager.getTaskService().findById(taskId).getProcess().getId();
Expand Down
6 changes: 6 additions & 0 deletions Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ emptyTask=Beispiel f\u00FCr eine lang laufende Aufgabe
mapping=ElasticSearch Mapping
NOT=Enth\u00E4lt nicht
NoCataloguePluginForCatalogue=Keines der verf\u00fcgbaren OPAC-Plugins unterst\u00fctzt diesen Katalog.
acknowledged=Best\u00E4tigt
active=Aktiv
ACTIVE=Aktiv
activeUsers=Aktive Benutzer
Expand Down Expand Up @@ -681,6 +682,7 @@ locked=Gesperrt
location=Standort
loggedIn=Angemeldet
logical=Logische
loggedInUsers=Angemeldete Benutzer
login=Login
loginNoteText=Kitodo.Production ist das Workflowmanagementmodul der Kitodo-Suite. Es unterst\u00FCtzt den Digitalisierungsprozess verschiedener Materialarten wie z.B. Drucken, Periodika, Handschriften, Noten und Musikalien, Einblattmedien und Dokumentennachl\u00E4ssen.
logout=Logout
Expand Down Expand Up @@ -996,6 +998,7 @@ selectProject=Bitte Projekt ausw\u00E4hlen
selectTemplate=Bitte Produktionsvorlage ausw\u00E4hlen
selectWorkflow=Bitte Workflow ausw\u00E4hlen
selfAssignTask=Die Bearbeitung dieser Aufgabe \u00FCbernehmen
send=Absenden
sendSolutionMessageNextTask=Meldung \u00FCber Probleml\u00F6sung an nachfolgende Station senden
sendSolutionMessage=Meldung \u00FCber Probleml\u00F6sung senden
sendSolutionMessageForAll=Meldung \u00FCber Probleml\u00F6sung f\u00FCr alle Schritte senden
Expand Down Expand Up @@ -1073,6 +1076,9 @@ systemErrorInformAdminMessage=Bitte informieren Sie einen Administrator!
systemErrorMessage=Es ist ein Fehler im System aufgetreten.
systemMaintenanceHeader=Systemwartung
systemMaintenanceMessage=Das System wird derzeit gewartet.
systemMessage=Systemnachricht
systemMessage.broadcast=Broadcast
systemMessage.static=Statische Systemnachricht
table=Tabelle
tableSize=Tabellengr\u00F6\u00DFe
task=Aufgabe
Expand Down
6 changes: 6 additions & 0 deletions Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ emptyTask=Example of a long-running task
mapping=ElasticSearch mapping
NOT=does not contain
NoCataloguePluginForCatalogue=None of the OPAC plugins available is capable of reading this catalogue.
acknowledged=Acknowledged
active=Active
ACTIVE=Active
activeUsers=Current users
Expand Down Expand Up @@ -682,6 +683,7 @@ locked=Locked
location=Location
loggedIn=Logged in
logical=Logical
loggedInUsers=Logged in users
login=Login
loginNoteText=Kitodo.Production is the workflow management module in the Kitodo suite. It supports the process of digitising a range of material types, such as books, periodicals, manuscripts, printed music, single-sheet media, and document collections.
logout=Log out
Expand Down Expand Up @@ -997,6 +999,7 @@ selectProject=Please select a project
selectTemplate=Please select a template
selectWorkflow=Please select a workflow
selfAssignTask=Accept editing of this task
send=Send
sendSolutionMessageNextTask=Send message about problem solution to following task
sendSolutionMessage=Send message about problem solution
sendSolutionMessageForAll=send troubleshooting message to all steps
Expand Down Expand Up @@ -1074,6 +1077,9 @@ systemErrorInformAdminMessage=Please inform an administrator!
systemErrorMessage=A system error occurred.
systemMaintenanceHeader=System maintenance
systemMaintenanceMessage=The system is currently under maintenance.
systemMessage=System message
systemMessage.broadcast=Broadcast
systemMessage.static=Static system message
table=Table
tableSize=Table size
task=Task
Expand Down
Loading

0 comments on commit 2cbe9d1

Please sign in to comment.