List of usage examples for org.springframework.beans BeanUtils copyProperties
public static void copyProperties(Object source, Object target, String... ignoreProperties) throws BeansException
From source file:de.steilerdev.myVerein.server.model.Message.java
/** * This function copies the current object, ignoring the member fields specified by the ignored properties vararg. * @param ignoredProperties The member fields ignored during the copying. * @return A copy of the current object, not containing information about the ignored properties. *///from w ww . ja v a2 s . c o m @JsonIgnore @Transient private Message getSendingObject(String... ignoredProperties) { Message sendingObject = new Message(); BeanUtils.copyProperties(this, sendingObject, ignoredProperties); return sendingObject; }
From source file:de.steilerdev.myVerein.server.model.Division.java
/** * This function copies the current object, ignoring the member fields specified by the ignored properties vararg. * @param ignoredProperties The member fields ignored during the copying. * @return A copy of the current object, not containing information about the ignored properties. *//* w w w .ja v a 2s . c om*/ @JsonIgnore @Transient private Division getSendingObject(String... ignoredProperties) { Division sendingObject = new Division(); BeanUtils.copyProperties(this, sendingObject, ignoredProperties); return sendingObject; }
From source file:com.ylink.ylpay.project.mp.workorder.service.WorkOrderManagerImpl.java
private WorkOrder dtoToEntity(WorkOrderDTO workOrderDTO) { if (workOrderDTO == null) return null; WorkOrder workOrder = new WorkOrder(); BeanUtils.copyProperties(workOrderDTO, workOrder, new String[] { "type", "status", "plate", "id" }); if (workOrderDTO.getId() != null) { workOrder.setId(Long.parseLong(workOrderDTO.getId())); }//from www. java2 s. com return workOrder; }
From source file:org.syncope.core.rest.data.TaskDataBinder.java
public TaskTO getTaskTO(final Task task, final TaskUtil taskUtil) { TaskTO taskTO = taskUtil.newTaskTO(); BeanUtils.copyProperties(task, taskTO, IGNORE_TASK_PROPERTIES); TaskExec latestExec = taskExecDAO.findLatestStarted(task); taskTO.setLatestExecStatus(latestExec == null ? "" : latestExec.getStatus()); for (TaskExec execution : task.getExecs()) { taskTO.addExecution(getTaskExecTO(execution)); }//ww w . j a v a2s .co m switch (taskUtil) { case PROPAGATION: ((PropagationTaskTO) taskTO).setResource(((PropagationTask) task).getResource().getName()); if (((PropagationTask) task).getSyncopeUser() != null) { ((PropagationTaskTO) taskTO).setUser(((PropagationTask) task).getSyncopeUser().getId()); } break; case SCHED: setExecTime((SchedTaskTO) taskTO, task); break; case SYNC: setExecTime((SchedTaskTO) taskTO, task); ((SyncTaskTO) taskTO).setResource(((SyncTask) task).getResource().getName()); break; case NOTIFICATION: break; default: } return taskTO; }
From source file:com.ylink.ylpay.project.mp.workorder.service.WorkOrderManagerImpl.java
private WorkOrderDTO entityToDTO(WorkOrder workOrder) { if (workOrder == null) return null; WorkOrderDTO workOrderDTO = new WorkOrderDTO(); BeanUtils.copyProperties(workOrder, workOrderDTO, new String[] { "type", "status", "plate", "id" }); if (workOrder.getId() != null) { workOrderDTO.setId(workOrder.getId().toString()); }// w w w. ja va 2 s . c o m return workOrderDTO; }
From source file:com.hybris.integration.service.tmall.impl.BaseServiceImpl.java
private void checkTheTokenIsValidAndUpdateAccessToken(final AccessToken accessToken) throws TmallAppException { final long nowTimeStamp = System.currentTimeMillis(); //Whether the current token expired if (nowTimeStamp > accessToken.getExpireTime()) { // Default refresh failed boolean refreshFlag = true; LOGGER.trace("Refresh token valid time:" + new Date(accessToken.getRefreshTokenValidTime())); //Whether the current refresh token expired if (nowTimeStamp < accessToken.getRefreshTokenValidTime()) { try { final AccessToken newAccessToken = refresh(accessToken.getAppkey(), accessToken.getSecret(), accessToken.getRefreshToken()); final String[] ignoreProperties = new String[] { "appkey", "secret", "integrationId", "authorized", "marketplaceStoreId" }; BeanUtils.copyProperties(newAccessToken, accessToken, ignoreProperties); this.save(accessToken); refreshFlag = false;/* w ww .j av a 2s . co m*/ } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } } //If refresh fails, it sends a message notification token has expired if (refreshFlag) { accessToken.setAuthorized("false"); accessToken.setSecret(null); dhAuthService.saveAuthInfo(accessToken); LOGGER.error("Token has been completely invalid, please re-login authorization."); throw new TmallAppException(ResponseCode.OBJECT_EXPIRED.getCode(), "Token has been completely invalid, please re-login authorization."); } } }
From source file:org.shept.persistence.provider.DaoUtils.java
private static Object copyTemplate_Experimental(HibernateDaoSupport dao, Object entityModelTemplate) { ClassMetadata modelMeta = getClassMetadata(dao, entityModelTemplate); if (null == modelMeta) { return null; }//w ww. j a v a 2s . c om String idName = modelMeta.getIdentifierPropertyName(); Object modelCopy = BeanUtils.instantiateClass(entityModelTemplate.getClass()); BeanUtils.copyProperties(entityModelTemplate, modelCopy, new String[] { idName }); Type idType = modelMeta.getIdentifierType(); if (null == idType || !idType.isComponentType()) { return modelCopy; } Object idValue = modelMeta.getPropertyValue(entityModelTemplate, idName, EntityMode.POJO); if (null == idValue) { return modelCopy; } Object idCopy = BeanUtils.instantiate(idValue.getClass()); BeanUtils.copyProperties(idValue, idCopy); if (null == idValue || (null != idType)) { return modelCopy; } Method idMth = ReflectionUtils.findMethod(entityModelTemplate.getClass(), "set" + StringUtils.capitalize(idName), new Class[] {}); if (idMth != null) { ReflectionUtils.invokeMethod(idMth, modelCopy, idCopy); } return modelCopy; }
From source file:com.arvato.thoroughly.service.tmall.impl.BaseServiceImpl.java
private void checkTheTokenIsValidAndUpdateAccessToken(final AccessToken accessToken) throws TmallAppException { final long nowTimeStamp = System.currentTimeMillis(); //Whether the current token expired if (nowTimeStamp > accessToken.getExpireTime()) { // Default refresh failed boolean refreshFlag = true; LOGGER.trace("Refresh token valid time:" + new Date(accessToken.getRefreshTokenValidTime())); //Whether the current refresh token expired if (nowTimeStamp < accessToken.getRefreshTokenValidTime()) { try { final AccessToken newAccessToken = refresh(accessToken.getAppkey(), accessToken.getSecret(), accessToken.getRefreshToken()); final String[] ignoreProperties = new String[] { "appkey", "secret", "integrationId", "authorized", "marketplaceStoreId" }; BeanUtils.copyProperties(newAccessToken, accessToken, ignoreProperties); this.save(accessToken); refreshFlag = false;// w ww .j av a2s . co m } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } } //If refresh fails, it sends a message notification token has expired if (refreshFlag) { accessToken.setAuthorized("false"); accessToken.setSecret(null); // dhAuthService.saveAuthInfo(accessToken); LOGGER.error("Token has been completely invalid, please re-login authorization."); throw new TmallAppException(ResponseCode.OBJECT_EXPIRED.getCode(), "Token has been completely invalid, please re-login authorization."); } } }
From source file:ch.silviowangler.dox.export.DoxExporterImpl.java
private Set<DocumentClass> processDocumentClasses(Set<ch.silviowangler.dox.api.DocumentClass> documentClasses) { Set<DocumentClass> docClasses = new HashSet<>(documentClasses.size()); for (ch.silviowangler.dox.api.DocumentClass documentClass : documentClasses) { logger.debug("Processing document class {}", documentClass); try {//from w w w .j a va2 s . com SortedSet<ch.silviowangler.dox.api.Attribute> attributes = documentService .findAttributes(documentClass); Set<Attribute> exportAttributes = Sets.newHashSetWithExpectedSize(attributes.size()); for (ch.silviowangler.dox.api.Attribute attribute : attributes) { Attribute exportAttribute = new Attribute(); BeanUtils.copyProperties(attribute, exportAttribute, new String[] { "domain" }); if (attribute.containsDomain()) { Domain domain = new Domain(attribute.getDomain().getShortName()); for (String domainValue : attribute.getDomain().getValues()) { domain.getValues().add(domainValue); } exportAttribute.setDomain(domain); } exportAttributes.add(exportAttribute); } docClasses.add(new DocumentClass(exportAttributes, documentClass.getShortName())); } catch (DocumentClassNotFoundException e) { logger.error("Unexpected error. That document class must exist {}", documentClass, e); } } return docClasses; }
From source file:mx.edu.um.mateo.inventario.dao.impl.ProductoDaoHibernate.java
@Override public Producto actualiza(Producto otro, Usuario usuario) { Date fecha = new Date(); Session session = currentSession(); Producto producto = (Producto) session.get(Producto.class, otro.getId()); BeanUtils.copyProperties(otro, producto, new String[] { "id", "version", "precioUnitario", "ultimoPrecio", "existencia", "puntoReorden", "tipoProducto", "almacen", "imagenes", "fechaCreacion", "fechaInactivo", "inactivo" }); producto.setTipoProducto((TipoProducto) session.get(TipoProducto.class, otro.getTipoProducto().getId())); if (otro.getInactivo() && (producto.getInactivo() == null || !producto.getInactivo())) { producto.setInactivo(true);//from www .j av a2s. com producto.setFechaInactivo(fecha); } else if (!otro.getInactivo() && producto.getInactivo() != null && producto.getInactivo()) { producto.setInactivo(false); producto.setFechaInactivo(null); } producto.setFechaModificacion(fecha); if (producto.getImagenes().size() > 0) { Imagen imagen = producto.getImagenes().get(0); producto.getImagenes().clear(); producto.getImagenes().add(otro.getImagenes().get(0)); session.delete(imagen); session.flush(); } else if (otro.getImagenes() != null && otro.getImagenes().size() > 0) { producto.getImagenes().add(otro.getImagenes().get(0)); } session.update(producto); audita(producto, usuario, Constantes.ACTUALIZAR, fecha); session.flush(); return producto; }