// Process the http POST of the form
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    String kvartalName = req.getParameter("kvartal");
    if (kvartalName == null) {
      kvartalName = (String) req.getSession(true).getAttribute("kvartal");
    }

    String objectName = req.getParameter("objectName");
    if (objectName == null || objectName.length() == 0) {
      req.getSession(true).setAttribute("kvartal", kvartalName);
      resp.sendRedirect("/kvartal.jsp");
      return;
    }

    String category = req.getParameter("category");
    if (category == null) {
      category = "";
    }

    String opinion = req.getParameter("opinion");
    byte evaluation = 0;

    if (req.getParameter("evaluation") != null && req.getParameter("evaluation").length() > 0) {
      evaluation = Byte.parseByte(req.getParameter("evaluation"));
    }

    Key<Kvartal> getKvartalKey = Key.create(Kvartal.class, kvartalName);
    Key<OpinionObject> getOpinionObjectKey = Key.create(OpinionObject.class, objectName);

    OpinionObject nextObject = null;

    nextObject =
        ObjectifyService.ofy()
            .load()
            .type(OpinionObject.class)
            .filterKey(getOpinionObjectKey)
            .first()
            .now();

    if (nextObject == null) {
      nextObject = new OpinionObject(getKvartalKey, objectName);
    }

    // no address as of now
    nextObject.AddOpinionObject(objectName, category, "", opinion, evaluation);
    ObjectifyService.ofy().save().entity(nextObject).now(); // Update DB

    req.getSession(true).setAttribute("kvartal", kvartalName);

    resp.sendRedirect("/kvartal.jsp");
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public Object invoke(final Object proxy, final Method method, final Object[] args)
      throws Throwable {
    try {
      final Method implementationMethod =
          implementation.getClass().getMethod(method.getName(), method.getParameterTypes());
      final Transactional transactional = implementationMethod.getAnnotation(Transactional.class);

      if (transactional != null) {

        final IdempotencyHandler idempotencyHandler =
            IdempotencyHandlerFactory.createHandlerAnnotationBased(transactional);

        return ObjectifyService.ofy()
            .execute(
                transactional.type(),
                new Work() {
                  @Override
                  public Object run() {
                    if (idempotencyHandler.shouldTransactionProceed(proxy, method, args)) {
                      Object result = invokeMethod(args, implementationMethod);
                      idempotencyHandler.setReturn(result);
                    }
                    return idempotencyHandler.getReturn();
                  }
                });

      } else {
        return invokeMethod(args, implementationMethod);
      }
    } catch (RuntimeException err) {
      throw getRootCause(err, 5);
    }
  }
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    ObjectifyService.register(Subscriber.class);
    Subscriber newSubscriber = new Subscriber(user.getEmail());
    ofy().save().entity(newSubscriber).now();

    // MailUpdate.subscribers.add(user);

    System.out.println(user.getEmail() + " has subscribed");
    List<Subscriber> subscribers = ObjectifyService.ofy().load().type(Subscriber.class).list();
    // for (Subscriber subscriber : subscribers){
    // ofy().delete().entity(subscriber);
    // }
    Collections.sort(subscribers);
    System.out.println("size" + subscribers.size());
    for (Subscriber subscriber : subscribers) {
      System.out.println(subscriber.getEmail());
    }
    // try{
    // RequestDispatcher view = req.getRequestDispatcher("");
    // view.forward(req, resp);

    // } catch (Exception e){}
    resp.sendRedirect("/");
  }
示例#4
0
  /**
   * Deletes given bean
   *
   * @param bean The bean to delete.
   */
  public void delete(T bean) {

    if (bean == null) {
      throw new IllegalArgumentException("null bean object");
    }
    LOGGER.info("Deleting bean " + bean.getId());
    ObjectifyService.ofy().delete().entity(bean);
  }
示例#5
0
  /**
   * Saves given bean.
   *
   * @param bean The bean to store.
   */
  public void save(T bean) {

    if (bean == null) {
      throw new IllegalArgumentException("null bean object");
    }
    LOGGER.info("Saving bean " + bean.getId());
    ObjectifyService.ofy().save().entity(bean).now();
  }
 public static void put(String name, String value) {
   SettingStore setting =
       ObjectifyService.ofy().load().type(SettingStore.class).filter("name", name).first().now();
   if (setting == null) {
     setting = new SettingStore();
     setting.name = name;
   }
   setting.value = value;
   setting.save();
 }
示例#7
0
 @Override
 public List<Product> list() {
   Key<Project> parent = Key.create(Project.class, Constant.PROJECT_NAME);
   return ObjectifyService.ofy()
       .load()
       .type(Product.class)
       .ancestor(parent)
       .order("position")
       .list();
 }
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String gameId = request.getParameter("gameKey");
    Objectify ofy = ObjectifyService.ofy();
    Game game = ofy.load().type(Game.class).id(gameId).safe();

    UserService userService = UserServiceFactory.getUserService();
    String currentUserId = userService.getCurrentUser().getUserId();

    // TODO(you): In practice, first validate that the user has permission to delete the Game
    game.deleteChannel(currentUserId);
  }
示例#9
0
  /**
   * Returns the stored list of beans according the possible sort criteria.
   *
   * @param fieldToSortBy The field name to sort the result list.
   * @param descendingSort True to apply descending sort, false to apply ascending sort.
   * @return The list of beans.
   */
  public List<T> list(String fieldToSortBy, Boolean descendingSort) {

    LOGGER.info("Retrieving list of ordered beans");
    StringBuilder sortCriteria = new StringBuilder();

    if (descendingSort != null && descendingSort) {
      sortCriteria.append(DESC_PREFIX);
    }

    if (fieldToSortBy == null || fieldToSortBy.equals("")) {
      sortCriteria.append(ID_FIELD_NAME);
    } else {
      sortCriteria.append(fieldToSortBy);
    }

    LOGGER.info("sortCriteria: " + sortCriteria.toString());
    return ObjectifyService.ofy().load().type(classType).order(sortCriteria.toString()).list();
  }
 public void save() {
   ObjectifyService.ofy().save().entity(this);
 }
示例#11
0
 @Override
 public void delete(String code) {
   Key<Project> parent = Key.create(Project.class, Constant.PROJECT_NAME);
   ObjectifyService.ofy().delete().type(Product.class).parent(parent).id(code).now();
 }
示例#12
0
 @Override
 public Long save(Product item) {
   Key<Product> key = ObjectifyService.ofy().save().entity(item).now();
   return key.getId();
 }
示例#13
0
 @Override
 public Product load(String code) {
   if (code == null) return new Product();
   Key<Project> parent = Key.create(Project.class, Constant.PROJECT_NAME);
   return ObjectifyService.ofy().load().type(Product.class).parent(parent).id(code).now();
 }
示例#14
0
 public static Objectify ofy() {
   return com.googlecode.objectify.ObjectifyService.ofy();
 }
示例#15
0
  /**
   * Returns given bean.
   *
   * @param id The id to retrieve the bean.
   * @return The bean with given id.
   */
  public T get(Long id) {

    LOGGER.info("Retrieving bean " + id);
    return ObjectifyService.ofy().load().type(classType).id(id).now();
  }
 public static boolean has(String name) {
   SettingStore setting =
       ObjectifyService.ofy().load().type(SettingStore.class).filter("name", name).first().now();
   return setting != null;
 }
 /** Adds community event to data store. */
 public void addCommunityEvent(Date date, String heading, String description) {
   Event communityEvent =
       new Event(
           Event.EVENT_TYPE_COMMUNITY, date, heading, description, Event.EVENT_FREQUENCY_ONCE);
   ObjectifyService.ofy().save().entity(communityEvent).now();
 }
 private static Objectify backend() {
   // Docs suggest never caching the result of this.
   return ObjectifyService.ofy();
 }
 /** Adds anniversary event to data store. */
 public void addAnniversaryEvent(Date date, String heading, String description) {
   Event anniversaryEvent =
       new Event(
           Event.EVENT_TYPE_ANNIVERSARY, date, heading, description, Event.EVENT_FREQUENCY_YEARLY);
   ObjectifyService.ofy().save().entity(anniversaryEvent).now();
 }
示例#20
0
 /**
  * Returns the Objectify service wrapper.
  *
  * @return The Objectify service wrapper.
  */
 public static Objectify ofy() {
   return ObjectifyService.ofy();
 }
 /** Adds birthday event to data store. */
 public void addBirthdayEvent(Date date, String heading, String description) {
   Event birthdayEvent =
       new Event(
           Event.EVENT_TYPE_BIRTHDAY, date, heading, description, Event.EVENT_FREQUENCY_YEARLY);
   ObjectifyService.ofy().save().entity(birthdayEvent).now();
 }
示例#22
-3
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    StringBuffer jb = new StringBuffer();
    String line = null;
    try {
      BufferedReader reader = request.getReader();
      while ((line = reader.readLine()) != null) jb.append(line);
    } catch (Exception e) {
      System.out.println("Erreur");
    }
    JSONObject json = new JSONObject(jb.toString());
    System.out.println(jb.toString());

    Petition p = new Petition();

    p.setTitle(json.getValue("title"));
    p.setDescription(json.getValue("text"));
    response.getWriter().println(p.toString());

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    // Récupération de l'utilisateur google courant

    if (user != null) {
      System.out.println(user.toString());
    } else {
      System.out.println("user null");
    }

    ObjectifyService.ofy().save().entities(p).now();
    response.getWriter().println("Ajout effectué");
  }