private String getCreatedAttachmentContentId() throws TException {
   List<Release> importedReleases = componentClient.getReleaseSummary(user);
   sortByField(importedReleases, Release._Fields.VERSION);
   sortByField(importedReleases, Release._Fields.NAME);
   final Release release = importedReleases.get(4);
   final Set<Attachment> attachments = release.getAttachments();
   assertThat(attachments.size(), is(1));
   final Attachment theAttachment = getFirst(attachments);
   return theAttachment.getAttachmentContentId();
 }
예제 #2
0
  public VulnerabilityUpdateStatus updateForRelease(Release release) {
    Optional<List<CveSearchData>> cveSearchDatas = cveSearchWrapper.searchForRelease(release);
    if (!cveSearchDatas.isPresent()) {
      return new VulnerabilityUpdateStatus().setRequestStatus(RequestStatus.FAILURE);
    }

    CveSearchDataTranslator cveSearchDataTranslator = new CveSearchDataTranslator();
    List<CveSearchDataTranslator.VulnerabilityWithRelation> translated =
        cveSearchDatas
            .get()
            .stream()
            .map(cveSearchData -> cveSearchDataTranslator.apply(cveSearchData))
            .map(
                vulnerabilityWithRelation -> {
                  vulnerabilityWithRelation.relation.setReleaseId(release.getId());
                  return vulnerabilityWithRelation;
                })
            .collect(Collectors.toList());

    VulnerabilityUpdateStatus updateStatus = getEmptyVulnerabilityUpdateStatus();
    for (CveSearchDataTranslator.VulnerabilityWithRelation vulnerabilityWithRelation : translated) {
      updateStatus =
          vulnerabilityConnector.addOrUpdate(
              vulnerabilityWithRelation.vulnerability,
              vulnerabilityWithRelation.relation,
              updateStatus);
    }

    return updateStatus;
  }
예제 #3
0
  @Override
  public RequestStatus updateReleaseFossology(Release release, User user) throws TException {
    assertNotNull(release);
    assertId(release.getId());
    assertUser(user);

    return handler.updateRelease(release, user, ThriftUtils.immutableOfReleaseForFossology());
  }
예제 #4
0
  @Override
  public AddDocumentRequestSummary addRelease(Release release, User user) throws TException {
    assertNotNull(release);
    assertIdUnset(release.getId());
    assertUser(user);

    return handler.addRelease(release, user.getEmail());
  }
  @Test
  public void testFillRelease() throws Exception {
    final String releaseName = "myRelease";
    final String releaseVersion = "1.862b";

    final Release release = new Release();
    release.setName(releaseName).setVersion(releaseVersion);

    final ComponentAttachmentCSVRecordBuilder componentAttachmentCSVRecordBuilder =
        new ComponentAttachmentCSVRecordBuilder();
    componentAttachmentCSVRecordBuilder.fill(release);

    final ComponentAttachmentCSVRecord filledRecord = componentAttachmentCSVRecordBuilder.build();

    assertThat(
        filledRecord.getReleaseIdentifier(),
        is(SW360Utils.getVersionedName(releaseName, releaseVersion)));
  }
  private void assertExpectedComponentsInDb() throws TException {
    List<Component> importedComponents = componentClient.getComponentSummary(user);
    List<Release> importedReleases = componentClient.getReleaseSummary(user);

    assertThat(importedComponents, hasSize(7)); // see the test file
    assertThat(importedReleases, hasSize(8)); // see the test file

    sortByField(importedComponents, Component._Fields.NAME);
    sortByField(importedReleases, Release._Fields.VERSION);
    sortByField(importedReleases, Release._Fields.NAME);

    Component component = importedComponents.get(0);
    assertThat(component.getName(), is("7-Zip"));

    component = componentClient.getComponentById(component.getId(), user);
    assertThat(component.getName(), is("7-Zip"));
    assertThat(component.getHomepage(), is("http://commons.apache.org/proper/commons-exec"));
    assertThat(component.getVendorNames(), is(emptyOrNullCollectionOf(String.class)));
    assertThat(component.getAttachments(), is(emptyOrNullCollectionOf(Attachment.class)));
    assertThat(component.getCreatedBy(), equalTo(user.getEmail()));
    assertThat(component.getReleases(), is(not(nullValue())));
    assertThat(
        getReleaseIds(component.getReleases()),
        containsInAnyOrder(importedReleases.get(0).getId(), importedReleases.get(1).getId()));

    final Release release = importedReleases.get(4);
    assertThat(release.getVersion(), is("1.2.11"));
    // This release has an download url so the import creates an attachmen
    final Set<Attachment> attachments = release.getAttachments();
    assertThat(attachments.size(), is(1));
    final Attachment theAttachment = getFirst(attachments);
    final String attachmentContentId = theAttachment.getAttachmentContentId();

    final AttachmentContent attachmentContent =
        attachmentClient.getAttachmentContent(attachmentContentId);

    assertThat(attachmentContent.isOnlyRemote(), is(true));

    assertThat(attachmentContent.getRemoteUrl(), is(REMOTE_URL));
  }