use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class ProjectController method downloadClearingReports.
@RequestMapping(value = PROJECTS_URL + "/{projectId}/attachments/clearingReports", method = RequestMethod.GET, produces = "application/zip")
public void downloadClearingReports(@PathVariable("projectId") String projectId, HttpServletResponse response, OAuth2Authentication oAuth2Authentication) throws TException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
final Project project = projectService.getProjectForUserById(projectId, sw360User);
final String filename = "Clearing-Reports-" + project.getName() + ".zip";
final Set<Attachment> attachments = project.getAttachments();
final Set<AttachmentContent> clearingAttachments = new HashSet<>();
for (final Attachment attachment : attachments) {
if (attachment.getAttachmentType().equals(AttachmentType.CLEARING_REPORT)) {
clearingAttachments.add(attachmentService.getAttachmentContent(attachment.getAttachmentContentId()));
}
}
try (InputStream attachmentStream = attachmentService.getStreamToAttachments(clearingAttachments, sw360User, project)) {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
FileCopyUtils.copy(attachmentStream, response.getOutputStream());
} catch (final TException | IOException e) {
log.error(e.getMessage());
}
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class ProjectController method createReleases.
@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = PROJECTS_URL + "/{id}/releases", method = RequestMethod.POST)
public ResponseEntity createReleases(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication, @RequestBody List<String> releaseURIs) throws URISyntaxException, TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
Project project = projectService.getProjectForUserById(id, sw360User);
Map<String, ProjectReleaseRelationship> releaseIdToUsage = new HashMap<>();
for (String releaseURIString : releaseURIs) {
URI releaseURI = new URI(releaseURIString);
String path = releaseURI.getPath();
String releaseId = path.substring(path.lastIndexOf('/') + 1);
releaseIdToUsage.put(releaseId, new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE));
}
project.setReleaseIdToUsage(releaseIdToUsage);
projectService.updateProject(project, sw360User);
return new ResponseEntity<>(HttpStatus.CREATED);
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class ProjectController method getLicensesOfReleases.
@RequestMapping(value = PROJECTS_URL + "/{id}/licenses", method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<License>>> getLicensesOfReleases(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
final Project project = projectService.getProjectForUserById(id, sw360User);
final List<Resource<License>> licenseResources = new ArrayList<>();
final Set<String> allLicenseIds = new HashSet<>();
final Set<String> releaseIdToUsage = project.getReleaseIdToUsage().keySet();
for (final String releaseId : releaseIdToUsage) {
final Release sw360Release = releaseService.getReleaseForUserById(releaseId, sw360User);
final Set<String> licenseIds = sw360Release.getMainLicenseIds();
if (licenseIds != null && !licenseIds.isEmpty()) {
allLicenseIds.addAll(licenseIds);
}
}
for (final String licenseId : allLicenseIds) {
final License sw360License = licenseService.getLicenseById(licenseId);
final License embeddedLicense = restControllerHelper.convertToEmbeddedLicense(sw360License);
final Resource<License> licenseResource = new Resource<>(embeddedLicense);
licenseResources.add(licenseResource);
}
final Resources<Resource<License>> resources = new Resources<>(licenseResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class ReleaseController method createRelease.
@PreAuthorize("hasAuthority('WRITE')")
@RequestMapping(value = RELEASES_URL, method = RequestMethod.POST)
public ResponseEntity<Resource<Release>> createRelease(OAuth2Authentication oAuth2Authentication, @RequestBody Release release) throws URISyntaxException, TException {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
if (release.isSetComponentId()) {
URI componentURI = new URI(release.getComponentId());
String path = componentURI.getPath();
String componentId = path.substring(path.lastIndexOf('/') + 1);
release.setComponentId(componentId);
}
if (release.isSetVendorId()) {
URI vendorURI = new URI(release.getVendorId());
String path = vendorURI.getPath();
String vendorId = path.substring(path.lastIndexOf('/') + 1);
release.setVendorId(vendorId);
}
if (release.getMainLicenseIds() != null) {
Set<String> mainLicenseIds = new HashSet<>();
Set<String> mainLicenseUris = release.getMainLicenseIds();
for (String licenseURIString : mainLicenseUris.toArray(new String[mainLicenseUris.size()])) {
URI licenseURI = new URI(licenseURIString);
String path = licenseURI.getPath();
String licenseId = path.substring(path.lastIndexOf('/') + 1);
mainLicenseIds.add(licenseId);
}
release.setMainLicenseIds(mainLicenseIds);
}
Release sw360Release = releaseService.createRelease(release, sw360User);
HalResource<Release> halResource = restControllerHelper.createHalReleaseResource(sw360Release, true);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(sw360Release.getId()).toUri();
return ResponseEntity.created(location).body(halResource);
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class Sw360ReleaseService method updateRelease.
public RequestStatus updateRelease(Release release, User sw360User) throws TException {
ComponentService.Iface sw360ComponentClient = getThriftComponentClient();
RequestStatus requestStatus = sw360ComponentClient.updateRelease(release, sw360User);
if (requestStatus != RequestStatus.SUCCESS) {
throw new RuntimeException("sw360 release with name '" + release.getName() + " cannot be updated.");
}
return requestStatus;
}
Aggregations