Search in sources :

Example 6 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class RestControllerHelper method addEmbeddedProject.

private void addEmbeddedProject(HalResource halResource, Project project) {
    Project embeddedProject = convertToEmbeddedProject(project);
    HalResource<Project> halProject = new HalResource<>(embeddedProject);
    Link projectLink = linkTo(ProjectController.class).slash("api" + ProjectController.PROJECTS_URL + "/" + project.getId()).withSelfRel();
    halProject.add(projectLink);
    halResource.addEmbeddedResource("sw360:projects", halProject);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Link(org.springframework.hateoas.Link)

Example 7 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class RestControllerHelper method addEmbeddedUser.

public void addEmbeddedUser(HalResource halResource, User user, String relation) {
    User embeddedUser = convertToEmbeddedUser(user);
    Resource<User> embeddedUserResource = new Resource<>(embeddedUser);
    try {
        String userUUID = Base64.getEncoder().encodeToString(user.getEmail().getBytes("utf-8"));
        Link userLink = linkTo(UserController.class).slash("api/users/" + userUUID).withSelfRel();
        embeddedUserResource.add(userLink);
    } catch (Exception e) {
        LOGGER.error("cannot create embedded user with email: " + user.getEmail());
    }
    halResource.addEmbeddedResource(relation, embeddedUserResource);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Resource(org.springframework.hateoas.Resource) Link(org.springframework.hateoas.Link) TException(org.apache.thrift.TException)

Example 8 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class RestControllerHelper method createHalReleaseResource.

public HalResource<Release> createHalReleaseResource(Release release, boolean verbose) {
    HalResource<Release> halRelease = new HalResource<>(release);
    Link componentLink = linkTo(ReleaseController.class).slash("api" + ComponentController.COMPONENTS_URL + "/" + release.getComponentId()).withRel("component");
    halRelease.add(componentLink);
    release.setComponentId(null);
    if (verbose) {
        if (release.getModerators() != null) {
            Set<String> moderators = release.getModerators();
            this.addEmbeddedModerators(halRelease, moderators);
            release.setModerators(null);
        }
        if (release.getAttachments() != null) {
            Set<Attachment> attachments = release.getAttachments();
            this.addEmbeddedAttachments(halRelease, attachments);
            release.setAttachments(null);
        }
        if (release.getVendor() != null) {
            Vendor vendor = release.getVendor();
            HalResource<Vendor> vendorHalResource = this.addEmbeddedVendor(vendor.getFullname());
            halRelease.addEmbeddedResource("sw360:vendors", vendorHalResource);
            release.setVendor(null);
        }
        if (release.getMainLicenseIds() != null) {
            this.addEmbeddedLicenses(halRelease, release.getMainLicenseIds());
            release.setMainLicenseIds(null);
        }
    }
    return halRelease;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Link(org.springframework.hateoas.Link)

Example 9 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class UserController method getUser.

@RequestMapping(value = USERS_URL + "/{id:.+}", method = RequestMethod.GET)
public ResponseEntity<Resource<User>> getUser(@PathVariable("id") String id) {
    byte[] base64decodedBytes = Base64.getDecoder().decode(id);
    String decodedId;
    try {
        decodedId = new String(base64decodedBytes, "utf-8");
    } catch (UnsupportedEncodingException e) {
        throw (new RuntimeException(e));
    }
    User sw360User = userService.getUserByEmail(decodedId);
    HalResource<User> halResource = createHalUser(sw360User);
    return new ResponseEntity<>(halResource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with HalResource

use of org.eclipse.sw360.rest.resourceserver.core.HalResource in project sw360portal by sw360.

the class AttachmentController method getAttachmentForId.

@RequestMapping(value = ATTACHMENTS_URL + "/{id}", method = RequestMethod.GET)
public ResponseEntity<Resource<Attachment>> getAttachmentForId(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
    User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    AttachmentInfo attachmentInfo = attachmentService.getAttachmentByIdForUser(id, sw360User);
    HalResource<Attachment> attachmentResource = createHalAttachment(attachmentInfo.getAttachment(), attachmentInfo.getRelease(), sw360User);
    return new ResponseEntity<>(attachmentResource, 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) 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