private static ShowWsResponse buildResponse(ComponentDto component, OrganizationDto organizationDto, List<ComponentDto> orderedAncestors, Optional<SnapshotDto> lastAnalysis) { ShowWsResponse.Builder response = ShowWsResponse.newBuilder(); response.setComponent(componentDtoToWsComponent(component, organizationDto, lastAnalysis)); // ancestors are ordered from root to leaf, whereas it's the opposite in WS response int size = orderedAncestors.size() - 1; IntStream.rangeClosed(0, size).forEach( index -> response.addAncestors(componentDtoToWsComponent(orderedAncestors.get(size - index), organizationDto, lastAnalysis))); return response.build(); }
private static Components.Component.Builder toWsComponent(ComponentDto component, OrganizationDto organizationDto, Map<String, ComponentDto> referenceComponentsByUuid) { Components.Component.Builder wsComponent = componentDtoToWsComponent(component, organizationDto, Optional.empty()); ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid()); if (referenceComponent != null) { wsComponent.setRefId(referenceComponent.uuid()); wsComponent.setRefKey(referenceComponent.getKey()); } return wsComponent; }
static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, OrganizationDto organizationDto, Optional<SnapshotDto> lastAnalysis) { checkArgument( Objects.equals(dto.getOrganizationUuid(), organizationDto.getUuid()), "OrganizationUuid (%s) of ComponentDto to convert to Ws Component is not the same as the one (%s) of the specified OrganizationDto", dto.getOrganizationUuid(), organizationDto.getUuid()); return componentDtoToWsComponent(dto, organizationDto.getKey(), lastAnalysis); }
@Test public void componentDtoToWsComponent_throws_IAE_if_organization_uuid_of_component_does_not_match_organizationDto_uuid() { OrganizationDto organizationDto1 = OrganizationTesting.newOrganizationDto(); OrganizationDto organizationDto2 = OrganizationTesting.newOrganizationDto(); ComponentDto componentDto = ComponentTesting.newPrivateProjectDto(organizationDto1); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("OrganizationUuid (" + organizationDto1.getUuid() + ") of ComponentDto to convert " + "to Ws Component is not the same as the one (" + organizationDto2.getUuid() + ") of the specified OrganizationDto"); componentDtoToWsComponent(componentDto, organizationDto2, Optional.empty()); }
private static ShowWsResponse buildResponse(ComponentDto component, OrganizationDto organizationDto, List<ComponentDto> orderedAncestors, Optional<SnapshotDto> lastAnalysis) { ShowWsResponse.Builder response = ShowWsResponse.newBuilder(); response.setComponent(componentDtoToWsComponent(component, organizationDto, lastAnalysis)); // ancestors are ordered from root to leaf, whereas it's the opposite in WS response int size = orderedAncestors.size() - 1; IntStream.rangeClosed(0, size).forEach( index -> response.addAncestors(componentDtoToWsComponent(orderedAncestors.get(size - index), organizationDto, lastAnalysis))); return response.build(); }
private static Components.Component.Builder toWsComponent(ComponentDto component, OrganizationDto organizationDto, Map<String, ComponentDto> referenceComponentsByUuid) { Components.Component.Builder wsComponent = componentDtoToWsComponent(component, organizationDto, Optional.empty()); ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyResourceUuid()); if (referenceComponent != null) { wsComponent.setRefId(referenceComponent.uuid()); wsComponent.setRefKey(referenceComponent.getDbKey()); } return wsComponent; }
static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, OrganizationDto organizationDto, Optional<SnapshotDto> lastAnalysis) { checkArgument( Objects.equals(dto.getOrganizationUuid(), organizationDto.getUuid()), "OrganizationUuid (%s) of ComponentDto to convert to Ws Component is not the same as the one (%s) of the specified OrganizationDto", dto.getOrganizationUuid(), organizationDto.getUuid()); return componentDtoToWsComponent(dto, organizationDto.getKey(), lastAnalysis); }