use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectPortletUtils method makeAttachmentUsages.
public static List<AttachmentUsage> makeAttachmentUsages(Project project, Map<String, Set<String>> selectedReleaseAndAttachmentIds, Map<String, Set<LicenseNameWithText>> excludedLicensesPerAttachmentId) {
List<AttachmentUsage> attachmentUsages = Lists.newArrayList();
for (String releaseId : selectedReleaseAndAttachmentIds.keySet()) {
for (String attachmentContentId : selectedReleaseAndAttachmentIds.get(releaseId)) {
AttachmentUsage usage = new AttachmentUsage();
usage.setUsedBy(Source.projectId(project.getId()));
usage.setOwner(Source.releaseId(releaseId));
usage.setAttachmentContentId(attachmentContentId);
Set<String> licenseIds = CommonUtils.nullToEmptySet(excludedLicensesPerAttachmentId.get(attachmentContentId)).stream().filter(LicenseNameWithText::isSetLicenseName).map(LicenseNameWithText::getLicenseName).collect(Collectors.toSet());
usage.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(licenseIds)));
attachmentUsages.add(usage);
}
}
return attachmentUsages;
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class DisplayProjectChanges method prepareLicenseInfoHeaderTextInProject.
private Project prepareLicenseInfoHeaderTextInProject(Project project) {
Project modifiedProject = project.deepCopy();
String defaultTextAsHtmlForDisplay = "<span title=\"" + defaultLicenseInfoHeaderText + "\">" + PortalConstants.DEFAULT_LICENSE_INFO_HEADER_TEXT_FOR_DISPALY + "</span>";
if (!modifiedProject.isSetLicenseInfoHeaderText()) {
// if the project contains the default license info header text, we wrap it into an html span-element such that the default text is given as a hover text.
// this is only done for displaying it in a three-way merge in a moderation request.
modifiedProject.setLicenseInfoHeaderText(defaultTextAsHtmlForDisplay);
} else {
// for a custom text escape html properly
modifiedProject.setLicenseInfoHeaderText(StringEscapeUtils.escapeHtml(modifiedProject.getLicenseInfoHeaderText()).replace("\n", "<br>"));
}
return modifiedProject;
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class DisplayProjectChanges method renderProjectLinkListCompare.
private void renderProjectLinkListCompare(StringBuilder display, Map<String, ProjectRelationship> oldProjectRelationshipMap, Map<String, ProjectRelationship> deleteProjectRelationshipMap, Map<String, ProjectRelationship> updateProjectRelationshipMap, Set<String> projectIds, User user) {
if (projectIds.isEmpty())
return;
StringBuilder candidate = new StringBuilder();
try {
ProjectService.Iface client = new ThriftClients().makeProjectClient();
Map<String, ProjectRelationship> changeMap = new HashMap<>();
for (String projectId : projectIds) {
ProjectRelationship updateProjectRelationship = updateProjectRelationshipMap.get(projectId);
ProjectRelationship oldProjectRelationship = oldProjectRelationshipMap.get(projectId);
if (!updateProjectRelationship.equals(oldProjectRelationship)) {
changeMap.put(projectId, oldProjectRelationshipMap.get(projectId));
}
}
// ! This code doubling is done to reduce the database queries. I.e. one big query instead of multiple small ones
for (ProjectLink projectLink : client.getLinkedProjects(changeMap, user)) {
ProjectRelationship updateProjectRelationship = updateProjectRelationshipMap.get(projectLink.getId());
ProjectRelationship deleteProjectRelationship = deleteProjectRelationshipMap.get(projectLink.getId());
ProjectRelationship oldProjectRelationship = oldProjectRelationshipMap.get(projectLink.getId());
candidate.append(String.format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", projectLink.getName(), oldProjectRelationship, deleteProjectRelationship, updateProjectRelationship));
}
} catch (TException ignored) {
}
String tableContent = candidate.toString();
if (!tableContent.isEmpty()) {
display.append(String.format("<table class=\"%s\" id=\"%sUpdated\" >", tableClasses, idPrefix));
display.append("<thead><tr><th colspan=\"4\">Updated Project Links</th></tr>" + "<tr><th>Project Name</th>" + "<th>Current Project Relationship</th>" + "<th>Deleted Project Relationship</th>" + "<th>Suggested Project Relationship</th></tr>" + "</thead><tbody>");
display.append(tableContent);
display.append("</tbody></table>");
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class DisplayProjectChanges method doStartTag.
public int doStartTag() throws JspException {
JspWriter jspWriter = pageContext.getOut();
StringBuilder display = new StringBuilder();
String namespace = getNamespace();
if (additions == null || deletions == null) {
return SKIP_BODY;
}
try {
for (Project._Fields field : Project._Fields.values()) {
switch(field) {
// ignored Fields
case ID:
case REVISION:
case TYPE:
case CREATED_BY:
case CREATED_ON:
case PERMISSIONS:
case RELEASE_CLEARING_STATE_SUMMARY:
case DOCUMENT_STATE:
// Taken care of externally
case ATTACHMENTS:
// Done in extra tables
case LINKED_PROJECTS:
case RELEASE_ID_TO_USAGE:
break;
default:
FieldMetaData fieldMetaData = Project.metaDataMap.get(field);
displaySimpleFieldOrSet(display, actual, additions, deletions, field, fieldMetaData, "");
}
}
String renderString = display.toString();
if (Strings.isNullOrEmpty(renderString)) {
renderString = "<h4> No changes in basic fields </h4>";
} else {
renderString = String.format("<table class=\"%s\" id=\"%schanges\" >", tableClasses, idPrefix) + "<thead><tr><th colspan=\"4\"> Changes for Basic fields</th></tr>" + String.format("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr></thead><tbody>", FIELD_NAME, CURRENT_VAL, DELETED_VAL, SUGGESTED_VAL) + renderString + "</tbody></table>";
}
StringBuilder linkedProjectsDisplay = new StringBuilder();
User user = getUserFromContext("Cannot render project changes without logged in user in request");
renderLinkedProjects(linkedProjectsDisplay, user);
StringBuilder releaseUsageDisplay = new StringBuilder();
renderReleaseIdToUsage(releaseUsageDisplay, user);
jspWriter.print(renderString + linkedProjectsDisplay.toString() + releaseUsageDisplay.toString());
} catch (Exception e) {
throw new JspException(e);
}
return SKIP_BODY;
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class DisplayProjectChanges method renderProjectLinkList.
private void renderProjectLinkList(StringBuilder display, Map<String, ProjectRelationship> projectRelationshipMap, Set<String> projectIds, String msg, User user) {
if (projectIds.isEmpty())
return;
Map<String, ProjectRelationship> filteredMap = new HashMap<>();
for (String id : projectIds) {
filteredMap.put(id, projectRelationshipMap.get(id));
}
StringBuilder candidate = new StringBuilder();
try {
ProjectService.Iface client = new ThriftClients().makeProjectClient();
for (ProjectLink projectLink : client.getLinkedProjects(filteredMap, user)) {
candidate.append(String.format("<tr><td>%s</td><td>%s</td></tr>", projectLink.getName(), projectLink.getRelation()));
}
} catch (TException ignored) {
}
String tableContent = candidate.toString();
if (!tableContent.isEmpty()) {
display.append(String.format("<table class=\"%s\" id=\"%s%s\" >", tableClasses, idPrefix, msg));
display.append(String.format("<thead><tr><th colspan=\"2\">%s</th></tr>" + "<tr><th>Project Name</th><th>Project Relationship</th></tr></thead><tbody>", msg));
display.append(tableContent);
display.append("</tbody></table>");
}
}
Aggregations