Example #1
0
  public void testPagingInCollection() throws Exception {
    // create objects in database
    Formula formula = Formula.findByName("HTML TEST");
    Ingredient ingredient = Ingredient.findByName("LECHE");
    for (int x = 0; x <= 12; x++) {
      FormulaIngredient fi = new FormulaIngredient();
      fi.setFormula(formula);
      fi.setIngredient(ingredient);
      XPersistence.getManager().persist(fi);
    }
    XPersistence.commit();

    //
    execute("Mode.detailAndFirst");
    assertValue("name", "HTML TEST");
    assertCollectionRowCount("ingredients", 10);
    checkRowCollection("ingredients", 0);
    execute("List.goNextPage", "collection=ingredients");
    execute("List.goPreviousPage", "collection=ingredients");
    assertRowCollectionChecked("ingredients", 0);

    // remove objects from database
    String sentencia = " DELETE FROM FormulaIngredient WHERE ingredient.oid = :ingredient ";
    Query query = XPersistence.getManager().createQuery(sentencia);
    query.setParameter("ingredient", ingredient.getOid());
    query.executeUpdate();
    XPersistence.commit();
  }
  public void testBeanValidation() throws Exception {
    Artist a = new Artist();
    a.setName("TOO OLD ARTIST");
    a.setAge(120);

    XPersistence.getManager().persist(a);
    try {
      XPersistence.commit();
    } catch (RollbackException ex) {

      if (ex.getCause() instanceof javax.validation.ConstraintViolationException) {
        javax.validation.ConstraintViolationException vex =
            (javax.validation.ConstraintViolationException) ex.getCause();
        assertEquals("1 invalid value is expected", 1, vex.getConstraintViolations().size());
        ConstraintViolation violation = vex.getConstraintViolations().iterator().next();
        assertEquals("Bean", "Artist", violation.getRootBeanClass().getSimpleName());
        String expectedMessage =
            "es".equals(Locale.getDefault().getLanguage())
                ? "tiene que ser menor o igual que 90"
                : "must be less than or equal to 90";
        assertEquals("Message text", expectedMessage, violation.getMessage());
        return;
      }
    }
    fail("A constraint violation exception should be thrown");
  }
Example #3
0
  public int update(int oid, String quantity, String memo) { // 更新揀貨單的揀貨數量
    logger.debug(
        "OrderPlaceDDAO.update: "
            + "pickId: "
            + oid
            + ", quantity: "
            + quantity
            + ", memo: "
            + memo);

    EntityManager em = XPersistence.getManager();
    OrderPlaceD bean = em.find(OrderPlaceD.class, oid);
    logger.debug("OrderPlaceD.update: orderPlaceD: " + bean);
    if (bean != null) {
      //			bean.setQuantity(quantity);
      bean.setRemark(memo);
      try {
        em.merge(bean);
        XPersistence.commit();
      } catch (Exception e) {
        logger.error("OrderPlaceD.update: " + e);
      }
      return 1; // 1:成功
    }
    return 0; // 0:失敗
  }
Example #4
0
 private void createDeliveryType(int number, String description) {
   DeliveryType type = new DeliveryType();
   type.setNumber(number);
   type.setDescription(description);
   XPersistence.getManager().persist(type);
   XPersistence.commit();
 }
Example #5
0
 public boolean insert(OrderStoreD beanD) {
   XPersistence.getManager().persist(beanD);
   XPersistence
       .commit(); // 若 UUID 重複,會有例外: org.hibernate.PersistentObjectException: detached entity
                  // passed to persist: com.kaijung.jpa.OrderStoreD
   // XHibernate.commit();
   return true;
 }
