Skip to content

Commit

Permalink
Merge pull request #4224 from effective-webwork/images-check
Browse files Browse the repository at this point in the history
Deactivate export buttons when process does not contain images
  • Loading branch information
Kathrin-Huber authored Apr 13, 2021
2 parents d45bc91 + bcd59d6 commit 84af2df
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class ProcessListBaseView extends BaseForm {
private final String doneDirectoryName = ConfigCore.getParameterOrDefaultValue(ParameterCore.DONE_DIRECTORY_NAME);
DeleteProcessDialog deleteProcessDialog = new DeleteProcessDialog();

private final HashMap<Integer, Boolean> exportable = new HashMap<>();

/**
* Get selectedProcesses.
*
Expand Down Expand Up @@ -453,4 +456,23 @@ public void delete(ProcessDTO processDTO) {
public DeleteProcessDialog getDeleteProcessDialog() {
return this.deleteProcessDialog;
}

/**
* Check and return whether process with given ID can be exported or not.
*
* @param processId process ID
* @return whether process with given ID can be exported or not
*/
public boolean canBeExported(int processId) {
try {
if (!exportable.containsKey(processId)) {
exportable.put(processId, ProcessService.canBeExported(processId));
}
return exportable.get(processId);
} catch (IOException | DAOException e) {
Helper.setErrorMessage(e);
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.kitodo.config.enums.ParameterCore;
import org.kitodo.data.database.beans.Batch;
import org.kitodo.data.database.beans.Comment;
import org.kitodo.data.database.beans.Folder;
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.beans.Project;
import org.kitodo.data.database.beans.Property;
Expand Down Expand Up @@ -2699,4 +2700,24 @@ public List<TaskDTO> getCurrentTasksForUser(ProcessDTO processDTO, User user) {
.collect(Collectors.toSet()).isEmpty())
.collect(Collectors.toList());
}

/**
* Checks and returns whether the process with the given ID 'processId' can be exported or not.
* @param processId process ID
* @return whether process can be exported or not
*/
public static boolean canBeExported(int processId) throws IOException, DAOException {
Process process = ServiceManager.getProcessService().getById(processId);
// superordinate processes normally do not contain images but should always be exportable
if (!process.getChildren().isEmpty()) {
return true;
}
Folder generatorSource = process.getProject().getGeneratorSource();
// processes without a generator source should be exportable because they may contain multimedia files
// that are not used as generator sources
if (Objects.isNull(generatorSource)) {
return true;
}
return FileService.hasImages(process, generatorSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,20 @@ public URI deleteFirstSlashFromPath(URI uri) {
}
return URI.create(uriString);
}

/**
* Check and return whether given process has an empty generator folder or not.
*
* @param process Process
* @param generatorSource Folder
* @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(Process process, Folder generatorSource) throws IOException, DAOException {
if (Objects.nonNull(generatorSource)) {
Subfolder sourceFolder = new Subfolder(process, generatorSource);
return !sourceFolder.listContents().isEmpty();
}
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 @@ -392,6 +392,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 oder untergeordnete Vorg\u00e4nge
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 @@ -403,6 +403,7 @@ existingTemplate=Existing template
exportBatch=Export batch to DMS
exportDMS=Export DMS
exportDmsTask=Export process
exportUnavailableNoImages=Export unavailable, process does not contain any images or subordinate processes
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.canBeExported(process.id) ? '' : 'disabled'}"
disabled="#{not ProcessForm.canBeExported(process.id)}"
title="#{ProcessForm.canBeExported(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.canBeExported(process.id) ? '' : 'disabled'}"
disabled="#{not ProcessForm.canBeExported(process.id)}"
title="#{ProcessForm.canBeExported(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

0 comments on commit 84af2df

Please sign in to comment.