Search in sources :

Example 36 with Vendor

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

the class VendorHandlerTest method testAddVendor.

@Test
public void testAddVendor() throws Exception {
    Vendor oracle = new Vendor().setShortname("Oracle").setFullname("Oracle Corporation Inc").setUrl("http://www.oracle.com");
    String id = vendorHandler.addVendor(oracle);
    assertNotNull(id);
    assertEquals(vendorList.size() + 1, vendorHandler.getAllVendors().size());
    Vendor actual = vendorHandler.getByID(id);
    assertVendorEquals(oracle, actual);
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Test(org.junit.Test)

Example 37 with Vendor

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

the class VendorHandlerTest method testGetByID.

@Test
public void testGetByID() throws Exception {
    for (Vendor vendor : vendorList) {
        String id = vendor.getId();
        Vendor actualVendor = vendorHandler.getByID(id);
        assertVendorEquals(vendor, actualVendor);
    }
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Test(org.junit.Test)

Example 38 with Vendor

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

the class CombinedCLIParserTest method setUp.

@Before
public void setUp() throws Exception {
    cliTestfile = IOUtils.toString(makeAttachmentContentStream(TEST_XML_FILENAME));
    attachment = new Attachment("A1", "a.xml").setAttachmentType(AttachmentType.COMPONENT_LICENSE_INFO_COMBINED);
    content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
    parser = spy(new CombinedCLIParser(connector, attachment -> content, componentDatabaseHandler));
    doReturn("external-correlation-id").when(parser).getCorrelationKey();
    Release r1 = new Release().setId("id1").setName("r1").setVersion("1.0").setVendor(new Vendor().setFullname("VendorA Fullname").setShortname("VendorA")).setExternalIds(ImmutableMap.of(parser.getCorrelationKey(), "1234"));
    Release r2 = new Release().setId("id2").setName("r2").setVersion("2.0").setVendor(new Vendor().setFullname("VendorB Fullname").setShortname("VendorB")).setExternalIds(ImmutableMap.of(parser.getCorrelationKey(), "4321"));
    Release r3 = new Release().setId("id3").setName("r3").setVersion("3.0").setVendor(new Vendor().setFullname("VendorC Fullname").setShortname("VendorC"));
    Release r4 = new Release().setId("id4").setName("r4").setVersion("4.0").setVendor(new Vendor().setFullname("VendorD Fullname").setShortname("VendorD")).setExternalIds(ImmutableMap.of("some_external_id", "1234"));
    when(componentDatabaseHandler.getAllReleasesIdMap()).thenReturn(ImmutableMap.of(r1.getId(), r1, r2.getId(), r2, r3.getId(), r3, r4.getId(), r4));
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 39 with Vendor

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

the class ComponentController method createComponent.

@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = COMPONENTS_URL, method = RequestMethod.POST)
public ResponseEntity<Resource<Component>> createComponent(OAuth2Authentication oAuth2Authentication, @RequestBody Component component) throws URISyntaxException, TException {
    User user = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    if (component.getVendorNames() != null) {
        Set<String> vendors = new HashSet<>();
        for (String vendorUriString : component.getVendorNames()) {
            URI vendorURI = new URI(vendorUriString);
            String path = vendorURI.getPath();
            String vendorId = path.substring(path.lastIndexOf('/') + 1);
            Vendor vendor = vendorService.getVendorById(vendorId);
            String vendorFullName = vendor.getFullname();
            vendors.add(vendorFullName);
        }
        component.setVendorNames(vendors);
    }
    Component sw360Component = componentService.createComponent(component, user);
    HalResource<Component> halResource = createHalComponent(sw360Component, user);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(sw360Component.getId()).toUri();
    return ResponseEntity.created(location).body(halResource);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Component(org.eclipse.sw360.datahandler.thrift.components.Component) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 40 with Vendor

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

the class ComponentImportUtils method getVendorNameToId.

@NotNull
public static Map<String, String> getVendorNameToId(Iterable<ComponentCSVRecord> compCSVRecords, VendorService.Iface vendorClient) throws TException {
    Map<String, String> vendorNameToVendorId = getVendorNameToVendorId(vendorClient);
    for (ComponentCSVRecord componentCSVRecord : compCSVRecords) {
        if (componentCSVRecord.isSetVendor()) {
            String vendorName = componentCSVRecord.getVendorName();
            if (!vendorNameToVendorId.containsKey(vendorName)) {
                Vendor vendor = componentCSVRecord.getVendor();
                String vendorId = vendorClient.addVendor(vendor);
                vendorNameToVendorId.put(vendorName, vendorId);
                log.trace(format("created vendor with name '%s' as %s: %s", vendorName, vendorId, vendor));
            } else {
                log.trace(format("recognized vendor with name '%s' as %s", vendorName, vendorNameToVendorId.get(vendorName)));
            }
        } else {
            log.info("invalid vendor in record " + componentCSVRecord);
        }
    }
    return vendorNameToVendorId;
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) NotNull(org.jetbrains.annotations.NotNull)

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