Skip to content

Commit

Permalink
Merge pull request 'Release v24.08' (!344) from release_24.08 into ma…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
janvonde committed Sep 5, 2024
2 parents a01eb7f + 4ffb4bf commit df0afb2
Show file tree
Hide file tree
Showing 82 changed files with 2,361 additions and 1,654 deletions.
9 changes: 1 addition & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.goobi.workflow</groupId>
<artifactId>workflow-base</artifactId>
<version>24.07</version>
<version>24.08</version>
<relativePath/>
</parent>
<artifactId>workflow-core</artifactId>
Expand All @@ -15,13 +15,6 @@
<url>https://nexus.intranda.com/repository/maven-public</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.goobi.vocabulary</groupId>
<artifactId>vocabulary-server-exchange</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/de/sub/goobi/config/ConfigurationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,10 @@ public int getVocabularyServerPort() {
return getLocalInt("vocabularyServerPort", 8081);
}

public String getVocabularyServerToken() {
return getLocalString("vocabularyServerToken", "secret");
}

/**
* This setter is only used by unit tests and makes manipulation of the configuration possible.
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/sub/goobi/export/download/ExportMets.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.goobi.beans.Process;
import org.goobi.beans.ProjectFileGroup;
Expand Down Expand Up @@ -1246,7 +1247,7 @@ private static String getShaString(MessageDigest messageDigest, String algorithm
private void buildPDFMetadata(Document document, Path file, Element object) throws IOException {

addObjectIdentifier(document, object, identifierLocal, file.getFileName().normalize().toString());
PDDocument doc = PDDocument.load(file.toFile());
PDDocument doc = Loader.loadPDF(file.toFile());
addSignificantProperty(document, object, "PageNumber", String.valueOf(doc.getNumberOfPages()));
Element objectCharacteristics = document.createElementNS(premisNamespace, elementObjectCharacteristics);
object.appendChild(objectCharacteristics);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/de/sub/goobi/forms/MassImportForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ public void uploadFile() {

String filename = this.createUploadFileName();

try (InputStream inputStream = this.uploadedFile.getInputStream(); OutputStream outputStream = new FileOutputStream(filename)) { // NOSONAR filename is safe here, any prefix folder name from user input is removed from it (see basename above)
try (InputStream inputStream = this.uploadedFile.getInputStream();
OutputStream outputStream = new FileOutputStream(filename)) { // NOSONAR
// filename is safe here, any prefix folder name from user input is removed from it (see basename above)

byte[] buf = new byte[1024];
int len;
Expand Down
103 changes: 78 additions & 25 deletions src/main/java/de/sub/goobi/forms/ProzesskopieForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.regex.PatternSyntaxException;
Expand All @@ -52,6 +53,8 @@
import javax.naming.NamingException;
import javax.servlet.http.Part;

import io.goobi.vocabulary.exchange.FieldDefinition;
import io.goobi.vocabulary.exchange.VocabularySchema;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
Expand All @@ -70,6 +73,7 @@
import org.goobi.beans.Templateproperty;
import org.goobi.beans.User;
import org.goobi.managedbeans.LoginBean;
import org.goobi.production.cli.helper.StringPair;
import org.goobi.production.enums.LogType;
import org.goobi.production.enums.UserRole;
import org.goobi.production.flow.jobs.HistoryAnalyserJob;
Expand Down Expand Up @@ -198,6 +202,9 @@ public class ProzesskopieForm implements Serializable {
@Getter
@Setter
private String addToWikiField = "";
@Getter
@Setter
private boolean importantWikiField = false;
private transient List<ConfigOpacCatalogue> catalogues;
private List<String> catalogueTitles;
private transient ConfigOpacCatalogue currentCatalogue;
Expand Down Expand Up @@ -242,7 +249,6 @@ public class ProzesskopieForm implements Serializable {

private List<Project> availableProjects = new ArrayList<>();

@Getter
private List<ProcessProperty> configuredProperties;

@Getter
Expand Down Expand Up @@ -454,11 +460,6 @@ private AdditionalField readAdditionalFieldConfiguration(HierarchicalConfigurati
/* Children durchlaufen und SelectItems erzeugen */

if (!parameterList.isEmpty()) {
if (item.getBoolean("@multiselect", true)) { // NOSONAR
fa.setMultiselect(true);
} else {
fa.setMultiselect(false);
}
fa.setSelectList(new ArrayList<>());
}

Expand All @@ -475,11 +476,34 @@ private AdditionalField readAdditionalFieldConfiguration(HierarchicalConfigurati
}

