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