use of org.goobi.beans.Process in project goobi-workflow by intranda.
the class ProcessSwapInTask method run.
/**
* Aufruf als Thread ================================================================
*/
@SuppressWarnings("deprecation")
@Override
public void run() {
setStatusProgress(5);
String swapPath = null;
// ProzessDAO dao = new ProzessDAO();
String processDirectory = "";
if (ConfigurationHelper.getInstance().isUseSwapping()) {
swapPath = ConfigurationHelper.getInstance().getSwapPath();
} else {
setStatusMessage("swapping not activated");
setStatusProgress(-1);
return;
}
if (swapPath == null || swapPath.length() == 0) {
setStatusMessage("no swappingPath defined");
setStatusProgress(-1);
return;
}
Path swapFile = Paths.get(swapPath);
if (!StorageProvider.getInstance().isFileExists(swapFile)) {
setStatusMessage("Swap folder does not exist or is not mounted");
setStatusProgress(-1);
return;
}
try {
processDirectory = getProzess().getProcessDataDirectoryIgnoreSwapping();
// TODO: Don't catch Exception (the super class)
} catch (Exception e) {
log.warn("Exception:", e);
setStatusMessage("Error while getting process data folder: " + e.getClass().getName() + " - " + e.getMessage());
setStatusProgress(-1);
return;
}
Path fileIn = Paths.get(processDirectory);
Path fileOut = Paths.get(swapPath + getProzess().getId() + FileSystems.getDefault().getSeparator());
if (!StorageProvider.getInstance().isFileExists(fileOut)) {
setStatusMessage(getProzess().getTitel() + ": swappingOutTarget does not exist");
setStatusProgress(-1);
return;
}
if (!StorageProvider.getInstance().isFileExists(fileIn)) {
setStatusMessage(getProzess().getTitel() + ": process data folder does not exist");
setStatusProgress(-1);
return;
}
SAXBuilder builder = new SAXBuilder();
Document docOld;
try {
Path swapLogFile = Paths.get(processDirectory, "swapped.xml");
docOld = builder.build(swapLogFile.toFile());
// TODO: Don't catch Exception (the super class)
} catch (Exception e) {
log.warn("Exception:", e);
setStatusMessage("Error while reading swapped.xml in process data folder: " + e.getClass().getName() + " - " + e.getMessage());
setStatusProgress(-1);
return;
}
/*
* --------------------- alte Checksummen in HashMap schreiben -------------------
*/
setStatusMessage("reading checksums");
Element rootOld = docOld.getRootElement();
HashMap<String, String> crcMap = new HashMap<String, String>();
// TODO: Don't use Iterators
for (Iterator<Element> it = rootOld.getChildren("file").iterator(); it.hasNext(); ) {
Element el = it.next();
crcMap.put(el.getAttribute("path").getValue(), el.getAttribute("crc32").getValue());
}
StorageProvider.getInstance().deleteDataInDir(fileIn);
/*
* --------------------- Dateien kopieren und Checksummen ermitteln -------------------
*/
Document doc = new Document();
Element root = new Element("goobiArchive");
doc.setRootElement(root);
/*
* --------------------- Verzeichnisse und Dateien kopieren und anschliessend den Ordner leeren -------------------
*/
setStatusProgress(50);
try {
setStatusMessage("copying process files");
Helper.copyDirectoryWithCrc32Check(fileOut, fileIn, swapPath.length(), root);
} catch (IOException e) {
log.warn("IOException:", e);
setStatusMessage("IOException in copyDirectory: " + e.getMessage());
setStatusProgress(-1);
return;
}
setStatusProgress(80);
/*
* --------------------- Checksummen vergleichen -------------------
*/
setStatusMessage("checking checksums");
// TODO: Don't use Iterators
for (Iterator<Element> it = root.getChildren("file").iterator(); it.hasNext(); ) {
Element el = it.next();
String newPath = el.getAttribute("path").getValue();
String newCrc = el.getAttribute("crc32").getValue();
if (crcMap.containsKey(newPath)) {
if (!crcMap.get(newPath).equals(newCrc)) {
setLongMessage(getLongMessage() + "File " + newPath + " has different checksum<br/>");
}
crcMap.remove(newPath);
}
}
setStatusProgress(85);
/*
* --------------------- prüfen, ob noch Dateien fehlen -------------------
*/
setStatusMessage("checking missing files");
if (crcMap.size() > 0) {
for (String myFile : crcMap.keySet()) {
setLongMessage(getLongMessage() + "File " + myFile + " is missing<br/>");
}
}
setStatusProgress(90);
/* in Prozess speichern */
StorageProvider.getInstance().deleteDir(fileOut);
try {
setStatusMessage("saving process");
Process myProzess = ProcessManager.getProcessById(getProzess().getId());
myProzess.setSwappedOutGui(false);
ProcessManager.saveProcess(myProzess);
} catch (DAOException e) {
setStatusMessage("DAOException while saving process: " + e.getMessage());
log.warn("DAOException:", e);
setStatusProgress(-1);
return;
}
setStatusMessage("done");
setStatusProgress(100);
}
use of org.goobi.beans.Process in project goobi-workflow by intranda.
the class FileManipulation method importFiles.
public void importFiles() {
if (selectedFiles == null || selectedFiles.isEmpty()) {
Helper.setFehlerMeldung("noFileSelected");
return;
}
String tempDirectory = ConfigurationHelper.getInstance().getTemporaryFolder();
// String masterPrefix = "";
boolean useMasterFolder = false;
if (ConfigurationHelper.getInstance().isUseMasterDirectory()) {
useMasterFolder = true;
// masterPrefix = ConfigurationHelper.getInstance().getMasterDirectoryPrefix();
}
Process currentProcess = metadataBean.getMyProzess();
List<String> importedFilenames = new ArrayList<>();
for (String importName : selectedFiles) {
List<Path> subfolderList = StorageProvider.getInstance().listFiles(tempDirectory + "fileupload" + FileSystems.getDefault().getSeparator() + importName);
for (Path subfolder : subfolderList) {
if (useMasterFolder) {
// check if current import folder is master folder
if (subfolder.getFileName().toString().equals(VariableReplacer.simpleReplace(ConfigurationHelper.getInstance().getProcessImagesSourceDirectoryName(), metadataBean.getMyProzess()))) {
try {
String masterFolderName = currentProcess.getImagesOrigDirectory(false);
Path masterDirectory = Paths.get(masterFolderName);
if (!StorageProvider.getInstance().isFileExists(masterDirectory)) {
StorageProvider.getInstance().createDirectories(masterDirectory);
}
List<Path> objectInFolder = StorageProvider.getInstance().listFiles(subfolder.toString());
for (Path object : objectInFolder) {
Path dest = Paths.get(masterDirectory.toString(), object.getFileName().toString());
StorageProvider.getInstance().copyFile(object, dest);
}
} catch (SwapException | DAOException | IOException | InterruptedException e) {
log.error(e);
}
} else {
if (subfolder.getFileName().toString().contains("_")) {
String folderSuffix = subfolder.getFileName().toString().substring(subfolder.getFileName().toString().lastIndexOf("_") + 1);
String folderName = currentProcess.getMethodFromName(folderSuffix);
if (folderName != null) {
try {
Path directory = Paths.get(folderName);
List<Path> objectInFolder = StorageProvider.getInstance().listFiles(subfolder.toString());
for (Path object : objectInFolder) {
if (currentProcess.getImagesTifDirectory(false).equals(folderName + FileSystems.getDefault().getSeparator())) {
importedFilenames.add(object.getFileName().toString());
}
Path dest = Paths.get(directory.toString(), object.getFileName().toString());
StorageProvider.getInstance().copyFile(object, dest);
}
} catch (IOException | SwapException | DAOException | InterruptedException e) {
log.error(e);
}
}
}
}
} else {
if (subfolder.getFileName().toString().contains("_")) {
String folderSuffix = subfolder.getFileName().toString().substring(subfolder.getFileName().toString().lastIndexOf("_") + 1);
String folderName = currentProcess.getMethodFromName(folderSuffix);
if (folderName != null) {
Path directory = Paths.get(folderName);
List<Path> objectInFolder = StorageProvider.getInstance().listFiles(subfolder.toString());
for (Path object : objectInFolder) {
try {
if (currentProcess.getImagesTifDirectory(false).equals(folderName + FileSystems.getDefault().getSeparator())) {
importedFilenames.add(object.getFileName().toString());
}
Path dest = Paths.get(directory.toString(), object.getFileName().toString());
StorageProvider.getInstance().copyFile(object, dest);
} catch (IOException | SwapException | DAOException | InterruptedException e) {
log.error(e);
}
}
}
}
}
}
}
// update pagination
try {
if (insertPage == null || insertPage.isEmpty() || insertPage.equals("lastPage")) {
metadataBean.createPagination();
} else {
int indexToImport = Integer.parseInt(insertPage);
for (String filename : importedFilenames) {
updatePagination(filename);
insertPage = String.valueOf(++indexToImport);
}
}
} catch (TypeNotAllowedForParentException | SwapException | DAOException | MetadataTypeNotAllowedException | IOException | InterruptedException e) {
log.error(e);
}
for (String importName : selectedFiles) {
Path importfolder = Paths.get(tempDirectory + "fileupload" + FileSystems.getDefault().getSeparator() + importName);
StorageProvider.getInstance().deleteDir(importfolder);
}
metadataBean.retrieveAllImages();
metadataBean.changeFolder();
// save current state
metadataBean.Reload();
}
use of org.goobi.beans.Process in project goobi-workflow by intranda.
the class StepBean method saveProcessProperties.
public void saveProcessProperties() {
boolean valid = true;
for (IProperty p : this.processPropertyList) {
if (!p.isValid()) {
String value = Helper.getTranslation("propertyNotValid", p.getName());
Helper.setFehlerMeldung(value);
valid = false;
}
}
if (valid) {
for (ProcessProperty p : this.processPropertyList) {
if (p.getProzesseigenschaft() == null) {
Processproperty pe = new Processproperty();
pe.setProzess(this.mySchritt.getProzess());
p.setProzesseigenschaft(pe);
this.mySchritt.getProzess().getEigenschaften().add(pe);
}
p.transfer();
if (!this.mySchritt.getProzess().getEigenschaften().contains(p.getProzesseigenschaft())) {
this.mySchritt.getProzess().getEigenschaften().add(p.getProzesseigenschaft());
}
}
Process p = this.mySchritt.getProzess();
List<Processproperty> props = p.getEigenschaftenList();
for (Processproperty pe : props) {
if (pe.getTitel() == null) {
p.getEigenschaften().remove(pe);
}
}
// try {
PropertyManager.saveProcessProperty(processProperty.getProzesseigenschaft());
Helper.setMeldung("propertiesSaved");
// } catch (DAOException e) {
// mylog.error(e);
// Helper.setFehlerMeldung("propertiesNotSaved");
// }
}
}
use of org.goobi.beans.Process in project goobi-workflow by intranda.
the class CopyProcess method Prepare.
public String Prepare() {
if (this.prozessVorlage.getContainsUnreachableSteps()) {
for (Step s : this.prozessVorlage.getSchritteList()) {
if (s.getBenutzergruppenSize() == 0 && s.getBenutzerSize() == 0) {
Helper.setFehlerMeldung("Kein Benutzer festgelegt für: ", s.getTitel());
}
}
return "";
}
clearValues();
this.co = ConfigOpac.getInstance();
try {
String type = MetadatenHelper.getMetaFileType(metadataFile);
this.myRdf = MetadatenHelper.getFileformatByName(type, prozessVorlage.getRegelsatz());
this.myRdf.read(this.metadataFile);
} catch (ReadException e) {
log.error(e);
} catch (IOException e) {
log.error(e);
}
;
this.prozessKopie = new Process();
this.prozessKopie.setTitel("");
this.prozessKopie.setIstTemplate(false);
this.prozessKopie.setInAuswahllisteAnzeigen(false);
this.prozessKopie.setProjekt(this.prozessVorlage.getProjekt());
this.prozessKopie.setRegelsatz(this.prozessVorlage.getRegelsatz());
this.digitalCollections = new ArrayList<>();
/*
* -------------------------------- Kopie der Prozessvorlage anlegen --------------------------------
*/
this.bhelp.SchritteKopieren(this.prozessVorlage, this.prozessKopie);
this.bhelp.ScanvorlagenKopieren(this.prozessVorlage, this.prozessKopie);
this.bhelp.WerkstueckeKopieren(this.prozessVorlage, this.prozessKopie);
this.bhelp.EigenschaftenKopieren(this.prozessVorlage, this.prozessKopie);
initializePossibleDigitalCollections();
return this.naviFirstPage;
}
use of org.goobi.beans.Process in project goobi-workflow by intranda.
the class ProcessMysqlHelper method getAllProcesses.
public static List<Process> getAllProcesses() throws SQLException {
Connection connection = null;
StringBuilder sql = new StringBuilder();
sql.append("SELECT * FROM prozesse");
try {
connection = MySQLHelper.getInstance().getConnection();
if (log.isTraceEnabled()) {
log.trace(sql.toString());
}
List<Process> ret = new QueryRunner().query(connection, sql.toString(), resultSetToProcessListHandler);
return ret;
} finally {
if (connection != null) {
MySQLHelper.closeConnection(connection);
}
}
}
Aggregations