Search in sources :

Example 11 with User

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

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);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) License(org.eclipse.sw360.datahandler.thrift.licenses.License) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with User

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) 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) Resources(org.springframework.hateoas.Resources) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 14 with User

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());
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) LicenseInfoFile(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoFile) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) OutputFormatInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatInfo) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 15 with User

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);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Release(org.eclipse.sw360.datahandler.thrift.components.Release) ReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ReleaseRelationship) Sw360LicenseService(org.eclipse.sw360.rest.resourceserver.license.Sw360LicenseService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) URISyntaxException(java.net.URISyntaxException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) VulnerabilityDTO(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO) URI(java.net.URI) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) RepositoryLinksResource(org.springframework.data.rest.webmvc.RepositoryLinksResource) LicenseInfoFile(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoFile) NonNull(lombok.NonNull) Sw360VulnerabilityService(org.eclipse.sw360.rest.resourceserver.vulnerability.Sw360VulnerabilityService) MediaType(org.springframework.http.MediaType) Resource(org.springframework.hateoas.Resource) Collectors(java.util.stream.Collectors) RestControllerHelper(org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper) Slf4j(lombok.extern.slf4j.Slf4j) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ResourceProcessor(org.springframework.hateoas.ResourceProcessor) FileCopyUtils(org.springframework.util.FileCopyUtils) java.util(java.util) Sw360LicenseInfoService(org.eclipse.sw360.rest.resourceserver.licenseinfo.Sw360LicenseInfoService) MainlineState(org.eclipse.sw360.datahandler.thrift.MainlineState) BasePathAwareController(org.springframework.data.rest.webmvc.BasePathAwareController) Sw360AttachmentService(org.eclipse.sw360.rest.resourceserver.attachment.Sw360AttachmentService) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) AttachmentType(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) License(org.eclipse.sw360.datahandler.thrift.licenses.License) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) IOException(java.io.IOException) HttpStatus(org.springframework.http.HttpStatus) MultipartFile(org.springframework.web.multipart.MultipartFile) Resources(org.springframework.hateoas.Resources) ResponseEntity(org.springframework.http.ResponseEntity) ProjectReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship) Sw360ReleaseService(org.eclipse.sw360.rest.resourceserver.release.Sw360ReleaseService) OutputFormatInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatInfo) InputStream(java.io.InputStream) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ResponseEntity(org.springframework.http.ResponseEntity) 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) Resources(org.springframework.hateoas.Resources)

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