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:com.logicaalternativa.ejemplomock.repository.mock.PromotionCodeRepositoryMock.java

private PromotionCode clone(final PromotionCode sourceObject) {

    final PromotionCode newObject = new PromotionCode();

    BeanUtils.copyProperties(sourceObject, newObject);

    return newObject;

}

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

/**
 * Private method to update the data in database<br>
 * The method specific 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/* w w  w  . jav a 2s . c o  m*/
 */
private T update(ReferenceBase 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());
            throw new Exception(e);
        }
    } else {
        logger.info("Class " + obj.getClass().getName()
                + " is not extend ReferenceBase class, cannot use Common saveOrUpdate method");
        return null;
    }
}

From source file:org.syncope.core.rest.data.UserRequestDataBinder.java

public UserRequestTO getUserRequestTO(final UserRequest request) {
    UserRequestTO result = new UserRequestTO();
    BeanUtils.copyProperties(request, result);

    return result;
}

From source file:com.oneops.search.msg.processor.DeploymentMessageProcessor.java

@Override
public void processMessage(String message, String msgType, String msgId) {
    CmsDeployment od = GSON.fromJson(message, CmsDeployment.class);
    String dpmtEventMessage = GSON_ES.toJson(od);
    indexer.indexEvent(DEPLOYMENT, dpmtEventMessage);
    CmsDeploymentSearch deployment = new CmsDeploymentSearch();
    BeanUtils.copyProperties(od, deployment);
    deployment = processDeploymentMsg(deployment);
    message = GSON_ES.toJson(deployment);
    indexer.index(String.valueOf(deployment.getDeploymentId()), DEPLOYMENT, message);
}

From source file:com.greenline.guahao.web.module.home.controllers.mobile.MobileHealthTopicController.java

/**
 * ?//w  w  w .  java 2  s .c  o  m
 * 
 * @return
 */
@MethodRemark(value = "remark=?,method=get")
@RequestMapping(value = "/mobile/jkx", method = RequestMethod.GET)
public String jkzgx(ModelMap model) {
    request.setAttribute("noBack", Boolean.TRUE);

    // ?
    HealthTopicsDO startHealthTopics = healthTopicsManager.getHealthTopicByState("2");
    // 
    HealthTopicsDO currentHealthTopics = healthTopicsManager.getHealthTopicByState("3");
    List<HealthTopicsDO> list = healthTopicsManager.queryHTContentListByPageQuery();
    List<HealthTopicsDO> result = new ArrayList<HealthTopicsDO>();
    HealthTopicsDO topic = new HealthTopicsDO();
    List<HealthTopicsContentDO> listVideos = new ArrayList<HealthTopicsContentDO>();
    for (HealthTopicsDO healthTopicsDO : list) {
        if (result.size() == 0) {
            BeanUtils.copyProperties(healthTopicsDO, topic);
            for (HealthTopicsDO healthTopics : list) {
                if (topic.getId().equals(healthTopics.getId())) {
                    HealthTopicsContentDO healthTopicsContentDO = new HealthTopicsContentDO();
                    healthTopicsContentDO.setTopicsID(healthTopics.getId());
                    healthTopicsContentDO.setTitle(healthTopics.getShortVideosTitle());
                    healthTopicsContentDO.setYoukuUrl(healthTopics.getShortYoukuUrl());
                    listVideos.add(healthTopicsContentDO);
                }
            }
            topic.setHealthTopicsShortVideos(listVideos);
            result.add(topic);
        } else {
            BeanUtils.copyProperties(healthTopicsDO, topic);
            boolean flag = false;
            for (HealthTopicsDO resultTopic : result) {
                if (topic.getId().equals(resultTopic.getId())) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                for (HealthTopicsDO healthTopics : list) {
                    if (topic.getId().equals(healthTopics.getId())) {
                        HealthTopicsContentDO healthTopicsContentDO = new HealthTopicsContentDO();
                        healthTopicsContentDO.setTopicsID(healthTopics.getId());
                        healthTopicsContentDO.setTitle(healthTopics.getShortVideosTitle());
                        healthTopicsContentDO.setYoukuUrl(healthTopics.getShortYoukuUrl());
                        listVideos.add(healthTopicsContentDO);
                    }
                }
                topic.setHealthTopicsShortVideos(listVideos);
                result.add(topic);
            }
        }
        if (list.indexOf(healthTopicsDO) != (list.size() - 1)) {
            topic = new HealthTopicsDO();
            listVideos = new ArrayList<HealthTopicsContentDO>();
        }
    }
    if (currentHealthTopics != null) {
        model.put("currentHealthTopics", currentHealthTopics);
    } else if (startHealthTopics != null) {
        model.put("currentHealthTopics", startHealthTopics);
    } else {
        model.put("currentHealthTopics", result.get(0));
    }

    model.put("list", result);
    return "mobile/jkx/index";
}

