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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations