Package com.changestuffs.server.persistence.beans

Examples of com.changestuffs.server.persistence.beans.Product


    log.info("Adding " + arg0);
    ArticlesAddResult result = null;
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    ArticlesOAM oam = provider.get();
    Product product = null;
    if (arg0.getKeyHash() == null) {
      product = oam.insertArticle(arg0, user.getEmail());
    } else {
      product = oam.updateArticle(arg0, user.getEmail());
    }
    result = new ArticlesAddResult(KeyFactory.keyToString(product.getKey()), Tags.valueOf(product.getTag().getTagId()));
    return result;
  }
View Full Code Here


    this.model = model;
  }

  @Transactional
  public Product insertArticle(ArticlesAddAction dto, String userId) {
    Product product = new Product();
    product.setDate(dto.getDate());
    product.setDescription(new Text(dto.getDescription()));
    product.setName(dto.getName());
    product.setTag(getTagBean(dto.getTag()));
    product.setUserId(userId);
    product.setInterestedIn(new Text(dto.getInterestedIn()));
    product.setOffer(new ArrayList<Offer>());
    product.setLocale(dto.getLanguage());
    model.persist(product);
    log.info("Product saved");
    return product;
  }
View Full Code Here

    return product;
  }

  @Transactional
  public Product updateArticle(ArticlesAddAction dto, String userId) {
    Product product = model.find(Product.class,
        KeyFactory.stringToKey(dto.getKeyHash()));
    if (userId.equals(product.getUserId())) {
      product.setDate(dto.getDate());
      product.setDescription(new Text(dto.getDescription()));
      product.setName(dto.getName());
      product.setInterestedIn(new Text(dto.getInterestedIn()));
      product.setLocale(dto.getLanguage());
      log.info("Updating product");
    } else {
      log.warning("User " + userId + " is not allowed to update product");
    }
    return product;
View Full Code Here

  public void remove(String keyHash, String userId) {
    Key key = KeyFactory.stringToKey(keyHash);
    log.info("Key: " + KeyFactory.keyToString(key) + " Kind: "
        + key.getKind() + " Id: " + key.getId() + " Name: "
        + key.getName() + " Namespace: " + key.getNamespace());
    Product product = model.find(Product.class, key);
    log.info("Product: " + product);
    if (product != null && userId.equals(product.getUserId())) {
      model.remove(product);
    } else {
      throw new IllegalAccessError("Illegal user");
    }
  }
View Full Code Here

        log.info("Getting " + articles.size() + " articles for tag "
            + input.getTag());
      }
    }
    if (input.getIdKey() != null) {
      Product product = model.find(Product.class, input.getIdKey());
      if (product != null) {
        IArticlesDto dto = getIArticlesDto(product, true, email);
        articles.put(dto.getKeyHash(), dto);
      }
    }
View Full Code Here

      if (product.getOffer() != null) {
        for (Offer offer : product.getOffer()) {
          Map<String, String> offerPerUser = new HashMap<String, String>();
          for (ProductOffered productOffered : offer.getProductOffered()) {
            String productId = productOffered.getProductId();
            Product offered = model.find(Product.class,
                KeyFactory.stringToKey(productId));
            // Maybe it was removed
            if(offered != null)
              offerPerUser.put(productId, offered.getName());
          }
          if(offerPerUser.size()>0){
            Offers offers = new Offers();
            offers.setIdNameProducts(offerPerUser);
            offers.setUserId(offer.getUserId());
View Full Code Here

    return offers;
  }

  public GetOffersResult createOffer(String productId, String userId) {
    GetOffersResult result = null;
    Product product = model.find(Product.class,
        KeyFactory.stringToKey(productId));
    Offer offer = new Offer();
    offer.setAcceptIt(false);
    offer.setProduct(product);
    offer.setProductOffered(new HashSet<ProductOffered>());
    offer.setUserId(userId);
    model.getTransaction().begin();
    model.persist(offer);
    model.getTransaction().commit();
    OffersPerProduct offerPerProduct = new OffersPerProduct(KeyFactory.keyToString(offer.getKey()), productId, product.getName(), new HashMap<String, String>());
    Map<String, OffersPerProduct> offers = new HashMap<String, OffersPerProduct>();
    offers.put(offerPerProduct.getOfferKey(), offerPerProduct);
    result = new GetOffersResult(offers);
    log.info("Offer created");
    return result;
View Full Code Here

  }
 
  @Test
  public void testGetArticles(){ 
    ArticlesAddAction dto1 = createArticlesDtoIn(tag);
    Product product1 = oam.insertArticle(dto1, userId);
   
    ArticlesAddAction dto2 = createArticlesDtoIn(Tags.entertainment);
    Product product2 = oam.insertArticle(dto2, userId);
   
    LookForAction action1 = new LookForAction(dto1.getTag(), null);
    Map<String, IArticlesDto> articles1 = oam.getArticles(action1, null);
    assertEquals(1, articles1.size());
    String key1 = KeyFactory.keyToString(product1.getKey());
    assertTrue(articles1.containsKey(key1));
    assertEquals(dto1.getTag(), articles1.get(key1).getTag());
   
    LookForAction action2 = new LookForAction(null, KeyFactory.keyToString(product2.getKey()));
    Map<String, IArticlesDto> articles2 = oam.getArticles(action2, null);
    assertEquals(1, articles2.size());
    String key2 = KeyFactory.keyToString(product2.getKey());
    assertTrue(articles2.containsKey(key2));
    assertEquals(dto2.getTag(), articles2.get(key2).getTag());
  }
View Full Code Here

    assertNotNull(products);
    assertEquals(0, products.size());
  }
 
  private void checksInsert(ArticlesAddAction dto){
    Product productNotDb = oam.insertArticle(dto, userId);
    assertNotNull(productNotDb.getKey());
    Product product = lookUpProduct(productNotDb.getKey());
    assertEquals(tag.name(), product.getTag().getTagId());
    assertEquals(description, product.getDescription().getValue());
    assertEquals(name, product.getName());
    assertEquals(userId, product.getUserId());
    assertEquals(date, product.getDate());
   
    ArticlesAddAction forUpdate = new ArticlesAddAction(Tags.clothes, "anyName", "anyDescription", new Date(), KeyFactory.keyToString(product.getKey()), "interest", null);
    Product productUpdatedNoDb = oam.updateArticle(forUpdate, userId);
    Product productUpdated = lookUpProduct(productUpdatedNoDb.getKey());
    assertNotNull(productUpdated);
    assertEquals(forUpdate.getName(), productUpdated.getName());
    assertEquals(forUpdate.getDate(), productUpdated.getDate());
    assertEquals(forUpdate.getDescription(), productUpdated.getDescription().getValue());
  }
View Full Code Here

TOP

Related Classes of com.changestuffs.server.persistence.beans.Product

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.