use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class ProjectController method createProject.
@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = PROJECTS_URL, method = RequestMethod.POST)
public ResponseEntity createProject(OAuth2Authentication oAuth2Authentication, @RequestBody Project project) throws URISyntaxException, TException {
if (project.getReleaseIdToUsage() != null) {
Map<String, ProjectReleaseRelationship> releaseIdToUsage = new HashMap<>();
Map<String, ProjectReleaseRelationship> oriReleaseIdToUsage = project.getReleaseIdToUsage();
for (String releaseURIString : oriReleaseIdToUsage.keySet()) {
URI releaseURI = new URI(releaseURIString);
String path = releaseURI.getPath();
String releaseId = path.substring(path.lastIndexOf('/') + 1);
releaseIdToUsage.put(releaseId, oriReleaseIdToUsage.get(releaseURIString));
}
project.setReleaseIdToUsage(releaseIdToUsage);
}
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
project = projectService.createProject(project, sw360User);
HalResource<Project> halResource = createHalProject(project, sw360User);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(project.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 addAttachmentToProject.
@RequestMapping(value = PROJECTS_URL + "/{projectId}/attachments", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" })
public ResponseEntity<HalResource> addAttachmentToProject(@PathVariable("projectId") String projectId, 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 Project project = projectService.getProjectForUserById(projectId, sw360User);
project.addToAttachments(attachment);
projectService.updateProject(project, sw360User);
final HalResource<Project> halResource = createHalProject(project, sw360User);
return new ResponseEntity<>(halResource, HttpStatus.OK);
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class VulnerabilityController method getVulnerability.
@RequestMapping(VULNERABILITIES_URL + "/{id}")
public ResponseEntity<HalResource<Vulnerability>> getVulnerability(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) {
User user = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
Vulnerability vulnerability = vulnerabilityService.getVulnerabilityByExternalId(id, user);
HalResource<Vulnerability> vulnerabilityHalResource = createHalVulnerability(vulnerability, user);
return new ResponseEntity<>(vulnerabilityHalResource, HttpStatus.OK);
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class RestControllerHelper method addEmbeddedLicense.
private HalResource<License> addEmbeddedLicense(String licenseId) {
License embeddedLicense = convertToEmbeddedLicense(licenseId);
HalResource<License> halLicense = new HalResource<>(embeddedLicense);
try {
License licenseById = licenseService.getLicenseById(licenseId);
embeddedLicense.setFullname(licenseById.getFullname());
Link licenseSelfLink = linkTo(UserController.class).slash("api" + LicenseController.LICENSES_URL + "/" + licenseById.getId()).withSelfRel();
halLicense.add(licenseSelfLink);
return halLicense;
} catch (Exception e) {
LOGGER.error("cannot create self link for license with id: " + licenseId);
}
return null;
}
use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.
the class RestControllerHelper method addEmbeddedVendor.
private HalResource<Vendor> addEmbeddedVendor(String vendorFullName) {
Vendor embeddedVendor = convertToEmbeddedVendor(vendorFullName);
HalResource<Vendor> halVendor = new HalResource<>(embeddedVendor);
try {
Vendor vendorByFullName = vendorService.getVendorByFullName(vendorFullName);
Link vendorSelfLink = linkTo(UserController.class).slash("api" + VendorController.VENDORS_URL + "/" + vendorByFullName.getId()).withSelfRel();
halVendor.add(vendorSelfLink);
return halVendor;
} catch (Exception e) {
LOGGER.error("cannot create self link for vendor with full name: " + vendorFullName);
}
return null;
}
Aggregations