/** * Write <code>subscription;project;projetKey;projectName;node</code>. * * @param writer * Target output. * @param subscription * Related subscription. */ private void writeCommon(final Writer writer, final Subscription subscription) throws IOException { final Project project = subscription.getProject(); writer.write('\n'); writer.write(String.valueOf(subscription.getId())); writer.write(';'); writer.write(String.valueOf(project.getId())); writer.write(';'); writer.write(project.getPkey()); writer.write(';'); writer.write(project.getName().replaceAll("\"", "'")); writer.write(';'); writer.write(subscription.getNode().getId()); }
@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; }
@Override public void create(final int subscription) { final Map<String, String> parameters = subscriptionResource.getParameters(subscription); final String group = parameters.get(IdentityResource.PARAMETER_GROUP); final String parentGroup = parameters.get(IdentityResource.PARAMETER_PARENT_GROUP); final String ou = parameters.get(IdentityResource.PARAMETER_OU); final Project project = subscriptionRepository.findOne(subscription).getProject(); final String pkey = project.getPkey(); // Check the relationship between group, OU and project validateGroup(group, ou, pkey); // Check the relationship between group, and parent final String parentDn = validateAndCreateParent(group, parentGroup, ou, pkey); // Create the group inside the parent (OU or parent CN) final String groupDn = "cn=" + group + "," + parentDn; log.info("New Group CN would be created {} project {} and subscription {}", group, pkey); final GroupLdapRepository repository = getGroup(); final GroupOrg groupLdap = repository.create(groupDn, group); // Complete as needed the relationship between parent and this new group if (StringUtils.isNotBlank(parentGroup)) { // This group will be added as "uniqueMember" of its parent repository.addGroup(groupLdap, parentGroup); } // Associate the project to this group in the cache final CacheProjectGroup projectGroup = new CacheProjectGroup(); projectGroup.setProject(project); projectGroup.setGroup(repository.getCacheRepository().findOneExpected(groupLdap.getId())); cacheProjectGroupRepository.saveAndFlush(projectGroup); }