Skip to content

Commit

Permalink
Merge pull request 'Release v24.06' (#9) from release_24.06 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
janvonde committed Jul 10, 2024
2 parents 5d2564c + 123c0cf commit 0d1592e
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 364 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<arg value="package"/>
<arg value="-Dmaven.test.skip=true" />
</exec>
<copy file="module-gui/target/plugin_intranda_step_metadata_edition-GUI.jar" todir="/opt/digiverso/goobi/plugins/GUI/"/>
<copy file="module-main/target/plugin_intranda_step_metadata_edition.jar" todir="/opt/digiverso/goobi/plugins/step/"/>
<copy file="module-gui/target/plugin-step-metadata-edition-gui.jar" todir="/opt/digiverso/goobi/plugins/GUI/"/>
<copy file="module-base/target/plugin-step-metadata-edition-base.jar" todir="/opt/digiverso/goobi/plugins/step/"/>
</target>
</project>
1 change: 1 addition & 0 deletions install/plugin_intranda_step_metadata_edition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@
<showImages>false</showImages>
<showAddMetadata>false</showAddMetadata>
<showImportMetadata>false</showImportMetadata>
<showDownloadFiles>false</showDownloadFiles>
</config>
</config_plugin>
2 changes: 1 addition & 1 deletion module-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.goobi.workflow.plugin</groupId>
<artifactId>plugin-step-metadata-edition</artifactId>
<version>24.05</version>
<version>24.06</version>
</parent>
<artifactId>plugin-step-metadata-edition-base</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.intranda.goobi.plugins;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
Expand All @@ -15,10 +17,14 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
Expand Down Expand Up @@ -179,6 +185,9 @@ public class MetadataEditionPlugin implements IStepPluginVersion2 {
@Getter
private boolean displayMetadataAddButton = true;

@Getter
private boolean displayDownloadButton = false;

private transient List<MetadataField> deleteList = new ArrayList<>();

@Getter
Expand Down Expand Up @@ -277,6 +286,7 @@ public void initialize(Step step, String returnPath) {
this.displayImageArea = this.myconfig.getBoolean("showImages", false);
this.displayMetadataImportButton = this.myconfig.getBoolean("showImportMetadata", false);
this.displayMetadataAddButton = this.myconfig.getBoolean("showAddMetadata", false);
displayDownloadButton = myconfig.getBoolean("showDownloadFiles", false);

try {
if ("master".equalsIgnoreCase(this.myconfig.getString("imageFolder", null))) {
Expand Down Expand Up @@ -392,6 +402,11 @@ private void initDisplayFields(SubnodeConfiguration config) {
}
}
}

if (vocabularyRecords == null) {
vocabularyRecords = Collections.emptyList();
}

MetadataConfiguredField metadataField = new MetadataConfiguredField(source, name, fieldType, label, required, helpText, searchable);
metadataField.setStructType(structType);
metadataField.setDefaultValue(defaultValue);
Expand Down Expand Up @@ -651,7 +666,7 @@ private void importSelectedMetadata(DocStruct source, ProcessMetadataField pmf,
Person p = new Person(mdt);
p.setFirstname(personToImport.getFirstname());
p.setLastname(personToImport.getLastname());
p.setAutorityFile(personToImport.getAuthorityID(), personToImport.getAuthorityURI(), personToImport.getAuthorityValue());
p.setAuthorityFile(personToImport.getAuthorityID(), personToImport.getAuthorityURI(), personToImport.getAuthorityValue());
destination.addPerson(p);
} catch (MetadataTypeNotAllowedException e) {
log.error(e);
Expand All @@ -673,7 +688,7 @@ private void importSelectedMetadata(DocStruct source, ProcessMetadataField pmf,
try {
Metadata md = new Metadata(mdt);
md.setValue(metadataToImport.getValue());
md.setAutorityFile(metadataToImport.getAuthorityID(), metadataToImport.getAuthorityURI(), metadataToImport.getAuthorityValue());
md.setAuthorityFile(metadataToImport.getAuthorityID(), metadataToImport.getAuthorityURI(), metadataToImport.getAuthorityValue());
destination.addMetadata(md);
} catch (MetadataTypeNotAllowedException e) {
log.error(e);
Expand Down Expand Up @@ -855,7 +870,7 @@ private static Map<Integer, String> getAllProcessesWithMetadata(String filter) {
return Collections.emptyMap();
}

public static final ResultSetHandler<Map<Integer, String>> resultSetToMapHandler = new ResultSetHandler<Map<Integer, String>>() {
public static final ResultSetHandler<Map<Integer, String>> resultSetToMapHandler = new ResultSetHandler<>() {
@Override
public Map<Integer, String> handle(ResultSet rs) throws SQLException {
Map<Integer, String> answer = new HashMap<>();
Expand Down Expand Up @@ -1018,7 +1033,7 @@ public void addField() {
Person person = new Person(this.currentField.getPerson().getType());
person.setFirstname(this.currentField.getPerson().getFirstname());
person.setLastname(this.currentField.getPerson().getLastname());
person.setAutorityFile(this.currentField.getPerson().getAuthorityID(), this.currentField.getPerson().getAuthorityURI(),
person.setAuthorityFile(this.currentField.getPerson().getAuthorityID(), this.currentField.getPerson().getAuthorityURI(),
this.currentField.getPerson().getAuthorityValue());
this.currentField.getPerson().getParent().addPerson(person);
metadataField.setPerson(person);
Expand Down Expand Up @@ -1088,7 +1103,7 @@ public void addMetadataField() {
for (SelectItem item : this.selectedField.getVocabularyList()) {
if (this.newValue.equals(item.getValue())) {
md.setValue(item.getLabel());
md.setAutorityFile(this.selectedField.getVocabularyName(), this.selectedField.getVocabularyUrl(),
md.setAuthorityFile(this.selectedField.getVocabularyName(), this.selectedField.getVocabularyUrl(),
this.selectedField.getVocabularyUrl() + "/" + this.newValue);
break;
}
Expand Down Expand Up @@ -1140,4 +1155,61 @@ public void setNewField(String newField) {
}
}

public void downloadAllFiles() throws IOException {
// get all files in folder
Path path = Paths.get(imageFolderName);
if (StorageProvider.getInstance().isFileExists(path)) {
List<String> files = StorageProvider.getInstance().list(imageFolderName);

// if no files -> do nothing
if (files.isEmpty()) {
return;
} else {

FacesContext facesContext = FacesContextHelper.getCurrentFacesContext();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
OutputStream out = response.getOutputStream();

if (files.size() == 1) {
// if one file -> write to output stream
String fileName = files.get(0);
String contentType = servletContext.getMimeType(fileName);
response.setContentType(contentType);
response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");

Path p = Paths.get(imageFolderName, fileName);
try (InputStream inputStream = StorageProvider.getInstance().newInputStream(p)) {
inputStream.transferTo(out);
}

} else {
// if more than one -> create zip, send zip to stream

response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment;filename=\"" + process.getTitel() + ".zip\"");

ZipOutputStream zos = new ZipOutputStream(out);
for (String fileName : files) {

try (InputStream in = StorageProvider.getInstance().newInputStream(Paths.get(imageFolderName, fileName))) {
zos.putNextEntry(new ZipEntry(fileName));
byte[] b = new byte[1024];
int count;

while ((count = in.read(b)) > 0) {
out.write(b, 0, count);
}
}
}
zos.flush();
zos.close();

}

}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void setVocabularyValue(String value) {
if (value.equals(item.getValue())) {
if (metadata != null) {
metadata.setValue(item.getLabel());
metadata.setAutorityFile(configuredField.getVocabularyName(), configuredField.getVocabularyUrl(),
metadata.setAuthorityFile(configuredField.getVocabularyName(), configuredField.getVocabularyUrl(),
configuredField.getVocabularyUrl() + "/" + value);
} else if (property != null) {
property.setWert(item.getLabel());
Expand Down
2 changes: 1 addition & 1 deletion module-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.goobi.workflow.plugin</groupId>
<artifactId>plugin-step-metadata-edition</artifactId>
<version>24.05</version>
<version>24.06</version>
</parent>
<artifactId>plugin-step-metadata-edition-gui</artifactId>
<packaging>jar</packaging>
Expand Down
Loading

0 comments on commit 0d1592e

Please sign in to comment.