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> getApplication(String appname) {
    Webapp app = Webapp.getByAppName(appname);
    if (app == null) {
        throw new RuntimeException("not find app for appname :" + appname);
    }//from w  w  w.  j a  va  2s. co  m
    App da = new App();
    BeanUtils.copyProperties(app, da);
    return (JSONObject) JSONObject.toJSON(da);
}

From source file:org.senro.metadata.aop.AOPMetadataManager.java

/**
 * Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and
 * ApplicationContextAware). <p>This method allows the bean instance to perform initialization only possible when
 * all bean properties have been set and to throw an exception in the event of misconfiguration.
 *
 * @throws Exception in the event of misconfiguration (such as failure to set an essential property) or if
 *                   initialization fails.
 *///from   w ww. ja  v  a  2  s. c  om
public void afterPropertiesSet() throws Exception {
    for (Class clazz : types) {
        Metadata metadata = cache.get(clazz);
        if (metadata == null) {
            metadata = metadataFactory.createClass(clazz);
            for (MetadataProvider provider : metadataFactory.getProviders()) {
                if (provider.supports(clazz)) {
                    Object metadata1 = provider.getClassMetadata(clazz);
                    BeanUtils.copyProperties(metadata1, metadata);
                    //todo Brian: what is the use of next lines. I'm asking because adding providers to metadata, wicket will try to serialize these too.
                    //                        List<MetadataProvider> providers = metadata.getProviders();
                    //                        if (!providers.contains(provider)) {
                    //                            providers.add(provider);
                    //                        }
                }
            }
            cache.put(clazz, metadata);
        }
        //            for (Method method : metadata.getMethods()) {
        //                Metadata metadataMethod = cache.get(method);
        //                if (metadataMethod == null) {
        //                    metadataMethod = metadataFactory.createMethod(method);
        //                    for (MetadataProvider provider : metadataFactory.getProviders()) {
        //                        BeanUtils.copyProperties(provider.getMethodMetadata(method), metadataMethod);
        //                    }
        //                    cache.put(method, metadataMethod);
        //                }
        //            }
        for (Method method : metadata.getProperties()) {
            Metadata metadataProperty = cache.get(method);
            if (metadataProperty == null) {
                metadataProperty = metadataFactory.createProperty(method);
                for (MetadataProvider provider : metadataFactory.getProviders()) {
                    BeanUtils.copyProperties(provider.getPropertyMetadata(method), metadataProperty);
                }
                cache.put(method, metadataProperty);
            }
        }
    }
}

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

@Override
public CountryDto getCountryByCode(String code) throws EntityNotFoundException, CopyPropertiesException {
    CountryModel countryModel = this.countryDao.getCountryByCode(code);
    CountryDto countryDto = (CountryDto) CountryFactory.createCountry(EntityType.DTO);
    BeanUtils.copyProperties(countryModel, countryDto);
    List<StateModel> stateModels = countryModel.getStates();
    for (StateModel stateModel : stateModels) {
        StateDto stateDto = (StateDto) StateFactory.createState(EntityType.DTO);
        BeanUtils.copyProperties(stateModel, stateDto);
        countryDto.addState(stateDto);//from w w w .j av  a2  s.c  o m
    }
    return countryDto;
}

From source file:com.iselect.kernal.account.service.AccountServiceImpl.java

@Override
@Transactional(readOnly = false)//from www.  jav  a 2  s.  c  o  m
public void insertUser(UserDto user) {
    UserModel userModel = modelFactory.createUser();
    BeanUtils.copyProperties(user, userModel);
    userDaoExt.save(userModel);
    BeanUtils.copyProperties(userModel, user);
}

From source file:com.kazuki43zoo.jpetstore.ui.controller.OrderForm.java

Order toOrder(Cart cart) {
    Order order = new Order();
    BeanUtils.copyProperties(this, order);
    order.setTotalPrice(cart.getSubTotal());
    cart.getCartItems().forEach(x -> order.addLine(x.toOrderLine()));
    return order;
}

From source file:org.josescalia.common.dao.impl.CommonDaoImpl.java

/**
 * Private method to update the data in database<br>
 * The method spesific set the version incrementally changed, the class
 * which use this method must extend Auditable class
 *
 * @param obj instance of extended Auditable Class
 * @return T an object its own after some validation by fetching the
 * database//from www  . j  av a 2s  . com
 */
