Search in sources :

Example 1 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class ComponentController method getComponent.

@RequestMapping(value = COMPONENTS_URL + "/{id}", method = RequestMethod.GET)
public ResponseEntity<Resource<Component>> getComponent(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
    User user = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    Component sw360Component = componentService.getComponentForUserById(id, user);
    HalResource<Component> userHalResource = createHalComponent(sw360Component, user);
    return new ResponseEntity<>(userHalResource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 2 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class LicenseController method getLicense.

@RequestMapping(value = LICENSES_URL + "/{id:.+}", method = RequestMethod.GET)
public ResponseEntity<Resource<License>> getLicense(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
    License sw360License = licenseService.getLicenseById(id);
    HalResource<License> licenseHalResource = createHalLicense(sw360License);
    return new ResponseEntity<>(licenseHalResource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) License(org.eclipse.sw360.datahandler.thrift.licenses.License) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class LicenseController method createLicense.

@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = LICENSES_URL, method = RequestMethod.POST)
public ResponseEntity<Resource<License>> createLicense(OAuth2Authentication oAuth2Authentication, @RequestBody License license) throws URISyntaxException, TException {
    User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    license = licenseService.createLicense(license, sw360User);
    HalResource<License> halResource = createHalLicense(license);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(license.getId()).toUri();
    return ResponseEntity.created(location).body(halResource);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) License(org.eclipse.sw360.datahandler.thrift.licenses.License) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class ReleaseController method createRelease.

@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = RELEASES_URL, method = RequestMethod.POST)
public ResponseEntity<Resource<Release>> createRelease(OAuth2Authentication oAuth2Authentication, @RequestBody Release release) throws URISyntaxException, TException {
    User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    if (release.isSetComponentId()) {
        URI componentURI = new URI(release.getComponentId());
        String path = componentURI.getPath();
        String componentId = path.substring(path.lastIndexOf('/') + 1);
        release.setComponentId(componentId);
    }
    if (release.isSetVendorId()) {
        URI vendorURI = new URI(release.getVendorId());
        String path = vendorURI.getPath();
        String vendorId = path.substring(path.lastIndexOf('/') + 1);
        release.setVendorId(vendorId);
    }
    if (release.getMainLicenseIds() != null) {
        Set<String> mainLicenseIds = new HashSet<>();
        Set<String> mainLicenseUris = release.getMainLicenseIds();
        for (String licenseURIString : mainLicenseUris.toArray(new String[mainLicenseUris.size()])) {
            URI licenseURI = new URI(licenseURIString);
            String path = licenseURI.getPath();
            String licenseId = path.substring(path.lastIndexOf('/') + 1);
            mainLicenseIds.add(licenseId);
        }
        release.setMainLicenseIds(mainLicenseIds);
    }
    Release sw360Release = releaseService.createRelease(release, sw360User);
    HalResource<Release> halResource = restControllerHelper.createHalReleaseResource(sw360Release, true);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(sw360Release.getId()).toUri();
    return ResponseEntity.created(location).body(halResource);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) URI(java.net.URI) Release(org.eclipse.sw360.datahandler.thrift.components.Release) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource 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)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)16 ResponseEntity (org.springframework.http.ResponseEntity)12 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)8 Link (org.springframework.hateoas.Link)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Release (org.eclipse.sw360.datahandler.thrift.components.Release)6 URI (java.net.URI)5 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)4 IOException (java.io.IOException)3 TException (org.apache.thrift.TException)3 Component (org.eclipse.sw360.datahandler.thrift.components.Component)3 License (org.eclipse.sw360.datahandler.thrift.licenses.License)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ProjectReleaseRelationship (org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship)1 Vulnerability (org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)1 Resource (org.springframework.hateoas.Resource)1