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

Deactivate export buttons when process does not contain images #4224

Merged
merged 2 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.kitodo.production.services.ServiceManager;
import org.kitodo.production.services.data.ProcessService;
import org.kitodo.production.services.dataformat.MetsService;
import org.kitodo.production.services.file.FileService;
import org.primefaces.PrimeFaces;
import org.primefaces.model.charts.hbar.HorizontalBarChartModel;
import org.primefaces.model.charts.pie.PieChartModel;
Expand Down Expand Up @@ -453,4 +454,20 @@ public void delete(ProcessDTO processDTO) {
public DeleteProcessDialog getDeleteProcessDialog() {
return this.deleteProcessDialog;
}

/**
* Check and return whether process with given ID has an empty generator folder or not.
*
* @param processId process ID
* @return whether given URI points to empty directory or not
*/
public boolean hasImages(int processId) {
try {
return FileService.hasImages(processId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, we do access File Service using the Service Loader. However, I prefer static access where possible. See #3327.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I take it you agree with hasImages remaining static?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kathrin-Huber should decide

} catch (IOException | DAOException e) {
logger.error(e);
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Arrays;
Expand All @@ -31,6 +33,7 @@
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import org.apache.commons.httpclient.util.URIUtil;
import org.apache.commons.io.FilenameUtils;
Expand Down Expand Up @@ -1281,4 +1284,25 @@ public URI deleteFirstSlashFromPath(URI uri) {
}
return URI.create(uriString);
}

/**
* Check and return whether process with given ID has an empty generator folder or not.
*
* @param processId process ID
* @return whether given URI points to empty directory or not
* @throws IOException thrown if listing contents of given URI is not possible
*/
public static boolean hasImages(int processId) throws IOException, DAOException {
Process process = ServiceManager.getProcessService().getById(processId);
URI processUri = ServiceManager.getProcessService().getProcessDataDirectory(process);
String sourceDir = processUri.toString() + process.getProject().getGeneratorSource().getRelativePath();
solth marked this conversation as resolved.
Show resolved Hide resolved

Path directoryPath = Paths.get(ConfigCore.getParameter(ParameterCore.DIR_PROCESSES) + sourceDir);
if (Files.isDirectory(directoryPath)) {
try (Stream<Path> entries = Files.list(directoryPath)) {
return entries.findFirst().isPresent();
}
}
return false;
}
}
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ existingTemplate=Existierende Produktionsvorlage
exportBatch=Gesamten Batch ins DMS exportieren
exportDMS=Export DMS
exportDmsTask=Vorgang exportieren
exportUnavailableNoImages=Export nicht m\u00F6glich, Vorgang enth\u00e4lt keine Bilder
exportFiles=Dateien exportieren
exportFinished=Export abgeschlossen.
exportMets=Export der Metadaten als METS-Datei in das Homeverzeichnis
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ existingTemplate=Existing template
exportBatch=Export batch to DMS
exportDMS=Export DMS
exportDmsTask=Export process
exportUnavailableNoImages=Export unavailable, process does not contain any images
exportFinished=Export finished.
exportFiles=Export files
exportMets=Export metadata as METS file to home directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@

<h:commandLink action="#{ProcessListView.exportMets(process.id)}"
id="exportMets"
styleClass="action"
title="#{msgs.exportMets}"
styleClass="action #{ProcessForm.hasImages(process.id) ? '' : 'disabled'}"
disabled="#{not ProcessForm.hasImages(process.id)}"
solth marked this conversation as resolved.
Show resolved Hide resolved
title="#{ProcessForm.hasImages(process.id) ? msgs.exportMets : msgs.exportUnavailableNoImages}"
rendered="#{SecurityAccessController.hasAuthorityToExportProcess()}">
<h:outputText><i class="fa fa-file-code-o fa-lg"/></h:outputText>
</h:commandLink>
<h:commandLink id="exportDms"
action="#{ProcessListView.exportDMS(process.id)}"
styleClass="action"
title="#{msgs.exportDMS}"
styleClass="action #{ProcessForm.hasImages(process.id) ? '' : 'disabled'}"
disabled="#{not ProcessForm.hasImages(process.id)}"
title="#{ProcessForm.hasImages(process.id) ? msgs.exportDMS : msgs.exportUnavailableNoImages} "
rendered="#{SecurityAccessController.hasAuthorityToExportProcess()}">
<h:outputText><i class="fa fa-file-archive-o fa-lg"/></h:outputText>
</h:commandLink>
Expand Down