Search in sources :

Example 26 with HalResource

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) IOException(java.io.IOException) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 27 with HalResource

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 28 with HalResource

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

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