Package org.myphotodiary.model

Examples of org.myphotodiary.model.Directory


    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();

      Directory directory = null;
      // search if directory exists, or create it
      try {
        TypedQuery<Directory> query = em.createQuery(SELECT_DIR, Directory.class).setParameter(1, path);
        directory = query.getSingleResult();
      }
      catch (NoResultException ex) {
        cfg.getCtxt().log("No directory data for: " + path, ex);
        directory = new Directory(path, null);
        em.persist(directory);
      }

      // clear directory attributes, if any
      List<Attribute> attributes = directory.getAttributes();
      if (attributes.size() > 0) {
        attributes.clear();
      }

      List<Image> indexedImages = directory.getImages();
      // Remove image attributes relationship
      for (Image image: indexedImages) {
        attributes = image.getAttributes();
        if (attributes.size() > 0) {
          attributes.clear();
        }
      }
      // remove all indexed images from current directory database index
      if (indexedImages != null) {
        indexedImages.clear();
      }
      // But do not remove directory entry and disallow automatic indexing
      directory.setIndexingAllowedBoolean(false);
    }
    catch (Exception ex) {

    }
    finally {
View Full Code Here


    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();

      Directory directory = null;
      // search if directory exists, or create it
      try {
        TypedQuery<Directory> query = em.createQuery(SELECT_DIR, Directory.class).setParameter(1, path);
        directory = query.getSingleResult();

        // clear directory attributes, if any
        List<Attribute> attributes = directory.getAttributes();
        if (attributes.size() > 0) {
          attributes.clear();
        }

        List<Image> indexedImages = directory.getImages();
        // Remove image attributes relationship
        for (Image image: indexedImages) {
          attributes = image.getAttributes();
          if (attributes.size() > 0) {
            attributes.clear();
View Full Code Here

    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();

      Directory directory = null;

      // search if directory exists, or create it
      try {
        TypedQuery<Directory> query = em.createQuery(SELECT_DIR, Directory.class).setParameter(1, path);
        directory = query.getSingleResult();
        // If directory already exists only re-index if "force" option (force = administrative command)
        if (!force) {
          return this;
        }
       
      }
      catch (NoResultException ex) {
        cfg.getCtxt().log("No directory data for: " + path + ", create it.", ex);
        directory = ModelFactory.newDirectory(path, null, null, em, tx);
        em.persist(directory);
      }

      // RBAC
      AccessController.checkAuthorization(directory, request, Action.editSequence, em);

      // Try to match a date out of the directory path/name
      // It will be used as a default date for images contained in that directory
      java.sql.Date dirDate = getDirDate(path);
      directory.setDate(dirDate);
      directory.setIndexingAllowedBoolean(true);


      if (directory.getImages() == null) {
        directory.setImages(new LinkedList<Image>());
      }
      // list and sort all indexed images in current directory (database index)
      List<Image> indexedImages = directory.getImages();
      Collections.sort(indexedImages);

      // list and sort all image files in current directory (file system)
      Arrays.sort(allImages);
      int ix = 0;
View Full Code Here

    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();
      Image img = null;
      Directory directory = null;
      // search if directory exists, or create it
      try {
        TypedQuery<Directory> query = em.createQuery("select directory from Directory directory where directory.path = ?1",
            Directory.class).setParameter(1, dir);
        directory = query.getSingleResult();
        if (!directory.isIndexingAllowedBoolean()) {
          getServletContext().log("Cannot record image data - indexing not allowed");
          return;
        }
      } catch (NoResultException ex) {
        getServletContext().log("No directory data for: " + dir, ex);
        directory = ModelFactory.newDirectory(path, null, null, em, tx);
        em.persist(directory);
      }
     
      // RBAC
      AccessController.checkAuthorization(directory, request, Action.editImg, em);

      // search if image exists or create it
      try {
        img = em
            .createQuery(
                "select image from Image image where image.name = ?1 and image.directory.path = ?2",
                Image.class).setParameter(1, name)
                .setParameter(2, dir).getSingleResult();
        // Update image data and persist it
        img.setDescription(imgData.getDesc());
        img.setRating(imgData.getRating());
        if (imgData.getDate() != null) {img.setDate(new java.sql.Date(imgData.getDate().getTime()));}
        updateAttributes(img, imgData, em);
        em.persist(img);
      } catch (NoResultException ex) {
        getServletContext().log(
            "No image data for: " + dir + " / " + name, ex);
        img = new Image(
            name,
            imgData.getDesc(),
            directory,
            imgData.getRating(),
            (imgData.getDate() != null ? new java.sql.Date(imgData.getDate().getTime()) : directory.getDate()));
        updateAttributes(img, imgData, em);
        em.persist(img);
      }
    } catch (AuthenticationException ex) {
      getServletContext().log("Unauthenticated user" , ex);
View Full Code Here

      Image image = null;
      try {
        TypedQuery<Image> query = em.createQuery(SELECT_IMAGE, Image.class).setParameter(2, dir).setParameter(1, name);
        image = query.getSingleResult();
        Directory directory = image.getDirectory();
        // Remove image data from DB
        if (directory != null) {
          // RBAC
          AccessController.checkAuthorization(directory, request, Action.deleteImg, em);

          directory.getImages().remove(image);
          image.setDirectory(null);
          em.remove(image);
        }
        // Remove image attributes relationship
        List<Attribute> attributes = image.getAttributes();
View Full Code Here

    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();
      Image img = null;
      Directory directory = null;
      // search if directory exists, or create it
      try {
        TypedQuery<Directory> query = em.createQuery("select directory from Directory directory where directory.path = ?1",
            Directory.class).setParameter(1, dir);
        directory = query.getSingleResult();
        if (!directory.isIndexingAllowedBoolean()) {
          getServletContext().log("Cannot record image data - indexing not allowed");
          return;
        }
      } catch (NoResultException ex) {
        getServletContext().log("No directory data for: " + dir, ex);
        directory = ModelFactory.newDirectory(path, null, null, em, tx);
        em.persist(directory);
      }
     
      // RBAC
      AccessController.checkAuthorization(directory, request, Action.editImg, em);

      // search if image exists or create it
      try {
        img = em
            .createQuery(
                "select image from Image image where image.name = ?1 and image.directory.path = ?2",
                Image.class).setParameter(1, name)
                .setParameter(2, dir).getSingleResult();
        // Update image data and persist it
        img.setDescription(imgData.getDesc());
        img.setRating(imgData.getRating());
        if (imgData.getDate() != null) {img.setDate(new java.sql.Date(imgData.getDate().getTime()));}
        updateAttributes(img, imgData, em);
        em.persist(img);
      } catch (NoResultException ex) {
        getServletContext().log(
            "No image data for: " + dir + " / " + name, ex);
        img = new Image(
            name,
            imgData.getDesc(),
            directory,
            imgData.getRating(),
            (imgData.getDate() != null ? new java.sql.Date(imgData.getDate().getTime()) : directory.getDate()));
        updateAttributes(img, imgData, em);
        em.persist(img);
      }
    } catch (AuthenticationException ex) {
      getServletContext().log("Unauthenticated user" , ex);
View Full Code Here

      Image image = null;
      try {
        TypedQuery<Image> query = em.createQuery(SELECT_IMAGE, Image.class).setParameter(2, dir).setParameter(1, name);
        image = query.getSingleResult();
        Directory directory = image.getDirectory();
        // Remove image data from DB
        if (directory != null) {
          // RBAC
          AccessController.checkAuthorization(directory, request, Action.deleteImg, em);

          directory.getImages().remove(image);
          image.setDirectory(null);
          em.remove(image);
        }
        // Remove image attributes relationship
        List<Attribute> attributes = image.getAttributes();
View Full Code Here

    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();

      Directory directory = null;

      // search if directory exists, or create it
      try {
        TypedQuery<Directory> query = em.createQuery(SELECT_DIR, Directory.class).setParameter(1, path);
        directory = query.getSingleResult();
        // If directory already exists only re-index if "force" option (force = administrative command)
        if (!force) {
          return this;
        }
       
      }
      catch (NoResultException ex) {
        cfg.getCtxt().log("No directory data for: " + path + ", create it.", ex);
        directory = ModelFactory.newDirectory(path, null, null, em, tx);
        em.persist(directory);
      }

      // RBAC - initial indexing is also allowed for first user only having "browse" access (READER)
      AccessController.checkAuthorization(directory, request, Action.browse, em);

      // Try to match a date out of the directory path/name
      // It will be used as a default date for images contained in that directory
      java.sql.Date dirDate = getDirDate(path);
      directory.setDate(dirDate);
      directory.setIndexingAllowedBoolean(true);


      if (directory.getImages() == null) {
        directory.setImages(new LinkedList<Image>());
      }
      // list and sort all indexed images in current directory (database index)
      List<Image> indexedImages = directory.getImages();
      Collections.sort(indexedImages);

      // list and sort all image files in current directory (file system)
      Arrays.sort(allImages);
      int ix = 0;
View Full Code Here

    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();

      Directory directory = null;
      // search if directory exists, or create it
      try {
        TypedQuery<Directory> query = em.createQuery(SELECT_DIR, Directory.class).setParameter(1, path);
        directory = query.getSingleResult();
      }
      catch (NoResultException ex) {
        cfg.getCtxt().log("No directory data for: " + path, ex);
        directory = ModelFactory.newDirectory(path, null, null, em, tx);
        em.persist(directory);
      }
      // RBAC
      AccessController.checkAuthorization(directory, request, Action.deleteSequence, em);

      // clear directory attributes, if any
      List<Attribute> attributes = directory.getAttributes();
      if (attributes.size() > 0) {
        attributes.clear();
      }

      List<Image> indexedImages = directory.getImages();
      // Remove image attributes relationship
      for (Image image: indexedImages) {
        attributes = image.getAttributes();
        if (attributes.size() > 0) {
          attributes.clear();
        }
      }
      // remove all indexed images from current directory database index
      if (indexedImages != null) {
        indexedImages.clear();
      }
      // But do not remove directory entry and disallow automatic indexing
      directory.setIndexingAllowedBoolean(false);
      tx.commit();
    }
    catch (Exception ex) {
      cfg.getCtxt().log("Index delete failure for directory: " + path, ex);
      tx.rollback();
View Full Code Here

    EntityTransaction tx = null;
    try {
      tx = em.getTransaction();
      tx.begin();

      Directory directory = null;
      // search if directory exists, or create it
      try {
        TypedQuery<Directory> query = em.createQuery(SELECT_DIR, Directory.class).setParameter(1, path);
        directory = query.getSingleResult();

        // RBAC
        AccessController.checkAuthorization(directory, request, Action.deleteSequence, em);
       
        // clear directory attributes, if any
        List<Attribute> attributes = directory.getAttributes();
        if (attributes.size() > 0) {
          attributes.clear();
        }

        List<Image> indexedImages = directory.getImages();
        // Remove image attributes relationship
        for (Image image: indexedImages) {
          attributes = image.getAttributes();
          if (attributes.size() > 0) {
            attributes.clear();
View Full Code Here

TOP

Related Classes of org.myphotodiary.model.Directory

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.