Search in sources :

Example 16 with HalResource

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);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) User(org.eclipse.sw360.datahandler.thrift.users.User) ProjectReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 17 with 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);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) IOException(java.io.IOException)

Example 18 with HalResource

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with HalResource

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;
}
Also used : License(org.eclipse.sw360.datahandler.thrift.licenses.License) Link(org.springframework.hateoas.Link) TException(org.apache.thrift.TException)

Example 20 with HalResource

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;
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Link(org.springframework.hateoas.Link) TException(org.apache.thrift.TException)

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