Search in sources :

Example 46 with Vendor

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

the class VendorController method getVendors.

@RequestMapping(value = VENDORS_URL, method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<Vendor>>> getVendors(OAuth2Authentication oAuth2Authentication) {
    List<Vendor> vendors = vendorService.getVendors();
    List<Resource<Vendor>> vendorResources = new ArrayList<>();
    for (Vendor vendor : vendors) {
        Vendor embeddedVendor = restControllerHelper.convertToEmbeddedVendor(vendor.getFullname());
        Resource<Vendor> vendorResource = new Resource<>(embeddedVendor);
        vendorResources.add(vendorResource);
    }
    Resources<Resource<Vendor>> resources = new Resources<>(vendorResources);
    return new ResponseEntity<>(resources, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RepositoryLinksResource(org.springframework.data.rest.webmvc.RepositoryLinksResource) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Resource(org.springframework.hateoas.Resource) ArrayList(java.util.ArrayList) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Resources(org.springframework.hateoas.Resources) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with Vendor

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

the class VendorController method createVendor.

@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = VENDORS_URL, method = RequestMethod.POST)
public ResponseEntity createVendor(OAuth2Authentication oAuth2Authentication, @RequestBody Vendor vendor) throws URISyntaxException {
    vendor = vendorService.createVendor(vendor);
    HalResource<Vendor> halResource = createHalVendor(vendor);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(vendor.getId()).toUri();
    return ResponseEntity.created(location).body(halResource);
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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