private static Project addBranchChange(Collection<EventComponentChangeDto> changes) { if (changes.size() != 2) { throw new IllegalStateException(format("Too many changes on same project (%d) for eventComponentChange uuids : %s", changes.size(), changes.stream().map(EventComponentChangeDto::getUuid).collect(Collectors.joining(",")))); } Optional<EventComponentChangeDto> addedChange = changes.stream().filter(c -> c.getCategory().equals(EventComponentChangeDto.ChangeCategory.ADDED)).findFirst(); Optional<EventComponentChangeDto> removedChange = changes.stream().filter(c -> c.getCategory().equals(EventComponentChangeDto.ChangeCategory.REMOVED)).findFirst(); if (!addedChange.isPresent() || !removedChange.isPresent() || addedChange.equals(removedChange)) { Iterator<EventComponentChangeDto> iterator = changes.iterator(); // We are missing two different ADDED and REMOVED changes EventComponentChangeDto firstChange = iterator.next(); EventComponentChangeDto secondChange = iterator.next(); throw new IllegalStateException(format("Incorrect changes : [uuid=%s change=%s, branch=%s] and [uuid=%s, change=%s, branch=%s]", firstChange.getUuid(), firstChange.getCategory().name(), firstChange.getComponentBranchKey(), secondChange.getUuid(), secondChange.getCategory().name(), secondChange.getComponentBranchKey())); } return new Project() .setName(addedChange.get().getComponentName()) .setKey(addedChange.get().getComponentKey()) .setChangeType("BRANCH_CHANGED") .setNewBranch(addedChange.get().getComponentBranchKey()) .setOldBranch(removedChange.get().getComponentBranchKey()); }
private static ProjectAnalyses.Failing toFailing(EventComponentChangeDto change) { ProjectAnalyses.Failing.Builder builder = ProjectAnalyses.Failing.newBuilder() .setKey(change.getComponentKey()) .setName(change.getComponentName()); if (change.getComponentBranchKey() != null) { builder.setBranch(change.getComponentBranchKey()); } return builder.build(); }
private static Project addSingleChange(EventComponentChangeDto componentChange) { Project project = new Project() .setKey(componentChange.getComponentKey()) .setName(componentChange.getComponentName()) .setBranch(componentChange.getComponentBranchKey()); switch (componentChange.getCategory()) { case ADDED: project.setChangeType("ADDED"); break; case REMOVED: project.setChangeType("REMOVED"); break; default: throw new IllegalStateException(format("Unknown change %s for eventComponentChange uuid: %s", componentChange.getCategory(), componentChange.getUuid())); } return project; }
dto.getComponentKey(), dto.getComponentName(), dto.getComponentBranchKey(), now));
dto.getComponentKey(), dto.getComponentName(), dto.getComponentBranchKey(), now));