private T update(AuditableBase obj) throws Exception {
    T temp = getById((PK) obj.getId());
    if (temp != null) {
        BeanUtils.copyProperties(obj, temp);
        try {
            getCurrentSession().update(temp);
            return temp;
        } catch (Exception e) {
            logger.error("Exception : " + e.getMessage());
            //return null;
            throw new Exception(e);
        }

    } else {
        logger.info("Class " + obj.getClass().getName()
                + " is not extend Auditable class, cannot use Common saveOrUpdate method");
        return null;
    }
}

From source file:org.openmrs.web.controller.patient.ShortPatientModel.java

/**
 * Constructor that creates a shortPatientModel object from a given patient object
 *
 * @param patient/*from  w w w  . j av a  2  s  .c om*/
 */
@SuppressWarnings("unchecked")
public ShortPatientModel(Patient patient) {
    if (patient != null) {
        this.patient = patient;
        this.personName = patient.getPersonName();
        this.personAddress = patient.getPersonAddress();
        List<PatientIdentifier> activeIdentifiers = patient.getActiveIdentifiers();
        if (activeIdentifiers.isEmpty()) {
            final PatientIdentifierType defaultIdentifierType = getDefaultIdentifierType();
            activeIdentifiers.add(new PatientIdentifier(null, defaultIdentifierType,
                    (LocationUtility.getUserDefaultLocation() != null)
                            ? LocationUtility.getUserDefaultLocation()
                            : LocationUtility.getDefaultLocation()));
        }

        identifiers = ListUtils.lazyList(new ArrayList<PatientIdentifier>(activeIdentifiers),
                FactoryUtils.instantiateFactory(PatientIdentifier.class));

        List<PersonAttributeType> viewableAttributeTypes = Context.getPersonService()
                .getPersonAttributeTypes(PERSON_TYPE.PATIENT, ATTR_VIEW_TYPE.VIEWING);

        personAttributes = new ArrayList<PersonAttribute>();
        if (!CollectionUtils.isEmpty(viewableAttributeTypes)) {
            for (PersonAttributeType personAttributeType : viewableAttributeTypes) {
                PersonAttribute persistedAttribute = patient.getAttribute(personAttributeType);
                //This ensures that empty attributes are added for those we want to display 
                //in the view, but have no values
                PersonAttribute formAttribute = new PersonAttribute(personAttributeType, null);

                //send a clone to the form so that we can use the original to track changes in the values
                if (persistedAttribute != null) {
                    BeanUtils.copyProperties(persistedAttribute, formAttribute);
                }

                personAttributes.add(formAttribute);
            }
        }
    }
}

From source file:$.AccountSoapServiceImpl.java

@Override
    public IdResult createUser(UserSoapDTO userDto) {
        if (logger.isInfoEnabled())
            logger.info("!");
        IdResult result = new IdResult();
        UserPO userPo = null;// w  w  w.  j av  a 2 s .c  o  m
        try {
            Validate.notNull(userDto, "?");

            userPo = new UserPO();
            BeanUtils.copyProperties(userDto, userPo);
            //         User userEntity = BeanMapper.map(user, User.class);
            BeanValidators.validateWithException(validator, userDto);
            BeanUtils.copyProperties(userDto, userPo);
            accountDomain.saveUser(userPo);

            return new IdResult(userPo.getUserId());
        } catch (ConstraintViolationException e) {
            String message = StringUtils.join(BeanValidators.extractPropertyAndMessageAsList(e, " "), "\n");
            return handleParameterError(result, e, message);
        } catch (RuntimeException e) {
            if (ServiceExceptions.isCausedBy(e, DuplicateKeyException.class)) {
                String message = "??(:" + userPo + ")";
                if (logger.isErrorEnabled())
                    logger.error(message, e.getMessage());
                return handleParameterError(result, e, message);
            } else {
                if (logger.isErrorEnabled())
                    logger.error(e.getMessage());

                return handleParameterError(result, e);
            }
        }
    }

From source file:com.wandrell.example.mule.wss.endpoint.CodeFirstExampleEntityEndpoint.java

@Override
public XmlExampleEntity getEntity(final Integer id) {
    final XmlExampleEntity response; // XML response with the entity data
    final ExampleEntity entity; // Found entity

    checkNotNull(id, "Received a null pointer as id");

    LOGGER.debug(String.format("Received request for id %d", id));

    // Acquires the entity
    entity = getExampleEntityService().findById(id);

    response = new XmlExampleEntity();
    BeanUtils.copyProperties(entity, response);

    LOGGER.debug(String.format("Found entity with id %1$d and name %2$s", entity.getId(), entity.getName()));

    return response;
}