Example #1
0
  @Override
  public void savePurchase(final Purchase purchase) {
    PurchaseEntity entity;
    ModelMapper mapper = new ModelMapper();
    entity = mapper.map(purchase, PurchaseEntity.class);

    // TODO: remove CustomerEntity Depenency
    CustomerEntity ce =
        mapper.map(cdl.getCustomerById(purchase.getCustomer().getId()), CustomerEntity.class);
    entity.setCustomerid(ce);

    List<PurchaseitemEntity> list = new LinkedList<PurchaseitemEntity>();
    for (PurchaseItem pi : purchase.getPurchaseItems()) {
      PurchaseitemEntity e = mapper.map(pi, PurchaseitemEntity.class);
      // ProductEntity pe = new ProductEntity(pi.getProductid());
      // e.setProductid(pe);
      e.setProductno(pi.getProductNo());
      e.setPurchaseid(entity);
      list.add(e);
    }

    entity.setPurchaseitemCollection(list);

    try {
      this.pfl.create(entity);
    } catch (Exception ex) {
      Logger.getGlobal().log(Level.WARNING, ex.toString());
    }
  }
Example #2
0
 @Override
 public List<Purchase> getPurchaseByCustomer(final Customer customer) {
   List<Purchase> purchases = new LinkedList<Purchase>();
   List<PurchaseEntity> entities = pfl.findAll();
   ModelMapper mapper = new ModelMapper();
   for (PurchaseEntity e : entities) {
     if (e.getCustomerid().getId() == customer.getId()) {
       Purchase p = mapper.map(e, Purchase.class);
       for (PurchaseitemEntity pie : e.getPurchaseitemCollection()) {
         PurchaseItem pi = new PurchaseItem();
         pi.setDescription(pie.getDescription());
         pi.setId(pie.getId());
         pi.setQuantity(pie.getQuantity());
         pi.setProductNo(pie.getProductno());
         p.getPurchaseItems().add(pi);
       }
       purchases.add(p);
     }
   }
   return purchases;
 }