use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method serveProjectSearchResults.
private void serveProjectSearchResults(ResourceRequest request, ResourceResponse response, String searchText) throws IOException, PortletException {
final User user = UserCacheHolder.getUserFromRequest(request);
List<Project> searchResult;
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
if (isNullOrEmpty(searchText)) {
searchResult = client.getAccessibleProjectsSummary(user);
} else {
searchResult = client.searchByName(searchText, user);
}
} catch (TException e) {
log.error("Error searching projects", e);
searchResult = Collections.emptyList();
}
request.setAttribute(PortalConstants.PROJECT_SEARCH, searchResult);
include("/html/projects/ajax/searchProjectsAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method removeProject.
private RequestStatus removeProject(PortletRequest request) {
String projectId = request.getParameter(PortalConstants.PROJECT_ID);
String encodedDeleteComment = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
final User user = UserCacheHolder.getUserFromRequest(request);
if (encodedDeleteComment != null) {
String deleteComment = new String(Base64.getDecoder().decode(encodedDeleteComment));
user.setCommentMadeDuringModerationRequest(deleteComment);
}
try {
deleteUnneededAttachments(user.getEmail(), projectId);
ProjectService.Iface client = thriftClients.makeProjectClient();
return client.deleteProject(projectId, user);
} catch (TException e) {
log.error("Error deleting project from backend", e);
}
return RequestStatus.FAILURE;
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method prepareDetailView.
private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
User user = UserCacheHolder.getUserFromRequest(request);
String id = request.getParameter(PROJECT_ID);
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
request.setAttribute(DOCUMENT_ID, id);
request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());
if (id != null) {
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
Project project = client.getProjectById(id, user);
project = getWithFilledClearingStateSummary(project, user);
request.setAttribute(PROJECT, project);
setAttachmentsInRequest(request, project.getAttachments());
List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, user);
request.setAttribute(PROJECT_LIST, mappedProjectLinks);
putDirectlyLinkedReleasesInRequest(request, project);
Set<Project> usingProjects = client.searchLinkingProjects(id, user);
request.setAttribute(USING_PROJECTS, usingProjects);
putReleasesAndProjectIntoRequest(request, id, user);
putVulnerabilitiesInRequest(request, id, user);
request.setAttribute(VULNERABILITY_RATINGS_EDITABLE, PermissionUtils.makePermission(project, user).isActionAllowed(RequestedAction.WRITE));
addProjectBreadcrumb(request, response, project);
} catch (TException e) {
log.error("Error fetching project from backend!", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method prepareLicenseInfo.
private void prepareLicenseInfo(RenderRequest request, RenderResponse response) throws IOException, PortletException {
User user = UserCacheHolder.getUserFromRequest(request);
String id = request.getParameter(PROJECT_ID);
request.setAttribute(PortalConstants.SW360_USER, user);
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
request.setAttribute(PROJECT_LINK_TABLE_MODE, PROJECT_LINK_TABLE_MODE_LICENSE_INFO);
if (id != null) {
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
Project project = client.getProjectById(id, user);
request.setAttribute(PROJECT, project);
request.setAttribute(DOCUMENT_ID, id);
LicenseInfoService.Iface licenseInfoClient = thriftClients.makeLicenseInfoClient();
List<OutputFormatInfo> outputFormats = licenseInfoClient.getPossibleOutputFormats();
request.setAttribute(PortalConstants.LICENSE_INFO_OUTPUT_FORMATS, outputFormats);
List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, filterAndSortAttachments(SW360Constants.LICENSE_INFO_ATTACHMENT_TYPES), true, user);
request.setAttribute(PROJECT_LIST, mappedProjectLinks);
addProjectBreadcrumb(request, response, project);
AttachmentService.Iface attachmentClient = thriftClients.makeAttachmentClient();
Map<Source, Set<String>> containedAttachments = ProjectPortletUtils.extractContainedAttachments(mappedProjectLinks);
Map<Map<Source, String>, Integer> attachmentUsages = attachmentClient.getAttachmentUsageCount(containedAttachments, UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet())));
Map<String, Integer> countMap = attachmentUsages.entrySet().stream().collect(Collectors.toMap(entry -> {
Entry<Source, String> key = entry.getKey().entrySet().iterator().next();
return key.getKey().getFieldValue() + "_" + key.getValue();
}, entry -> entry.getValue()));
request.setAttribute(ATTACHMENT_USAGE_COUNT_MAP, countMap);
} catch (TException e) {
log.error("Error fetching project from backend!", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method serveReleasesFromLinkedProjects.
private void serveReleasesFromLinkedProjects(ResourceRequest request, ResourceResponse response, String projectId) throws IOException, PortletException {
List<Release> searchResult;
Set<String> releaseIdsFromLinkedProjects = new HashSet<>();
User user = UserCacheHolder.getUserFromRequest(request);
try {
ComponentService.Iface componentClient = thriftClients.makeComponentClient();
ProjectService.Iface projectClient = thriftClients.makeProjectClient();
Project project = projectClient.getProjectById(projectId, user);
Map<String, ProjectRelationship> linkedProjects = CommonUtils.nullToEmptyMap(project.getLinkedProjects());
for (String linkedProjectId : linkedProjects.keySet()) {
Project linkedProject = projectClient.getProjectById(linkedProjectId, user);
if (linkedProject != null) {
Map<String, ProjectReleaseRelationship> releaseIdToUsage = CommonUtils.nullToEmptyMap(linkedProject.getReleaseIdToUsage());
releaseIdsFromLinkedProjects.addAll(releaseIdToUsage.keySet());
}
}
if (releaseIdsFromLinkedProjects.size() > 0) {
searchResult = componentClient.getReleasesById(releaseIdsFromLinkedProjects, user);
} else {
searchResult = Collections.emptyList();
}
} catch (TException e) {
log.error("Error searching projects", e);
searchResult = Collections.emptyList();
}
request.setAttribute(PortalConstants.RELEASE_SEARCH, searchResult);
include("/html/utils/ajax/searchReleasesAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
Aggregations