use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class AttachmentController method getAttachmentForSha1.
@RequestMapping(value = ATTACHMENTS_URL, params = "sha1", method = RequestMethod.GET)
public ResponseEntity<Resource<Attachment>> getAttachmentForSha1(OAuth2Authentication oAuth2Authentication, @RequestParam String sha1) throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
AttachmentInfo attachmentInfo = attachmentService.getAttachmentBySha1ForUser(sha1, sw360User);
HalResource<Attachment> attachmentResource = createHalAttachment(attachmentInfo.getAttachment(), attachmentInfo.getRelease(), sw360User);
return new ResponseEntity<>(attachmentResource, HttpStatus.OK);
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class AttachmentController method createHalAttachment.
private HalResource<Attachment> createHalAttachment(Attachment sw360Attachment, Release sw360Release, User sw360User) {
HalResource<Attachment> halAttachment = new HalResource<>(sw360Attachment);
String componentUUID = sw360Attachment.getAttachmentContentId();
Link releaseLink = linkTo(AttachmentController.class).slash("api/releases/" + sw360Release.getId()).withRel("release");
halAttachment.add(releaseLink);
restControllerHelper.addEmbeddedRelease(halAttachment, sw360Release);
restControllerHelper.addEmbeddedUser(halAttachment, sw360User, "createdBy");
return halAttachment;
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class ComponentController method addAttachmentToComponent.
@RequestMapping(value = COMPONENTS_URL + "/{componentId}/attachments", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" })
public ResponseEntity<HalResource> addAttachmentToComponent(@PathVariable("componentId") String componentId, 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("failed to upload attachment", e);
throw new RuntimeException("failed to upload attachment", e);
}
final Component component = componentService.getComponentForUserById(componentId, sw360User);
component.addToAttachments(attachment);
componentService.updateComponent(component, sw360User);
final HalResource halRelease = createHalComponent(component, sw360User);
return new ResponseEntity<>(halRelease, HttpStatus.OK);
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class ComponentController method createComponent.
@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = COMPONENTS_URL, method = RequestMethod.POST)
public ResponseEntity<Resource<Component>> createComponent(OAuth2Authentication oAuth2Authentication, @RequestBody Component component) throws URISyntaxException, TException {
User user = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
if (component.getVendorNames() != null) {
Set<String> vendors = new HashSet<>();
for (String vendorUriString : component.getVendorNames()) {
URI vendorURI = new URI(vendorUriString);
String path = vendorURI.getPath();
String vendorId = path.substring(path.lastIndexOf('/') + 1);
Vendor vendor = vendorService.getVendorById(vendorId);
String vendorFullName = vendor.getFullname();
vendors.add(vendorFullName);
}
component.setVendorNames(vendors);
}
Component sw360Component = componentService.createComponent(component, user);
HalResource<Component> halResource = createHalComponent(sw360Component, user);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(sw360Component.getId()).toUri();
return ResponseEntity.created(location).body(halResource);
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class ProjectController method getProject.
@RequestMapping(value = PROJECTS_URL + "/{id}", method = RequestMethod.GET)
public ResponseEntity<Resource<Project>> getProject(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
Project sw360Project = projectService.getProjectForUserById(id, sw360User);
HalResource<Project> userHalResource = createHalProject(sw360Project, sw360User);
return new ResponseEntity<>(userHalResource, HttpStatus.OK);
}
Aggregations