use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields 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.components.Release._Fields 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.components.Release._Fields 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;
}
use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields 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.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.
the class RestControllerHelper method convertToEmbeddedRelease.
public Release convertToEmbeddedRelease(Release release) {
Release embeddedRelease = new Release();
embeddedRelease.setId(release.getId());
embeddedRelease.setName(release.getName());
embeddedRelease.setVersion(release.getVersion());
embeddedRelease.setType(null);
return embeddedRelease;
}
Aggregations