Search in sources :

Example 41 with Project

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;
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 42 with Project

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;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 43 with Project

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>");
    }
}
Also used : TException(org.apache.thrift.TException) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) HashMap(java.util.HashMap) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Example 44 with Project

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;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) JspException(javax.servlet.jsp.JspException) FieldMetaData(org.apache.thrift.meta_data.FieldMetaData) User(org.eclipse.sw360.datahandler.thrift.users.User) JspWriter(javax.servlet.jsp.JspWriter) JspException(javax.servlet.jsp.JspException) TException(org.apache.thrift.TException)

Example 45 with Project

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>");
    }
}
Also used : TException(org.apache.thrift.TException) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) HashMap(java.util.HashMap) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)87 User (org.eclipse.sw360.datahandler.thrift.users.User)46 Test (org.junit.Test)42 TException (org.apache.thrift.TException)27 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)16 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)12 Release (org.eclipse.sw360.datahandler.thrift.components.Release)12 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)10 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)6 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 HashSet (java.util.HashSet)5 ResponseEntity (org.springframework.http.ResponseEntity)5