Search in sources :

Example 81 with Release

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

the class ComponentSummary method summary.

@Override
protected Component summary(SummaryType type, Component document) {
    Component copy = new Component();
    if (type == SummaryType.EXPORT_SUMMARY) {
        List<Release> releases = releaseRepository.getReleasesFromComponentId(document.getId());
        return makeExportSummary(document, releases);
    } else if (type == SummaryType.DETAILED_EXPORT_SUMMARY) {
        List<Release> releases = releaseRepository.getReleasesFromComponentId(document.getId());
        final Map<String, Vendor> vendorsById = ThriftUtils.getIdMap(vendorRepository.getAll());
        for (Release release : releases) {
            if (!release.isSetVendor() && release.isSetVendorId()) {
                release.setVendor(vendorsById.get(release.getVendorId()));
            }
        }
        return makeDetailedExportSummary(document, releases);
    } else if (type == SummaryType.HOME) {
        copyField(document, copy, Component._Fields.ID);
        copyField(document, copy, Component._Fields.DESCRIPTION);
    }
    copyField(document, copy, Component._Fields.ID);
    copyField(document, copy, Component._Fields.NAME);
    copyField(document, copy, Component._Fields.VENDOR_NAMES);
    copyField(document, copy, Component._Fields.COMPONENT_TYPE);
    if (type == SummaryType.SUMMARY) {
        for (Component._Fields field : Component.metaDataMap.keySet()) {
            copyField(document, copy, field);
        }
    }
    return copy;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 82 with Release

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

the class ReleaseSummary method makeSummary.

@Override
public List<Release> makeSummary(SummaryType type, Collection<Release> fullDocuments) {
    if (fullDocuments == null)
        return Collections.emptyList();
    Set<String> vendorIds = fullDocuments.stream().map(Release::getVendorId).filter(Objects::nonNull).filter(s -> !s.isEmpty()).collect(Collectors.toSet());
    Map<String, Vendor> vendorById = ThriftUtils.getIdMap(vendorRepository.get(vendorIds));
    List<Release> documents = new ArrayList<>(fullDocuments.size());
    for (Release fullDocument : fullDocuments) {
        Release document = summary(type, fullDocument, vendorById::get);
        if (document != null)
            documents.add(document);
    }
    return documents;
}
Also used : ThriftUtils(org.eclipse.sw360.datahandler.thrift.ThriftUtils) Strings(com.google.common.base.Strings) ReleaseExporter(org.eclipse.sw360.exporter.ReleaseExporter) java.util(java.util) VendorRepository(org.eclipse.sw360.datahandler.db.VendorRepository) Release(org.eclipse.sw360.datahandler.thrift.components.Release) ThriftUtils.copyField(org.eclipse.sw360.datahandler.thrift.ThriftUtils.copyField) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release._Fields(org.eclipse.sw360.datahandler.thrift.components.Release._Fields) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 83 with Release

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

the class ReleaseSummary method summary.

protected Release summary(SummaryType type, Release document, Function<String, Vendor> vendorProvider) {
    Release copy = new Release();
    if (type == SummaryType.DETAILED_EXPORT_SUMMARY) {
        setDetailedExportSummaryFields(document, copy);
    } else {
        setShortSummaryFields(document, copy);
        if (type != SummaryType.SHORT) {
            setAdditionalFieldsForSummariesOtherThanShortAndDetailedExport(document, copy);
        }
    }
    if (document.isSetVendorId()) {
        final String vendorId = document.getVendorId();
        if (!Strings.isNullOrEmpty(vendorId)) {
            Vendor vendor = vendorProvider.apply(vendorId);
            copy.setVendor(vendor);
        }
    }
    return copy;
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 84 with Release

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

the class ProjectDatabaseHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    assertTestString(dbName);
    assertTestString(attachmentsDbName);
    List<Project> projects = new ArrayList<>();
    Project p1 = new Project().setId("P1").setName("Project1").setBusinessUnit("AB CD EF").setCreatedBy("user1").setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r4", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r5", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r6", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
    projects.add(p1);
    Project p2 = new Project().setId("P2").setName("Project2").setBusinessUnit("AB CD FE").setCreatedBy("user2").setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r3", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build());
    projects.add(p2);
    projects.get(1).addToContributors("user1");
    projects.add(new Project().setId("P3").setName("Project3").setBusinessUnit("AB CD EF").setCreatedBy("user3"));
    Project p4 = new Project().setId("P4").setName("Project4").setBusinessUnit("AB CD EF").setCreatedBy("user1").setVisbility(Visibility.PRIVATE).setReleaseIdToUsage(ImmutableMap.<String, ProjectReleaseRelationship>builder().put("r1", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).put("r2", new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE)).build()).setLinkedProjects(ImmutableMap.<String, ProjectRelationship>builder().put("P5", ProjectRelationship.CONTAINED).build());
    projects.add(p4);
    projects.add(new Project().setId("P5").setName("Project5").setBusinessUnit("AB CD EF").setCreatedBy("user1"));
    List<Release> releases = new ArrayList<>();
    releases.add(new Release().setId("r1").setComponentId("c1"));
    releases.add(new Release().setId("r2").setComponentId("c1"));
    releases.add(new Release().setId("r3").setComponentId("c1"));
    releases.add(new Release().setId("r4").setComponentId("c1"));
    releases.add(new Release().setId("r5").setComponentId("c1"));
    releases.add(new Release().setId("r6").setComponentId("c1"));
    // Create the database
    TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Prepare the database
    DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    for (Project project : projects) {
        databaseConnector.add(project);
    }
    for (Release r : releases) {
        databaseConnector.add(r);
    }
    databaseConnector.add(new Component("comp1").setId("c1"));
    componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
    handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentDbName, moderator, componentHandler);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 85 with Release

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

the class ComponentDatabaseHandlerTest method testDontDeleteUsedRelease.

@Test
public void testDontDeleteUsedRelease() throws Exception {
    final Release r1A = handler.getRelease("R1A", user1);
    r1A.setReleaseIdToRelationship(ImmutableMap.of("R2A", ReleaseRelationship.CONTAINED));
    handler.updateRelease(r1A, user1, ThriftUtils.IMMUTABLE_OF_RELEASE);
    RequestStatus status = handler.deleteRelease("R2A", user1);
    assertEquals(RequestStatus.IN_USE, status);
    List<Release> releaseSummary = handler.getReleaseSummary();
    assertEquals(5, releaseSummary.size());
    assertTrue("Release not deleted", releasesContain(releaseSummary, "R2A"));
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)93 User (org.eclipse.sw360.datahandler.thrift.users.User)39 TException (org.apache.thrift.TException)34 Test (org.junit.Test)22 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)20 Component (org.eclipse.sw360.datahandler.thrift.components.Component)18 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)13 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)13 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 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)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 java.util (java.util)5