Search in sources :

Example 11 with Release._Fields

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

the class ComponentDatabaseHandlerTest method testDontDeleteComponentWithReleaseContained.

@Test
public void testDontDeleteComponentWithReleaseContained() throws Exception {
    Component component = new Component().setId("Del").setName("delete").setDescription("d1").setCreatedBy(email1);
    Release release = new Release().setId("DelR").setComponentId("Del").setName("delete Release").setVersion("1.0").setCreatedBy(email1).setVendorId("V1").setClearingState(ClearingState.NEW_CLEARING);
    handler.addComponent(component, email1);
    handler.addRelease(release, email1);
    {
        Component del = handler.getComponent("Del", user1);
        assertThat(del.getName(), is("delete"));
        Release delR = handler.getRelease("DelR", user1);
        assertThat(delR.getName(), is("delete Release"));
    }
    RequestStatus status = handler.deleteComponent("Del", user1);
    assertThat(status, is(RequestStatus.IN_USE));
    {
        Component del = handler.getComponent("Del", user1);
        assertThat(del.getName(), is("delete"));
        Release delR = handler.getRelease("DelR", user1);
        assertThat(delR.getName(), is("delete Release"));
    }
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 12 with Release._Fields

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

the class ComponentDatabaseHandlerTest method testAddReleaseUpdatesProgrammingLanguagesOperatingSystemsAndVendorNames.

@Test
public void testAddReleaseUpdatesProgrammingLanguagesOperatingSystemsAndVendorNames() throws Exception {
    String componentId = "C4";
    {
        Component component = new Component().setId(componentId).setName("component4").setDescription("d4").setCreatedBy(email1);
        handler.addComponent(component, email1);
    }
    {
        Component component = handler.getComponent(componentId, user1);
        assertTrue("Check that languages are not initialized", component.languages == null);
        assertTrue("Check that operating systems are not initialized", component.operatingSystems == null);
        assertTrue("Check that vendor names are not initialized", component.vendorNames == null);
    }
    Set<String> os = new HashSet<>();
    os.add("Linux Ubuntu");
    os.add("Linux Mint");
    Set<String> lang = new HashSet<>();
    lang.add("C");
    lang.add("C++");
    Release release = new Release().setName("REL").setVersion("VER").setOperatingSystems(os).setLanguages(lang).setVendorId("V1");
    release.setComponentId(componentId);
    String id = handler.addRelease(release, user1.getEmail()).getId();
    assertNotNull(id);
    {
        Component component = handler.getComponent(componentId, user1);
        assertThat(component.languages, containsInAnyOrder("C", "C++"));
        assertThat(component.operatingSystems, containsInAnyOrder("Linux Ubuntu", "Linux Mint"));
        assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V1").getShortname()));
    }
    Set<String> os2 = new HashSet<>();
    os2.add("Linux Debian");
    os2.add("Linux Mint");
    Set<String> lang2 = new HashSet<>();
    lang2.add("C#");
    lang2.add("C++");
    Release release2 = new Release().setName("REL2").setVersion("VER2").setOperatingSystems(os2).setLanguages(lang2).setVendorId("V2");
    release2.setComponentId(componentId);
    String id2 = handler.addRelease(release2, user1.getEmail()).getId();
    {
        Component component = handler.getComponent(componentId, user1);
        assertThat(component.languages, containsInAnyOrder("C", "C++", "C#"));
        assertThat(component.operatingSystems, containsInAnyOrder("Linux Ubuntu", "Linux Mint", "Linux Debian"));
        assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V1").getShortname(), vendors.get("V2").getShortname()));
    }
    handler.deleteRelease(id, user1);
    {
        Component component = handler.getComponent(componentId, user1);
        assertThat(component.languages, containsInAnyOrder("C++", "C#"));
        assertThat(component.operatingSystems, containsInAnyOrder("Linux Mint", "Linux Debian"));
        assertThat(component.vendorNames, containsInAnyOrder(vendors.get("V2").getShortname()));
    }
    handler.deleteRelease(id2, user1);
    {
        Component component = handler.getComponent(componentId, user1);
        assertThat(component.languages, is(empty()));
        assertThat(component.operatingSystems, is(empty()));
        assertThat(component.vendorNames, is(empty()));
    }
}
Also used : TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString)

Example 13 with Release._Fields

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

the class ComponentDatabaseHandlerTest method testDeleteRelease.