Example #6
0
 public String getTable() {
   // Change this if by polymorphism ?
   if (isCodeGenerationTime()) return table;
   if (XavaPreferences.getInstance().isJPAPersistence()
       && getSchema() == null
       && !Is.emptyString(XPersistence.getDefaultSchema())) {
     return XPersistence.getDefaultSchema() + "." + table;
   } else if (XavaPreferences.getInstance().isHibernatePersistence()
       && getSchema() == null
       && !Is.emptyString(XHibernate.getDefaultSchema())) {
     return XHibernate.getDefaultSchema() + "." + table;
   }
   return table;
 }
 // User defined finders/Buscadores definidos por el usuario
 public static FilterBySubfamily findBy() throws javax.ejb.ObjectNotFoundException {
   if (XavaPreferences.getInstance().isJPAPersistence()) {
     javax.persistence.Query query =
         org.openxava.jpa.XPersistence.getManager().createQuery("from FilterBySubfamily as o");
     try {
       return (FilterBySubfamily) query.getSingleResult();
     } catch (Exception ex) {
       // In this way in order to work with Java pre 5
       if (ex.getClass().getName().equals("javax.persistence.NoResultException")) {
         throw new javax.ejb.ObjectNotFoundException(
             XavaResources.getString("object_not_found", "FilterBySubfamily"));
       } else {
         ex.printStackTrace();
         throw new RuntimeException(ex.getMessage());
       }
     }
   } else {
     org.hibernate.Query query =
         org.openxava.hibernate.XHibernate.getSession().createQuery("from FilterBySubfamily as o");
     FilterBySubfamily r = (FilterBySubfamily) query.uniqueResult();
     if (r == null) {
       throw new javax.ejb.ObjectNotFoundException(
           XavaResources.getString("object_not_found", "FilterBySubfamily"));
     }
     return r;
   }
 }
Example #8
0
 // User defined finders/Buscadores definidos por el usuario
 public static Size findById(int id) throws javax.ejb.ObjectNotFoundException {
   if (XavaPreferences.getInstance().isJPAPersistence()) {
     javax.persistence.Query query =
         org.openxava.jpa.XPersistence.getManager()
             .createQuery("from Size as o where o.id = :arg0");
     query.setParameter("arg0", new Integer(id));
     try {
       return (Size) query.getSingleResult();
     } catch (Exception ex) {
       // In this way in order to work with Java pre 5
       if (ex.getClass().getName().equals("javax.persistence.NoResultException")) {
         throw new javax.ejb.ObjectNotFoundException(
             XavaResources.getString("object_not_found", "Size"));
       } else {
         ex.printStackTrace();
         throw new RuntimeException(ex.getMessage());
       }
     }
   } else {
     org.hibernate.Query query =
         org.openxava.hibernate.XHibernate.getSession()
             .createQuery("from Size as o where o.id = :arg0");
     query.setParameter("arg0", new Integer(id));
     Size r = (Size) query.uniqueResult();
     if (r == null) {
       throw new javax.ejb.ObjectNotFoundException(
           XavaResources.getString("object_not_found", "Size"));
     }
     return r;
   }
 }
Example #9
0
  public void testCreateReferencesFromDescriptionsList() throws Exception {

    execute("CRUD.new");

    // Verifying initial state
    String[][] familyValues = {
      {"", ""},
      {"1", "SOFTWARE"},
      {"2", "HARDWARE"},
      {"3", "SERVICIOS"}
    };
    assertValidValues("family.number", familyValues);

    execute("Reference.createNew", "model=Family2,keyProperty=xava.Product2.family.number");
    assertAction("NewCreation.saveNew");
    assertAction("NewCreation.cancel");
    execute("NewCreation.cancel");
    execute("Reference.createNew", "model=Family2,keyProperty=xava.Product2.family.number");
    assertAction("NewCreation.saveNew");
    assertAction("NewCreation.cancel");
    execute("NewCreation.saveNew");
    assertError("Value for Number in Family is required");
    assertError("Value for Description in Family is required");
    setValue("Family2", "number", "1");
    setValue("Family2", "description", "JUNIT TEST");
    execute("NewCreation.saveNew");
    assertError("Impossible to create: an object with that key already exists");
    setValue("Family2", "number", "66");
    execute("NewCreation.saveNew");
    assertNoErrors();

    // Test just added
    String[][] familyValuesUpdated = {
      {"", ""},
      {"1", "SOFTWARE"},
      {"2", "HARDWARE"},
      {"3", "SERVICIOS"},
      {"66", "JUNIT TEST"}
    };
    assertValidValues("family.number", familyValuesUpdated);
    assertValue("family.number", "66"); // The just created family is automatically selected

    // Delete it
    Family2 f = XPersistence.getManager().find(Family2.class, 66);
    XPersistence.getManager().remove(f);
  }
