Skip to content

Commit

Permalink
kitodo#3408 code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Oct 6, 2021
1 parent 1584744 commit e8ded63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class ProcessDataTab {
private List<SelectItem> allDocTypes;
private final CreateProcessForm createProcessForm;
private String docType;
private String atstsl = "";
private String tiffHeaderImageDescription = "";
private String tiffHeaderDocumentName = "";
private int guessedImages = 0;
Expand Down Expand Up @@ -223,12 +222,7 @@ public void generateProcessTitleAndTiffHeader() {
if (Objects.nonNull(parentProcess)) {

// get title of workpiece property "Haupttitle" from chosen title record process
for (Property property : parentProcess.getWorkpieces()) {
if ("Haupttitel".equals(property.getTitle())) {
currentTitle = property.getValue();
break;
}
}
currentTitle = parentProcess.getWorkpieces().stream().filter(property -> "Haupttitel".equals(property.getTitle())).findFirst().map(Property::getValue).orElse(currentTitle);

} else {
int processesSize = createProcessForm.getProcesses().size();
Expand All @@ -238,27 +232,24 @@ public void generateProcessTitleAndTiffHeader() {

// get title of ancestors where TitleDocMain exists when several processes were imported
for (TempProcess tempProcess : ancestors) {

ProcessFieldedMetadata processFieldedMetadata = initializeTempProcessDetails(tempProcess);
if (Objects.nonNull(processFieldedMetadata)) {
AtomicReference<String> tempTitle = new AtomicReference<>();
processFieldedMetadata.getChildMetadata().parallelStream().filter(metadata -> TitleGenerator.TITLE_DOC_MAIN.equals(metadata.getKey())).findFirst().ifPresent(metadata -> {
if (metadata instanceof MetadataEntry) {
tempTitle.set(((MetadataEntry) metadata).getValue());
}
});

if (Objects.nonNull(tempTitle.get()) && !tempTitle.get().isEmpty()) {
currentTitle = tempTitle.get();
break;
AtomicReference<String> tempTitle = new AtomicReference<>();
processFieldedMetadata.getChildMetadata().parallelStream().filter(metadata -> TitleGenerator.TITLE_DOC_MAIN.equals(metadata.getKey())).findFirst().ifPresent(metadata -> {
if (metadata instanceof MetadataEntry) {
tempTitle.set(((MetadataEntry) metadata).getValue());
}
});

if (Objects.nonNull(tempTitle.get()) && !tempTitle.get().isEmpty()) {
currentTitle = tempTitle.get();
break;
}
}
}
}
}

atstsl = ProcessService.generateProcessTitleAndGetAtstsl(atstsl, processDetails, processTitle, process, currentTitle);
String atstsl = ProcessService.generateProcessTitleAndGetAtstsl(processDetails, processTitle, process, currentTitle);
// document name is generally equal to process title
tiffHeaderDocumentName = process.getTitle();
tiffHeaderImageDescription = ProcessService.generateTiffHeader(processDetails, atstsl,
Expand All @@ -276,7 +267,7 @@ public void generateProcessTitleAndTiffHeader() {
* whose metadata should be queried
*/
private ProcessFieldedMetadata initializeTempProcessDetails(TempProcess tempProcess) {
ProcessFieldedMetadata metadata = ImportService.initializeProcessDetails(tempProcess.getWorkpiece().getLogicalStructure(), createProcessForm.getRulesetManagement(),
var metadata = ImportService.initializeProcessDetails(tempProcess.getWorkpiece().getLogicalStructure(), createProcessForm.getRulesetManagement(),
createProcessForm.getAcquisitionStage(), createProcessForm.getPriorityList());
metadata.setMetadata(ImportService.importMetadata(tempProcess.getMetadataNodes(), MdSec.DMD_SEC));
return metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ public static void createProcessTitle(TempProcess tempProcess,
StructuralElementViewInterface docTypeView = rulesetManagementInterface
.getStructuralElementView(docType, acquisitionStage, priorityList);
String processTitle = docTypeView.getProcessTitle().orElse("");
ProcessService.generateProcessTitleAndGetAtstsl("", processDetails,
ProcessService.generateProcessTitleAndGetAtstsl(processDetails,
processTitle, tempProcess.getProcess());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2303,17 +2303,18 @@ private HashSet<Process> getProcessesLinkedInLogicalDivision(LogicalDivision log
* Generate and set the title to process and gets the atstsl
* @return String atstsl
*/
public static String generateProcessTitleAndGetAtstsl(String atstsl, List<ProcessDetail> processDetails, String titleDefinition, Process process) throws ProcessGenerationException {
return generateProcessTitleAndGetAtstsl(atstsl, processDetails, titleDefinition, process, TitleGenerator.getCurrentValue(TitleGenerator.TITLE_DOC_MAIN, processDetails));
public static String generateProcessTitleAndGetAtstsl(List<ProcessDetail> processDetails, String titleDefinition, Process process) throws ProcessGenerationException {
return generateProcessTitleAndGetAtstsl(processDetails, titleDefinition, process, TitleGenerator.getCurrentValue(TitleGenerator.TITLE_DOC_MAIN, processDetails));
}

/**
* Generate and set the title to process using current title parameter and gets the atstsl
* @param title of the work to generate atstsl
* @return String atstsl
*/
public static String generateProcessTitleAndGetAtstsl(String atstsl, List<ProcessDetail> processDetails, String titleDefinition, Process process, String currentTitle) throws ProcessGenerationException {
TitleGenerator titleGenerator = new TitleGenerator(atstsl, processDetails);
String newTitle = titleGenerator.generateTitle(titleDefinition, null, (Objects.nonNull(currentTitle) ? currentTitle : ""));
public static String generateProcessTitleAndGetAtstsl(List<ProcessDetail> processDetails, String titleDefinition, Process process, String title) throws ProcessGenerationException {
TitleGenerator titleGenerator = new TitleGenerator(null, processDetails);
String newTitle = titleGenerator.generateTitle(titleDefinition, null, (Objects.nonNull(title) ? title : ""));
process.setTitle(newTitle);
// atstsl is created in title generator and next used in tiff header generator
return titleGenerator.getAtstsl();
Expand Down

0 comments on commit e8ded63

Please sign in to comment.