Skip to content

Commit 99fcef6

Browse files
committed
Merge Main
2 parents 9279108 + a022f70 commit 99fcef6

51 files changed

Lines changed: 761 additions & 541 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Kitodo/src/main/java/org/kitodo/production/forms/CommentForm.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.List;
1919
import java.util.Objects;
2020

21-
import jakarta.enterprise.context.SessionScoped;
21+
import jakarta.faces.view.ViewScoped;
2222
import jakarta.inject.Named;
2323

2424
import org.apache.logging.log4j.LogManager;
@@ -40,7 +40,7 @@
4040
import org.xml.sax.SAXException;
4141

4242
@Named("CommentForm")
43-
@SessionScoped
43+
@ViewScoped
4444
public class CommentForm extends BaseForm {
4545
private static final Logger logger = LogManager.getLogger(CommentForm.class);
4646
private boolean correctionComment = false;
@@ -206,7 +206,6 @@ private void reportProblem(Comment comment) {
206206
} catch (DAOException e) {
207207
Helper.setErrorMessage("reportingProblem", logger, e);
208208
}
209-
refreshProcess(this.currentTask.getProcess());
210209
}
211210

212211
/**
@@ -272,7 +271,6 @@ public String solveProblem(Comment comment) {
272271
} catch (DAOException | IOException | SAXException | FileStructureValidationException e) {
273272
Helper.setErrorMessage("SolveProblem", logger, e);
274273
}
275-
refreshProcess(comment.getCurrentTask().getProcess());
276274
return MessageFormat.format(REDIRECT_PATH, "tasks");
277275
}
278276

@@ -311,18 +309,6 @@ private static boolean verifyCorrectionTasks(Task commentCorrectionTask, Task pr
311309
return processCommentCorrectionTask.getTitle().equals(commentCorrectionTask.getTitle());
312310
}
313311

314-
/**
315-
* refresh the process in the session.
316-
*
317-
* @param process Object process to refresh
318-
*/
319-
private void refreshProcess(Process process) {
320-
if (!Objects.equals(process.getId(), 0) && Objects.nonNull(this.currentTask)) {
321-
ServiceManager.getProcessService().refresh(process);
322-
this.currentTask.setProcess(process);
323-
}
324-
}
325-
326312
/**
327313
* Set current task by ID.
328314
*

Kitodo/src/main/java/org/kitodo/production/forms/dataeditor/GalleryMediaContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private StreamedContent sendData(URI uri, String mimeType) {
263263
try {
264264
InputStream viewData = ServiceManager.getFileService().read(uri);
265265
return DefaultStreamedContent.builder().stream(() -> viewData).contentType(mimeType)
266-
.name(Paths.get(uri.getPath()).getFileName().toString()).contentLength(viewData.available())
266+
.name(Paths.get(uri.getPath()).getFileName().toString()).contentLength((long) viewData.available())
267267
.build();
268268
} catch (IOException e) {
269269
logger.catching(e);

Kitodo/src/main/java/org/kitodo/production/forms/process/ProcessListBaseView.java

Lines changed: 94 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@
2323
import java.util.Map;
2424
import java.util.Objects;
2525

26+
import org.apache.commons.lang3.StringUtils;
2627
import org.apache.logging.log4j.LogManager;
2728
import org.apache.logging.log4j.Logger;
2829
import org.kitodo.config.ConfigCore;
2930
import org.kitodo.config.enums.ParameterCore;
31+
import org.kitodo.data.database.beans.ImportConfiguration;
3032
import org.kitodo.data.database.beans.Process;
3133
import org.kitodo.data.database.enums.TaskStatus;
3234
import org.kitodo.data.database.exceptions.DAOException;
3335
import org.kitodo.data.database.persistence.TaskDAO;
3436
import org.kitodo.exceptions.FileStructureValidationException;
3537
import org.kitodo.export.ExportDms;
38+
import org.kitodo.production.enums.ExportFormat;
3639
import org.kitodo.production.enums.ObjectType;
3740
import org.kitodo.production.forms.BaseListView;
3841
import org.kitodo.production.forms.DeleteProcessDialog;
@@ -43,14 +46,17 @@
4346
import org.kitodo.production.services.ServiceManager;
4447
import org.kitodo.production.services.data.ProcessService;
4548
import org.kitodo.utils.Stopwatch;
49+
import org.omnifaces.util.Ajax;
4650
import org.primefaces.PrimeFaces;
4751
import org.primefaces.event.data.PageEvent;
4852
import org.xml.sax.SAXException;
4953

5054
public class ProcessListBaseView extends BaseListView {
5155

5256
private static final Logger logger = LogManager.getLogger(ProcessListBaseView.class);
53-
57+
58+
private String errorMessage = "";
59+
5460
protected List<Process> selectedProcesses = new ArrayList<>();
5561
private final String doneDirectoryName = ConfigCore.getParameterOrDefaultValue(ParameterCore.DONE_DIRECTORY_NAME);
5662
private DeleteProcessDialog deleteProcessDialog = new DeleteProcessDialog();
@@ -59,7 +65,7 @@ public class ProcessListBaseView extends BaseListView {
5965

6066
boolean allSelected = false;
6167
HashSet<Integer> excludedProcessIds = new HashSet<>();
62-
private final ProcessProgressHelper progressService = new ProcessProgressHelper();
68+
private final ProcessProgressHelper processProgressHelper = new ProcessProgressHelper();
6369

6470
/**
6571
* Constructor.
@@ -136,6 +142,13 @@ public List<Process> getSelectedProcesses() {
136142
return stopwatch.stop(selectedProcesses);
137143
}
138144

145+
private List<Integer> getSelectedProcessIds() {
146+
return selectedProcesses.stream()
147+
.map(Process::getId)
148+
.filter(Objects::nonNull)
149+
.toList();
150+
}
151+
139152
private LazyProcessModel getLazyProcessModel() {
140153
return (LazyProcessModel) this.lazyBeanModel;
141154
}
@@ -147,7 +160,7 @@ private LazyProcessModel getLazyProcessModel() {
147160
* @return true if at least one task exists, otherwise false
148161
*/
149162
public boolean hasAnyTasks(Process process) {
150-
return progressService.hasAnyTasks(getCachedTaskStatusCounts(process));
163+
return processProgressHelper.hasAnyTasks(getCachedTaskStatusCounts(process));
151164
}
152165