Example #10
0
 private void createProduct(int number, String description, int zone) throws Exception {
   Product2 p = new Product2();
   p.setNumber(number);
   p.setDescription(description);
   Family2 f = new Family2();
   f.setNumber(1);
   p.setFamily(f);
   Subfamily2 sf = new Subfamily2();
   sf.setNumber(1);
   p.setSubfamily(sf);
   Warehouse w = new Warehouse();
   w.setNumber(1);
   w.setZoneNumber(zone);
   p.setWarehouse(w);
   p.setUnitPrice(new BigDecimal("1.00"));
   XPersistence.getManager().persist(p);
   XPersistence.commit();
 }
  public void testRequiredAsBeanValidationAnnotation() throws Exception {
    DrivingLicence dl = new DrivingLicence();
    dl.setType("X");
    dl.setLevel(1);
    dl.setDescription(""); // This is annotated with @Required

    XPersistence.getManager().persist(dl);
    try {
      XPersistence.commit();
    } catch (RollbackException ex) {
      if (ex.getCause() instanceof ConstraintViolationException) {
        ConstraintViolationException cex = (ConstraintViolationException) ex.getCause();
        assertEquals("1 constraint violation expected", 1, cex.getConstraintViolations().size());
        ConstraintViolation v = cex.getConstraintViolations().iterator().next();
        assertEquals("Property", "description", v.getPropertyPath().toString());
        assertEquals("Message text", "{required}", v.getMessage());
        return;
      }
    }
    fail("A constraint violation exception should be thrown");
  }
Example #12
0
  public Stock getStockByItem(int itemid) { // 用 商品編號 查出 該商品所在的某一貨架
    Query query =
        XPersistence.getManager()
            .createQuery(
                "FROM Stock o WHERE o.item.oid = :itemid order by o.volume desc"); // JPQL query
    query.setParameter("itemid", itemid);

    List<Stock> beans = query.getResultList();
    logger.debug("OrderPlaceDDAO.getStockByItem beans: " + beans);

    return beans.get(0);
  }
