use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class ReleaseController method addAttachmentToRelease.
@RequestMapping(value = RELEASES_URL + "/{releaseId}/attachments", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" })
public ResponseEntity<HalResource> addAttachmentToRelease(@PathVariable("releaseId") String releaseId, OAuth2Authentication oAuth2Authentication, @RequestPart("file") MultipartFile file, @RequestPart("attachment") Attachment newAttachment) throws TException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
Attachment attachment;
try {
attachment = attachmentService.uploadAttachment(file, newAttachment, sw360User);
} catch (IOException e) {
log.error(e.getMessage());
throw new RuntimeException(e);
}
final Release release = releaseService.getReleaseForUserById(releaseId, sw360User);
release.addToAttachments(attachment);
releaseService.updateRelease(release, sw360User);
final HalResource halRelease = restControllerHelper.createHalReleaseResource(release, true);
return new ResponseEntity<>(halRelease, HttpStatus.OK);
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class ReleaseController method getRelease.
@RequestMapping(value = RELEASES_URL + "/{id}", method = RequestMethod.GET)
public ResponseEntity<Resource> getRelease(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
Release sw360Release = releaseService.getReleaseForUserById(id, sw360User);
HalResource halRelease = restControllerHelper.createHalReleaseResource(sw360Release, true);
return new ResponseEntity<>(halRelease, HttpStatus.OK);
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource 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);
}
Aggregations