use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class Sw360ComponentService method updateComponent.
public RequestStatus updateComponent(Component component, User sw360User) throws TException {
ComponentService.Iface sw360ComponentClient = getThriftComponentClient();
RequestStatus requestStatus = sw360ComponentClient.updateComponent(component, sw360User);
if (requestStatus != RequestStatus.SUCCESS) {
throw new RuntimeException("sw360 component with name '" + component.getName() + " cannot be updated.");
}
return requestStatus;
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class LicenseController method createLicense.
@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = LICENSES_URL, method = RequestMethod.POST)
public ResponseEntity<Resource<License>> createLicense(OAuth2Authentication oAuth2Authentication, @RequestBody License license) throws URISyntaxException, TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
license = licenseService.createLicense(license, sw360User);
HalResource<License> halResource = createHalLicense(license);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(license.getId()).toUri();
return ResponseEntity.created(location).body(halResource);
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class ProjectController method getProjectReleases.
@RequestMapping(value = PROJECTS_URL + "/{id}/releases", method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<Release>>> getProjectReleases(@PathVariable("id") String id, @RequestParam(value = "transitive", required = false) String transitive, OAuth2Authentication oAuth2Authentication) throws TException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
final Set<String> releaseIds = projectService.getReleaseIds(id, sw360User, transitive);
final List<Resource<Release>> releaseResources = new ArrayList<>();
for (final String releaseId : releaseIds) {
final Release sw360Release = releaseService.getReleaseForUserById(releaseId, sw360User);
final Release embeddedRelease = restControllerHelper.convertToEmbeddedRelease(sw360Release);
final Resource<Release> releaseResource = new Resource<>(embeddedRelease);
releaseResources.add(releaseResource);
}
final Resources<Resource<Release>> resources = new Resources<>(releaseResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class ProjectController method downloadLicenseInfo.
@RequestMapping(value = PROJECTS_URL + "/{id}/licenseinfo", method = RequestMethod.GET)
public void downloadLicenseInfo(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication, @RequestParam("generatorClassName") String generatorClassName, HttpServletResponse response) throws TException, IOException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
final Project sw360Project = projectService.getProjectForUserById(id, sw360User);
final Map<String, Set<String>> selectedReleaseAndAttachmentIds = new HashMap<>();
for (final String releaseId : sw360Project.getReleaseIdToUsage().keySet()) {
final Release release = releaseService.getReleaseForUserById(releaseId, sw360User);
if (release.isSetAttachments()) {
if (!selectedReleaseAndAttachmentIds.containsKey(releaseId)) {
selectedReleaseAndAttachmentIds.put(releaseId, new HashSet<>());
}
final Set<Attachment> attachments = release.getAttachments();
for (final Attachment attachment : attachments) {
selectedReleaseAndAttachmentIds.get(releaseId).add(attachment.getAttachmentContentId());
}
}
}
// TODO: implement method to determine excluded licenses
final Map<String, Set<LicenseNameWithText>> excludedLicenses = new HashMap<>();
final String projectName = sw360Project.getName();
final String timestamp = SW360Utils.getCreatedOn();
final OutputFormatInfo outputFormatInfo = licenseInfoService.getOutputFormatInfoForGeneratorClass(generatorClassName);
final String filename = String.format("LicenseInfo-%s-%s.%s", projectName, timestamp, outputFormatInfo.getFileExtension());
final LicenseInfoFile licenseInfoFile = licenseInfoService.getLicenseInfoFile(sw360Project, sw360User, generatorClassName, selectedReleaseAndAttachmentIds, excludedLicenses);
byte[] byteContent = licenseInfoFile.bufferForGeneratedOutput().array();
response.setContentType(outputFormatInfo.getMimeType());
response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
FileCopyUtils.copy(byteContent, response.getOutputStream());
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class ProjectController method getProjectsForUser.
@RequestMapping(value = PROJECTS_URL, method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<Project>>> getProjectsForUser(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "type", required = false) String projectType, OAuth2Authentication oAuth2Authentication) throws TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
List<Project> sw360Projects = new ArrayList<>();
if (name != null && !name.isEmpty()) {
sw360Projects.addAll(projectService.searchProjectByName(name, sw360User));
} else {
sw360Projects.addAll(projectService.getProjectsForUser(sw360User));
}
List<Resource<Project>> projectResources = new ArrayList<>();
sw360Projects.stream().filter(project -> projectType == null || projectType.equals(project.projectType.name())).forEach(p -> {
Project embeddedProject = restControllerHelper.convertToEmbeddedProject(p);
projectResources.add(new Resource<>(embeddedProject));
});
Resources<Resource<Project>> resources = new Resources<>(projectResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}
Aggregations