Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathrin-Huber committed Nov 23, 2020
1 parent 23dce57 commit 6d90e9c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,42 @@ public DataCopyrule(List<String> command) {
* @param data
* data to apply yourself on
*/
public void apply(CopierData data){
public void apply(CopierData data) {
Workpiece workpiece = data.getDigitalDocument().getWorkpiece();
List<IncludedStructuralElement> allIncludedStructuralElements = workpiece.getAllIncludedStructuralElements();

System.out.println("allChildrenSize" + allIncludedStructuralElements.size());
for (IncludedStructuralElement child : allIncludedStructuralElements) {
System.out.println(child.getLabel());
Collection<Metadata> metadata = child.getMetadata();
System.out.println("metadatasize" + metadata.size());
MdSec domain = null;
for (Metadata metadatum : metadata) {
domain = metadatum.getDomain();
System.out.println("key: " + metadatum.getKey());

if(metadatum instanceof MetadataEntry) {
if (metadatum.getKey().equals(this.command.get(0))) {
((MetadataEntry) metadatum).setValue(this.command.get(2));
break;
}
System.out.println("value: " + ((MetadataEntry) metadatum).getValue());
}
if (metadatum instanceof MetadataGroup){
Collection<Metadata> group = ((MetadataGroup) metadatum).getGroup();
if (metadatum.getKey().equals(this.command.get(0))) {

}
for (Metadata groupelement : group) {
System.out.println("value: " + ((MetadataEntry) groupelement).getValue());
}

}

}
//TODO: should be replaced by further methodes
// for (Metadata metadatum : metadata) {
// domain = metadatum.getDomain();
//
// if (metadatum instanceof MetadataEntry) {
// if (metadatum.getKey().equals(this.command.get(0))) {
// ((MetadataEntry) metadatum).setValue(this.command.get(2));
// break;
// }
// }
// if (metadatum instanceof MetadataGroup) {
// Collection<Metadata> group = ((MetadataGroup) metadatum).getGroup();
// if (metadatum.getKey().equals(this.command.get(0))) {
//
// }
// for (Metadata groupelement : group) {
// }
// }
// }
MetadataEntry metadataEntry = new MetadataEntry();
metadataEntry.setKey(command.get(0));
metadataEntry.setValue(command.get(2));
metadataEntry.setDomain(domain);
child.getMetadata().add(metadataEntry);

try (OutputStream out = ServiceManager.getFileService().write(ServiceManager.getFileService().getMetadataFilePath(data.getProcess()))) {
try (OutputStream out = ServiceManager.getFileService()
.write(ServiceManager.getFileService().getMetadataFilePath(data.getProcess()))) {
ServiceManager.getMetsService().save(workpiece, out);
ServiceManager.getProcessService().saveToIndex(data.getProcess(),false);
ServiceManager.getProcessService().saveToIndex(data.getProcess(), false);
} catch (IOException | CustomResponseException | DataException e) {
System.out.println("log me");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
/*
* (c) Kitodo. Key to digital objects e. V. <contact@kitodo.org>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.production.services.command;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.kitodo.api.MdSec;
Expand All @@ -13,13 +31,6 @@
import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyMetsModsDigitalDocumentHelper;
import org.kitodo.production.services.ServiceManager;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

public class AddDataScript {

private static final Logger logger = LogManager.getLogger(AddDataScript.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* (c) Kitodo. Key to digital objects e. V. <contact@kitodo.org>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.production.services.command;

public class MetadataScript {
Expand Down Expand Up @@ -46,7 +57,7 @@ public String getValue() {
}

/**
* Set Value
* Set value.
* @param value the value to set.
*/
public void setValue(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -214,7 +215,6 @@ public void shouldGenerateDerivativeImages() throws Exception {

@Test
public void shouldCopyDataWithValue() throws Exception {
KitodoScriptService kitodoScript = new KitodoScriptService();
Process process = ServiceManager.getProcessService().getById(2);
String metadataKey = "LegalNoteAndTermsOfUse";
HashMap<String, String> metadataSearchMap = new HashMap<>();
Expand All @@ -226,6 +226,7 @@ public void shouldCopyDataWithValue() throws Exception {
String script = "action:addData " + metadataKey + "=PDM1.0";
List<Process> processes = new ArrayList<>();
processes.add(process);
KitodoScriptService kitodoScript = new KitodoScriptService();
kitodoScript.execute(processes, script);
Thread.sleep(2000);
final List<ProcessDTO> processByMetadataAfter = ServiceManager.getProcessService()
Expand Down

0 comments on commit 6d90e9c

Please sign in to comment.