Search in sources :

Example 1 with Vendor

use of org.eclipse.sw360.datahandler.thrift.vendors.Vendor 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 2 with Vendor

use of org.eclipse.sw360.datahandler.thrift.vendors.Vendor 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 3 with Vendor

use of org.eclipse.sw360.datahandler.thrift.vendors.Vendor in project sw360portal by sw360.

the class VendorRepository method fillVendor.

public void fillVendor(Release release) {
    if (release.isSetVendorId()) {
        final String vendorId = release.getVendorId();
        if (!isNullOrEmpty(vendorId)) {
            final Vendor vendor = get(vendorId);
            if (vendor != null)
                release.setVendor(vendor);
        }
        release.unsetVendorId();
    }
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor)

Example 4 with Vendor

use of org.eclipse.sw360.datahandler.thrift.vendors.Vendor in project sw360portal by sw360.

the class VendorController method getVendor.

@RequestMapping(value = VENDORS_URL + "/{id}", method = RequestMethod.GET)
public ResponseEntity<Resource<Vendor>> getVendor(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) {
    Vendor sw360Vendor = vendorService.getVendorById(id);
    HalResource<Vendor> halResource = createHalVendor(sw360Vendor);
    return new ResponseEntity<>(halResource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Vendor

use of org.eclipse.sw360.datahandler.thrift.vendors.Vendor in project sw360portal by sw360.

the class RestControllerHelper method createHalReleaseResource.

public HalResource<Release> createHalReleaseResource(Release release, boolean verbose) {
    HalResource<Release> halRelease = new HalResource<>(release);
    Link componentLink = linkTo(ReleaseController.class).slash("api" + ComponentController.COMPONENTS_URL + "/" + release.getComponentId()).withRel("component");
    halRelease.add(componentLink);
    release.setComponentId(null);
    if (verbose) {
        if (release.getModerators() != null) {
            Set<String> moderators = release.getModerators();
            this.addEmbeddedModerators(halRelease, moderators);
            release.setModerators(null);
        }
        if (release.getAttachments() != null) {
            Set<Attachment> attachments = release.getAttachments();
            this.addEmbeddedAttachments(halRelease, attachments);
            release.setAttachments(null);
        }
        if (release.getVendor() != null) {
            Vendor vendor = release.getVendor();
            HalResource<Vendor> vendorHalResource = this.addEmbeddedVendor(vendor.getFullname());
            halRelease.addEmbeddedResource("sw360:vendors", vendorHalResource);
            release.setVendor(null);
        }
        if (release.getMainLicenseIds() != null) {
            this.addEmbeddedLicenses(halRelease, release.getMainLicenseIds());
            release.setMainLicenseIds(null);
        }
    }
    return halRelease;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Link(org.springframework.hateoas.Link)

Aggregations

Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)37 TException (org.apache.thrift.TException)14 VendorService (org.eclipse.sw360.datahandler.thrift.vendors.VendorService)12 Release (org.eclipse.sw360.datahandler.thrift.components.Release)8 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)5 User (org.eclipse.sw360.datahandler.thrift.users.User)5 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)4 Before (org.junit.Before)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 Component (org.eclipse.sw360.datahandler.thrift.components.Component)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 URI (java.net.URI)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 ComponentDatabaseHandler (org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler)2 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)2 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2