Search in sources :

Example 1 with ReleaseClearingStateSummary

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

the class ProjectSummaryTest method testAllRequiredFieldsAreSet.

@Test
public void testAllRequiredFieldsAreSet() throws Exception {
    Project project = new Project();
    Project copy = new Project();
    for (Project._Fields renderedField : PROJECT_RENDERED_FIELDS) {
        switch(renderedField) {
            case STATE:
                project.state = ProjectState.ACTIVE;
                break;
            case PERMISSIONS:
                project.permissions = Collections.emptyMap();
                break;
            case EXTERNAL_IDS:
                project.externalIds = Collections.emptyMap();
                break;
            case ATTACHMENTS:
                project.attachments = Collections.emptySet();
                break;
            case PROJECT_TYPE:
                project.projectType = ProjectType.INTERNAL;
                break;
            case MODERATORS:
                project.moderators = ImmutableSet.of("moderator@sw360.org");
                break;
            case CONTRIBUTORS:
                project.contributors = ImmutableSet.of("contributor1@sw360.org", "contributor2@sw360.org");
                break;
            case SECURITY_RESPONSIBLES:
                project.securityResponsibles = ImmutableSet.of("securityresponsible1@sw360.org", "securityresponsible2@sw360.org");
                break;
            case VISBILITY:
                project.visbility = Visibility.EVERYONE;
                break;
            case LINKED_PROJECTS:
                project.linkedProjects = Collections.emptyMap();
                break;
            case RELEASE_ID_TO_USAGE:
                project.releaseIdToUsage = Collections.emptyMap();
                break;
            case RELEASE_CLEARING_STATE_SUMMARY:
                project.releaseClearingStateSummary = new ReleaseClearingStateSummary();
                break;
            case CLEARING_STATE:
                project.clearingState = ProjectClearingState.OPEN;
                break;
            case ROLES:
                project.roles = Collections.emptyMap();
                break;
            case ENABLE_SVM:
                project.enableSvm = true;
                break;
            default:
                // most fields are string
                project.setFieldValue(renderedField, "asd");
                break;
        }
    }
    ProjectSummary.setSummaryFields(project, copy);
    for (Project._Fields renderedField : PROJECT_RENDERED_FIELDS) {
        assertNotNull(copy.getFieldValue(renderedField));
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReleaseClearingStateSummary(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary) Test(org.junit.Test)

Example 2 with ReleaseClearingStateSummary

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

the class ProjectDatabaseHandler method fillClearingStateSummary.

public List<Project> fillClearingStateSummary(List<Project> projects, User user) {
    Function<Project, Set<String>> extractReleaseIds = project -> CommonUtils.nullToEmptyMap(project.getReleaseIdToUsage()).keySet();
    Set<String> allReleaseIds = projects.stream().map(extractReleaseIds).reduce(Sets.newHashSet(), Sets::union);
    if (!allReleaseIds.isEmpty()) {
        Map<String, Release> releasesById = ThriftUtils.getIdMap(componentDatabaseHandler.getReleasesForClearingStateSummary(allReleaseIds));
        for (Project project : projects) {
            final Set<String> releaseIds = extractReleaseIds.apply(project);
            List<Release> releases = releaseIds.stream().map(releasesById::get).collect(Collectors.toList());
            final ReleaseClearingStateSummary releaseClearingStateSummary = ReleaseClearingStateSummaryComputer.computeReleaseClearingStateSummary(releases, project.getClearingTeam());
            project.setReleaseClearingStateSummary(releaseClearingStateSummary);
        }
    }
    return projects;
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) SW360Assert.fail(org.eclipse.sw360.datahandler.common.SW360Assert.fail) MailConstants(org.eclipse.sw360.mail.MailConstants) ProjectVulnerabilityRating(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ReleaseClearingStateSummaryComputer(org.eclipse.sw360.datahandler.businessrules.ReleaseClearingStateSummaryComputer) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) Logger(org.apache.log4j.Logger) AttachmentConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentConnector) org.eclipse.sw360.datahandler.thrift(org.eclipse.sw360.datahandler.thrift) ProjectModerator(org.eclipse.sw360.datahandler.entitlement.ProjectModerator) HttpClient(org.ektorp.http.HttpClient) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) MailUtil(org.eclipse.sw360.mail.MailUtil) com.google.common.collect(com.google.common.collect) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) org.eclipse.sw360.datahandler.common(org.eclipse.sw360.datahandler.common) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) PermissionUtils.makePermission(org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission) MalformedURLException(java.net.MalformedURLException) SummaryType(org.eclipse.sw360.components.summary.SummaryType) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple) VisibleForTesting(com.google.common.annotations.VisibleForTesting) org.eclipse.sw360.datahandler.thrift.components(org.eclipse.sw360.datahandler.thrift.components) SW360Assert.assertNotNull(org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull) Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 3 with ReleaseClearingStateSummary

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

