Package org.myphotodiary.json

Examples of org.myphotodiary.json.JsonImgData


    getServletContext().log(
        "-> ImageDataSvr.doPost()\nParameters= "
            + request.getParameterMap().toString());
    // Extract request parameters
    String path=null, name=null, dir=null;
    JsonImgData imgData = null;
    try {
      imgData = JsonImgData.decode(request.getInputStream());
      path = urlToPath(imgData.getUrl());
      name = pathToName(path);
      dir = pathToDir(path);
    }
    catch (Exception ex) {
      getServletContext().log("Cannot get POSTed image parameters", ex);
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // Persist the image description data into database
    EntityManager em = ModelFactory.getEntityManager();
    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);
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
View Full Code Here


    getServletContext().log(
        "-> ImageDataSvr.doPost()\nParameters= "
            + request.getParameterMap().toString());
    // Extract request parameters
    String path=null, name=null, dir=null;
    JsonImgData imgData = null;
    try {
      imgData = JsonImgData.decode(request.getInputStream());
      path = urlToPath(imgData.getUrl(), request);
      name = PathUtil.pathToName(path);
      dir = PathUtil.pathToSequenceDir(path);
    }
    catch (Exception ex) {
      getServletContext().log("Cannot get POSTed image parameters", ex);
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // Persist the image description data into database
    EntityManager em = ModelFactory.getEntityManager();
    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

    getServletContext().log(
        "-> ImageDataSvr.doPost()\nParameters= "
            + request.getParameterMap().toString());
    // Extract request parameters
    String path=null, name=null, dir=null;
    JsonImgData imgData = null;
    try {
      imgData = JsonImgData.decode(request.getInputStream());
      path = urlToPath(imgData.getUrl(), request);
      name = pathToName(path);
      dir = pathToDir(path);
    }
    catch (Exception ex) {
      getServletContext().log("Cannot get POSTed image parameters", ex);
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // Persist the image description data into database
    EntityManager em = ModelFactory.getEntityManager();
    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.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 (AuthenticationException ex) {
      getServletContext().log("Unauthorized user", ex);
      response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
View Full Code Here

    getServletContext().log(
        "-> ImageDataSvr.doPost()\nParameters= "
            + request.getParameterMap().toString());
    // Extract request parameters
    String path=null, name=null, dir=null;
    JsonImgData imgData = null;
    try {
      imgData = JsonImgData.decode(request.getInputStream());
      path = urlToPath(imgData.getUrl(), request);
      name = pathToName(path);
      dir = pathToDir(path);
    }
    catch (Exception ex) {
      getServletContext().log("Cannot get POSTed image parameters", ex);
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // Persist the image description data into database
    EntityManager em = ModelFactory.getEntityManager();
    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

TOP

Related Classes of org.myphotodiary.json.JsonImgData

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.