Skip to content

Commit

Permalink
Fix creation of duplicates during creation of newspaper-processes
Browse files Browse the repository at this point in the history
  • Loading branch information
IkramMaalej committed Jan 28, 2022
1 parent 1587d38 commit 005eb2c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
20 changes: 11 additions & 9 deletions Kitodo/src/main/java/org/kitodo/production/forms/CalendarForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import javax.naming.ConfigurationException;
import javax.xml.transform.TransformerException;

import org.apache.commons.lang3.tuple.ImmutablePair;
Expand All @@ -46,6 +47,8 @@
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.data.exceptions.DataException;
import org.kitodo.exceptions.DoctypeMissingException;
import org.kitodo.exceptions.ProcessGenerationException;
import org.kitodo.production.forms.createprocess.ProcessDetail;
import org.kitodo.production.forms.createprocess.ProcessTextMetadata;
import org.kitodo.production.helper.Helper;
Expand All @@ -59,6 +62,7 @@
import org.kitodo.production.model.bibliography.course.IndividualIssue;
import org.kitodo.production.model.bibliography.course.Issue;
import org.kitodo.production.model.bibliography.course.metadata.CountableMetadata;
import org.kitodo.production.process.NewspaperProcessesGenerator;
import org.kitodo.production.services.ServiceManager;
import org.kitodo.production.services.calendar.CalendarService;
import org.primefaces.PrimeFaces;
Expand Down Expand Up @@ -899,16 +903,14 @@ public String getMetadataTranslation(String key) {
}

/**
* Check if course has issues with same name.
* Check if process with the same processtitle already exists.
*/
public void checkDuplicatesIssues() {
boolean check = false;
for (Block block : course) {
if (block.checkIssuesWithSameHeading()) {
check = true;
}
}
if (!check) {
public void checkDuplicatedTitles() throws ProcessGenerationException, DataException, DAOException,
ConfigurationException, IOException, DoctypeMissingException {
Process process = ServiceManager.getProcessService().getById(parentId);
NewspaperProcessesGenerator newspaperProcessesGenerator = new NewspaperProcessesGenerator(process, course);
newspaperProcessesGenerator.initialize();
if (!newspaperProcessesGenerator.isDuplicatedTitles()) {
PrimeFaces.current().executeScript("PF('createProcessesConfirmDialog').show();");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public boolean nextStep() throws ConfigurationException, DAOException, DataExcep
* if something goes wrong when reading or writing one of the
* affected files
*/
private void initialize() throws ConfigurationException, IOException, DoctypeMissingException {
public void initialize() throws ConfigurationException, IOException, DoctypeMissingException {
final long begin = System.nanoTime();

overallMetadataFileUri = processService.getMetadataFileUri(overallProcess);
Expand Down Expand Up @@ -531,7 +531,13 @@ private void createProcess(int index) throws DAOException, DataException, IOExce
}
}

private String makeTitle(String definition, Map<String, String> genericFields) throws ProcessGenerationException {
/**
* Generate process title.
* @param definition as String
* @param genericFields a map with generic fields that can be configured for process
* @return process title as String
*/
public String makeTitle(String definition, Map<String, String> genericFields) throws ProcessGenerationException {
String title;
boolean prefixWithProcessTitle = definition.startsWith("+");
if (prefixWithProcessTitle) {
Expand Down Expand Up @@ -801,20 +807,26 @@ private void finish() throws DataException, IOException {
}
}

private boolean isDuplicatedTitles() throws ProcessGenerationException, DataException {
/**
* Check if process with the same processtitle already exists.
* @return 'true' if Duplicated titles are found and 'false' if not
*/
public boolean isDuplicatedTitles() throws ProcessGenerationException, DataException {
List<List<IndividualIssue>> processes = course.getProcesses();
List<String> issueTitles = new ArrayList<>();
boolean check = false;
for (List<IndividualIssue> individualProcess : processes) {
for (IndividualIssue individualIssue : individualProcess) {
Map<String, String> genericFields = individualIssue.getGenericFields();
String title = makeTitle(issueDivisionView.getProcessTitle().orElse("+'_'+#YEAR+#MONTH+#DAY+#ISSU"),
genericFields);
if (!ServiceManager.getProcessService().findByTitle(title).isEmpty() || issueTitles.contains(title)) {
return true;
Helper.setErrorMessage("duplicatedTitles", individualIssue.toString());
check = true;
}
issueTitles.add(title);
}
}
return false;
return check;
}
}
2 changes: 1 addition & 1 deletion Kitodo/src/main/webapp/pages/calendarEdit.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
value="#{msgs['granularity.create']}"
icon="fa fa-floppy-o fa-lg"
iconPos="right"
action="#{CalendarForm.checkDuplicatesIssues()}"
action="#{CalendarForm.checkDuplicatedTitles()}"
actionListener="#{CalendarForm.setGranularity(CalendarForm.granularity)}"
onclick="setConfirmUnload(false);"
update="notifications"/>
Expand Down

0 comments on commit 005eb2c

Please sign in to comment.