/** * Copy data from the memory object to the cache entity. */ private <T extends CacheContainer> T fillCacheContainer(final ContainerOrg container, final T entity) { DescribedBean.copy(container, entity); return entity; }
/** * From a {@link IDescribableBean} to a new {@link DescribedBean} bean clone. * * @param <T> * Bean type. * @param from * the {@link IDescribableBean} source. May be null. * @return <code>null</code> or new {@link DescribedBean} instance copied from the source. */ public static <T extends Serializable> DescribedBean<T> clone(final IDescribableBean<T> from) { if (from == null) { return null; } final DescribedBean<T> bean = new DescribedBean<>(); copy(from, bean); return bean; }
/** * /** Converter from {@link ProjectEditionVo} to {@link Project} */ private static Project toEntity(final ProjectEditionVo vo) { final Project entity = new Project(); // map project DescribedBean.copy(vo, entity); entity.setPkey(vo.getPkey()); entity.setTeamLeader(vo.getTeamLeader()); return entity; }
@Override public ProjectVo apply(final Project entity) { final ProjectVo vo = new ProjectVo(); vo.copyAuditData(entity, userConverter); DescribedBean.copy(entity, vo); vo.setPkey(entity.getPkey()); vo.setTeamLeader(userConverter.apply(entity.getTeamLeader())); // Build the subscriptions final Map<Integer, SubscriptionVo> subscriptions = new TreeMap<>(); for (final Object[] resultSet : this.subscriptionsAndParam) { // Add subscription value final ParameterValue parameterValue = (ParameterValue) resultSet[1]; addVo(subscriptions, (Subscription) resultSet[0]).getParameters().put(parameterValue.getParameter().getId(), ParameterValueResource.parseValue(parameterValue, new ParameterValueVo())); } // Merge with subscription without parameters entity.getSubscriptions().forEach(s -> addVo(subscriptions, s)); // Return the subscription to order by the related node vo.setSubscriptions(subscriptions.values().stream().sorted(Comparator.comparing(s -> s.getNode().getId(), String::compareTo)) .collect(Collectors.toList())); return vo; }
/** * Converter from {@link Project} to {@link ProjectLightVo} without subscription count. * * @param entity * Entity to convert. * @return The project description without subscription counter. */ public ProjectLightVo toVoLight(final Project entity) { // Convert users, project and subscriptions final ProjectLightVo vo = new ProjectLightVo(); vo.copyAuditData(entity, toUser()); DescribedBean.copy(entity, vo); vo.setPkey(entity.getPkey()); vo.setTeamLeader(toUser().apply(entity.getTeamLeader())); return vo; }
private void save(final SlaEditionVo vo, final Sla entity) { DescribedBean.copy(vo, entity); entity.setStop(StringUtils.join(identifierHelper.normalize(vo.getStop()), ',')); entity.setStart(StringUtils.join(identifierHelper.normalize(vo.getStart()), ',')); entity.setThreshold(vo.getThreshold()); vo.setPause(ObjectUtils.defaultIfNull(vo.getPause(), new ArrayList<>())); vo.setPriorities(ObjectUtils.defaultIfNull(vo.getPriorities(), new ArrayList<>())); vo.setResolutions(ObjectUtils.defaultIfNull(vo.getResolutions(), new ArrayList<>())); vo.setTypes(ObjectUtils.defaultIfNull(vo.getTypes(), new ArrayList<>())); checkSlaBounds(vo); entity.setPause(StringUtils.join(identifierHelper.normalize(vo.getPause()), ',')); entity.setPriorities(StringUtils.join(vo.getPriorities(), ',')); entity.setResolutions(StringUtils.join(vo.getResolutions(), ',')); entity.setTypes(StringUtils.join(vo.getTypes(), ',')); slaRepository.saveAndFlush(entity); }
/** * Update project. Should be protected with RBAC. * * @param vo * the object to save. */ @PUT public void update(final ProjectEditionVo vo) { // pkey can't be updated if there is at least subscription. final Project project = repository.findOneExpected(vo.getId()); final long nbSubscriptions = subscriptionRepository.countByProject(vo.getId()); if (nbSubscriptions == 0) { project.setPkey(vo.getPkey()); } DescribedBean.copy(vo, project); project.setTeamLeader(vo.getTeamLeader()); repository.saveAndFlush(project); }
/** * Prepare SLA configuration to optimize the computations. * * @param slas * the fresh SLA entities. * @return the SLA configuration where status identifiers have been resolved to text. Paused statuses are ordered. */ public List<SlaConfiguration> toSlaConfiguration(final List<Sla> slas) { final List<SlaConfiguration> slaConfigurations = new ArrayList<>(); for (final Sla sla : slas) { // Build the SLA configuration final SlaConfiguration configuration = new SlaConfiguration(); configuration.setPause(identifierHelper.normalize(identifierHelper.asList(sla.getPause()))); configuration.setStart(identifierHelper.normalize(identifierHelper.asList(sla.getStart()))); configuration.setStop(identifierHelper.normalize(identifierHelper.asList(sla.getStop()))); configuration.setPriorities(identifierHelper.asList(sla.getPriorities())); configuration.setResolutions(identifierHelper.asList(sla.getResolutions())); configuration.setTypes(identifierHelper.asList(sla.getTypes())); configuration.setThreshold(sla.getThreshold()); DescribedBean.copy(sla, configuration); slaConfigurations.add(configuration); } return slaConfigurations; }