String vocabularyTitle = item.getString("@vocabulary");
Optional<String> filter = Optional.ofNullable(item.getString("@vocabulary-filter"));
Optional<String> filterQuery = Optional.empty();
if (StringUtils.isNotBlank(vocabularyTitle)) {
Vocabulary vocabulary = VocabularyAPIManager.getInstance().vocabularies().findByName(vocabularyTitle);
VocabularySchema schema = VocabularyAPIManager.getInstance().vocabularySchemas().get(vocabulary.getSchemaId());

if (filter.isPresent() && filter.get().contains("=")) {
String[] parts = filter.get().split("=");
String field = parts[0];
String value = parts[1];

String finalFieldName = field;
Optional<FieldDefinition> searchField = schema.getDefinitions().stream()
.filter(d -> d.getName().equals(finalFieldName))
.findFirst();

if (searchField.isEmpty()) {
Helper.setFehlerMeldung("Field " + field + " not found in vocabulary " + vocabulary.getName());
return fa;
}

filterQuery = Optional.of(searchField.get().getId() + ":" + value);
}

List<ExtendedVocabularyRecord> records = VocabularyAPIManager.getInstance()
.vocabularyRecords()
.list(vocabulary.getId())
.search(filterQuery)
.all()
.request()
.getContent();
Expand All @@ -490,6 +514,12 @@ private AdditionalField readAdditionalFieldConfiguration(HierarchicalConfigurati
.map(v -> new SelectItem(v, v))
.collect(Collectors.toList()));
}

