use of org.eclipse.sw360.portal.common.ThriftJsonSerializer 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));
}
use of org.eclipse.sw360.portal.common.ThriftJsonSerializer in project sw360portal by sw360.
the class ProjectPortlet method serveGetClearingStateSummaries.
private void serveGetClearingStateSummaries(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
User user = UserCacheHolder.getUserFromRequest(request);
List<Project> projects;
String[] ids = request.getParameterValues(Project._Fields.ID.toString() + "[]");
if (ids == null || ids.length == 0) {
JSONArray jsonResponse = createJSONArray();
writeJSON(request, response, jsonResponse);
} else {
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
projects = client.getProjectsById(Arrays.asList(ids), user);
} catch (TException e) {
log.error("Could not fetch project summary from backend!", e);
projects = Collections.emptyList();
}
projects = getWithFilledClearingStateSummaryIncludingSubprojects(projects, user);
JSONArray jsonResponse = createJSONArray();
ThriftJsonSerializer thriftJsonSerializer = new ThriftJsonSerializer();
for (Project project : projects) {
try {
JSONObject row = createJSONObject();
row.put("id", project.getId());
row.put("clearing", JsonHelpers.toJson(project.getReleaseClearingStateSummary(), thriftJsonSerializer));
ProjectClearingState clearingState = project.getClearingState();
if (clearingState == null) {
row.put("clearingstate", "Unknown");
} else {
row.put("clearingstate", ThriftEnumUtils.enumToString(clearingState));
}
jsonResponse.put(row);
} catch (JSONException e) {
log.error("cannot serialize json", e);
}
}
writeJSON(request, response, jsonResponse);
}
}
Aggregations