Search in sources :

Example 76 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class FossologyFileHandler method sendToFossology.

public RequestStatus sendToFossology(String releaseId, User user, String clearingTeam) throws TException {
    Release release;
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    release = getReleaseAndUnlockIt(releaseId, user, componentClient);
    Set<Attachment> sourceAttachments = getSourceAttachment(releaseId, user, componentClient);
    if (sourceAttachments.size() != 1) {
        log.error("release " + releaseId + " does not have a single source attachment");
        // TODO return a summary and better fitting status
        return RequestStatus.FAILURE;
    }
    final Attachment attachment = getFirst(sourceAttachments);
    final FilledAttachment filledAttachment = fillAttachment(attachment);
    if (!release.isSetFossologyId()) {
        /* send the attachment as a new upload */
        AttachmentContent attachmentContent = filledAttachment.getAttachmentContent();
        return sendToFossologyNewUpload(release, user, clearingTeam, attachmentContent, componentClient);
    } else {
        if (!checkSourceAttachment(release, filledAttachment)) {
            // TODO summary
            return RequestStatus.FAILURE;
        } else {
            /* duplicate the old upload making it visible for clearingTeam */
            return sendToFossologyExistingUpload(release, user, clearingTeam, componentClient);
        }
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 77 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class TestComponentClient method main.

public static void main(String[] args) throws TException, IOException {
    THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/components/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    ComponentService.Iface client = new ComponentService.Client(protocol);
// List<Component> components = client.getComponentSummary(user);
// List<Component> recentComponents = client.getRecentComponents();
// List<Release> releases = client.getReleaseSummary(user);
// 
// System.out.println("Fetched " + components.size() + " components from license service");
// System.out.println("Fetched " + releases.size() + " releases from license service");
// System.out.println("Fetched " + recentComponents.size() + " recent components from license service");
// 
// String referenceId =null;
// for (Component component : recentComponents) {
// if(referenceId==null) referenceId=component.getId();
// System.out.println(component.getId() + ": " + component.getName());
// }
// 
// if(referenceId!=null) {
// System.out.println(client.getComponentById(referenceId, user).toString());
// Component component = new ComponentHandler("http://localhost:5984", "sw360db", "sw360attachments").getComponentById(referenceId, user);
// System.out.println(component.toString());
// System.out.println(client.getComponentById(referenceId, user).toString());
// }
// 
// for(Release release : releases) {
// System.out.println(release.toString());
// }
// // This fails with a thrift error... debug!
// if(releases.size()>0) {
// String releaseNameStart = releases.get(0).getName().substring(0,1);
// System.out.println("The following releases start with " + releaseNameStart );
// 
// List<Release> releases1 = client.searchReleaseByName(releaseNameStart);
// for(Release release : releases1) {
// System.out.println(release.toString());
// }
// 
// }
// final Component cpe = client.getComponentForReportFromCPEId("cpe");
// System.out.println(cpe.toString());
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) THttpClient(org.apache.thrift.transport.THttpClient)

Example 78 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class SearchLevels method guessForRelease.

private List<NeedleWithMeta> guessForRelease(CveSearchGuesser cveSearchGuesser, Release release, boolean useVersionInformation) throws IOException {
    if (useVersionInformation && !release.isSetVersion()) {
        return Collections.emptyList();
    }
    List<Match> vendorProductList;
    String productHaystack = release.getName();
    if (release.isSetVendor() && (release.getVendor().isSetShortname() || release.getVendor().isSetFullname())) {
        String vendorHaystack = nullToEmptyString(release.getVendor().getShortname()) + " " + nullToEmptyString(release.getVendor().getFullname());
        vendorProductList = cveSearchGuesser.guessVendorAndProducts(vendorHaystack, productHaystack);
    } else {
        vendorProductList = cveSearchGuesser.guessVendorAndProducts(productHaystack);
    }
    String cpeNeedlePostfix = ":" + (useVersionInformation ? release.getVersion() : "") + CPE_WILDCARD;
    Function<String, String> cpeBuilder = cpeNeedle -> CPE_NEEDLE_PREFIX + cpeNeedle + cpeNeedlePostfix;
    return vendorProductList.stream().map(match -> new NeedleWithMeta(cpeBuilder.apply(match.getNeedle()), "heuristic (dist. " + (useVersionInformation ? "0" : "1") + match.getDistance() + ")")).collect(Collectors.toList());
}
Also used : Properties(java.util.Properties) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Predicate(java.util.function.Predicate) Match(org.eclipse.sw360.cvesearch.datasource.matcher.Match) CveSearchApi(org.eclipse.sw360.cvesearch.datasource.CveSearchApi) IOException(java.io.IOException) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Logger(org.apache.log4j.Logger) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) List(java.util.List) Stream(java.util.stream.Stream) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString) CveSearchGuesser(org.eclipse.sw360.cvesearch.datasource.CveSearchGuesser) Collections(java.util.Collections) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString) Match(org.eclipse.sw360.cvesearch.datasource.matcher.Match)

Example 79 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class ReleaseLinkCSVRecordBuilderTest method testFillRelease.

@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 ReleaseLinkCSVRecordBuilder releaseLinkCSVRecordBuilder = new ReleaseLinkCSVRecordBuilder();
    releaseLinkCSVRecordBuilder.fill(release);
    final ReleaseLinkCSVRecord filledRecord = releaseLinkCSVRecordBuilder.build();
    assertThat(filledRecord.getReleaseIdentifier(), is(SW360Utils.getVersionedName(releaseName, releaseVersion)));
}
Also used : Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 80 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class ReleaseLinkCSVRecordBuilderTest method testFillLinkedRelease.

@Test
public void testFillLinkedRelease() throws Exception {
    final String releaseName = "myRelease";
    final String releaseVersion = "1.862b";
    final Release release = new Release();
    release.setName(releaseName).setVersion(releaseVersion);
    final ReleaseLinkCSVRecordBuilder releaseLinkCSVRecordBuilder = new ReleaseLinkCSVRecordBuilder();
    releaseLinkCSVRecordBuilder.fillLinking(release);
    final ReleaseLinkCSVRecord filledRecord = releaseLinkCSVRecordBuilder.build();
    assertThat(filledRecord.getLinkedReleaseIdentifier(), is(SW360Utils.getVersionedName(releaseName, releaseVersion)));
}
Also used : Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)93 User (org.eclipse.sw360.datahandler.thrift.users.User)42 TException (org.apache.thrift.TException)38 Test (org.junit.Test)23 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)20 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)13 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)13 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)12 FieldMetaData (org.apache.thrift.meta_data.FieldMetaData)11 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)11 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)10 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)7 Before (org.junit.Before)7 Collectors (java.util.stream.Collectors)6 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)6 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)6 IOException (java.io.IOException)5