153166
/**
@@ -179,7 +192,7 @@ public boolean hasVisibleTasks(Process process) {
179192
* @return formatted task titles or an empty string if none exist
180193
*/
181194
public String getCurrentTaskTitles(Process process) {
182-
return progressService.buildTaskTitleTooltip(
195+
return processProgressHelper.buildTaskTitleTooltip(
183196
getLazyProcessModel().getTaskTitleCache().get(process.getId())
184197
);
185198
}
@@ -216,7 +229,7 @@ public Map<TaskStatus, Integer> getCachedTaskStatusCounts(Process process) {
216229
* @return progress percentage for the given status
217230
*/
218231
public double progress(Process process, TaskStatus status) {
219-
return progressService.progress(
232+
return processProgressHelper.progress(
220233
getCachedTaskStatusCounts(process),
221234
status
222235
);
@@ -231,7 +244,7 @@ public double progress(Process process, TaskStatus status) {
231244
* @return percentage of tasks completed
232245
*/
233246
public double progressClosed(Process process) {
234-
return progressService.progressClosed(getCachedTaskStatusCounts(process));
247+
return processProgressHelper.progressClosed(getCachedTaskStatusCounts(process));
235248
}
236249

237250
/**
@@ -243,7 +256,7 @@ public double progressClosed(Process process) {
243256
* @return percentage of tasks in progress
244257
*/
245258
public double progressInProcessing(Process process) {
246-
return progressService.progressInProcessing(
259+
return processProgressHelper.progressInProcessing(
247260
getCachedTaskStatusCounts(process)
248261
);
249262
}
@@ -258,7 +271,7 @@ public double progressInProcessing(Process process) {
258271
* @return percentage of startable tasks
259272
*/
260273
public double progressOpen(Process process) {
261-
return progressService.progressOpen(
274+
return processProgressHelper.progressOpen(
262275
getCachedTaskStatusCounts(process)
263276
);
264277
}
@@ -323,49 +336,65 @@ public void exportDMSForSelection() {
323336
}
324337

325338
/**
326-
* Generates the current search result as an Excel file.
339+
* Generates and downloads the current search result as an Excel file using the active filter,
340+
* visibility flags (closed/inactive), and selection state (all selected, selected IDs, excluded IDs).
327341
*/
328342
public void generateExcel() {
329343
Stopwatch stopwatch = new Stopwatch(this, "generateExcel");
330344
try {
331-
ServiceManager.getProcessService().generateExcel(
345+
ServiceManager.getProcessService().export(
332346
this.filter,
333347
this.isShowClosedProcesses(),
334-
this.isShowInactiveProjects()
348+
this.isShowInactiveProjects(),
349+
ExportFormat.EXCEL,
350+
this.allSelected,
351+
getSelectedProcessIds(),
352+
this.excludedProcessIds
335353
);
336354
} catch (IOException | DocumentException e) {
337-
Helper.setErrorMessage(ERROR_CREATING,
338-
new Object[] {Helper.getTranslation("resultSet")}, logger, e);
355+
Helper.setErrorMessage(ERROR_CREATING, new Object[] {Helper.getTranslation("resultSet")}, logger, e);
339356
}
340357
stopwatch.stop();
341358
}
342359

343360
/**
344-
* Generates the current search result as a CSV file.
361+
* Generates and downloads the current search result as a CSV file using the active filter,
362+
* visibility flags (closed/inactive), and selection state (all selected, selected IDs, excluded IDs).
345363
*/
346364
public void generateCsv() {
347365
Stopwatch stopwatch = new Stopwatch(this, "generateCsv");
348366
try {
349-
ServiceManager.getProcessService().generateCsv(
367+
ServiceManager.getProcessService().export(
350368
this.filter,
351369
this.isShowClosedProcesses(),
352-
this.isShowInactiveProjects()
370+
this.isShowInactiveProjects(),
371+
ExportFormat.CSV,
372+
this.allSelected,
373+
getSelectedProcessIds(),
374+
this.excludedProcessIds
353375
);
354376
} catch (IOException | DocumentException e) {
355-
Helper.setErrorMessage(ERROR_CREATING,
356-
new Object[] {Helper.getTranslation("resultSet")}, logger, e);
377+
Helper.setErrorMessage(ERROR_CREATING, new Object[] {Helper.getTranslation("resultSet")}, logger, e);
357378
}
358379
stopwatch.stop();
359380
}
360381

361382
/**
362-
* Generate result as PDF.
383+
* Generates and downloads the current search result as a PDF file using the active filter,
384+
* visibility flags (closed/inactive), and selection state (all selected, selected IDs, excluded IDs).
363385
*/
364386
public void generateResultAsPdf() {
365387
Stopwatch stopwatch = new Stopwatch(this, "generateResultAsPdf");
366388
try {
367-
ServiceManager.getProcessService().generatePdf(this.filter, this.isShowClosedProcesses(),
368-
this.isShowInactiveProjects());
389+
ServiceManager.getProcessService().export(
390+
this.filter,
391+
this.isShowClosedProcesses(),
392+
this.isShowInactiveProjects(),
393+
ExportFormat.PDF,
394+
this.allSelected,
395+
getSelectedProcessIds(),
396+
this.excludedProcessIds
397+
);
369398
} catch (IOException | DocumentException e) {
370399
Helper.setErrorMessage(ERROR_CREATING, new Object[] {Helper.getTranslation("resultPDF") }, logger, e);
371400
}
@@ -548,17 +577,27 @@ public void uploadFromHome(Process process) {
548577
*/
549578
public void delete(Process process) {
550579
Stopwatch stopwatch = new Stopwatch(this.getClass(), process, "delete");
551-
if (process.getChildren().isEmpty()) {
552-
try {
553-
ProcessService.deleteProcess(process.getId());
554-
} catch (DAOException | IOException | SAXException | FileStructureValidationException e) {
555-
Helper.setErrorMessage(ERROR_DELETING, new Object[] {ObjectType.PROCESS.getTranslationSingular() },
556-
logger, e);
580+
try {
581+
List<ImportConfiguration> configurations = ServiceManager.getImportConfigurationService()
582+
.getProcessTemplateConfigurationByProcessId(process.getId());
583+
if (!configurations.isEmpty()) {
584+
errorMessage = Helper.getTranslation("processUsedAsTemplateProcess", configurations.getFirst().getTitle());
585+
Ajax.update("errorDialog");
586+
PrimeFaces.current().executeScript("PF('errorDialog').show();");
587+
} else if (process.getChildren().isEmpty()) {
588+
try {
589+
ProcessService.deleteProcess(process.getId());
590+
} catch (DAOException | IOException | SAXException | FileStructureValidationException e) {
591+
Helper.setErrorMessage(ERROR_DELETING, new Object[]{ObjectType.PROCESS.getTranslationSingular()}, logger, e);
592+
}
557593
}
558-
} else {
559-
this.deleteProcessDialog = new DeleteProcessDialog();
560-
this.deleteProcessDialog.setProcess(process);
561-
PrimeFaces.current().executeScript("PF('deleteChildrenDialog').show();");
594+
else {
595+
this.deleteProcessDialog = new DeleteProcessDialog();
596+
this.deleteProcessDialog.setProcess(process);
597+
PrimeFaces.current().executeScript("PF('deleteChildrenDialog').show();");
598+
}
599+
} catch (DAOException e) {
600+
Helper.setErrorMessage(ERROR_LOADING_MANY, new Object[]{ObjectType.IMPORT_CONFIGURATION.getTranslationSingular()}, logger, e);
562601
}
563602
stopwatch.stop();
564603
}
@@ -635,5 +674,28 @@ public void onPageChange(PageEvent pageEvent) {
635674
stopwatch.stop();
636675
}
637676

638-
677+
/**
678+
* Rename media files of all selected processes.
679+
*/
680+
public void renameMedia() {
681+
Stopwatch stopwatch = new Stopwatch(this, "renameMedia");
682+
List<Process> processes = getSelectedProcesses();
683+
errorMessage = ServiceManager.getFileService().tooManyProcessesSelectedForMediaRenaming(processes.size());
684+
if (StringUtils.isBlank(errorMessage)) {
685+
PrimeFaces.current().executeScript("PF('renameMediaConfirmDialog').show();");
686+
} else {
687+
Ajax.update("errorDialog");
688+
PrimeFaces.current().executeScript("PF('errorDialog').show();");
689+
}
690+
stopwatch.stop();
691+
}
692+
693+
/**
694+
* Get error message.
695+
* @return error message
696+
*/
697+
public String getErrorMessage() {
698+
Stopwatch stopwatch = new Stopwatch(this, "getErrorMessage");
699+
return stopwatch.stop(errorMessage);
700+
}
639701
}

0 commit comments

Comments
 (0)