2323import java .util .Map ;
2424import java .util .Objects ;
2525
26+ import org .apache .commons .lang3 .StringUtils ;
2627import org .apache .logging .log4j .LogManager ;
2728import org .apache .logging .log4j .Logger ;
2829import org .kitodo .config .ConfigCore ;
2930import org .kitodo .config .enums .ParameterCore ;
31+ import org .kitodo .data .database .beans .ImportConfiguration ;
3032import org .kitodo .data .database .beans .Process ;
3133import org .kitodo .data .database .enums .TaskStatus ;
3234import org .kitodo .data .database .exceptions .DAOException ;
3335import org .kitodo .data .database .persistence .TaskDAO ;
3436import org .kitodo .exceptions .FileStructureValidationException ;
3537import org .kitodo .export .ExportDms ;
38+ import org .kitodo .production .enums .ExportFormat ;
3639import org .kitodo .production .enums .ObjectType ;
3740import org .kitodo .production .forms .BaseListView ;
3841import org .kitodo .production .forms .DeleteProcessDialog ;
4346import org .kitodo .production .services .ServiceManager ;
4447import org .kitodo .production .services .data .ProcessService ;
4548import org .kitodo .utils .Stopwatch ;
49+ import org .omnifaces .util .Ajax ;
4650import org .primefaces .PrimeFaces ;
4751import org .primefaces .event .data .PageEvent ;
4852import org .xml .sax .SAXException ;
4953
5054public 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