Search in sources :

Example 16 with User

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());
    }
}
Also used : TException(org.apache.thrift.TException) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) User(org.eclipse.sw360.datahandler.thrift.users.User) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) IOException(java.io.IOException)

Example 17 with User

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);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) ProjectReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 18 with User

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);
}
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 19 with User

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);
}
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 20 with User

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

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)169 TException (org.apache.thrift.TException)100 Release (org.eclipse.sw360.datahandler.thrift.components.Release)58 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)44 Test (org.junit.Test)30 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)27 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)26 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)20 ResponseEntity (org.springframework.http.ResponseEntity)20 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)19 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)18 IOException (java.io.IOException)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)16 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)13 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)12 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)12 Before (org.junit.Before)12 ArrayList (java.util.ArrayList)11