use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method prepareProjectEdit.
private void prepareProjectEdit(RenderRequest request) {
User user = UserCacheHolder.getUserFromRequest(request);
String id = request.getParameter(PROJECT_ID);
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
Project project;
Set<Project> usingProjects;
request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());
if (id != null) {
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
project = client.getProjectByIdForEdit(id, user);
usingProjects = client.searchLinkingProjects(id, user);
} catch (TException e) {
log.error("Something went wrong with fetching the project", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
return;
}
request.setAttribute(PROJECT, project);
request.setAttribute(DOCUMENT_ID, id);
setAttachmentsInRequest(request, project.getAttachments());
try {
putDirectlyLinkedProjectsInRequest(request, project, user);
putDirectlyLinkedReleasesInRequest(request, project);
} catch (TException e) {
log.error("Could not fetch linked projects or linked releases in projects view.", e);
return;
}
request.setAttribute(USING_PROJECTS, usingProjects);
Map<RequestedAction, Boolean> permissions = project.getPermissions();
DocumentState documentState = project.getDocumentState();
addEditDocumentMessage(request, permissions, documentState);
} else {
if (request.getAttribute(PROJECT) == null) {
project = new Project();
project.setBusinessUnit(user.getDepartment());
request.setAttribute(PROJECT, project);
setAttachmentsInRequest(request, project.getAttachments());
try {
putDirectlyLinkedProjectsInRequest(request, project, user);
putDirectlyLinkedReleasesInRequest(request, project);
} catch (TException e) {
log.error("Could not put empty linked projects or linked releases in projects view.", e);
}
request.setAttribute(USING_PROJECTS, Collections.emptySet());
SessionMessages.add(request, "request_processed", "New Project");
}
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method downloadLicenseInfo.
private void downloadLicenseInfo(ResourceRequest request, ResourceResponse response) throws IOException {
final User user = UserCacheHolder.getUserFromRequest(request);
final String projectId = request.getParameter(PROJECT_ID);
final String outputGenerator = request.getParameter(PortalConstants.LICENSE_INFO_SELECTED_OUTPUT_FORMAT);
final Map<String, Set<String>> selectedReleaseAndAttachmentIds = ProjectPortletUtils.getSelectedReleaseAndAttachmentIdsFromRequest(request);
final Set<String> attachmentIds = selectedReleaseAndAttachmentIds.values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
final Map<String, Set<LicenseNameWithText>> excludedLicensesPerAttachmentId = ProjectPortletUtils.getExcludedLicensesPerAttachmentIdFromRequest(attachmentIds, request);
try {
final LicenseInfoService.Iface licenseInfoClient = thriftClients.makeLicenseInfoClient();
final ProjectService.Iface projectClient = thriftClients.makeProjectClient();
Project project = projectClient.getProjectById(projectId, user);
LicenseInfoFile licenseInfoFile = licenseInfoClient.getLicenseInfoFile(project, user, outputGenerator, selectedReleaseAndAttachmentIds, excludedLicensesPerAttachmentId);
try {
replaceAttachmentUsages(user, selectedReleaseAndAttachmentIds, excludedLicensesPerAttachmentId, project);
} catch (TException e) {
// there's no need to abort the user's desired action just because the ancillary action of storing selection failed
log.warn("LicenseInfo usage is not stored due to exception: ", e);
}
OutputFormatInfo outputFormatInfo = licenseInfoFile.getOutputFormatInfo();
String filename = String.format("LicenseInfo-%s-%s.%s", project.getName(), SW360Utils.getCreatedOn(), outputFormatInfo.getFileExtension());
String mimetype = outputFormatInfo.getMimeType();
if (isNullOrEmpty(mimetype)) {
mimetype = URLConnection.guessContentTypeFromName(filename);
}
PortletResponseUtil.sendFile(request, response, filename, licenseInfoFile.getGeneratedOutput(), mimetype);
} catch (TException e) {
log.error("Error getting LicenseInfo file for project with id " + projectId + " and generator " + outputGenerator, e);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method exportExcel.
private void exportExcel(ResourceRequest request, ResourceResponse response) {
final User user = UserCacheHolder.getUserFromRequest(request);
try {
boolean extendedByReleases = Boolean.valueOf(request.getParameter(PortalConstants.EXTENDED_EXCEL_EXPORT));
List<Project> projects = getFilteredProjectList(request);
ProjectExporter exporter = new ProjectExporter(thriftClients.makeComponentClient(), thriftClients.makeProjectClient(), user, projects, extendedByReleases);
PortletResponseUtil.sendFile(request, response, "Projects.xlsx", exporter.makeExcelExport(projects), CONTENT_TYPE_OPENXML_SPREADSHEET);
} catch (IOException | SW360Exception e) {
log.error("An error occurred while generating the Excel export", e);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortlet method updateVulnerabilityRating.
private void updateVulnerabilityRating(ResourceRequest request, ResourceResponse response) throws IOException {
String projectId = request.getParameter(PortalConstants.PROJECT_ID);
User user = UserCacheHolder.getUserFromRequest(request);
VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
RequestStatus requestStatus = RequestStatus.FAILURE;
try {
Optional<ProjectVulnerabilityRating> projectVulnerabilityRatings = wrapThriftOptionalReplacement(vulClient.getProjectVulnerabilityRatingByProjectId(projectId, user));
ProjectVulnerabilityRating link = ProjectPortletUtils.updateProjectVulnerabilityRatingFromRequest(projectVulnerabilityRatings, request);
requestStatus = vulClient.updateProjectVulnerabilityRating(link, user);
} catch (TException e) {
log.error("Error updating vulnerability ratings for project in backend.", e);
}
JSONObject responseData = JSONFactoryUtil.createJSONObject();
responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
PrintWriter writer = response.getWriter();
writer.write(responseData.toString());
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortletUtils method extractContainedAttachments.
/**
* Walks through a list of project links and extracts all release attachments
* with their owner. The returned map is a mapping from a release to its
* attachment content ids.
*
* @param projectLinks
* list of project links to walk through
*
* @return map of releases and their attachment content ids
*/
public static Map<Source, Set<String>> extractContainedAttachments(Collection<ProjectLink> projectLinks) {
Map<Source, Set<String>> attachments = Maps.newHashMap();
for (ProjectLink projectLink : projectLinks) {
for (ReleaseLink releaseLink : projectLink.linkedReleases) {
Set<String> attachmentIds = attachments.getOrDefault(Source.releaseId(releaseLink.getId()), Sets.newHashSet());
attachmentIds.addAll(releaseLink.getAttachments().stream().map(a -> a.getAttachmentContentId()).collect(Collectors.toList()));
attachments.put(Source.releaseId(releaseLink.getId()), attachmentIds);
}
}
return attachments;
}
Aggregations