use of ugh.dl.Prefs in project goobi-workflow by intranda.
the class FileManipulation method updatePagination.
private void updatePagination(String filename) throws TypeNotAllowedForParentException, IOException, InterruptedException, SwapException, DAOException, MetadataTypeNotAllowedException {
if (!matchesFileConfiguration(filename)) {
return;
}
if (insertPage.equals("lastPage")) {
metadataBean.createPagination();
} else {
Prefs prefs = metadataBean.getMyProzess().getRegelsatz().getPreferences();
DigitalDocument doc = metadataBean.getDocument();
DocStruct physical = doc.getPhysicalDocStruct();
List<DocStruct> pageList = physical.getAllChildren();
int indexToImport = Math.max(Integer.parseInt(insertPage) - 1, 0);
DocStructType newPageType = prefs.getDocStrctTypeByName("page");
DocStruct newPage = doc.createDocStruct(newPageType);
MetadataType physicalPageNoType = prefs.getMetadataTypeByName("physPageNumber");
MetadataType logicalPageNoType = prefs.getMetadataTypeByName("logicalPageNumber");
for (int index = 0; index < pageList.size(); index++) {
if (index == indexToImport) {
DocStruct oldPage = pageList.get(index);
// physical page no for new page
Metadata mdTemp = new Metadata(physicalPageNoType);
mdTemp.setValue(String.valueOf(indexToImport + 1));
newPage.addMetadata(mdTemp);
// new physical page no for old page
oldPage.getAllMetadataByType(physicalPageNoType).get(0).setValue(String.valueOf(indexToImport + 2));
// logical page no
// logicalPageNoType = prefs.getMetadataTypeByName("logicalPageNumber");
mdTemp = new Metadata(logicalPageNoType);
if (insertMode.equalsIgnoreCase("uncounted")) {
mdTemp.setValue("uncounted");
} else {
// set new logical no. for new and old page
Metadata oldPageNo = oldPage.getAllMetadataByType(logicalPageNoType).get(0);
mdTemp.setValue(oldPageNo.getValue());
if (index + 1 < pageList.size()) {
Metadata pageNoOfFollowingElement = pageList.get(index + 1).getAllMetadataByType(logicalPageNoType).get(0);
oldPageNo.setValue(pageNoOfFollowingElement.getValue());
} else {
oldPageNo.setValue("uncounted");
}
}
newPage.addMetadata(mdTemp);
doc.getLogicalDocStruct().addReferenceTo(newPage, "logical_physical");
ContentFile cf = new ContentFile();
cf.setLocation(filename);
newPage.addContentFile(cf);
doc.getFileSet().addFile(cf);
}
if (index > indexToImport) {
DocStruct currentPage = pageList.get(index);
// check if element is last element
currentPage.getAllMetadataByType(physicalPageNoType).get(0).setValue(String.valueOf(index + 2));
if (!insertMode.equalsIgnoreCase("uncounted")) {
if (index + 1 == pageList.size()) {
currentPage.getAllMetadataByType(logicalPageNoType).get(0).setValue("uncounted");
} else {
DocStruct followingPage = pageList.get(index + 1);
currentPage.getAllMetadataByType(logicalPageNoType).get(0).setValue(followingPage.getAllMetadataByType(logicalPageNoType).get(0).getValue());
}
}
}
}
pageList.add(indexToImport, newPage);
}
}
use of ugh.dl.Prefs in project goobi-workflow by intranda.
the class ExportMets method collectMetadataToSave.
private ExportFileformat collectMetadataToSave(Process myProzess, Fileformat gdzfile, boolean writeLocalFilegroup, ConfigurationHelper config) throws IOException, InterruptedException, SwapException, DAOException, PreferencesException, TypeNotAllowedForParentException {
ExportFileformat mm = MetadatenHelper.getExportFileformatByName(myProzess.getProjekt().getFileFormatDmsExport(), myProzess.getRegelsatz());
mm.setWriteLocal(writeLocalFilegroup);
mm.setCreateUUIDs(config.isExportCreateUUIDsAsFileIDs());
String imageFolderPath = myProzess.getImagesTifDirectory(true);
Path imageFolder = Paths.get(imageFolderPath);
/*
* before creating mets file, change relative path to absolute -
*/
DigitalDocument dd = gdzfile.getDigitalDocument();
MetadatenImagesHelper mih = new MetadatenImagesHelper(this.myPrefs, dd);
if (dd.getFileSet() == null || dd.getFileSet().getAllFiles().isEmpty()) {
Helper.setMeldung(myProzess.getTitel() + ": digital document does not contain images; adding them for mets file creation");
mih.createPagination(myProzess, null);
try {
myProzess.writeMetadataFile(gdzfile);
} catch (UGHException | IOException | InterruptedException | SwapException | DAOException e) {
log.error(e);
}
} else {
mih.checkImageNames(myProzess, imageFolder.getFileName().toString());
}
/*
* get the topstruct element of the digital document depending on anchor property
*/
DocStruct topElement = dd.getLogicalDocStruct();
if (topElement.getType().isAnchor()) {
if (topElement.getAllChildren() == null || topElement.getAllChildren().size() == 0) {
throw new PreferencesException(myProzess.getTitel() + ": the topstruct element is marked as anchor, but does not have any children for physical docstrucs");
} else {
topElement = topElement.getAllChildren().get(0);
}
}
if (config.isExportValidateImages()) {
if (topElement.getAllToReferences("logical_physical") == null || topElement.getAllToReferences("logical_physical").size() == 0) {
if (dd.getPhysicalDocStruct() != null && dd.getPhysicalDocStruct().getAllChildren() != null) {
Helper.setMeldung(myProzess.getTitel() + ": topstruct element does not have any referenced images yet; temporarily adding them for mets file creation");
for (DocStruct mySeitenDocStruct : dd.getPhysicalDocStruct().getAllChildren()) {
topElement.addReferenceTo(mySeitenDocStruct, "logical_physical");
}
} else {
Helper.setFehlerMeldung(myProzess.getTitel() + ": could not find any referenced images, export aborted");
dd = null;
return null;
}
}
for (ContentFile cf : dd.getFileSet().getAllFiles()) {
String location = cf.getLocation();
// use the file protocol.
if (!location.contains("://")) {
if (!location.matches("^[A-Z]:.*") && !location.matches("^\\/.*")) {
// is a relative path
Path f = Paths.get(imageFolder.toString(), location);
location = f.toString();
}
location = "file://" + location;
}
cf.setLocation(location);
}
}
mm.setDigitalDocument(dd);
// if configured, extract metadata from files and store them as techMd premis
if (config.isExportCreateTechnicalMetadata()) {
int counter = 1;
for (DocStruct page : dd.getPhysicalDocStruct().getAllChildren()) {
Path path = Paths.get(page.getImageName());
if (!path.isAbsolute()) {
path = Paths.get(imageFolder.toString(), page.getImageName());
}
Element techMd = createTechMd(path);
if (techMd != null) {
Md md = new Md(techMd);
md.setType("techMD");
md.setId(String.format("AMD_%04d", counter++));
dd.addTechMd(md);
page.setAdmId(md.getId());
}
}
}
Map<String, String> additionalMetadataMap = config.getExportWriteAdditionalMetadata();
if (!additionalMetadataMap.isEmpty()) {
String projectMetadataName = additionalMetadataMap.get("Project");
String institutionMetadataName = additionalMetadataMap.get("Institution");
Prefs prefs = myProzess.getRegelsatz().getPreferences();
if (StringUtils.isNotBlank(projectMetadataName)) {
MetadataType mdt = prefs.getMetadataTypeByName(projectMetadataName);
if (mdt != null) {
try {
ugh.dl.Metadata md = new ugh.dl.Metadata(mdt);
md.setValue(myProzess.getProjekt().getTitel());
topElement.addMetadata(md);
} catch (MetadataTypeNotAllowedException e) {
log.warn("Configured metadata for project name is unknown or not allowed.");
}
if (topElement.getParent() != null) {
try {
ugh.dl.Metadata md = new ugh.dl.Metadata(mdt);
md.setValue(myProzess.getProjekt().getTitel());
topElement.getParent().addMetadata(md);
} catch (MetadataTypeNotAllowedException e) {
log.warn("Configured metadata for project name is unknown or not allowed.");
}
}
}
}
if (StringUtils.isNotBlank(institutionMetadataName)) {
MetadataType mdt = prefs.getMetadataTypeByName(institutionMetadataName);
if (mdt != null) {
try {
ugh.dl.Metadata md = new ugh.dl.Metadata(mdt);
md.setValue(myProzess.getProjekt().getInstitution().getLongName());
topElement.addMetadata(md);
} catch (MetadataTypeNotAllowedException e) {
log.warn("Configured metadata for institution name is unknown or not allowed.");
}
if (topElement.getParent() != null) {
try {
ugh.dl.Metadata md = new ugh.dl.Metadata(mdt);
md.setValue(myProzess.getProjekt().getInstitution().getLongName());
topElement.getParent().addMetadata(md);
} catch (MetadataTypeNotAllowedException e) {
log.warn("Configured metadata for institution name is unknown or not allowed.");
}
}
}
}
}
/*
* -------------------------------- wenn Filegroups definiert wurden, werden diese jetzt in die Metsstruktur übernommen
* --------------------------------
*/
// Replace all pathes with the given VariableReplacer, also the file
// group pathes!
VariableReplacer vp = new VariableReplacer(mm.getDigitalDocument(), this.myPrefs, myProzess, null);
List<ProjectFileGroup> myFilegroups = myProzess.getProjekt().getFilegroups();
boolean useOriginalFiles = false;
if (myFilegroups != null && myFilegroups.size() > 0) {
for (ProjectFileGroup pfg : myFilegroups) {
if (pfg.isUseOriginalFiles()) {
useOriginalFiles = true;
}
// check if source files exists
if (pfg.getFolder() != null && pfg.getFolder().length() > 0) {
String foldername = myProzess.getMethodFromName(pfg.getFolder());
if (foldername != null) {
Path folder = Paths.get(myProzess.getMethodFromName(pfg.getFolder()));
if (folder != null && StorageProvider.getInstance().isFileExists(folder) && !StorageProvider.getInstance().list(folder.toString()).isEmpty()) {
VirtualFileGroup v = createFilegroup(vp, pfg);
mm.getDigitalDocument().getFileSet().addVirtualFileGroup(v);
}
}
} else {
VirtualFileGroup v = createFilegroup(vp, pfg);
mm.getDigitalDocument().getFileSet().addVirtualFileGroup(v);
}
}
}
if (useOriginalFiles) {
// check if media folder contains images
List<Path> filesInFolder = StorageProvider.getInstance().listFiles(myProzess.getImagesTifDirectory(false));
if (!filesInFolder.isEmpty()) {
// compare image names with files in mets file
List<DocStruct> pages = dd.getPhysicalDocStruct().getAllChildren();
if (pages != null && pages.size() > 0) {
for (DocStruct page : pages) {
Path completeNameInMets = Paths.get(page.getImageName());
String filenameInMets = completeNameInMets.getFileName().toString();
int dotIndex = filenameInMets.lastIndexOf('.');
if (dotIndex != -1) {
filenameInMets = filenameInMets.substring(0, dotIndex);
}
for (Path imageNameInFolder : filesInFolder) {
String imageName = imageNameInFolder.getFileName().toString();
dotIndex = imageName.lastIndexOf('.');
if (dotIndex != -1) {
imageName = imageName.substring(0, dotIndex);
}
if (filenameInMets.toLowerCase().equals(imageName.toLowerCase())) {
// found matching filename
page.setImageName(imageNameInFolder.toString());
break;
}
}
}
// replace filename in mets file
}
}
}
// Replace rights and digiprov entries.
mm.setRightsOwner(vp.replace(myProzess.getProjekt().getMetsRightsOwner()));
mm.setRightsOwnerLogo(vp.replace(myProzess.getProjekt().getMetsRightsOwnerLogo()));
mm.setRightsOwnerSiteURL(vp.replace(myProzess.getProjekt().getMetsRightsOwnerSite()));
mm.setRightsOwnerContact(vp.replace(myProzess.getProjekt().getMetsRightsOwnerMail()));
mm.setDigiprovPresentation(vp.replace(myProzess.getProjekt().getMetsDigiprovPresentation()));
mm.setDigiprovReference(vp.replace(myProzess.getProjekt().getMetsDigiprovReference()));
mm.setDigiprovPresentationAnchor(vp.replace(myProzess.getProjekt().getMetsDigiprovPresentationAnchor()));
mm.setDigiprovReferenceAnchor(vp.replace(myProzess.getProjekt().getMetsDigiprovReferenceAnchor()));
mm.setMetsRightsLicense(vp.replace(myProzess.getProjekt().getMetsRightsLicense()));
mm.setMetsRightsSponsor(vp.replace(myProzess.getProjekt().getMetsRightsSponsor()));
mm.setMetsRightsSponsorLogo(vp.replace(myProzess.getProjekt().getMetsRightsSponsorLogo()));
mm.setMetsRightsSponsorSiteURL(vp.replace(myProzess.getProjekt().getMetsRightsSponsorSiteURL()));
mm.setPurlUrl(vp.replace(myProzess.getProjekt().getMetsPurl()));
mm.setContentIDs(vp.replace(myProzess.getProjekt().getMetsContentIDs()));
String pointer = myProzess.getProjekt().getMetsPointerPath();
pointer = vp.replace(pointer);
mm.setMptrUrl(pointer);
String anchor = myProzess.getProjekt().getMetsPointerPathAnchor();
pointer = vp.replace(anchor);
mm.setMptrAnchorUrl(pointer);
mm.setGoobiID(String.valueOf(myProzess.getId()));
mm.setIIIFUrl(vp.replace(myProzess.getProjekt().getMetsIIIFUrl()));
mm.setSruUrl(vp.replace(myProzess.getProjekt().getMetsSruUrl()));
// if (!ConfigMain.getParameter("ImagePrefix", "\\d{8}").equals("\\d{8}")) {
List<String> images = new ArrayList<>();
if (config.isExportValidateImages()) {
try {
images = new MetadatenImagesHelper(this.myPrefs, dd).getDataFiles(myProzess, imageFolderPath);
int sizeOfPagination = dd.getPhysicalDocStruct().getAllChildren().size();
if (images != null) {
int sizeOfImages = images.size();
if (sizeOfPagination == sizeOfImages) {
dd.overrideContentFiles(images);
} else {
String[] param = { String.valueOf(sizeOfPagination), String.valueOf(sizeOfImages) };
Helper.setFehlerMeldung(Helper.getTranslation("imagePaginationError", param));
return null;
}
}
} catch (IndexOutOfBoundsException e) {
log.error(e);
return null;
} catch (InvalidImagesException e) {
log.error(e);
return null;
}
} else {
// create pagination out of virtual file names
dd.addAllContentFiles();
}
return mm;
}
use of ugh.dl.Prefs in project goobi-workflow by intranda.
the class ProzesskopieForm method createNewFileformat.
/* =============================================================== */
private void createNewFileformat() throws TypeNotAllowedForParentException, TypeNotAllowedAsChildException {
Prefs myPrefs = this.prozessKopie.getRegelsatz().getPreferences();
try {
DigitalDocument dd = new DigitalDocument();
Fileformat ff = new XStream(myPrefs);
ff.setDigitalDocument(dd);
/* BoundBook hinzufügen */
DocStructType dst = myPrefs.getDocStrctTypeByName("BoundBook");
DocStruct dsBoundBook = dd.createDocStruct(dst);
dd.setPhysicalDocStruct(dsBoundBook);
ConfigOpacDoctype configOpacDoctype = co.getDoctypeByName(this.docType);
/* Monographie */
if (!configOpacDoctype.isPeriodical() && !configOpacDoctype.isMultiVolume()) {
DocStructType dsty = myPrefs.getDocStrctTypeByName(configOpacDoctype.getRulesetType());
DocStruct ds = dd.createDocStruct(dsty);
dd.setLogicalDocStruct(ds);
this.myRdf = ff;
} else /* periodica */
if (configOpacDoctype.isPeriodical() || configOpacDoctype.isMultiVolume()) {
DocStructType anchor = myPrefs.getDocStrctTypeByName(configOpacDoctype.getRulesetType());
DocStruct ds = dd.createDocStruct(anchor);
dd.setLogicalDocStruct(ds);
DocStructType dstyvolume = myPrefs.getDocStrctTypeByName(configOpacDoctype.getRulesetChildType());
DocStruct dsvolume = dd.createDocStruct(dstyvolume);
ds.addChild(dsvolume);
this.myRdf = ff;
}
// } catch (TypeNotAllowedForParentException e) {
// log.error(e);
// } catch (TypeNotAllowedAsChildException e) {
// log.error(e);
} catch (PreferencesException e) {
log.error(e);
}
}
use of ugh.dl.Prefs in project goobi-workflow by intranda.
the class Process method getReplacedVariable.
/**
* return specific variable for this process adapted by the central VariableReplacer
*
* @param inVariable
* @return adapted result with replaced value
*/
public String getReplacedVariable(String inVariable) {
// if replaced value is not stored already then do it now
if (!tempVariableMap.containsKey(inVariable)) {
DigitalDocument dd = null;
Prefs myPrefs = null;
// just load the mets file if needed
if (inVariable.startsWith("{meta")) {
myPrefs = getRegelsatz().getPreferences();
try {
Fileformat gdzfile = readMetadataFile();
dd = gdzfile.getDigitalDocument();
} catch (Exception e) {
log.error("error reading METS file for process " + id, e);
}
}
VariableReplacer replacer = new VariableReplacer(dd, myPrefs, this, null);
// put replaced value into temporary store
String replacedValue = replacer.replace(inVariable);
// return empty string, if value could not be found
if (replacedValue.equals(inVariable)) {
replacedValue = "";
}
tempVariableMap.put(inVariable, replacedValue);
}
return tempVariableMap.get(inVariable);
}
use of ugh.dl.Prefs 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