Package org.myphotodiary.model

Examples of org.myphotodiary.model.Directory


    EntityManager em = ModelFactory.getEntityManager();
    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 directory from Directory directory where directory.path = ?1",
            Directory.class).setParameter(1, path);
        directory = query.getSingleResult();
        if  (directory.isIndexingAllowedBoolean()) {
          updateDirectory(directory, dirData, em);
          em.merge(directory);
        }
      } catch (NoResultException ex) {
        getServletContext().log(
            "No directory data for: " + path, ex);
        directory = new Directory(path, null);
        updateDirectory(directory, dirData, em);
        em.persist(directory);
      }
    } catch (Exception ex) {
      getServletContext().log("Cannot persist directory data", ex);
View Full Code Here


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

      // Get the directory description data from database
      Directory directory = null;
      try {
        // Select distinct for objectDB which returns duplicated entries !
        directory = em.createQuery(
            "select distinct directory from Directory directory where directory.path = ?1", Directory.class)
            .setParameter(1, path).getSingleResult();
        // RBAC
        AccessController.checkAuthorization(directory, request, Action.browse, em);
      } catch (NoResultException ex) {
        getServletContext().log(
            "No directory data for: " + path, ex);
      }

      // Create Json response
      JsonObject rsp = new JsonObject();
      // Get the directory specific data
      if ((directory != null) && (directory.isIndexingAllowedBoolean())) {
        if (directory.getDescription() != null) {
          rsp.addParameter(Configuration.dirDescParam, directory.getDescription());
        }
        if (directory.getLatitude() != null) {
          rsp.addParameter(Configuration.latParam, directory.getLatitude());
        }
        if (directory.getLongitude() != null) {
          rsp.addParameter(Configuration.lngParam, directory.getLongitude());
        }
        if (directory.getDate() != null) {
          rsp.addParameter(Configuration.dirDateParam, directory.getDate());
        }
        rsp.addParameter(Configuration.groupParam,
            (directory.getGroup() == null ? Configuration.publicGroup : directory.getGroup().getGroupName()));

        List<Attribute> dirAttributes = directory.getAttributes();
        if (dirAttributes != null) {
          JsonArray attributes = new JsonArray();
          for (Attribute attribute: dirAttributes) {
            attributes.addItem(attribute.getName());
          }
View Full Code Here

    EntityManager em = ModelFactory.getEntityManager();
    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 directory from Directory directory where directory.path = ?1",
            Directory.class).setParameter(1, path);
        directory = query.getSingleResult();
       
        if  (directory.isIndexingAllowedBoolean()) {
          updateDirectory(directory, dirData, em);
          em.merge(directory);
        }
      } catch (NoResultException ex) {
        getServletContext().log(
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 = new Directory(dir, null);
        em.persist(directory);
      }

      // 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.getAttributes(), em);
        em.merge(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.getAttributes(), em);
        em.persist(img);
      }
    } catch (Exception ex) {
      getServletContext().log("Cannot persist image data", 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) {
          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();
      }
      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.editSequence, 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.editSequence, 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

    if (path == null) {
      throw new AuthenticationException("Invalid resource path");
    }

    // Check if that directory path is indexed
    Directory directory;
    boolean closeEm = false;
    if (em == null) {
      em = ModelFactory.getEntityManager();
      closeEm = true;
    }
    try {
      try {
        directory = em
            .createQuery(
                "select directory from Directory directory where directory.path = ?1",
                Directory.class).setParameter(1, path)
            .getSingleResult();
      } catch (NoResultException ex) {
        // non indexed directories are public (to allow navigation)
        return;
      }

      // Refresh user and roles assignment
      List<RoleAssignment> roles;
      try {
        user = em.find(User.class, user.getUserName());
        roles = user.getRoleAssignments();
      } catch (NoResultException ex) {
        // User is no longer registered,
        throw new AuthenticationException("Unknown user");
      }

      // Check if directory group can be accessed by this user
      for (RoleAssignment roleAssignment : roles) {
        if (!roleAssignment.getGroupName().equals(directory.getGroup().getGroupName())) {
          continue;
        }
        Role.isPermitted(roleAssignment.getRole(), action);
        return;
      }
View Full Code Here

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

      // Get the directory description data from database
      Directory directory = null;
      try {
        // Select distinct for objectDB which returns duplicated entries !
        directory = em.createQuery(
            "select distinct directory from Directory directory where directory.path = ?1", Directory.class)
            .setParameter(1, path).getSingleResult();
      } catch (NoResultException ex) {
        getServletContext().log(
            "No directory data for: " + path, ex);
      }

      // Create Json response
      JsonObject rsp = new JsonObject();
      // Get the directory specific data
      if ((directory != null) && (directory.isIndexingAllowedBoolean())) {
        if (directory.getDescription() != null) {
          rsp.addParameter(Configuration.dirDescParam, directory.getDescription());
        }
        if (directory.getLatitude() != null) {
          rsp.addParameter(Configuration.latParam, directory.getLatitude());
        }
        if (directory.getLongitude() != null) {
          rsp.addParameter(Configuration.lngParam, directory.getLongitude());
        }
        if (directory.getDate() != null) {
          rsp.addParameter(Configuration.dirDateParam, directory.getDate());
        }
        List<Attribute> dirAttributes = directory.getAttributes();
        if (dirAttributes != null) {
          JsonArray attributes = new JsonArray();
          for (Attribute attribute: dirAttributes) {
            attributes.addItem(attribute.getName());
          }
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 = new Directory(path, null);
        em.persist(directory);
      }

      // 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

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.