Search in sources :

Example 1 with ReleaseClearingStatusData

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

the class ProjectDatabaseHandler method getReleaseClearingStatuses.

public List<ReleaseClearingStatusData> getReleaseClearingStatuses(String projectId, User user) throws SW360Exception {
    Project project = getProjectById(projectId, user);
    SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdsToProject = releaseIdToProjects(project, user);
    List<Release> releasesById = componentDatabaseHandler.getFullReleases(releaseIdsToProject.keySet());
    Map<String, Component> componentsById = ThriftUtils.getIdMap(componentDatabaseHandler.getComponentsShort(releasesById.stream().map(Release::getComponentId).collect(Collectors.toSet())));
    List<ReleaseClearingStatusData> releaseClearingStatuses = new ArrayList<>();
    for (Release release : releasesById) {
        List<String> projectNames = new ArrayList<>();
        List<String> mainlineStates = new ArrayList<>();
        for (ProjectWithReleaseRelationTuple projectWithReleaseRelation : releaseIdsToProject.get(release.getId())) {
            projectNames.add(printName(projectWithReleaseRelation.getProject()));
            mainlineStates.add(ThriftEnumUtils.enumToString(projectWithReleaseRelation.getRelation().getMainlineState()));
            if (projectNames.size() > 3) {
                projectNames.add("...");
                mainlineStates.add("...");
                break;
            }
        }
        releaseClearingStatuses.add(new ReleaseClearingStatusData(release).setProjectNames(joinStrings(projectNames)).setMainlineStates(joinStrings(mainlineStates)).setComponentType(componentsById.get(release.getComponentId()).getComponentType()));
    }
    return releaseClearingStatuses;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple)

Example 2 with ReleaseClearingStatusData

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

the class ProjectPortlet method exportReleasesSpreadsheet.

private void exportReleasesSpreadsheet(ResourceRequest request, ResourceResponse response) {
    final User user = UserCacheHolder.getUserFromRequest(request);
    try {
        String id = request.getParameter(PROJECT_ID);
        ProjectService.Iface client = thriftClients.makeProjectClient();
        Project project = null;
        if (!isNullOrEmpty(id)) {
            project = client.getProjectById(id, user);
        }
        if (project != null) {
            List<ReleaseClearingStatusData> releaseStringMap = client.getReleaseClearingStatuses(id, user);
            List<Release> releases = releaseStringMap.stream().map(ReleaseClearingStatusData::getRelease).sorted(Comparator.comparing(SW360Utils::printFullname)).collect(Collectors.toList());
            ReleaseExporter exporter = new ReleaseExporter(thriftClients.makeComponentClient(), releases, user, releaseStringMap);
            PortletResponseUtil.sendFile(request, response, String.format("releases-%s-%s-%s.xlsx", project.getName(), project.getVersion(), SW360Utils.getCreatedOn()), exporter.makeExcelExport(releases), CONTENT_TYPE_OPENXML_SPREADSHEET);
        }
    } catch (IOException | TException e) {
        log.error("An error occurred while generating the Excel export", e);
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ReleaseClearingStatusData(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData) IOException(java.io.IOException) ReleaseExporter(org.eclipse.sw360.exporter.ReleaseExporter) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

IOException (java.io.IOException)1 TException (org.apache.thrift.TException)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 Release (org.eclipse.sw360.datahandler.thrift.components.Release)1 ReleaseClearingStatusData (org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData)1 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)1 ProjectWithReleaseRelationTuple (org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple)1 User (org.eclipse.sw360.datahandler.thrift.users.User)1 ReleaseExporter (org.eclipse.sw360.exporter.ReleaseExporter)1