use of org.eclipse.sw360.datahandler.thrift.projects.Project 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);
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method update.
@UsedAsLiferayAction
public void update(ActionRequest request, ActionResponse response) throws PortletException, IOException {
String id = request.getParameter(PROJECT_ID);
User user = UserCacheHolder.getUserFromRequest(request);
RequestStatus requestStatus;
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
if (id != null) {
Project project = client.getProjectByIdForEdit(id, user);
ProjectPortletUtils.updateProjectFromRequest(request, project);
String ModerationRequestCommentMsg = request.getParameter(MODERATION_REQUEST_COMMENT);
user.setCommentMadeDuringModerationRequest(ModerationRequestCommentMsg);
requestStatus = client.updateProject(project, user);
setSessionMessage(request, requestStatus, "Project", "update", printName(project));
cleanUploadHistory(user.getEmail(), id);
response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
response.setRenderParameter(PROJECT_ID, request.getParameter(PROJECT_ID));
} else {
// Add project
Project project = new Project();
ProjectPortletUtils.updateProjectFromRequest(request, project);
AddDocumentRequestSummary summary = client.addProject(project, user);
AddDocumentRequestStatus status = summary.getRequestStatus();
switch(status) {
case SUCCESS:
String successMsg = "Project " + printName(project) + " added successfully";
SessionMessages.add(request, "request_processed", successMsg);
response.setRenderParameter(PROJECT_ID, summary.getId());
response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
break;
case DUPLICATE:
setSW360SessionError(request, ErrorMessages.PROJECT_DUPLICATE);
response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
prepareRequestForEditAfterDuplicateError(request, project, user);
break;
default:
setSW360SessionError(request, ErrorMessages.PROJECT_NOT_ADDED);
response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
}
}
} catch (TException e) {
log.error("Error updating project in backend!", e);
setSW360SessionError(request, ErrorMessages.DEFAULT_ERROR_MESSAGE);
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method serveNewTableRowLinkedProjects.
private void serveNewTableRowLinkedProjects(ResourceRequest request, ResourceResponse response, String[] linkedIds) throws IOException, PortletException {
final User user = UserCacheHolder.getUserFromRequest(request);
List<ProjectLink> linkedProjects = new ArrayList<>();
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
for (String linkedId : linkedIds) {
Project project = client.getProjectById(linkedId, user);
ProjectLink linkedProject = new ProjectLink(linkedId, project.getName());
linkedProject.setRelation(ProjectRelationship.CONTAINED);
linkedProject.setVersion(project.getVersion());
linkedProjects.add(linkedProject);
}
} catch (TException e) {
log.error("Error getting projects!", e);
throw new PortletException("cannot get projects " + Arrays.toString(linkedIds), e);
}
request.setAttribute(PROJECT_LIST, linkedProjects);
include("/html/projects/ajax/linkedProjectsAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method getFilteredProjectList.
private List<Project> getFilteredProjectList(PortletRequest request) throws IOException {
final User user = UserCacheHolder.getUserFromRequest(request);
Map<String, Set<String>> filterMap = loadFilterMapFromRequest(request);
loadAndStoreStickyProjectGroup(request, user, filterMap);
String id = request.getParameter(Project._Fields.ID.toString());
return findProjectsByFiltersOrId(filterMap, id, user);
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method prepareProjectDuplicate.
private void prepareProjectDuplicate(RenderRequest request) {
User user = UserCacheHolder.getUserFromRequest(request);
String id = request.getParameter(PROJECT_ID);
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
try {
if (id != null) {
ProjectService.Iface client = thriftClients.makeProjectClient();
String emailFromRequest = LifeRayUserSession.getEmailFromRequest(request);
String department = user.getDepartment();
Project newProject = PortletUtils.cloneProject(emailFromRequest, department, client.getProjectById(id, user));
setAttachmentsInRequest(request, newProject.getAttachments());
request.setAttribute(PROJECT, newProject);
putDirectlyLinkedProjectsInRequest(request, newProject, user);
putDirectlyLinkedReleasesInRequest(request, newProject);
request.setAttribute(USING_PROJECTS, Collections.emptySet());
} else {
Project project = new Project();
project.setBusinessUnit(user.getDepartment());
setAttachmentsInRequest(request, project.getAttachments());
request.setAttribute(PROJECT, project);
putDirectlyLinkedProjectsInRequest(request, project, user);
putDirectlyLinkedReleasesInRequest(request, project);
request.setAttribute(USING_PROJECTS, Collections.emptySet());
}
} catch (TException e) {
log.error("Error fetching project from backend!", e);
}
}
Aggregations