Search in sources :

Example 11 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class ProjectRepository method filterAccessibleProjectsByIds.

@NotNull
private Set<Project> filterAccessibleProjectsByIds(User user, Set<String> searchIds) {
    final Set<Project> accessibleProjects = getAccessibleProjects(user);
    final Set<Project> output = new HashSet<>();
    for (Project accessibleProject : accessibleProjects) {
        if (searchIds.contains(accessibleProject.getId()))
            output.add(accessibleProject);
    }
    return output;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class ProjectDatabaseHandler method createProjectLink.

private Optional<ProjectLink> createProjectLink(String id, ProjectRelationship relationship, String parentNodeId, Deque<String> visitedIds, Map<String, Project> projectMap, Map<String, Release> releaseMap, int maxDepth) {
    ProjectLink projectLink = null;
    if (!visitedIds.contains(id) && (maxDepth < 0 || visitedIds.size() < maxDepth)) {
        visitedIds.push(id);
        Project project = projectMap.get(id);
        if (project != null) {
            projectLink = new ProjectLink(id, project.name);
            if (project.isSetReleaseIdToUsage() && (maxDepth < 0 || visitedIds.size() < maxDepth)) {
                // ProjectLink on the last level does not get children added
                List<ReleaseLink> linkedReleases = componentDatabaseHandler.getLinkedReleases(project, releaseMap, visitedIds);
                fillMainlineStates(linkedReleases, project.getReleaseIdToUsage());
                projectLink.setLinkedReleases(nullToEmptyList(linkedReleases));
            }
            projectLink.setNodeId(generateNodeId(id)).setParentNodeId(parentNodeId).setRelation(relationship).setVersion(project.getVersion()).setState(project.getState()).setProjectType(project.getProjectType()).setClearingState(project.getClearingState()).setTreeLevel(visitedIds.size() - 1);
            if (project.isSetLinkedProjects()) {
                List<ProjectLink> subprojectLinks = iterateProjectRelationShips(project.getLinkedProjects(), projectLink.getNodeId(), visitedIds, projectMap, releaseMap, maxDepth);
                projectLink.setSubprojects(subprojectLinks);
            }
        } else {
            log.error("Broken ProjectLink in project with id: " + parentNodeId + ". Linked project with id " + id + " was not in the project cache");
        }
        visitedIds.pop();
    }
    return Optional.ofNullable(projectLink);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)

Example 13 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project 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 14 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project 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)

Example 15 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project 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)

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)87 User (org.eclipse.sw360.datahandler.thrift.users.User)46 Test (org.junit.Test)42 TException (org.apache.thrift.TException)27 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)16 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)12 Release (org.eclipse.sw360.datahandler.thrift.components.Release)12 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)10 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)6 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 HashSet (java.util.HashSet)5 ResponseEntity (org.springframework.http.ResponseEntity)5