Search in sources :

Example 16 with Release._Fields

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

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class ReleaseModerator method updateEccInformation.

private Release updateEccInformation(Release release, Release releaseAdditions) {
    EccInformation actual = release.getEccInformation();
    EccInformation additions = releaseAdditions.getEccInformation();
    if (additions == null) {
        return release;
    }
    if (actual == null) {
        actual = newDefaultEccInformation();
    }
    for (EccInformation._Fields field : EccInformation._Fields.values()) {
        if (additions.isSet(field)) {
            actual.setFieldValue(field, additions.getFieldValue(field));
        }
    }
    release.setEccInformation(actual);
    return release;
}
Also used : SW360Utils.newDefaultEccInformation(org.eclipse.sw360.datahandler.common.SW360Utils.newDefaultEccInformation)

Example 18 with Release._Fields

use of org.eclipse.sw360.datahandler.thrift.components.Release._Fields in project sw360portal by sw360.

the class VendorRepository method fillVendor.

public void fillVendor(Release release) {
    if (release.isSetVendorId()) {
        final String vendorId = release.getVendorId();
        if (!isNullOrEmpty(vendorId)) {
            final Vendor vendor = get(vendorId);
            if (vendor != null)
                release.setVendor(vendor);
        }
        release.unsetVendorId();
    }
}
Also used : Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor)

Example 19 with Release._Fields

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

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

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)93 User (org.eclipse.sw360.datahandler.thrift.users.User)42 TException (org.apache.thrift.TException)38 Test (org.junit.Test)23 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)20 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)13 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)13 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)12 FieldMetaData (org.apache.thrift.meta_data.FieldMetaData)11 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 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