Example usage for org.apache.commons.beanutils BeanPropertyValueChangeClosure BeanPropertyValueChangeClosure

List of usage examples for org.apache.commons.beanutils BeanPropertyValueChangeClosure BeanPropertyValueChangeClosure

Introduction

In this page you can find the example usage for org.apache.commons.beanutils BeanPropertyValueChangeClosure BeanPropertyValueChangeClosure.

Prototype

public BeanPropertyValueChangeClosure(String propertyName, Object propertyValue) 

Source Link

Document

Constructor which takes the name of the property to be changed, the new value to set the property to, and assumes ignoreNull to be false.

Usage

From source file:io.coala.experimental.dynabean.DynaBeanTest.java

@Test
public void testDynaBeans() throws Exception {
    // for usage, see
    // http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/apidocs/org/apache/commons/beanutils/package-summary.html#package_description

    final DynaBean dynaBean = new LazyDynaBean(); // Create LazyDynaBean
    final MutableDynaClass dynaClass = (MutableDynaClass) dynaBean.getDynaClass(); // get DynaClass

    dynaClass.add("amount", java.lang.Integer.class); // add property
    dynaClass.add("myMap", java.util.TreeMap.class); // add mapped property

    final DynaBean employee = dynaClass.newInstance();

    // TODO experiment with Jackson's AnnotationIntrospector to annotate
    // DynaBean#get(...) method with @JsonAnyGetter and #set(...) method
    // with @JsonAnySetter

    employee.set("address", new HashMap<String, String>());
    employee.set("activeEmployee", Boolean.FALSE);
    employee.set("firstName", "Fred");
    employee.set("lastName", "Flintstone");

    LOG.trace("Employee: " + JsonUtil.toPrettyJSON(employee));

    // set all <activeEmployee> attribute values to <true>
    final BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("activeEmployee",
            Boolean.TRUE);/*from  ww  w.jav a  2  s .com*/

    final Collection<?> employees = Collections.singleton(employee);
    LOG.trace("Mutated employees: " + JsonUtil.toPrettyJSON(employees));

    // update the Collection
    CollectionUtils.forAllDo(employees, closure);

    // filter for beans with <activeEmployee> set to <false>
    final BeanPropertyValueEqualsPredicate predicate = new BeanPropertyValueEqualsPredicate("lastName",
            "Flintstone");

    // filter the Collection
    CollectionUtils.filter(employees, predicate);
    LOG.trace("Filtered employees: " + JsonUtil.toPrettyJSON(employees));
}

From source file:com.hiperium.bo.control.impl.TaskBOImpl.java

/**
 * {@inheritDoc}/*w ww. j a  v  a 2s.  c o  m*/
 */
@Override
public List<Task> updateRegisterState(@NotNull List<Task> list, boolean newState, @NotNull String sessionId)
        throws InformationException {
    this.log.debug("changeRegisterState - START");
    if (list != null && !list.isEmpty()) {
        List<Task> actualList = new ArrayList<Task>();
        for (Task task : list) {
            Task actual = super.getDaoFactory().getTaskDAO().findById(task.getId(), false, true);
            actualList.add(actual);
        }
        list.clear();
        BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("active", newState);
        CollectionUtils.forAllDo(actualList, closure);
        for (Task task : actualList) {
            Task updated = super.getDaoFactory().getTaskDAO().update(task);
            Task basic = new Task();
            BeanUtils.copyProperties(updated, basic);
            list.add(basic);
        }
    }
    this.log.debug("changeRegisterState - END");
    return list;
}

From source file:com.hiperium.bo.security.impl.ProfileBOImpl.java

/**
 * {@inheritDoc}/*ww w.  ja  va  2  s. co m*/
 */
@Override
public List<Profile> updateRegisterState(@NotNull List<Profile> list, boolean newState,
        @NotNull String sessionId) throws InformationException {
    this.log.debug("updateRegisterState - START");
    List<Profile> updatedList = new ArrayList<Profile>();
    if (list != null && !list.isEmpty()) {
        // TODO: VALIDATE THAT DO NOT INACTIVATE ADMINISTRATOR PROFILE
        BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("state", newState);
        CollectionUtils.forAllDo(list, closure);
        for (Profile profile : list) {
            Profile updated = super.getDaoFactory().getProfileDAO().update(profile);
            updatedList.add(updated);
        }
    }
    this.log.debug("updateRegisterState - END");
    return updatedList;
}

From source file:ar.com.zauber.commons.test.SpringHibernateRepositoryTest.java

/** test */
public final void testActualizarEliminarColeccion() {
    final Query<PersonaDummy> query = new SimpleQuery<PersonaDummy>(PersonaDummy.class,
            new EqualsPropertyFilter("numeroFiscal", new SimpleValue(new Integer(55555))), null, null);

    final PersonaDummy personaDummy = new PersonaDummy(55555, "Martin Contini", "Descripcion Martin Contini",
            crearGuardarDosDirecciones());

    // prueba actualizacion
    repository.saveOrUpdate(personaDummy);

    CollectionUtils.forAllDo(personaDummy.getDirecciones(),
            new BeanPropertyValueChangeClosure("codpostal", CODIGO_POSTAL_3));

    List<PersonaDummy> personas = repository.find(query);

    for (final Persistible persistible : personas) {
        final PersonaDummy persona = (PersonaDummy) persistible;
        for (final DireccionDummy direccion : persona.getDirecciones()) {
            Assert.assertEquals(CODIGO_POSTAL_3, direccion.getCodpostal());
        }//from   w  ww .  j  a  v  a2  s  .  c o  m
    }

    // prueba eliminacion
    personaDummy.getDirecciones().removeAll(personaDummy.getDirecciones());
    repository.saveOrUpdate(personaDummy);

    personas = repository.find(query);

    Assert.assertEquals(0, (personas.get(0)).getDirecciones().size());
}