Search in sources :

Example 1 with Source

use of org.eclipse.sw360.datahandler.thrift.Source in project sw360portal by sw360.

the class AttachmentHandlerTest method testAttachmentUsageCount.

@Test
public void testAttachmentUsageCount() throws Exception {
    AttachmentUsage usage1 = createUsage("p1", "r1", "a11");
    AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
    AttachmentUsage usage3 = createUsage("p2", "r2", "a21");
    AttachmentUsage usage4 = createUsage("p3", "r1", "a11");
    AttachmentUsage usage5 = createUsage("p4", "r1", "a11");
    AttachmentUsage usage6 = createUsage("p5", "r3", "a31");
    handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5, usage6));
    Map<Source, Set<String>> queryFor = ImmutableMap.of(Source.releaseId("r1"), ImmutableSet.of("a11", "a12"), Source.releaseId("r3"), ImmutableSet.of("a31"));
    Map<Map<Source, String>, Integer> counts = handler.getAttachmentUsageCount(queryFor, null);
    Map<Map<Source, String>, Integer> expected = ImmutableMap.of(ImmutableMap.of(Source.releaseId("r1"), "a11"), 3, ImmutableMap.of(Source.releaseId("r1"), "a12"), 1, ImmutableMap.of(Source.releaseId("r3"), "a31"), 1);
    for (Entry<Map<Source, String>, Integer> entry : expected.entrySet()) {
        Assert.assertThat(counts.get(entry.getKey()), is(entry.getValue()));
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Source(org.eclipse.sw360.datahandler.thrift.Source)

Example 2 with Source

use of org.eclipse.sw360.datahandler.thrift.Source 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);
        }
    }
}
Also used : ReleaseClearingStatusData(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData) User(org.eclipse.sw360.datahandler.thrift.users.User) Release(org.eclipse.sw360.datahandler.thrift.components.Release) TSimpleJSONProtocol(org.apache.thrift.protocol.TSimpleJSONProtocol) TSerializer(org.apache.thrift.TSerializer) ProjectExporter(org.eclipse.sw360.exporter.ProjectExporter) Logger(org.apache.log4j.Logger) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) SW360Utils.printName(org.eclipse.sw360.datahandler.common.SW360Utils.printName) CONTENT_TYPE_OPENXML_SPREADSHEET(org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET) LifeRayUserSession(org.eclipse.sw360.portal.users.LifeRayUserSession) com.google.common.collect(com.google.common.collect) UserUtils(org.eclipse.sw360.portal.users.UserUtils) PrintWriter(java.io.PrintWriter) CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) Predicate(java.util.function.Predicate) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) org.eclipse.sw360.portal.common(org.eclipse.sw360.portal.common) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) Collectors(java.util.stream.Collectors) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) Entry(java.util.Map.Entry) Organization(com.liferay.portal.model.Organization) NotNull(org.jetbrains.annotations.NotNull) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) java.util(java.util) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) JSONException(com.liferay.portal.kernel.json.JSONException) PortletResponseUtil(com.liferay.portal.kernel.portlet.PortletResponseUtil) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Function(java.util.function.Function) Strings(com.google.common.base.Strings) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) org.eclipse.sw360.datahandler.thrift.vulnerabilities(org.eclipse.sw360.datahandler.thrift.vulnerabilities) org.eclipse.sw360.datahandler.thrift(org.eclipse.sw360.datahandler.thrift) ReleaseLink(org.eclipse.sw360.datahandler.thrift.components.ReleaseLink) org.eclipse.sw360.datahandler.thrift.projects(org.eclipse.sw360.datahandler.thrift.projects) SessionMessages(com.liferay.portal.kernel.servlet.SessionMessages) URLConnection(java.net.URLConnection) BiConsumer(java.util.function.BiConsumer) javax.portlet(javax.portlet) org.eclipse.sw360.datahandler.thrift.attachments(org.eclipse.sw360.datahandler.thrift.attachments) org.eclipse.sw360.datahandler.common(org.eclipse.sw360.datahandler.common) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) JSONFactoryUtil(com.liferay.portal.kernel.json.JSONFactoryUtil) IOException(java.io.IOException) JSONObject(com.liferay.portal.kernel.json.JSONObject) FossologyAwarePortlet(org.eclipse.sw360.portal.portlets.FossologyAwarePortlet) ReleaseExporter(org.eclipse.sw360.exporter.ReleaseExporter) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) JSONArray(com.liferay.portal.kernel.json.JSONArray) org.eclipse.sw360.datahandler.thrift.licenseinfo(org.eclipse.sw360.datahandler.thrift.licenseinfo) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Entry(java.util.Map.Entry)