@Test
public void testDeleteRelease() throws Exception {
    RequestStatus status = handler.deleteRelease("R1B", user2);
    assertEquals(RequestStatus.SUCCESS, status);
    List<Release> releaseSummary = handler.getReleaseSummary();
    assertEquals(4, releaseSummary.size());
    assertFalse("Component deleted", releasesContain(releaseSummary, "R1B"));
    // Check deletion in component
    Component component = handler.getComponent("C1", user1);
    assertEquals(1, component.getReleasesSize());
    assertFalse("Release deleted", releasesContain(component.getReleases(), "R1B"));
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 14 with Release._Fields

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

the class ProjectDatabaseHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    assertTestString(dbName);
    assertTestString(attachmentsDbName);
    vendors = new ArrayList<>();
    vendors.add(new Vendor().setId("V1").setShortname("vendor").setFullname("vendor").setUrl("http://vendor.example.com"));
    releases = new ArrayList<>();
    Release release1a = new Release().setId("R1A").setComponentId("C1").setName("component1").setVersion("releaseA").setVendorId("V1");
    releases.add(release1a);
    Release release1b = new Release().setId("R1B").setComponentId("C1").setName("component1").setVersion("releaseB").setVendorId("V1");
    releases.add(release1b);
    Release release2a = new Release().setId("R2A").setComponentId("C2").setName("component2").setVersion("releaseA").setVendorId("V1");
    releases.add(release2a);
    Release release2b = new Release().setId("R2B").setComponentId("C2").setName("component2").setVersion("releaseB").setVendorId("V1");
    releases.add(release2b);
    components = new ArrayList<>();
    Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setComponentType(ComponentType.OSS);
    components.add(component1);
    Component component2 = new Component().setId("C2").setName("component2").setDescription("d2").setComponentType(ComponentType.COTS);
    components.add(component2);
    projects = new ArrayList<>();
    Project project1 = new Project().setId("P1").setName("project1").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project1);
    Project project2 = new Project().setId("P2").setName("project2").setLinkedProjects(ImmutableMap.of("P3", ProjectRelationship.REFERRED, "P4", ProjectRelationship.CONTAINED)).setReleaseIdToUsage(ImmutableMap.of("R1A", newDefaultProjectReleaseRelationship(), "R1B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
    projects.add(project2);
    Project project3 = new Project().setId("P3").setName("project3").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.UNKNOWN)).setReleaseIdToUsage(ImmutableMap.of("R2A", newDefaultProjectReleaseRelationship(), "R2B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
    projects.add(project3);
    Project project4 = new Project().setId("P4").setName("project4").setLinkedProjects(ImmutableMap.of("P1", ProjectRelationship.UNKNOWN)).setVisbility(Visibility.EVERYONE);
    projects.add(project4);
    Project project5 = new Project().setId("P5").setName("project5").setLinkedProjects(ImmutableMap.of("P6", ProjectRelationship.CONTAINED, "P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project5);
    Project project6 = new Project().setId("P6").setName("project6").setLinkedProjects(ImmutableMap.of("P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
    projects.add(project6);
    Project project7 = new Project().setId("P7").setName("project7").setVisbility(Visibility.EVERYONE);
    projects.add(project7);
    // Create the database
    TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Prepare the database
    DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    for (Vendor vendor : vendors) {
        databaseConnector.add(vendor);
    }
    for (Release release : releases) {
        databaseConnector.add(release);
    }
    for (Component component : components) {
        databaseConnector.add(component);
    }
    for (Project project : projects) {
        databaseConnector.add(project);
    }
    ComponentDatabaseHandler componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
    handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName, moderator, componentHandler);
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ComponentDatabaseHandler(org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler) ProjectDatabaseHandler(org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 15 with Release._Fields

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

the class ProjectDatabaseHandler method fillClearingStateSummary.

public List<Project> fillClearingStateSummary(List<Project> projects, User user) {
    Function<Project, Set<String>> extractReleaseIds = project -> CommonUtils.nullToEmptyMap(project.getReleaseIdToUsage()).keySet();
    Set<String> allReleaseIds = projects.stream().map(extractReleaseIds).reduce(Sets.newHashSet(), Sets::union);
    if (!allReleaseIds.isEmpty()) {
        Map<String, Release> releasesById = ThriftUtils.getIdMap(componentDatabaseHandler.getReleasesForClearingStateSummary(allReleaseIds));
        for (Project project : projects) {
            final Set<String> releaseIds = extractReleaseIds.apply(project);
            List<Release> releases = releaseIds.stream().map(releasesById::get).collect(Collectors.toList());
            final ReleaseClearingStateSummary releaseClearingStateSummary = ReleaseClearingStateSummaryComputer.computeReleaseClearingStateSummary(releases, project.getClearingTeam());
            project.setReleaseClearingStateSummary(releaseClearingStateSummary);
        }
    }
    return projects;
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) SW360Assert.fail(org.eclipse.sw360.datahandler.common.SW360Assert.fail) MailConstants(org.eclipse.sw360.mail.MailConstants) ProjectVulnerabilityRating(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ReleaseClearingStateSummaryComputer(org.eclipse.sw360.datahandler.businessrules.ReleaseClearingStateSummaryComputer) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) Logger(org.apache.log4j.Logger) AttachmentConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentConnector) org.eclipse.sw360.datahandler.thrift(org.eclipse.sw360.datahandler.thrift) ProjectModerator(org.eclipse.sw360.datahandler.entitlement.ProjectModerator) HttpClient(org.ektorp.http.HttpClient) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) MailUtil(org.eclipse.sw360.mail.MailUtil) com.google.common.collect(com.google.common.collect) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) org.eclipse.sw360.datahandler.common(org.eclipse.sw360.datahandler.common) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) PermissionUtils.makePermission(org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission) MalformedURLException(java.net.MalformedURLException) SummaryType(org.eclipse.sw360.components.summary.SummaryType) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple) VisibleForTesting(com.google.common.annotations.VisibleForTesting) org.eclipse.sw360.datahandler.thrift.components(org.eclipse.sw360.datahandler.thrift.components) SW360Assert.assertNotNull(org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull) Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

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