Example #13
0
  public Collection<Stock> getStocksByPlaceId(int placeid) { // 用上架單編號(單頭)查出明細檔
    Query query =
        XPersistence.getManager()
            .createQuery(
                "FROM Stock o WHERE o.item.oid IN (SELECT p.item.oid FROM OrderPlaceD p WHERE p.orderPlace.oid = :placeid ORDER BY p.oid DESC) )"); // JPQL query
    query.setParameter("placeid", placeid);
    // select * FROM Stock o WHERE o.itemid IN (SELECT p.itemid FROM OrderPlaceD p WHERE
    // p.orderPlace_oid = '1' ORDER BY p.oid DESC)
    Collection stocks = query.getResultList();

    logger.debug("OrderPlaceDDAO.getStocksByPlaceId stocks: " + stocks);

    return stocks;
  }
 private void setDefaultSchema(HttpServletRequest request) {
   String hibernateDefaultSchemaTab =
       (String) request.getSession().getAttribute("xava_hibernateDefaultSchemaTab");
   if (hibernateDefaultSchemaTab != null) {
     request.getSession().removeAttribute("xava_hibernateDefaultSchemaTab");
     XHibernate.setDefaultSchema(hibernateDefaultSchemaTab);
   }
   String jpaDefaultSchemaTab =
       (String) request.getSession().getAttribute("xava_jpaDefaultSchemaTab");
   if (jpaDefaultSchemaTab != null) {
     request.getSession().removeAttribute("xava_jpaDefaultSchemaTab");
     XPersistence.setDefaultSchema(jpaDefaultSchemaTab);
   }
 }
  public void testEntityValidatorsAsHibernateAnnotation() throws Exception {
    Product p = new Product();
    p.setNumber(66);
    p.setDescription("BUENO, BONITO, BARATO"); // It's cheap ('BARATO') thus...
    p.setFamilyNumber(1);
    p.setSubfamilyNumber(1);
    p.setWarehouseKey(new Warehouse());
    p.setUnitPrice(new BigDecimal("900")); // ... it cannot cost 900 (max 100)

    XPersistence.getManager().persist(p);
    try {
      XPersistence.commit();
    } catch (RollbackException ex) {
      if (ex.getCause() instanceof ConstraintViolationException) {
        ConstraintViolationException cex = (ConstraintViolationException) ex.getCause();
        assertEquals("1 constraint violation expected", 1, cex.getConstraintViolations().size());
        ConstraintViolation v = cex.getConstraintViolations().iterator().next();
        assertEquals("Bean", "Product", v.getRootBean().getClass().getSimpleName());
        assertEquals("Message text", "", v.getMessage());
        return;
      }
    }
    fail("A constraint violation exception should be thrown");
  }
  public void testPropertyValidatorsAsBeanValidationAnnotation() throws Exception {
    Product p = new Product();
    p.setNumber(66);
    p.setDescription("MOTO");
    p.setFamilyNumber(1);
    p.setSubfamilyNumber(1);
    p.setWarehouseKey(new Warehouse());
    p.setUnitPrice(new BigDecimal("900"));

    XPersistence.getManager().persist(p);
    try {
      XPersistence.commit();
    } catch (RollbackException ex) {
      if (ex.getCause() instanceof ConstraintViolationException) {
        ConstraintViolationException cex = (ConstraintViolationException) ex.getCause();
        assertEquals("1 constraint violation expected", 1, cex.getConstraintViolations().size());
        ConstraintViolation v = cex.getConstraintViolations().iterator().next();
        assertEquals("Property", "description", v.getPropertyPath().toString());
        assertEquals("Message text", "", v.getMessage());
        return;
      }
    }
    fail("A constraint violation exception should be thrown");
  }
Example #17
0
  public void testConverterWithMetaSets() throws Exception {
    // Creating new
    execute("CRUD.new");
    setValue("invoice.year", "2002");
    setValue("invoice.number", "1");
    setValue("type.number", "1");
    setValue("number", "66");
    setValue("description", "JUNIT");
    setValue("distance", usesAnnotatedPOJO() ? "1" : "2"); // National, in database 'N'
    execute("CRUD.save");
    assertNoErrors();
    assertValue("invoice.year", "");
    assertValue("invoice.number", "");
    assertValue("type.number", "");
    assertValue("number", "");
    assertValue("description", "");
    assertValue("distance", usesAnnotatedPOJO() ? "" : "0");
    // Search just created
    setValue("invoice.year", "2002");
    setValue("invoice.number", "1");
    setValue("type.number", "1");
    setValue("number", "66");
    execute("CRUD.refresh");
    assertNoErrors();
    assertValue("invoice.year", "2002");
    assertValue("invoice.number", "1");
    assertValue("type.number", "1");
    assertValue("number", "66");
    assertValue("description", "JUNIT");
    assertValue("distance", usesAnnotatedPOJO() ? "1" : "2");
    assertNoErrors();

    // Verifying database value
    Query query =
        XPersistence.getManager()
            .createNativeQuery(
                "select d.distance from XAVATEST.Delivery as d where "
                    + "invoice_year=2002 and invoice_number=1 and type=1 and number=66");
    String distanceDB = (String) query.getSingleResult();
    assertEquals("distance in database incorrect", "N", distanceDB);

    // Delete
    execute("CRUD.delete");
    assertNoErrors();
    assertMessage("Delivery deleted successfully");
  }
