Package de.sub.goobi.persistence

Examples of de.sub.goobi.persistence.ProzessDAO


              list = hotfolder.getCurrentFiles();
              logger.trace("8");
              if (size == getSize(list)) {
                hotfolder.lock();
                logger.trace("9");
                ProzessDAO dao = new ProzessDAO();
                Prozess template = dao.get(hotfolder.getTemplate());
                dao.refresh(template);
                logger.trace("10");
                List<String> metsfiles = hotfolder.getFileNamesByFilter(GoobiHotfolder.filter);
                logger.trace("11");
                HashMap<String, Integer> failedData = new HashMap<String, Integer>();
                logger.trace("12");
View Full Code Here


  public static boolean testTitle(String titel) {
    if (titel != null) {
      long anzahl = 0;
      try {
        anzahl = new ProzessDAO().count("from Prozess where titel='" + titel + "'");
      } catch (DAOException e) {
        return false;
      }
      if (anzahl > 0) {
        Helper.setFehlerMeldung("processTitleAllreadyInUse");
View Full Code Here

  @Override
  @SuppressWarnings("unchecked")
  public void run() {
    setStatusProgress(5);
    String swapPath = null;
    ProzessDAO dao = new ProzessDAO();
    String processDirectory = "";

    if (ConfigMain.getBooleanParameter("useSwapping")) {
      swapPath = ConfigMain.getParameter("swapPath", "");
    } else {
      setStatusMessage("swapping not activated");
      setStatusProgress(-1);
      return;
    }
    if (swapPath == null || swapPath.length() == 0) {
      setStatusMessage("no swappingPath defined");
      setStatusProgress(-1);
      return;
    }
    File swapFile = new File(swapPath);
    if (!swapFile.exists()) {
      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) {
      logger.warn("Exception:", e);
      setStatusMessage("Error while getting process data folder: " + e.getClass().getName() + " - " + e.getMessage());
      setStatusProgress(-1);
      return;
    }

    File fileIn = new File(processDirectory);
    File fileOut = new File(swapPath + getProzess().getId() + File.separator);

    if (!fileOut.exists()) {
      setStatusMessage(getProzess().getTitel() + ": swappingOutTarget does not exist");
      setStatusProgress(-1);
      return;
    }
    if (!fileIn.exists()) {
      setStatusMessage(getProzess().getTitel() + ": process data folder does not exist");
      setStatusProgress(-1);
      return;
    }

    SAXBuilder builder = new SAXBuilder();
    Document docOld;
    try {
      File swapLogFile = new File(processDirectory, "swapped.xml");
      docOld = builder.build(swapLogFile);
      // TODO: Don't catch Exception (the super class)
    } catch (Exception e) {
      logger.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());
    }
    Helper.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) {
      logger.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 */
    Helper.deleteDir(fileOut);
    try {
      setStatusMessage("saving process");
      Prozess myProzess = dao.get(getProzess().getId());
      myProzess.setSwappedOutGui(false);
      dao.save(myProzess);
    } catch (DAOException e) {
      setStatusMessage("DAOException while saving process: " + e.getMessage());
      logger.warn("DAOException:", e);
      setStatusProgress(-1);
      return;
View Full Code Here

   @Override
public void run() {
      setStatusProgress(5);
      Helper help = new Helper();
      String swapPath = null;
      ProzessDAO dao = new ProzessDAO();
      String processDirectory = "";

      if (ConfigMain.getBooleanParameter("useSwapping")) {
    swapPath = ConfigMain.getParameter("swapPath", "");
  } else {
         setStatusMessage("swapping not activated");
         setStatusProgress(-1);
         return;
      }
      if (swapPath == null || swapPath.length() == 0) {
         setStatusMessage("no swappingPath defined");
         setStatusProgress(-1);
         return;
      }
      File swapFile = new File(swapPath);
      if (!swapFile.exists()) {
         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) {
        logger.warn("Exception:", e);
         setStatusMessage("Error while getting process data folder: " + e.getClass().getName() + " - "
               + e.getMessage());
         setStatusProgress(-1);
         return;
      }

      File fileIn = new File(processDirectory);
      File fileOut = new File(swapPath + getProzess().getId() + File.separator);
      if (fileOut.exists()) {
         setStatusMessage(getProzess().getTitel() + ": swappingOutTarget already exists");
         setStatusProgress(-1);
         return;
      }
      fileOut.mkdir();

      /* ---------------------
       * Xml-Datei vorbereiten
      * -------------------*/
      Document doc = new Document();
      Element root = new Element("goobiArchive");
      doc.setRootElement(root);
      Element source = new Element("source").setText(fileIn.getAbsolutePath());
      Element target = new Element("target").setText(fileOut.getAbsolutePath());
      Element title = new Element("title").setText(getProzess().getTitel());
      Element mydate = new Element("date").setText(new Date().toString());
      root.addContent(source);
      root.addContent(target);
      root.addContent(title);
      root.addContent(mydate);

      /* ---------------------
       * Verzeichnisse und Dateien kopieren und anschliessend den Ordner leeren
      * -------------------*/
      setStatusProgress(50);
      try {
        setStatusMessage("copying process folder");
        Helper.copyDirectoryWithCrc32Check(fileIn, fileOut, help.getGoobiDataDirectory().length(), root);
      } catch (IOException e) {
        logger.warn("IOException:", e);
         setStatusMessage("IOException in copyDirectory: " + e.getMessage());
         setStatusProgress(-1);
         return;
      }
      setStatusProgress(80);
      Helper.deleteDataInDir(new File(fileIn.getAbsolutePath()));

      /* ---------------------
       * xml-Datei schreiben
      * -------------------*/
      Format format = Format.getPrettyFormat();
      format.setEncoding("UTF-8");
      try {
         setStatusMessage("writing swapped.xml");
         XMLOutputter xmlOut = new XMLOutputter(format);
         FileOutputStream fos = new FileOutputStream(processDirectory + File.separator + "swapped.xml");
         xmlOut.output(doc, fos);
         fos.close();
         //TODO: Don't catch Exception (the super class)
      } catch (Exception e) {
        logger.warn("Exception:", e);
         setStatusMessage(e.getClass().getName() + " in xmlOut.output: " + e.getMessage());
         setStatusProgress(-1);
         return;
      }
      setStatusProgress(90);     
     
      /* in Prozess speichern */
      try {
         setStatusMessage("saving process");
         Prozess myProzess = dao.get(getProzess().getId());
         myProzess.setSwappedOutGui(true);
         dao.save(myProzess);
      } catch (DAOException e) {
         setStatusMessage("DAOException while saving process: " + e.getMessage());
         logger.warn("DAOException:", e);
         setStatusProgress(-1);
         return;
View Full Code Here

public class ProcessSwapOutTaskTest {
   static Prozess proz = null;
  
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
      proz = new ProzessDAO().get(119);
   }
View Full Code Here

   *             ============================================================ == ==
   */
  @Override
  public String TemplateAuswahlAuswerten() throws DAOException {
    /* den ausgewählten Prozess laden */
    Prozess tempProzess = new ProzessDAO().get(this.auswahl);
    if (tempProzess.getWerkstueckeSize() > 0) {
      /* erstes Werkstück durchlaufen */
      Werkstueck werk = tempProzess.getWerkstueckeList().get(0);
      for (Werkstueckeigenschaft eig : werk.getEigenschaften()) {
        for (AdditionalField field : this.additionalFields) {
View Full Code Here

    /* prüfen, ob der Prozesstitel schon verwendet wurde */
    if (this.prozessKopie.getTitel() != null) {
      long anzahl = 0;
      try {
        anzahl = new ProzessDAO().count("from Prozess where titel='" + this.prozessKopie.getTitel() + "'");
      } catch (DAOException e) {
        Helper.setFehlerMeldung("Fehler beim Einlesen der Vorgaenge", e.getMessage());
        valide = false;
      }
      if (anzahl > 0) {
View Full Code Here

      /* prüfen, ob der Prozesstitel schon verwendet wurde */
      if (this.prozessKopie.getTitel() != null) {
        long anzahl = 0;
        try {
          anzahl = new ProzessDAO().count("from Prozess where titel='" + this.prozessKopie.getTitel() + "'");
        } catch (DAOException e) {
          Helper.setFehlerMeldung("Fehler beim Einlesen der Vorgaenge", e.getMessage());
          valide = false;
        }
        if (anzahl > 0) {
View Full Code Here

      }

    }

    try {
      ProzessDAO dao = new ProzessDAO();
      dao.save(this.prozessKopie);
      dao.refresh(this.prozessKopie);
    } catch (DAOException e) {
      e.printStackTrace();
      myLogger.error("error on save: ", e);
      return this.prozessKopie;
    }

    /*
     * wenn noch keine RDF-Datei vorhanden ist (weil keine Opac-Abfrage stattfand, dann jetzt eine anlegen
     */
    if (this.myRdf == null) {
      createNewFileformat();
    }

    // /*--------------------------------
    // * wenn eine RDF-Konfiguration
    // * vorhanden ist (z.B. aus dem Opac-Import, oder frisch angelegt),
    // dann
    // * diese ergänzen
    // * --------------------------------*/
    if (this.updateData) {
      if (this.myRdf != null) {
        for (AdditionalField field : this.additionalFields) {
          if (field.isUghbinding() && field.getShowDependingOnDoctype()) {
            /* welches Docstruct */
            DocStruct myTempStruct = this.myRdf.getDigitalDocument().getLogicalDocStruct();
            DocStruct myTempChild = null;
            if (field.getDocstruct().equals("firstchild")) {
              try {
                myTempStruct = this.myRdf.getDigitalDocument().getLogicalDocStruct().getAllChildren().get(0);
              } catch (RuntimeException e) {
                /*
                 * das Firstchild unterhalb des Topstructs konnte nicht ermittelt werden
                 */
              }
            }
            /*
             * falls topstruct und firstchild das Metadatum bekommen sollen
             */
            if (!field.getDocstruct().equals("firstchild") && field.getDocstruct().contains("firstchild")) {
              try {
                myTempChild = this.myRdf.getDigitalDocument().getLogicalDocStruct().getAllChildren().get(0);
              } catch (RuntimeException e) {
              }
            }
            if (field.getDocstruct().equals("boundbook")) {
              myTempStruct = this.myRdf.getDigitalDocument().getPhysicalDocStruct();
            }
            /* welches Metadatum */
            try {
              /*
               * bis auf die Autoren alle additionals in die Metadaten übernehmen
               */
              if (!field.getMetadata().equals("ListOfCreators")) {
                MetadataType mdt = this.ughHelp.getMetadataType(this.prozessKopie.getRegelsatz().getPreferences(),
                    field.getMetadata());
                Metadata md = this.ughHelp.getMetadata(myTempStruct, mdt);
                /*
                 * wenn das Metadatum null ist, dann jetzt initialisieren
                 */
                if (md == null) {
                  md = new Metadata(mdt);
                  md.setDocStruct(myTempStruct);
                  myTempStruct.addMetadata(md);
                }
                md.setValue(field.getWert());
                /*
                 * wenn dem Topstruct und dem Firstchild der Wert gegeben werden soll
                 */
                if (myTempChild != null) {
                  md = this.ughHelp.getMetadata(myTempChild, mdt);

                  md.setValue(field.getWert());
                }
              }
            } catch (NullPointerException e) {
            } catch (UghHelperException e) {

            } catch (MetadataTypeNotAllowedException e) {

            }
          } // end if ughbinding
        }// end for

        /*
         * -------------------------------- Collectionen hinzufügen --------------------------------
         */
        DocStruct colStruct = this.myRdf.getDigitalDocument().getLogicalDocStruct();
        try {
          addCollections(colStruct);
          /*
           * falls ein erstes Kind vorhanden ist, sind die Collectionen dafür
           */
          colStruct = colStruct.getAllChildren().get(0);
          addCollections(colStruct);
        } catch (RuntimeException e) {
          /*
           * das Firstchild unterhalb des Topstructs konnte nicht ermittelt werden
           */
        }

        /*
         * -------------------------------- Imagepfad hinzufügen (evtl. vorhandene zunächst löschen) --------------------------------
         */
        try {
          DigitalDocument dd = this.myRdf.getDigitalDocument();
          DocStructType dst = this.prozessVorlage.getRegelsatz().getPreferences().getDocStrctTypeByName("BoundBook");
          DocStruct dsBoundBook = dd.createDocStruct(dst);
          dd.setPhysicalDocStruct(dsBoundBook);

          UghHelper ughhelp = new UghHelper();
          MetadataType mdt = ughhelp.getMetadataType(this.prozessKopie, "pathimagefiles");

          if (this.myRdf != null && this.myRdf.getDigitalDocument() != null
              && this.myRdf.getDigitalDocument().getPhysicalDocStruct() != null) {
            List<? extends Metadata> alleImagepfade = this.myRdf.getDigitalDocument().getPhysicalDocStruct().getAllMetadataByType(mdt);
            if (alleImagepfade != null && alleImagepfade.size() > 0) {
              for (Metadata md : alleImagepfade) {
                this.myRdf.getDigitalDocument().getPhysicalDocStruct().getAllMetadata().remove(md);
              }
            }
            Metadata newmd = new Metadata(mdt);
            newmd.setValue("./" + this.prozessKopie.getTitel() + DIRECTORY_SUFFIX);
            this.myRdf.getDigitalDocument().getPhysicalDocStruct().addMetadata(newmd);
          }
          /* Rdf-File schreiben */
          this.prozessKopie.writeMetadataFile(this.myRdf);

          /*
           * -------------------------------- soll der Prozess als Vorlage verwendet werden? --------------------------------
           */
          if (this.useTemplates && this.prozessKopie.isInAuswahllisteAnzeigen()) {
            this.prozessKopie.writeMetadataAsTemplateFile(this.myRdf);
          }

        } catch (ugh.exceptions.DocStructHasNoTypeException e) {
          Helper.setFehlerMeldung("DocStructHasNoTypeException", e.getMessage());
          myLogger.error("creation of new process throws an error: ", e);
        } catch (UghHelperException e) {
          Helper.setFehlerMeldung("UghHelperException", e.getMessage());
          myLogger.error("creation of new process throws an error: ", e);
        } catch (MetadataTypeNotAllowedException e) {
          Helper.setFehlerMeldung("MetadataTypeNotAllowedException", e.getMessage());
          myLogger.error("creation of new process throws an error: ", e);
        } catch (TypeNotAllowedForParentException e) {
          myLogger.error(e);
        }
      }
    } else {
      this.prozessKopie.writeMetadataFile(this.myRdf);

    }

    // Adding process to history
    if (!HistoryAnalyserJob.updateHistoryForProcess(this.prozessKopie)) {
      Helper.setFehlerMeldung("historyNotUpdated");
    } else {
      try {
        new ProzessDAO().save(this.prozessKopie);
      } catch (DAOException e) {
        e.printStackTrace();
        myLogger.error("error on save: ", e);
        return this.prozessKopie;
      }
View Full Code Here

    if (io.getBatchId()!=null){
      this.prozessKopie.setBatchID(io.getBatchId());
    }
    try {
      ProzessDAO dao = new ProzessDAO();
      dao.save(this.prozessKopie);
      dao.refresh(this.prozessKopie);
    } catch (DAOException e) {
      e.printStackTrace();
      myLogger.error("error on save: ", e);
      return this.prozessKopie;
    }

    /*
     * wenn noch keine RDF-Datei vorhanden ist (weil keine Opac-Abfrage stattfand, dann jetzt eine anlegen
     */
    if (this.myRdf == null) {
      createNewFileformat();
    }
   
    File f = new File(this.prozessKopie.getProcessDataDirectoryIgnoreSwapping());
    if (!f.exists() && !f.mkdir()) {
      Helper.setFehlerMeldung("Could not create process directory");
      myLogger.error("Could not create process directory");
      return this.prozessKopie;
    }
   
    this.prozessKopie.writeMetadataFile(this.myRdf);

    // }

    // Adding process to history
    if (!HistoryAnalyserJob.updateHistoryForProcess(this.prozessKopie)) {
      Helper.setFehlerMeldung("historyNotUpdated");
    } else {
      try {
        new ProzessDAO().save(this.prozessKopie);
      } catch (DAOException e) {
        e.printStackTrace();
        myLogger.error("error on save: ", e);
        return this.prozessKopie;
      }
View Full Code Here

TOP

Related Classes of de.sub.goobi.persistence.ProzessDAO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.