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 componentDtoToWsComponent(ComponentDto dto, String organizationDtoKey, Optional<SnapshotDto> lastAnalysis) { Components.Component.Builder wsComponent = Components.Component.newBuilder() .setOrganization(organizationDtoKey) .setId(dto.uuid()) .setKey(dto.getKey()) .setName(dto.name()) .setQualifier(dto.qualifier()); ofNullable(emptyToNull(dto.getBranch())).ifPresent(wsComponent::setBranch); ofNullable(emptyToNull(dto.getPullRequest())).ifPresent(wsComponent::setPullRequest); ofNullable(emptyToNull(dto.path())).ifPresent(wsComponent::setPath); ofNullable(emptyToNull(dto.description())).ifPresent(wsComponent::setDescription); ofNullable(emptyToNull(dto.language())).ifPresent(wsComponent::setLanguage); setTags(dto, wsComponent); lastAnalysis.ifPresent( analysis -> { wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt())); ofNullable(analysis.getPeriodDate()).ifPresent(leak -> wsComponent.setLeakPeriodDate(formatDateTime(leak))); ofNullable(analysis.getVersion()).ifPresent(wsComponent::setVersion); }); if (QUALIFIERS_WITH_VISIBILITY.contains(dto.qualifier())) { wsComponent.setVisibility(Visibility.getLabel(dto.isPrivate())); } return wsComponent; }
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; }
private static Components.Component.Builder componentDtoToWsComponent(ComponentDto dto, String organizationDtoKey, Optional<SnapshotDto> lastAnalysis) { Components.Component.Builder wsComponent = Components.Component.newBuilder() .setOrganization(organizationDtoKey) .setId(dto.uuid()) .setKey(dto.getKey()) .setName(dto.name()) .setQualifier(dto.qualifier()); setNullable(emptyToNull(dto.getBranch()), wsComponent::setBranch); setNullable(emptyToNull(dto.getPullRequest()), wsComponent::setPullRequest); setNullable(emptyToNull(dto.path()), wsComponent::setPath); setNullable(emptyToNull(dto.description()), wsComponent::setDescription); setNullable(emptyToNull(dto.language()), wsComponent::setLanguage); setTags(dto, wsComponent); lastAnalysis.ifPresent( analysis -> { wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt())); setNullable(analysis.getPeriodDate(), leak -> wsComponent.setLeakPeriodDate(formatDateTime(leak))); setNullable(analysis.getVersion(), wsComponent::setVersion); }); if (QUALIFIERS_WITH_VISIBILITY.contains(dto.qualifier())) { wsComponent.setVisibility(Visibility.getLabel(dto.isPrivate())); } 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); }