From source file:$.AccountSoapServiceImpl.java

@Override
    @AspectLogger(value = "", discover = true)
    public GetUserResult getUser(Integer id) {
        if (logger.isInfoEnabled())
            logger.info("??!");

        GetUserResult result = new GetUserResult();
        try {//from w w  w.java2s .  com

            Validate.notNull(id, "id?");

            UserPO userPo = accountDomain.getUser(id);

            Validate.notNull(userPo, "?(id:" + id + ")");
            UserSoapDTO userDto = new UserSoapDTO();

            BeanUtils.copyProperties(userPo, userDto);

            result.setUser(userDto);
            return result;
        } catch (IllegalArgumentException e) {
            if (logger.isErrorEnabled())
                logger.error(e.getMessage());

            return handleParameterError(result, e);
        } catch (RuntimeException e) {
            if (logger.isErrorEnabled())
                logger.error(e.getMessage());

            return handleGeneralError(result, e);
        }
    }

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

private List<RegistrationSummary> extractSummaries(List<Registration> registrations) {
    List<RegistrationSummary> summaries = new ArrayList<RegistrationSummary>();

    for (Registration registration : registrations) {
        RegistrationSummary summary = new RegistrationSummary();

        BeanUtils.copyProperties(registration, summary);

        summaries.add(summary);/*  ww w . j a  v  a2s  .  c om*/
    }

    return summaries;
}

From source file:com.ryo.log4j2.context.core.AbstractJacksonLayout.java

/**
 *  MyLog4jLogEvent/* www . jav a 2 s. c om*/
 * 1)  traceId
 * @return
 */
private static MyLog4jLogEvent buildMyLog4jLogEvent(final LogEvent event) {
    MyLog4jLogEvent myLog4jLogEvent = new MyLog4jLogEvent();
    LogEvent logEvent = convertMutableToLog4jEvent(event);
    BeanUtils.copyProperties(logEvent, myLog4jLogEvent);

    myLog4jLogEvent.setLoggerName(logEvent.getLoggerName());
    myLog4jLogEvent.setMessage(logEvent.getMessage());
    myLog4jLogEvent.setEndOfBatch(logEvent.isEndOfBatch());
    myLog4jLogEvent.setLoggerFqcn(logEvent.getLoggerFqcn());

    myLog4jLogEvent.setTraceId("2017-2-15 18:19:23 TRACE ID");
    myLog4jLogEvent.setLogId(AppContextUtil.getCurrentInvokeId());

    return myLog4jLogEvent;
}

From source file:org.openmrs.module.webservices.rest.resource.BaseRestDataResource.java

public static <E extends OpenmrsObject> void syncCollection(Collection<E> base, Collection<E> sync,
        Action2<Collection<E>, E> add, Action2<Collection<E>, E> remove) {
    Map<String, E> baseMap = new HashMap<String, E>(base.size());
    Map<String, E> syncMap = new HashMap<String, E>(sync.size());
    for (E item : base) {
        baseMap.put(item.getUuid(), item);
    }/*from  ww  w.ja v a 2s.  c  o  m*/
    for (E item : sync) {
        syncMap.put(item.getUuid(), item);
    }

    for (E item : baseMap.values()) {
        if (syncMap.containsKey(item.getUuid())) {
            // Update the existing item
            E syncItem = syncMap.get(item.getUuid());
            syncItem.setId(item.getId());

            BeanUtils.copyProperties(syncItem, item);
        } else {
            // Delete item that is not in the sync collection
            remove.apply(base, item);
        }
    }

    for (E item : syncMap.values()) {
        if (!baseMap.containsKey(item.getUuid())) {
            // Add the item not in the base collection
            add.apply(base, item);
        }
    }
}

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

@PreAuthorize("hasRole('LOGGER_SET_LEVEL')")
@RequestMapping(method = RequestMethod.POST, value = "/set/{name}/{level}")
public LoggerTO setLevel(@PathVariable("name") final String name, @PathVariable("level") final Level level) {

    SyncopeLogger syncopeLogger = loggerDAO.find(name);
    if (syncopeLogger == null) {
        syncopeLogger = new SyncopeLogger();
        syncopeLogger.setName(name);//w ww .  j a  v a2 s  .c o  m
    }
    syncopeLogger.setLevel(LoggerLevel.fromLevel(level));
    syncopeLogger = loggerDAO.save(syncopeLogger);

    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger logger = lc.getLogger(name);
    logger.setLevel(level);

    LoggerTO result = new LoggerTO();
    BeanUtils.copyProperties(syncopeLogger, result);
    return result;
}