Example usage for org.springframework.beans BeanUtils copyProperties

List of usage examples for org.springframework.beans BeanUtils copyProperties

Introduction

In this page you can find the example usage for org.springframework.beans BeanUtils copyProperties.

Prototype

public static void copyProperties(Object source, Object target) throws BeansException 

Source Link

Document

Copy the property values of the given source bean into the target bean.

Usage

From source file:net.microwww.rurl.service.imp.HessianRightServiceImp.java

@Override
public Map<String, Object>[] listAccountUrlRight(String appname, String account) {
    Webapp app = Webapp.getByAppName(appname);
    List<Map<String, Object>> list = new ArrayList();
    List<Webappurl> accs = app.listAccountRight(account);
    for (Webappurl url : accs) {
        url.setWebapp(app);/*from   w  w w.  ja  v  a 2 s .c om*/
        RightURL rt = new RightURL();
        BeanUtils.copyProperties(url, rt);
        list.add((JSONObject) JSONObject.toJSON(rt));
    }
    return list.toArray(new Map[list.size()]);
}

From source file:org.syncope.core.rest.controller.LoggerController.java

@PreAuthorize("hasRole('LOGGER_LIST')")
@RequestMapping(method = RequestMethod.GET, value = "/list")
@Transactional(readOnly = true)//from w  w w. j  a va  2 s.c o  m
public List<LoggerTO> list() {
    List<LoggerTO> result = new ArrayList<LoggerTO>();
    for (SyncopeLogger syncopeLogger : loggerDAO.findAll()) {
        LoggerTO loggerTO = new LoggerTO();
        BeanUtils.copyProperties(syncopeLogger, loggerTO);
        result.add(loggerTO);
    }

    return result;
}

From source file:org.nebula.service.admin.GetHeartbeatsProcessor.java

private List<HeartbeatSummary> extractSummaries(List<Heartbeat> heartbeats) {
    List<HeartbeatSummary> summaries = new ArrayList<HeartbeatSummary>();

    for (Heartbeat heartbeat : heartbeats) {
        HeartbeatSummary summary = new HeartbeatSummary();

        BeanUtils.copyProperties(heartbeat, summary);

        summaries.add(summary);/*from w  w w. ja v a2 s  .  co m*/
    }

    return summaries;
}

From source file:com.iselect.kernal.geo.service.GeographicServiceImpl.java

@Override
//    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public List<CountryDto> getCountries() {
    List<CountryModel> countryModels = this.countryDao.getCountries();
    List<CountryDto> countryDtos = new ArrayList<>(countryModels.size());
    for (CountryModel countryModel : countryModels) {
        CountryDto countryDto = (CountryDto) CountryFactory.createCountry(EntityType.DTO);
        BeanUtils.copyProperties(countryModel, countryDto);
        countryDtos.add(countryDto);/*w w  w . jav  a  2  s.  com*/
    }
    return countryDtos;
}

From source file:de.ingrid.interfaces.csw.config.model.Configuration.java

/**
 * Create an instance from the given class configuration
 * @param config/* w w  w  .  j  av a2s  .com*/
 * @return T
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public <T> T createInstance(ClassConfiguration config) throws Exception {
    Class<?> clazz = Class.forName(config.getClassName());
    T instance = (T) clazz.newInstance();
    BeanUtils.copyProperties(config, instance);
    return instance;
}

From source file:com.clicktravel.cheddar.event.AbstractEvent.java

@Override
public final void deserializeAndApply(final String serializedString) {
    try {//from w  ww. ja  v  a2s .  c  om
        final Event event = MAPPER.readValue(serializedString, getClass());
        BeanUtils.copyProperties(event, this);
    } catch (final Exception e) {
        throw new IllegalStateException("Could not deserialize to event " + getClass().getName(), e);
    }
}

From source file:com.greenline.hrs.admin.user.service.UserInfoService.java

/**
 * //w  ww .java 2  s  .c om
 *
 * @param userNormalInfo
 * @return ?Longuid?null
 */
