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));
}
}
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;
}
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;
}
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));
}
Aggregations