Example #18
0
  public static void saveUpload(Reader csvFile, CSVStrategy strategy, ValueProcessorProvider vpp) {
    try {

      CSVReaderBuilder<Bank> builder = new CSVReaderBuilder<Bank>(csvFile);

      builder.strategy(strategy);
      CSVReader<Bank> csvReader =
          builder.entryParser(new AnnotationEntryParser<Bank>(Bank.class, vpp)).build();

      List<Bank> banks = csvReader.readAll();
      for (Bank bank : banks) {
        XPersistence.getManager().merge(bank);
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public void testRemoveValidator_postcreateCalculator_postmodifyCalculator() throws Exception {
    execute("CRUD.new");
    setValue("number", "66");
    setValue("description", "JUNIT");
    execute("CRUD.save");
    assertValue("number", "");
    assertValue("description", "");
    assertNoErrors();
    assertMessage("Delivery type created successfully");

    setValue("number", "66");
    execute("CRUD.refresh");
    assertValue("number", "66");
    assertValue("description", "JUNIT CREATED"); // 'CREATED' is added in postcreate
    setValue("description", "JUNIT");
    execute("CRUD.save");
    assertValue("number", "");
    assertValue("description", "");
    assertNoErrors();
    assertMessage("Delivery type modified successfully");

    setValue("number", "66");
    execute("CRUD.refresh");
    assertValue("number", "66");
    assertValue("description", "JUNIT MODIFIED"); // 'MODIFIED' is added in postmodify

    Delivery delivery = new Delivery();
    Invoice invoice = Invoice.findByYearNumber(2002, 1);
    delivery.setInvoice(invoice);
    DeliveryType deliveryType = XPersistence.getManager().find(DeliveryType.class, 66);
    delivery.setType(deliveryType);
    delivery.setNumber(66);
    delivery.setDescription("JUNIT FOR DELIVERY TYPE");
    delivery.setDate(new java.util.Date());
    setDeliveryAdvice(delivery, "JUNIT ADVICE");
    XPersistence.getManager().persist(delivery);
    XPersistence.commit();

    execute("CRUD.delete");
    assertError("Delivery type 66 can not delete because it is used in deliveries");
    assertEditable("description"); // because return to main view (and controllers)

    delivery = XPersistence.getManager().merge(delivery);
    XPersistence.getManager().remove(delivery);
    XPersistence.commit();

    execute("CRUD.delete");
    assertNoErrors();
    assertMessage("Delivery type deleted successfully");
  }
  // adding collection elements list
  public void execute() throws Exception {

    super.execute();

    String idMedidaPlanoDeMedicao = getPreviousView().getValueString("medidaPlanoDeMedicao.id");

    if (idMedidaPlanoDeMedicao != null && idMedidaPlanoDeMedicao.isEmpty() == false) {
      MedidaPlanoDeMedicao medidaPlanoDeMedicao =
          XPersistence.getManager().find(MedidaPlanoDeMedicao.class, idMedidaPlanoDeMedicao);

      String idMedida = medidaPlanoDeMedicao.getMedida().getId();

      if (idMedida != null && idMedida.isEmpty() == false) {
        getTab().setBaseCondition("'" + idMedida + "' IN (SELECT id from ${medida}) ");
      }
      return;
    }

    throw new Exception(
        "Para selecionar a Definição Operacional selecione primeiramente o Plano de Medição e a Medida do plano. Retorne a tela anterior de cadastro.");
  }
Example #21
0
  public void testDeleteSelectedOnesAndOrderBy() throws Exception {
    // Creating new
    execute("CRUD.new");
    setValue("invoice.year", "2009");
    setValue("invoice.number", "1");
    setValue("type.number", "1");
    setValue("number", "1");
    setValue("description", "JUNIT");
    execute("CRUD.save");
    assertNoErrors();

    // To list mode and order
    execute("Mode.list");
    assertActions(listActions);
    execute("List.orderBy", "property=invoice.year"); // ascending
    execute("List.orderBy", "property=invoice.year"); // descending
    assertNoErrors();

    // Delete
    assertValueInList(0, "invoice.year", "2009");
    assertValueInList(0, "invoice.number", "1");
    assertValueInList(0, "type.number", "1");
    assertValueInList(0, "number", "1");

    checkRow(0);

    execute("CRUD.deleteSelected");
    assertNoErrors();
    assertRowUnchecked(0);

    // Verifying that it is deleted
    Query query =
        XPersistence.getManager()
            .createQuery(
                "from Delivery d where "
                    + "d.invoice.year=2009 and d.invoice.number=1 and d.type.number=1 and d.number=1");
    if (!query.getResultList().isEmpty()) {
      fail("Delivery would be deleted and it is not the case");
    }
  }
 public static Product2 findByNumber(long number) throws NoResultException {
   Query query =
       XPersistence.getManager().createQuery("from Product2 as o where o.number = :number");
   query.setParameter("number", new Long(number));
   return (Product2) query.getSingleResult();
 }
Example #23
0
  public void testImagesGallery() throws Exception {
    // We remove oid from product 1 in order to test that images gallery works well in the first
    // attemp.
    Product2.findByNumber(1).setPhotos("");
    XPersistence.commit();
    // Verifying product 1 has no images
    assertTrue("At least 2 products are required to run this test", getListRowCount() >= 2);
    execute("Mode.detailAndFirst");
    assertValue("number", "1");
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertMessage("No images");
    assertNoAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());

    // Canceling the adding of and image
    execute("Gallery.addImage");
    assertNoErrors();
    String imageUrl = System.getProperty("user.dir") + "/test-images/foto_javi.jpg";
    setFileValue("newImage", imageUrl);
    execute("LoadImageIntoGallery.cancel");
    assertNoErrors();
    assertNoAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());

    // Adding one image
    execute("Gallery.addImage");
    assertNoErrors();
    imageUrl = System.getProperty("user.dir") + "/test-images/foto_javi.jpg";
    setFileValue("newImage", imageUrl);
    execute("LoadImageIntoGallery.loadImage");
    assertNoErrors();
    assertMessage("Image added to the gallery");
    assertAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());

    // Returning to the main entity
    execute("Gallery.return");
    // execute("CRUD.save"); It's not needed explicit saving of the main entity
    assertNoErrors();

    // Verifying that product 2 has no images
    execute("Navigation.next");
    assertValue("number", "2");
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertMessage("No images");
    assertNoAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());
    execute("Gallery.return");

    // Verifying that product 1 has the added image
    execute("CRUD.new");
    setValue("number", "1");
    execute("CRUD.refresh");
    assertNoErrors();
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertNoMessages();
    assertAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());
    String imageOid = getForm().getInputByName("xava.GALLERY.images").getValueAttribute();

    // Maximizing the image
    execute("Gallery.maximizeImage", "oid=" + imageOid);
    assertNoErrors();
    assertNoAction("Gallery.maximizeImage");
    assertAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");

    // Minimizing the image
    execute("Gallery.minimizeImage");
    assertNoErrors();
    assertAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());

    // Verifying read-only
    execute("Gallery.return");
    execute("EditableOnOff.setOff");
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertNoMessages();
    assertNoAction("Gallery.addImage");
    assertAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());
    execute("Return.return");
    execute("EditableOnOff.setOn");

    // Removing the image
    execute("Gallery.edit", "galleryProperty=photos");
    assertEquals(
        "Images count does not match", 1, getForm().getInputsByName("xava.GALLERY.images").size());
    execute("Gallery.removeImage", "oid=" + imageOid);
    assertNoErrors();
    assertNoAction("Gallery.maximizeImage");
    assertNoAction("Gallery.minimizeImage");
    assertNoAction("Gallery.removeImage");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());

    // Verifying that product 1 has no images
    execute("Gallery.return");
    execute("CRUD.new");
    setValue("number", "1");
    execute("CRUD.refresh");
    assertNoErrors();
    execute("Gallery.edit", "galleryProperty=photos");
    assertNoErrors();
    assertMessage("No images");
    assertEquals(
        "Images count does not match", 0, getForm().getInputsByName("xava.GALLERY.images").size());
  }
 static {
   XPersistence.setPersistenceUnit("junit");
   DataSourceConnectionProvider.setUseHibernateConnection(true);
 }
 protected void tearDown() throws Exception {
   XPersistence.commit();
 }
  public void execute() throws Exception {
    // TODO Auto-generated method stub

    Long key = (Long) getView().getAllValues().get("id");

    System.out.println("\n\n\n\n\n\n\n\n\n\n The value sent===" + getView().getAllValues());
    Map payingAcct = (Map) getView().getAllValues().get("payingAccount");

    PaymentBatch batch = XPersistence.getManager().find(PaymentBatch.class, key);
    TransitAccount debitAccount = batch.getPayingAccount();

    if (payingAcct.get("id") != null) {
      debitAccount = (TransitAccount) MapFacade.findEntity("TransitAccount", payingAcct);
      batch.setPayingAccount(debitAccount);
      XPersistence.getManager().merge(batch);
    }
    if (UserManager.loginUserHasRole("funder") && debitAccount == null) {
      addError("As funder, You Need to Attach Debit Account", null);
      return;
    }

    Long transId = (Long) getView().getObject("transId");

    Boolean fina = (Boolean) getView().getObject("final");

    if (fina) {
      if (debitAccount == null) {
        addError(" Debit Account Yet To be Attached", null);
        return;
      }
      String token = (String) getView().getObject("token");
      String softToken = (String) getView().getValue("softToken");
      if (Is.empty(softToken)) {
        addError("Soft Token Is Required", null);
        return;
      }
      DateTime dT = (DateTime) getView().getObject("fiveMinutes");
      DateTime presentTime = new DateTime(Dates.withTime(Dates.createCurrent()));

      if (!Is.equalAsStringIgnoreCase(token, softToken)) {
        addError("Incorrect Soft Token", null);
        return;
      }
      if (dT.getMillis() < presentTime.getMillis()) {
        addError("Token Has Expired", null);
        return;
      }

      System.out.println(
          "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The sent object to this place ===" + transId);
    }

    Transaction transaction = XPersistence.getManager().find(Transaction.class, transId);

    AsyncEventBus eventBus = new AsyncEventBus(Executors.newCachedThreadPool());
    eventBus.register(transaction);
    System.out.println(" 1111111approve already commented out......... ");
    eventBus.post(new Object());

    // transaction.approve();
    closeDialog();
    setNextMode(LIST);
  }
Example #27
0
 public static Ingredient findByName(String name) throws NoResultException {
   Query query = XPersistence.getManager().createQuery("from Ingredient where name = :name");
   query.setParameter("name", name);
   return (Ingredient) query.getSingleResult();
 }
Example #28
0
 private void deleteDeliveryType(int number) {
   DeliveryType type = XPersistence.getManager().find(DeliveryType.class, number);
   XPersistence.getManager().remove(type);
   XPersistence.commit();
 }
Example #29
0
 private void deleteProduct(long number) throws Exception {
   Product2 k = XPersistence.getManager().find(Product2.class, number);
   XPersistence.getManager().remove(k);
   XPersistence.commit();
 }