Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from kitodo:main #321

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Kitodo-DataEditor/src/test/resources/ruleset.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@
This can be used if a certain metadata entry must not be changed at a certain point in time. (If no
changes are to be made to the metadata in its whole, this should be mapped via the authorization
management, not via the ruleset.) With "excluded", a metadata entry can be hidden. It is not deleted,
it is simply not displayed. With "multiline", a larger input box can be requested for a metadata key.
it is simply not displayed. With "filterable" an input field is rendered for checkbox lists to filter
the list of available values. With "multiline", a larger input box can be requested for a metadata key.
This makes sense for entries that contain a lot of text, for example an abstract. Settings must be
nested in order to define properties of subkeys.
</xs:documentation>
Expand Down
3 changes: 2 additions & 1 deletion Kitodo/rulesets/ruleset.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@
This can be used if a certain metadata entry must not be changed at a certain point in time. (If no
changes are to be made to the metadata in its whole, this should be mapped via the authorization
management, not via the ruleset.) With "excluded", a metadata entry can be hidden. It is not deleted,
it is simply not displayed. With "multiline", a larger input box can be requested for a metadata key.
it is simply not displayed. With "filterable" an input field is rendered for checkbox lists to filter
the list of available values. With "multiline", a larger input box can be requested for a metadata key.
This makes sense for entries that contain a lot of text, for example an abstract. Settings must be
nested in order to define properties of subkeys.
</xs:documentation>
Expand Down
23 changes: 13 additions & 10 deletions Kitodo/src/main/java/org/kitodo/production/forms/WorkflowForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public WorkflowForm() {
/**
* Get list of workflow statues for select list.
*
* @return list of SelectItem objects
* @return array of SelectItem objects
*/
public WorkflowStatus[] getWorkflowStatuses() {
return WorkflowStatus.values();
Expand Down Expand Up @@ -160,7 +160,10 @@ public String saveAndRedirect() {
} else {
return this.stayOnCurrentPage;
}
} catch (IOException | DAOException | DataException e) {
} catch (DataException e) {
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
return this.stayOnCurrentPage;
} catch (IOException | DAOException e) {
Helper.setErrorMessage("errorDiagramFile", new Object[] {this.workflow.getTitle() }, logger, e);
return this.stayOnCurrentPage;
} catch (WorkflowException e) {
Expand Down Expand Up @@ -226,7 +229,11 @@ public String cancel() {
*/
public void archive() {
this.workflow.setStatus(WorkflowStatus.ARCHIVED);
saveWorkflow();
try {
saveWorkflow();
} catch (DataException e) {
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
}
}

/**
Expand Down Expand Up @@ -326,12 +333,8 @@ private String encodeXMLDiagramName(String xmlDiagramName) {
return xmlDiagramName;
}

private void saveWorkflow() {
try {
ServiceManager.getWorkflowService().save(this.workflow, true);
} catch (DataException e) {
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
}
private void saveWorkflow() throws DataException {
ServiceManager.getWorkflowService().saveWorkflow(this.workflow);
}

/**
Expand Down Expand Up @@ -535,7 +538,7 @@ public void setMigration(boolean migration) {
/**
* Get language.
*
* @return language of the currently logged in user
* @return language of the currently logged-in user
*/
public String getLanguage() {
return ServiceManager.getUserService().getCurrentUser().getLanguage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,28 @@ public List<Workflow> getAvailableWorkflows() {
public List<Workflow> getAllActiveWorkflows() {
return dao.getAllActive();
}

private List<Workflow> getByTitle(String title) {
return dao.getByQuery("FROM Workflow WHERE title = :title", Collections.singletonMap("title", title));
}

/**
* Save given workflow if it is an existing workflow (e.g. if it does have an ID)
* or if it is a new workflow and no workflow with the same name exists.
*
* @param workflow the object to save
*
* @throws DataException if the given workflow is a new workflow and a workflow with the same name already exists
*/
public void saveWorkflow(Workflow workflow) throws DataException {
if (Objects.nonNull(workflow.getId())) {
save(workflow, true);
} else {
if (getByTitle(workflow.getTitle()).isEmpty()) {
save(workflow, true);
} else {
throw new DataException(Helper.getTranslation("duplicateWorkflowTitle", workflow.getTitle()));
}
}
}
}
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/errors_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ docketNotFound=Die angegebene Datei konnte nicht gefunden werden.
docketTitleDuplicated=Der Laufzettel mit den gleichen Titel existiert schon.
docTypeNotFound=docType ''{0}'' wurde nicht im selektierten Regelsatz gefunden
duplicatedTitles=Es wurden dublette Ausgabe-Bezeichnungen gefunden. Dies erzeugt gegebenenfalls dublette Vorgangstitel!
duplicateWorkflowTitle=Ein Workflow mit dem Titel "{0}" existiert bereits.
emptySourceFolder=Der Quellordner zur Bildgenerierung ist leer
errorDataIncomplete=Unvollst\u00E4ndige Daten\:
errorDatabaseReading=Fehler beim Datenbanklesen von ''{0}'' with ID {1}.
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/errors_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ docketNotFound=The specified file could not be found.
docketTitleDuplicated=The docket with the same title exists already.
docTypeNotFound=docType ''{0}'' could not be found in selected ruleset
duplicatedTitles=Duplicate issue designations were found. This may produce duplicate process titles!
duplicateWorkflowTitle=Workflow with title "{0}" already exists.
emptySourceFolder=The source folder is empty
errorDataIncomplete=Incomplete data\:
errorDatabaseReading=Error on reading database for ''{0}'' with ID {1}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.kitodo.production.services.data;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
Expand All @@ -22,11 +23,13 @@
import org.kitodo.MockDatabase;
import org.kitodo.SecurityTestUtils;
import org.kitodo.data.database.beans.Workflow;
import org.kitodo.data.exceptions.DataException;
import org.kitodo.production.helper.Helper;
import org.kitodo.production.services.ServiceManager;

public class WorkflowServiceIT {

private WorkflowService workflowService = ServiceManager.getWorkflowService();
private final WorkflowService workflowService = ServiceManager.getWorkflowService();

@BeforeAll
public static void prepareDatabase() throws Exception {
Expand Down Expand Up @@ -62,4 +65,14 @@ public void shouldGetAvailableWorkflows() throws Exception {

SecurityTestUtils.cleanSecurityContext();
}

@Test
public void shouldNotSaveNewWorkflowWithExistingTitle() {
Workflow workflow = new Workflow("test");
String expectedExceptionMessage = Helper.getTranslation("duplicateWorkflowTitle", "test");
DataException dataException = assertThrows(DataException.class,
() -> workflowService.saveWorkflow(workflow),
"Expected DataException to be thrown when saving a new workflow with an existing title");
assertEquals(expectedExceptionMessage, dataException.getMessage());
}
}
Loading