Search in sources :

Example 16 with Release

use of org.eclipse.sw360.datahandler.thrift.components.Release 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);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) RepositoryLinksResource(org.springframework.data.rest.webmvc.RepositoryLinksResource) Resource(org.springframework.hateoas.Resource) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) License(org.eclipse.sw360.datahandler.thrift.licenses.License) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ResponseEntity(org.springframework.http.ResponseEntity) Resources(org.springframework.hateoas.Resources) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 17 with Release

use of org.eclipse.sw360.datahandler.thrift.components.Release 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);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) URI(java.net.URI) Release(org.eclipse.sw360.datahandler.thrift.components.Release) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 18 with Release

use of org.eclipse.sw360.datahandler.thrift.components.Release 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;
}
Also used : ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) AddDocumentRequestStatus(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 19 with Release

use of org.eclipse.sw360.datahandler.thrift.components.Release 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 20 with Release

use of org.eclipse.sw360.datahandler.thrift.components.Release 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;
}
Also used : Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)93 User (org.eclipse.sw360.datahandler.thrift.users.User)39 TException (org.apache.thrift.TException)34 Test (org.junit.Test)22 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)20 Component (org.eclipse.sw360.datahandler.thrift.components.Component)18 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)13 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)13 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)11 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)10 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)9 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)7 Before (org.junit.Before)7 Collectors (java.util.stream.Collectors)6 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)6 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)6 IOException (java.io.IOException)5 java.util (java.util)5