the class ReleaseClearingStateSummaryComputer method computeReleaseClearingStateSummary.

public static ReleaseClearingStateSummary computeReleaseClearingStateSummary(List<Release> releases, String clearingTeam) {
    ReleaseClearingStateSummary summary = new ReleaseClearingStateSummary(0, 0, 0, 0, 0);
    if (releases == null) {
        return summary;
    }
    for (Release release : releases) {
        Map<String, FossologyStatus> fossologyStatuses = nullToEmptyMap(release.getClearingTeamToFossologyStatus());
        ViewedState globalState = getGlobalState(release.getClearingState());
        ViewedState myTeamState = getStateOfFossology(fossologyStatuses.get(clearingTeam));
        ViewedState otherTeamState = getBestStateOfFossologyForOtherTeams(clearingTeam, fossologyStatuses);
        addReleaseWithStates(summary, globalState, myTeamState, otherTeamState);
    }
    return summary;
}
Also used : FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release) ReleaseClearingStateSummary(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary)

Example 4 with ReleaseClearingStateSummary

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

the class ProjectPortletTest method testJsonOfClearing.

@Test
public void testJsonOfClearing() throws Exception {
    ReleaseClearingStateSummary releaseClearingStateSummary = new ReleaseClearingStateSummary().setNewRelease(1).setReportAvailable(5).setUnderClearing(6).setUnderClearingByProjectTeam(17).setApproved(4);
    ThriftJsonSerializer thriftJsonSerializer = new ThriftJsonSerializer();
    String json = thriftJsonSerializer.toJson(releaseClearingStateSummary);
    assertThat(json, containsString("{\"newRelease\":1,\"underClearing\":6,\"underClearingByProjectTeam\":17,\"reportAvailable\":5,\"approved\":4}"));
    ObjectMapper objectMapper = new ObjectMapper();
    @SuppressWarnings("unchecked") Map<String, Object> map = objectMapper.readValue(json, Map.class);
    assertThat(map, hasEntry("newRelease", (Object) 1));
}
Also used : ThriftJsonSerializer(org.eclipse.sw360.portal.common.ThriftJsonSerializer) Matchers.containsString(org.hamcrest.Matchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReleaseClearingStateSummary(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary) Test(org.junit.Test)

Aggregations

ReleaseClearingStateSummary (org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 com.google.common.collect (com.google.common.collect)1 MalformedURLException (java.net.MalformedURLException)1 Instant (java.time.Instant)1 java.util (java.util)1 TimeUnit (java.util.concurrent.TimeUnit)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.log4j.Logger)1 SummaryType (org.eclipse.sw360.components.summary.SummaryType)1 ReleaseClearingStateSummaryComputer (org.eclipse.sw360.datahandler.businessrules.ReleaseClearingStateSummaryComputer)1 org.eclipse.sw360.datahandler.common (org.eclipse.sw360.datahandler.common)1 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)1 SW360Assert.assertNotNull (org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull)1 SW360Assert.fail (org.eclipse.sw360.datahandler.common.SW360Assert.fail)1