Example 3 with Source

use of org.eclipse.sw360.datahandler.thrift.Source 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;
}
Also used : ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) ReleaseLink(org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)

Example 4 with Source

use of org.eclipse.sw360.datahandler.thrift.Source in project sw360portal by sw360.

the class ComponentPortlet method generateComponentMergeWizardStep3Response.

private void generateComponentMergeWizardStep3Response(ActionRequest request, JsonGenerator jsonGenerator) throws IOException, TException {
    ObjectMapper om = new ObjectMapper();
    ComponentService.Iface cClient = thriftClients.makeComponentClient();
    // extract request data
    User sessionUser = UserCacheHolder.getUserFromRequest(request);
    Component componentSelection = om.readValue(request.getParameter(COMPONENT_SELECTION), Component.class);
    String componentSourceId = request.getParameter(COMPONENT_SOURCE_ID);
    // perform the real merge, update merge target and delete merge source
    RequestStatus status = cClient.mergeComponents(componentSelection.getId(), componentSourceId, componentSelection, sessionUser);
    // generate redirect url
    LiferayPortletURL componentUrl = createDetailLinkTemplate(request);
    componentUrl.setParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_DETAIL);
    componentUrl.setParameter(PortalConstants.COMPONENT_ID, componentSelection.getId());
    // write response JSON
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("redirectUrl", componentUrl.toString());
    if (status == RequestStatus.IN_USE) {
        jsonGenerator.writeStringField("error", "Cannot merge when one of the components has an active moderation request.");
    } else if (status == RequestStatus.FAILURE) {
        jsonGenerator.writeStringField("error", "You do not have sufficient permissions.");
    }
    jsonGenerator.writeEndObject();
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with Source

use of org.eclipse.sw360.datahandler.thrift.Source in project sw360portal by sw360.

the class FossologyFileHandler method sendToFossology.

public RequestStatus sendToFossology(String releaseId, User user, String clearingTeam) throws TException {
    Release release;
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    release = getReleaseAndUnlockIt(releaseId, user, componentClient);
    Set<Attachment> sourceAttachments = getSourceAttachment(releaseId, user, componentClient);
    if (sourceAttachments.size() != 1) {
        log.error("release " + releaseId + " does not have a single source attachment");
        // TODO return a summary and better fitting status
        return RequestStatus.FAILURE;
    }
    final Attachment attachment = getFirst(sourceAttachments);
    final FilledAttachment filledAttachment = fillAttachment(attachment);
    if (!release.isSetFossologyId()) {
        /* send the attachment as a new upload */
        AttachmentContent attachmentContent = filledAttachment.getAttachmentContent();
        return sendToFossologyNewUpload(release, user, clearingTeam, attachmentContent, componentClient);
    } else {
        if (!checkSourceAttachment(release, filledAttachment)) {
            // TODO summary
            return RequestStatus.FAILURE;
        } else {
            /* duplicate the old upload making it visible for clearingTeam */
            return sendToFossologyExistingUpload(release, user, clearingTeam, componentClient);
        }
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Map (java.util.Map)2 Set (java.util.Set)2 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)2 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2 Release (org.eclipse.sw360.datahandler.thrift.components.Release)2 ReleaseLink (org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)2 User (org.eclipse.sw360.datahandler.thrift.users.User)2 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 com.google.common.collect (com.google.common.collect)1 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONException (com.liferay.portal.kernel.json.JSONException)1 JSONFactoryUtil (com.liferay.portal.kernel.json.JSONFactoryUtil)1 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)1 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)1