use of de.sub.goobi.helper.exceptions.SwapException in project goobi-workflow by intranda.
the class Metadaten method saveAlto.
public void saveAlto() {
AltoChange[] changes = new Gson().fromJson(this.altoChanges, AltoChange[].class);
try {
AltoSaver.saveAltoChanges(getCurrentAltoPath(), changes);
this.loadJsonAlto();
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, Helper.getTranslation("savedAlto"), null);
FacesContext.getCurrentInstance().addMessage("altoChanges", fm);
} catch (JDOMException | IOException | SwapException | DAOException | InterruptedException e) {
// TODO Auto-generated catch block
log.error(e);
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, Helper.getTranslation("errorSavingAlto"), null);
FacesContext.getCurrentInstance().addMessage("altoChanges", fm);
}
}
use of de.sub.goobi.helper.exceptions.SwapException in project goobi-workflow by intranda.
the class Metadaten method XMLlesenStart.
/**
* Metadaten Einlesen
*
* @throws ReadException
* @throws InterruptedException
* @throws IOException
* @throws PreferencesException ============================================================ == ==
* @throws DAOException
* @throws SwapException
* @throws WriteException
*/
public String XMLlesenStart() throws ReadException, IOException, InterruptedException, PreferencesException, SwapException, DAOException, WriteException {
currentRepresentativePage = "";
this.myPrefs = this.myProzess.getRegelsatz().getPreferences();
enablePageArea = myPrefs.getDocStrctTypeByName("area") != null;
this.modusHinzufuegen = false;
this.modusHinzufuegenPerson = false;
this.modusStrukturelementVerschieben = false;
this.modusCopyDocstructFromOtherProcess = false;
this.currentTifFolder = null;
readAllTifFolders();
/*
* -------------------------------- Dokument einlesen --------------------------------
*/
this.gdzfile = this.myProzess.readMetadataFile();
if (gdzfile == null) {
return null;
}
this.document = this.gdzfile.getDigitalDocument();
this.document.addAllContentFiles();
this.metahelper = new MetadatenHelper(this.myPrefs, this.document);
this.imagehelper = new MetadatenImagesHelper(this.myPrefs, this.document);
/*
* -------------------------------- Das Hauptelement ermitteln --------------------------------
*/
this.logicalTopstruct = this.document.getLogicalDocStruct();
// this exception needs some serious feedback because data is corrupted
if (this.logicalTopstruct == null) {
throw new ReadException(Helper.getTranslation("metaDataError"));
}
// initialize page area editor
this.pageAreaManager = new PageAreaManager(this.myPrefs, this.document);
checkImageNames();
retrieveAllImages();
// check filenames, correct them
// initialize image list
numberOfImagesPerPage = ConfigurationHelper.getInstance().getMetsEditorNumberOfImagesPerPage();
thumbnailSizeInPixel = ConfigurationHelper.getInstance().getMetsEditorThumbnailSize();
pageNo = 0;
imageIndex = 0;
loadCurrentImages(true);
if (this.document.getPhysicalDocStruct().getAllMetadata() != null && this.document.getPhysicalDocStruct().getAllMetadata().size() > 0) {
List<Metadata> lstMetadata = this.document.getPhysicalDocStruct().getAllMetadata();
for (Metadata md : lstMetadata) {
if (md.getType().getName().equals("_representative")) {
try {
Integer value = Integer.valueOf(md.getValue());
currentRepresentativePage = String.valueOf(value);
updateRepresentativePage();
} catch (Exception e) {
}
}
}
DocStruct docstruct = logicalTopstruct;
if (docstruct.getType().isAnchor()) {
docstruct = docstruct.getAllChildren().get(0);
}
lstMetadata = docstruct.getAllMetadata();
if (lstMetadata != null) {
for (Metadata md : lstMetadata) {
if (md.getType().getName().equals("_directionRTL")) {
try {
Boolean value = Boolean.valueOf(md.getValue());
this.pagesRTL = value;
} catch (Exception e) {
}
}
}
}
}
createDefaultValues(this.logicalTopstruct);
MetadatenalsBeanSpeichern(this.logicalTopstruct);
MetadatenalsTree3Einlesen1(this.tree3, this.logicalTopstruct, false);
physicalTopstruct = document.getPhysicalDocStruct();
currentTopstruct = logicalTopstruct;
if (this.nurLesenModus || allImages.isEmpty()) {
// inserted to make Paginierung the starting view
this.modusAnsicht = "Metadaten";
}
return "metseditor";
}
use of de.sub.goobi.helper.exceptions.SwapException in project goobi-workflow by intranda.
the class MetadatenImagesHelper method createPagination.
/**
* Markus baut eine Seitenstruktur aus den vorhandenen Images ---------------- Steps - ---------------- Validation of images compare existing
* number images with existing number of page DocStructs if it is the same don't do anything if DocStructs are less add new pages to
* physicalDocStruct if images are less delete pages from the end of pyhsicalDocStruct --------------------------------
*
* @return null
* @throws TypeNotAllowedForParentException
* @throws TypeNotAllowedForParentException
* @throws InterruptedException
* @throws IOException
* @throws InterruptedException
* @throws IOException
* @throws DAOException
* @throws SwapException
*/
public void createPagination(Process inProzess, String directory) throws TypeNotAllowedForParentException, IOException, InterruptedException, SwapException, DAOException {
String mediaFolder = inProzess.getImagesTifDirectory(false);
String mediaFolderWithFallback = inProzess.getImagesTifDirectory(true);
DocStruct physicaldocstruct = this.mydocument.getPhysicalDocStruct();
DocStruct logical = this.mydocument.getLogicalDocStruct();
if (logical.getType().isAnchor()) {
if (logical.getAllChildren() != null && logical.getAllChildren().size() > 0) {
logical = logical.getAllChildren().get(0);
}
}
MetadataType MDTypeForPath = this.myPrefs.getMetadataTypeByName("pathimagefiles");
/*--------------------------------
* der physische Baum wird nur
* angelegt, wenn er noch nicht existierte
* --------------------------------*/
if (physicaldocstruct == null) {
DocStructType dst = this.myPrefs.getDocStrctTypeByName("BoundBook");
physicaldocstruct = this.mydocument.createDocStruct(dst);
this.mydocument.setPhysicalDocStruct(physicaldocstruct);
}
// check for valid filepath
try {
List<? extends Metadata> filepath = physicaldocstruct.getAllMetadataByType(MDTypeForPath);
if (filepath == null || filepath.isEmpty()) {
Metadata mdForPath = new Metadata(MDTypeForPath);
if (SystemUtils.IS_OS_WINDOWS) {
mdForPath.setValue("file:/" + mediaFolder);
} else {
mdForPath.setValue("file://" + mediaFolder);
}
physicaldocstruct.addMetadata(mdForPath);
}
} catch (Exception e) {
log.error(e);
}
Path folderToCheck = null;
if (directory == null) {
folderToCheck = Paths.get(mediaFolderWithFallback);
checkIfImagesValid(inProzess.getTitel(), mediaFolderWithFallback);
} else {
folderToCheck = Paths.get(directory);
if (!folderToCheck.isAbsolute()) {
folderToCheck = Paths.get(inProzess.getImagesDirectory(), directory);
}
checkIfImagesValid(inProzess.getTitel(), folderToCheck.toString());
}
DocStructType typePage = this.myPrefs.getDocStrctTypeByName("page");
DocStructType typeAudio = this.myPrefs.getDocStrctTypeByName("audio");
DocStructType typeVideo = this.myPrefs.getDocStrctTypeByName("video");
DocStructType type3dObject = this.myPrefs.getDocStrctTypeByName("object");
// use fallback to 'page', if additional types are not configured in ruleset
if (typeAudio == null) {
typeAudio = typePage;
}
if (typeVideo == null) {
typeVideo = typePage;
}
if (type3dObject == null) {
type3dObject = typePage;
}
/*-------------------------------
* retrieve existing pages/images
* -------------------------------*/
List<DocStruct> oldPages = physicaldocstruct.getAllChildren();
if (oldPages == null) {
oldPages = new ArrayList<>();
}
if (oldPages.size() == this.myLastImage) {
return;
}
String defaultPagination = ConfigurationHelper.getInstance().getMetsEditorDefaultPagination();
Map<String, DocStruct> assignedImages = new HashMap<>();
List<DocStruct> pageElementsWithoutImages = new ArrayList<>();
List<String> imagesWithoutPageElements = new ArrayList<>();
if (physicaldocstruct.getAllChildren() != null && !physicaldocstruct.getAllChildren().isEmpty()) {
List<String> imageFileList = null;
imageFileList = StorageProvider.getInstance().list(folderToCheck.toString());
Set<String> imageFileSet = new HashSet<>(imageFileList);
for (DocStruct page : physicaldocstruct.getAllChildren()) {
if (page.getImageName() != null) {
if (imageFileSet.contains(page.getImageName())) {
assignedImages.put(page.getImageName(), page);
} else {
try {
page.removeContentFile(page.getAllContentFiles().get(0));
pageElementsWithoutImages.add(page);
} catch (ContentFileNotLinkedException e) {
log.error(e);
}
}
} else {
pageElementsWithoutImages.add(page);
}
}
}
try {
List<String> imageNamesInMediaFolder = getDataFiles(inProzess, directory);
if (imageNamesInMediaFolder != null && !imageNamesInMediaFolder.isEmpty()) {
for (String imageName : imageNamesInMediaFolder) {
if (!assignedImages.containsKey(imageName)) {
imagesWithoutPageElements.add(imageName);
}
}
}
} catch (InvalidImagesException e1) {
log.error(e1);
}
// case 1: existing pages but no images (some images are removed)
if (!pageElementsWithoutImages.isEmpty() && imagesWithoutPageElements.isEmpty()) {
for (DocStruct pageToRemove : pageElementsWithoutImages) {
physicaldocstruct.removeChild(pageToRemove);
List<Reference> refs = new ArrayList<>(pageToRemove.getAllFromReferences());
for (ugh.dl.Reference ref : refs) {
DocStruct source = ref.getSource();
for (Reference reference : source.getAllToReferences()) {
if (reference.getTarget().equals(pageToRemove)) {
source.getAllToReferences().remove(reference);
break;
}
}
}
}
} else // case 2: no page docs but images (some images are added)
if (pageElementsWithoutImages.isEmpty() && !imagesWithoutPageElements.isEmpty()) {
int currentPhysicalOrder = assignedImages.size();
for (String newImage : imagesWithoutPageElements) {
String mimetype = NIOFileUtils.getMimeTypeFromFile(Paths.get(newImage));
DocStruct dsPage = null;
if (mimetype.startsWith("image")) {
dsPage = this.mydocument.createDocStruct(typePage);
} else if (mimetype.startsWith("video") || mimetype.equals("application/mxf")) {
dsPage = mydocument.createDocStruct(typeVideo);
} else if (mimetype.startsWith("audio")) {
dsPage = mydocument.createDocStruct(typeAudio);
} else if (mimetype.startsWith("object")) {
dsPage = mydocument.createDocStruct(type3dObject);
} else if (mimetype.startsWith("model")) {
dsPage = mydocument.createDocStruct(type3dObject);
} else {
// use old implementation as default
dsPage = mydocument.createDocStruct(typePage);
}
try {
// physical page no
physicaldocstruct.addChild(dsPage);
MetadataType mdt = this.myPrefs.getMetadataTypeByName("physPageNumber");
Metadata mdTemp = new Metadata(mdt);
mdTemp.setValue(String.valueOf(++currentPhysicalOrder));
dsPage.addMetadata(mdTemp);
// logical page no
mdt = this.myPrefs.getMetadataTypeByName("logicalPageNumber");
mdTemp = new Metadata(mdt);
if (defaultPagination.equalsIgnoreCase("arabic")) {
mdTemp.setValue(String.valueOf(currentPhysicalOrder));
} else if (defaultPagination.equalsIgnoreCase("roman")) {
RomanNumeral roman = new RomanNumeral();
roman.setValue(currentPhysicalOrder);
mdTemp.setValue(roman.getNumber());
} else {
mdTemp.setValue("uncounted");
}
dsPage.addMetadata(mdTemp);
logical.addReferenceTo(dsPage, "logical_physical");
// image name
ContentFile cf = new ContentFile();
cf.setMimetype(mimetype);
if (SystemUtils.IS_OS_WINDOWS) {
cf.setLocation("file:/" + mediaFolder + newImage);
} else {
cf.setLocation("file://" + mediaFolder + newImage);
}
dsPage.addContentFile(cf);
} catch (TypeNotAllowedAsChildException e) {
log.error(e);
} catch (MetadataTypeNotAllowedException e) {
log.error(e);
}
}
} else // case 3: empty page docs and unassinged images
{
for (DocStruct page : pageElementsWithoutImages) {
if (!imagesWithoutPageElements.isEmpty()) {
// assign new image name to page
String newImageName = imagesWithoutPageElements.get(0);
imagesWithoutPageElements.remove(0);
ContentFile cf = new ContentFile();
if (SystemUtils.IS_OS_WINDOWS) {
cf.setLocation("file:/" + mediaFolder + newImageName);
} else {
cf.setLocation("file://" + mediaFolder + newImageName);
}
page.addContentFile(cf);
} else {
// remove page
physicaldocstruct.removeChild(page);
List<Reference> refs = new ArrayList<>(page.getAllFromReferences());
for (ugh.dl.Reference ref : refs) {
ref.getSource().removeReferenceTo(page);
}
}
}
if (!imagesWithoutPageElements.isEmpty()) {
// create new page elements
int currentPhysicalOrder = physicaldocstruct.getAllChildren().size();
for (String newImage : imagesWithoutPageElements) {
String mimetype = NIOFileUtils.getMimeTypeFromFile(Paths.get(newImage));
DocStruct dsPage = null;
if (mimetype.startsWith("image")) {
dsPage = this.mydocument.createDocStruct(typePage);
} else if (mimetype.startsWith("video") || mimetype.equals("application/mxf")) {
dsPage = mydocument.createDocStruct(typeVideo);
} else if (mimetype.startsWith("audio")) {
dsPage = mydocument.createDocStruct(typeAudio);
} else if (mimetype.startsWith("object")) {
dsPage = mydocument.createDocStruct(type3dObject);
} else if (mimetype.startsWith("model")) {
dsPage = mydocument.createDocStruct(type3dObject);
} else {
// use old implementation as default
dsPage = mydocument.createDocStruct(typePage);
}
try {
// physical page no
physicaldocstruct.addChild(dsPage);
MetadataType mdt = this.myPrefs.getMetadataTypeByName("physPageNumber");
Metadata mdTemp = new Metadata(mdt);
mdTemp.setValue(String.valueOf(++currentPhysicalOrder));
dsPage.addMetadata(mdTemp);
// logical page no
mdt = this.myPrefs.getMetadataTypeByName("logicalPageNumber");
mdTemp = new Metadata(mdt);
if (defaultPagination.equalsIgnoreCase("arabic")) {
mdTemp.setValue(String.valueOf(currentPhysicalOrder));
} else if (defaultPagination.equalsIgnoreCase("roman")) {
RomanNumeral roman = new RomanNumeral();
roman.setValue(currentPhysicalOrder);
mdTemp.setValue(roman.getNumber());
} else {
mdTemp.setValue("uncounted");
}
dsPage.addMetadata(mdTemp);
logical.addReferenceTo(dsPage, "logical_physical");
// image name
ContentFile cf = new ContentFile();
cf.setMimetype(mimetype);
if (SystemUtils.IS_OS_WINDOWS) {
cf.setLocation("file:/" + mediaFolder + newImage);
} else {
cf.setLocation("file://" + mediaFolder + newImage);
}
dsPage.addContentFile(cf);
} catch (TypeNotAllowedAsChildException e) {
log.error(e);
} catch (MetadataTypeNotAllowedException e) {
log.error(e);
}
}
}
}
int currentPhysicalOrder = 1;
MetadataType mdt = this.myPrefs.getMetadataTypeByName("physPageNumber");
if (physicaldocstruct.getAllChildren() != null) {
for (DocStruct page : physicaldocstruct.getAllChildren()) {
List<? extends Metadata> pageNoMetadata = page.getAllMetadataByType(mdt);
if (pageNoMetadata == null || pageNoMetadata.size() == 0) {
currentPhysicalOrder++;
break;
}
for (Metadata pageNo : pageNoMetadata) {
pageNo.setValue(String.valueOf(currentPhysicalOrder));
}
currentPhysicalOrder++;
}
}
}
use of de.sub.goobi.helper.exceptions.SwapException in project goobi-workflow by intranda.
the class Metadaten method setImageIndex.
public void setImageIndex(int imageIndex) {
this.imageIndex = imageIndex;
if (this.imageIndex < 0) {
this.imageIndex = 0;
}
if (this.imageIndex >= getSizeOfImageList()) {
this.imageIndex = getSizeOfImageList() - 1;
}
if (!allImages.isEmpty() && allImages.size() >= this.imageIndex) {
setImage(allImages.get(this.imageIndex));
bildNummer = this.imageIndex;
try {
this.loadJsonAlto();
} catch (IOException | JDOMException | SwapException | DAOException | InterruptedException e) {
SimpleAlto alto = new SimpleAlto("Error reading ALTO, see application log for details.");
this.currentJsonAlto = new Gson().toJson(alto);
log.error(e);
}
}
cancelPageAreaEdition();
}
use of de.sub.goobi.helper.exceptions.SwapException in project goobi-workflow by intranda.
the class Metadaten method XMLschreiben.
/**
* Metadaten Schreiben
*
* @throws InterruptedException
* @throws IOException ============================================================ == ==
* @throws DAOException
* @throws SwapException
* @throws WriteException
* @throws PreferencesException
*/
public String XMLschreiben() {
XmlArtikelZaehlen zaehlen = new XmlArtikelZaehlen();
this.myProzess.setSortHelperDocstructs(zaehlen.getNumberOfUghElements(this.logicalTopstruct, CountType.DOCSTRUCT));
this.myProzess.setSortHelperMetadata(zaehlen.getNumberOfUghElements(this.logicalTopstruct, CountType.METADATA));
try {
this.myProzess.setSortHelperImages(StorageProvider.getInstance().getNumberOfFiles(Paths.get(this.myProzess.getImagesOrigDirectory(true))));
ProcessManager.saveProcess(this.myProzess);
} catch (DAOException e) {
Helper.setFehlerMeldung("fehlerNichtSpeicherbar", e);
log.error(e);
} catch (Exception e) {
Helper.setFehlerMeldung("error while counting current images", e);
log.error(e);
}
/* xml-Datei speichern */
// MetadatenDebuggen(gdzfile.getDigitalDocument().getLogicalDocStruct());
/*
* --------------------- vor dem Speichern alle ungenutzen Docstructs rauswerfen -------------------
*/
this.metahelper.deleteAllUnusedElements(this.document.getLogicalDocStruct());
updateRepresentativePage();
// reading direction
setRepresentativeMetadata();
try {
// if (!new MetadatenVerifizierungWithoutHibernate().validateIdentifier(gdzfile.getDigitalDocument().getLogicalDocStruct())) {
// return false;
// }
this.myProzess.writeMetadataFile(this.gdzfile);
} catch (Exception e) {
Helper.setFehlerMeldung("Metafile is not writable.", e);
log.error(e);
return "Metadaten";
}
myProzess.removeTemporaryMetadataFiles();
SperrungAufheben();
return this.zurueck;
}
Aggregations