public Long addUser(UserNormalInfo userNormalInfo) {
    if (userNormalInfo == null) {
        return null;
    }
    UserPassport userPassport = new UserPassport();
    UserNickName userNickName = new UserNickName();
    UserBasicInfo userBasicInfo = new UserBasicInfo();
    BeanUtils.copyProperties(userNormalInfo, userNickName);
    BeanUtils.copyProperties(userNormalInfo, userBasicInfo);
    BeanUtils.copyProperties(userNormalInfo, userPassport);
    //TODO ?salt?,?
    userPassport.setSalt(System.currentTimeMillis() + "");
    // 
    userPassport.setAuthType(EncryptType.DES.name());
    // 
    userBasicInfo.setUserStatus(UserStatus.ENABLE.name());
    Long uid = null;
    try {
        uid = userNickNameBiz.save(userNickName);
        //nickName?
        if (uid != null) {
            userBasicInfo.setUid(uid);
            userPassport.setUid(uid);
            userPassportBiz.save(userPassport);
            userBasicInfoBiz.saveUser(userBasicInfo);
        }
    } catch (DataIntegrityViolationException e) {
        LOG.error("Add user Exception", e);
        // ,uid?,?
        if (uid != null) {
            userNickNameBiz.delete(uid);
            userPassportBiz.delete(uid);
        }
        uid = null;
    }
    return uid;
}

From source file:technology.tikal.ventas.model.producto.ofy.AbstractProductoOfy.java

@Override
public void update(Producto source) {
    BeanUtils.copyProperties(source, this);
}

From source file:sample.service.AccountService.java

public void updateAccount(Account account) {
    accountDao.updateAccount(account);/*from ww w.  ja  va2s  .  c  o  m*/

    Profile profile = new Profile();
    BeanUtils.copyProperties(account, profile);
    profileDao.updateProfile(profile);

    Signon signon = new Signon();
    BeanUtils.copyProperties(account, signon);
    if (signon.getPassword() != null && signon.getPassword().length() > 0) {
        signonDao.updateSignon(signon);
    }
}

From source file:com.baculsoft.beanutils.test.TestBeanUtil2.java

@Test
public void testCopy() throws Throwable {
    PojoExample pojoSource = new PojoExample();
    pojoSource.setStringProp("String Property");
    pojoSource.setBooleanProp(true);// www.j  ava 2 s  . c o m
    pojoSource.setBooleanProp1(Boolean.TRUE);
    pojoSource.setDateProp(new Date());
    pojoSource.setByteProp1(new Byte((byte) 11));
    pojoSource.setIntProp1(new Integer(15125));
    pojoSource.setLongProp1(new Long(20053215235l));
    pojoSource.setFloatProp1(new Float(20053215235f));

    PojoExample pojoTarget = new PojoExample();
    pojoDescriptor.copy(pojoSource, pojoTarget);
    pojoDescriptor.reset(pojoTarget);

    PojoExample pojoTarget2 = new PojoExample();
    PojoExample pojoTarget3 = new PojoExample();

    BeanUtils.copyProperties(pojoSource, pojoTarget2);
    org.apache.commons.beanutils.BeanUtils.copyProperties(pojoSource, pojoTarget3);

    long t1 = System.currentTimeMillis();
    for (int i = 0; i < 50; i++) {
        pojoDescriptor.copy(pojoSource, pojoTarget);

    }
    t1 = System.currentTimeMillis() - t1;

    long t2 = System.currentTimeMillis();
    for (int i = 0; i < 50; i++) {
        BeanUtils.copyProperties(pojoSource, pojoTarget2);
    }
    t2 = System.currentTimeMillis() - t2;

    long t3 = System.currentTimeMillis();
    for (int i = 0; i < 50; i++) {
        org.apache.commons.beanutils.BeanUtils.copyProperties(pojoSource, pojoTarget3);
    }
    t3 = System.currentTimeMillis() - t3;

    System.out.println("Time to copy properties ");
    System.out.println("this class: t1 ---> " + t1);
    System.out.println("spring-beans: t2 --->" + t2);
    System.out.println("apache commons: t3 --->" + t3);

    System.out.println(pojoDescriptor.describe(pojoTarget).equals(pojoDescriptor.describe(pojoTarget2)));

    assertEquals(pojoDescriptor.describe(pojoTarget), pojoDescriptor.describe(pojoTarget2));
}