Search in sources :

Example 1 with Component

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

the class ComponentSummary method makeExportSummary.

private Component makeExportSummary(Component document, List<Release> releases) {
    if (releaseRepository == null) {
        throw new IllegalStateException("Cannot make export summary without database connection!");
    }
    Component copy = new Component();
    copyField(document, copy, Component._Fields.ID);
    copyField(document, copy, Component._Fields.NAME);
    copyField(document, copy, Component._Fields.LANGUAGES);
    copyField(document, copy, Component._Fields.OPERATING_SYSTEMS);
    copyField(document, copy, Component._Fields.SOFTWARE_PLATFORMS);
    copyField(document, copy, Component._Fields.CREATED_BY);
    copyField(document, copy, Component._Fields.CREATED_ON);
    copyField(document, copy, Component._Fields.VENDOR_NAMES);
    for (Release release : releases) {
        Release exportRelease = new Release();
        copyField(release, exportRelease, Release._Fields.NAME);
        copyField(release, exportRelease, Release._Fields.VERSION);
        exportRelease.setComponentId("");
        copy.addToReleases(exportRelease);
    }
    return copy;
}
Also used : Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 2 with Component

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

the class ComponentHandlerTest method testGetByUploadId.

@Test
public void testGetByUploadId() throws Exception {
    Component originalComponent = new Component("name").setDescription("a desc");
    String componentId = componentHandler.addComponent(originalComponent, adminUser).getId();
    Release release = new Release("name", "version", componentId).setFossologyId("id");
    String releaseId = componentHandler.addRelease(release, adminUser).getId();
    Component component = componentHandler.getComponentForReportFromFossologyUploadId("id");
    assertThat(component, is(not(nullValue())));
    assertThat(component, is(equalTo(originalComponent, restrictedToFields(ID, NAME, DESCRIPTION))));
    assertThat(componentHandler.getReleaseById(releaseId, adminUser), is(not(nullValue())));
    assertThat(componentHandler.getComponentById(componentId, adminUser), is(not(nullValue())));
    assertThat(componentHandler.deleteRelease(releaseId, adminUser), is(RequestStatus.SUCCESS));
    assertThat(componentHandler.deleteComponent(componentId, adminUser), is(RequestStatus.SUCCESS));
    try {
        componentHandler.getReleaseById(releaseId, adminUser);
        fail("expected exception not thrown");
    } catch (SW360Exception e) {
        assertThat(e.getWhy(), containsString("Could not fetch"));
    }
    try {
        componentHandler.getComponentById(componentId, adminUser);
        fail("expected exception not thrown");
    } catch (SW360Exception e) {
        assertThat(e.getWhy(), containsString("Could not fetch"));
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Test(org.junit.Test)

Example 3 with Component

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

the class ComponentDatabaseHandlerTest method testDeleteComponent.

@Test
public void testDeleteComponent() throws Exception {
    RequestStatus status = handler.deleteComponent("C3", user1);
    assertEquals(RequestStatus.SUCCESS, status);
    List<Component> componentSummary = handler.getComponentSummary(user1);
    assertEquals(2, componentSummary.size());
    assertFalse("Component deleted", componentsContain(componentSummary, "C3"));
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 4 with Component

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

the class ComponentDatabaseHandlerTest method testDeleteComponentNotModerator.

@Test
public void testDeleteComponentNotModerator() throws Exception {
    when(moderator.deleteComponent(any(Component.class), eq(user2))).thenReturn(RequestStatus.SENT_TO_MODERATOR);
    RequestStatus status = handler.deleteComponent("C3", user2);
    assertEquals(RequestStatus.SENT_TO_MODERATOR, status);
    List<Component> componentSummary = handler.getComponentSummary(user1);
    assertEquals(3, componentSummary.size());
    assertTrue("Component NOT deleted", componentsContain(componentSummary, "C1"));
    verify(moderator).deleteComponent(any(Component.class), eq(user2));
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 5 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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)

Aggregations

Component (org.eclipse.sw360.datahandler.thrift.components.Component)38 User (org.eclipse.sw360.datahandler.thrift.users.User)30 TException (org.apache.thrift.TException)23 Release (org.eclipse.sw360.datahandler.thrift.components.Release)23 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)10 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)8 Before (org.junit.Before)7 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)6 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)5 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)5 IOException (java.io.IOException)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Test (org.junit.Test)4 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 FluentIterable (com.google.common.collect.FluentIterable)2 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2