use of org.goobi.api.rest.model.RestMetadata in project goobi-workflow by intranda.
the class MetadataUtils method extractMetadataFromFile.
private static void extractMetadataFromFile(Path metsPath, RestProcess p, Map<String, Map<String, String>> labelMap, SearchRequest req) {
if (!Files.exists(metsPath)) {
return;
}
Document doc;
try (InputStream in = Files.newInputStream(metsPath)) {
doc = builder.build(in);
} catch (JDOMException | IOException e) {
log.error(e);
return;
}
for (Element el : authorityMetaXpath.evaluate(doc)) {
RestMetadata meta = new RestMetadata();
String name = el.getAttributeValue("name");
if (req.getWantedFields() != null && !req.getWantedFields().contains(name)) {
continue;
}
String type = el.getAttributeValue("type");
if ("person".equals(type)) {
meta.setValue(el.getChildText("displayName", goobiNamespace));
} else {
meta.setValue(el.getText());
}
meta.setAuthorityID(el.getChildText("authorityID", goobiNamespace));
meta.setAuthorityURI(el.getChildText("authorityURI", goobiNamespace));
meta.setAuthorityValue(el.getChildText("authorityValue", goobiNamespace));
meta.setLabels(labelMap.get(name));
p.addMetadata(name, meta);
}
}
use of org.goobi.api.rest.model.RestMetadata in project goobi-workflow by intranda.
the class MetadatumImpl method linkProcess.
public void linkProcess(RestProcess rp) {
Project p = this.getBean().getMyProzess().getProjekt();
XMLConfiguration xmlConf = ConfigPlugins.getPluginConfig("ProcessPlugin");
if (xmlConf == null) {
return;
}
HierarchicalConfiguration use = getConfigForProject(p, xmlConf);
Map<String, List<RestMetadata>> addMetadata = new HashMap<>();
List<HierarchicalConfiguration> mappings = use.configurationsAt("mapping");
for (HierarchicalConfiguration mapping : mappings) {
String from = mapping.getString("[@from]");
String to = mapping.getString("[@to]");
List<RestMetadata> fromMeta = rp.getMetadata().get(from);
if (fromMeta != null) {
addMetadata.put(to, fromMeta);
}
}
Prefs prefs = this.getBean().getMyPrefs();
DocStruct ds = this.getBean().getMyDocStruct();
for (String name : addMetadata.keySet()) {
try {
for (RestMetadata rmd : addMetadata.get(name)) {
if (!rmd.anyValue()) {
continue;
}
if (name.contains("/")) {
String[] split = name.split("/");
String group = split[0];
String metaName = split[1];
MetadataGroupType mgt = prefs.getMetadataGroupTypeByName(group);
MetadataGroup addGroup = null;
addGroup = new MetadataGroup(mgt);
List<Metadata> metaList = addGroup.getMetadataByType(metaName);
Metadata md;
if (metaList.isEmpty()) {
md = new Metadata(prefs.getMetadataTypeByName(metaName));
addGroup.addMetadata(md);
} else {
md = metaList.get(0);
}
if (rmd.getValue() != null) {
md.setValue(rmd.getValue());
}
if (rmd.getAuthorityID() != null) {
md.setAuthorityID(rmd.getAuthorityID());
}
if (rmd.getAuthorityURI() != null) {
md.setAuthorityURI(rmd.getAuthorityURI());
}
if (rmd.getAuthorityValue() != null) {
md.setAuthorityValue(rmd.getAuthorityValue());
}
ds.addMetadataGroup(addGroup);
} else {
Metadata md = new Metadata(prefs.getMetadataTypeByName(name));
if (rmd.getValue() != null) {
md.setValue(rmd.getValue());
}
if (rmd.getAuthorityID() != null) {
md.setAuthorityID(rmd.getAuthorityID());
}
if (rmd.getAuthorityURI() != null) {
md.setAuthorityURI(rmd.getAuthorityURI());
}
if (rmd.getAuthorityValue() != null) {
md.setAuthorityValue(rmd.getAuthorityValue());
}
ds.addMetadata(md);
}
}
} catch (MetadataTypeNotAllowedException e) {
Helper.setFehlerMeldung("Metadata " + name + " not allowed in preferences.", e);
}
}
this.getBean().reloadMetadataList();
}
Aggregations