if (item.getBoolean("@multiselect", true)) { // NOSONAR
fa.setMultiselect(true);
} else {
fa.setMultiselect(false);
}
// TODO: FIX
return fa;
}
Expand Down Expand Up @@ -657,6 +687,8 @@ private void clearValues() {
this.standardFields.put("preferences", true);
this.standardFields.put("images", true);
standardFields.put("fileUpload", true);
standardFields.put("processtitle", true);

this.additionalFields = new ArrayList<>();
this.tifHeaderDocumentname = "";
this.tifHeaderImagedescription = "";
Expand Down Expand Up @@ -695,27 +727,21 @@ public String readMetadataFromTemplate() throws DAOException {
this.myRdf = tempProcess.readMetadataAsTemplateFile();

/* falls ein erstes Kind vorhanden ist, sind die Collectionen dafür */
try {
DocStruct colStruct = this.myRdf.getDigitalDocument().getLogicalDocStruct();
DocStruct colStruct = this.myRdf.getDigitalDocument().getLogicalDocStruct();

List<Metadata> firstChildMetadata =
colStruct.getAllChildren().isEmpty() ? Collections.emptyList() : colStruct.getAllChildren().get(0).getAllMetadata();
fillTemplateFromMetadata(colStruct.getAllMetadata(), firstChildMetadata);
List<Metadata> firstChildMetadata =
colStruct.getAllChildren() == null || colStruct.getAllChildren().isEmpty() ? Collections.emptyList() : colStruct.getAllChildren().get(0).getAllMetadata();
fillTemplateFromMetadata(colStruct.getAllMetadata(), firstChildMetadata);

removeCollections(colStruct);
removeCollections(colStruct);

if (colStruct.getAllChildren() != null) {
colStruct = colStruct.getAllChildren().get(0);
removeCollections(colStruct);
} catch (PreferencesException e) {
Helper.setFehlerMeldung("Error on creating process", e);
log.error("Error on creating process", e);
} catch (RuntimeException e) {
e.printStackTrace();
/*
* das Firstchild unterhalb des Topstructs konnte nicht ermittelt werden
*/
}
} catch (Exception e) {
Helper.setFehlerMeldung("Error on reading template-metadata ", e);
Helper.setFehlerMeldung("Error on reading template-metadata", e);
log.error("Error on reading template-metadata", e);
}

return "";
Expand Down Expand Up @@ -828,7 +854,8 @@ private boolean isContentValid() {
/* keine Collektion ausgewählt */
if (this.standardFields.get("collections") && getDigitalCollections().size() == 0) {
valide = false;
Helper.setFehlerMeldung(Helper.getTranslation("UnvollstaendigeDaten") + " " + Helper.getTranslation("ProcessCreationErrorNoCollection"));
Helper.setFehlerMeldung(Helper.getTranslation("UnvollstaendigeDaten") + " "
+ Helper.getTranslation("ProcessCreationErrorNoCollection"));
}

/*
Expand Down Expand Up @@ -1047,7 +1074,8 @@ public String createNewProcess()
Metadata md = this.ughHelper.getMetadata(myTempStruct, mdt);
if (md != null) {
md.setValue(field.getWert());
} else if (this.ughHelper.lastErrorMessage != null && field.getWert() != null && !field.getWert().isEmpty())//if the md could not be found, warn!
} else if (this.ughHelper.lastErrorMessage != null && field.getWert() != null && !field.getWert().isEmpty())
//if the md could not be found, warn!
{
Helper.setFehlerMeldung(this.ughHelper.lastErrorMessage);
String strError = mdt.getName() + " : " + field.getWert();
Expand Down Expand Up @@ -1212,7 +1240,7 @@ private void createMetadata(DocStruct myTempStruct, MetadataType mdt, String sel
private void writeJournalEntry(LoginBean loginForm) {
User user = loginForm.getMyBenutzer();
JournalEntry logEntry =
new JournalEntry(prozessKopie.getId(), new Date(), user.getNachVorname(), LogType.INFO, addToWikiField, EntryType.PROCESS);
new JournalEntry(prozessKopie.getId(), new Date(), user.getNachVorname(), importantWikiField ? LogType.IMPORTANT_USER : LogType.USER, addToWikiField, EntryType.PROCESS);
JournalManager.saveJournalEntry(logEntry);
prozessKopie.getJournal().add(logEntry);
}
Expand Down Expand Up @@ -1586,7 +1614,8 @@ public List<ConfigOpacDoctype> getAllDoctypes() {
*/

public void setOpacKatalog(String opacKatalog) {
//currentCatalogue is set to null in prepare(), but is required in opacAuswerten(). So reset it here if it is null or if the catalog name (this.opacKatalog) has changed
// currentCatalogue is set to null in prepare(), but is required in opacAuswerten().
// So reset it here if it is null or if the catalog name (this.opacKatalog) has changed
if (this.currentCatalogue == null || !this.opacKatalog.equals(opacKatalog)) {
this.opacKatalog = opacKatalog;
currentCatalogue = null;
Expand Down Expand Up @@ -2104,4 +2133,28 @@ public int compareTo(UploadImage o) {
return one.compareTo(two);
}
}

public List<ProcessProperty> getConfiguredProperties() {
List<ProcessProperty> properties = new ArrayList<>();

for (ProcessProperty prop : configuredProperties) {
boolean match = true;
if (!prop.getProcessCreationConditions().isEmpty()) {
// check if condition matches
match = false;
for (StringPair sp : prop.getProcessCreationConditions()) {
for (ProcessProperty other : configuredProperties) {
if (other.getName().equals(sp.getOne()) && sp.getTwo().equals(other.getValue())) {
match = true;
}
}
}
}
if (match) {
properties.add(prop);
}
}

return properties;
}
}
17 changes: 10 additions & 7 deletions src/main/java/de/sub/goobi/helper/NIOFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class NIOFileUtils implements StorageProviderInterface {
private static final String REGEX_PLY = "\\.[pP][lL][yY]";
private static final String REGEX_STL = "\\.[sS][tT][lL]";
private static final String REGEX_TIFF = "\\.[tT][iI][fF][fF]?";
private static final String REGEX_PDF = "(?i)\\.pdf";
private static final String REGEX_X3D = "\\.[xX]3[dD]";
private static final String REGEX_XML = "\\.[xX][mM][lL]";

Expand Down Expand Up @@ -245,6 +246,11 @@ public static boolean checkImageType(String name) {
return isAllowed;
}

public static boolean checkPdfType(String name) {
String prefix = ConfigurationHelper.getInstance().getImagePrefix();
return name.matches(prefix + REGEX_PDF);
}

public static boolean check3DType(String name) {
if (name.endsWith(".xml")) {
return false;
Expand All @@ -262,6 +268,9 @@ public List<String> listDirNames(String folder) {
return this.list(folder, folderFilter);
}

public static final DirectoryStream.Filter<Path> imageOrPdfNameFilter =
path -> checkImageType(path.getFileName().toString()) || checkPdfType(path.toString());

public static final DirectoryStream.Filter<Path> imageNameFilter = path -> checkImageType(path.getFileName().toString());

public static final DirectoryStream.Filter<Path> objectNameFilter = path -> {
Expand Down Expand Up @@ -325,7 +334,7 @@ public boolean accept(Path path) {
public static final DirectoryStream.Filter<Path> imageOrObjectNameFilter = new DirectoryStream.Filter<>() {
@Override
public boolean accept(Path path) throws IOException {
return imageNameFilter.accept(path) || objectNameFilter.accept(path) || multimediaNameFilter.accept(path);
return imageOrPdfNameFilter.accept(path) || objectNameFilter.accept(path) || multimediaNameFilter.accept(path);
}
};

Expand Down Expand Up @@ -713,12 +722,6 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) {
return size.get();
}

@Override
public void createFile(Path path) throws IOException {
Files.createFile(path);

}

@Override
public void uploadFile(InputStream in, Path dest, Long contentLength) throws IOException {
// identical to uploadFile(InputStream, Path) because contentLength is irrelevant for local copy
Expand Down
Loading

0 comments on commit df0afb2

Please sign in to comment.