Search in sources :

Example 26 with Component

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

the class ComponentPortlet method prepareReleaseDetailView.

private void prepareReleaseDetailView(RenderRequest request, RenderResponse response) throws PortletException {
    String id = request.getParameter(COMPONENT_ID);
    String releaseId = request.getParameter(RELEASE_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    if (isNullOrEmpty(id) && isNullOrEmpty(releaseId)) {
        throw new PortletException("Component or Release ID not set!");
    }
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        Component component;
        Release release = null;
        if (!isNullOrEmpty(releaseId)) {
            release = client.getReleaseById(releaseId, user);
            request.setAttribute(RELEASE_ID, releaseId);
            request.setAttribute(RELEASE, release);
            request.setAttribute(DOCUMENT_ID, releaseId);
            request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_RELEASE);
            setAttachmentsInRequest(request, release.getAttachments());
            setUsingDocs(request, releaseId, user, client);
            putDirectlyLinkedReleaseRelationsInRequest(request, release);
            if (isNullOrEmpty(id)) {
                id = release.getComponentId();
            }
            putVulnerabilitiesInRequestRelease(request, releaseId, user);
            request.setAttribute(VULNERABILITY_VERIFICATION_EDITABLE, PermissionUtils.isUserAtLeast(UserGroup.SECURITY_ADMIN, user));
        }
        component = client.getComponentById(id, user);
        request.setAttribute(COMPONENT, component);
        addComponentBreadcrumb(request, response, component);
        if (release != null) {
            addReleaseBreadcrumb(request, response, release);
        }
    } catch (TException e) {
        log.error("Error fetching release from backend!", e);
        setSW360SessionError(request, ErrorMessages.ERROR_GETTING_RELEASE);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 27 with Component

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

the class ComponentPortlet method updateRelease.

@UsedAsLiferayAction
public void updateRelease(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String id = request.getParameter(COMPONENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    if (id != null) {
        try {
            ComponentService.Iface client = thriftClients.makeComponentClient();
            Component component = client.getComponentById(id, user);
            Release release;
            String releaseId = request.getParameter(RELEASE_ID);
            if (releaseId != null) {
                release = client.getReleaseByIdForEdit(releaseId, user);
                ComponentPortletUtils.updateReleaseFromRequest(request, release);
                String ModerationRequestCommentMsg = request.getParameter(MODERATION_REQUEST_COMMENT);
                user.setCommentMadeDuringModerationRequest(ModerationRequestCommentMsg);
                RequestStatus requestStatus = client.updateRelease(release, user);
                setSessionMessage(request, requestStatus, "Release", "update", printName(release));
                cleanUploadHistory(user.getEmail(), releaseId);
                response.setRenderParameter(PAGENAME, PAGENAME_RELEASE_DETAIL);
                response.setRenderParameter(COMPONENT_ID, request.getParameter(COMPONENT_ID));
                response.setRenderParameter(RELEASE_ID, request.getParameter(RELEASE_ID));
            } else {
                release = new Release();
                release.setComponentId(component.getId());
                release.setClearingState(ClearingState.NEW_CLEARING);
                ComponentPortletUtils.updateReleaseFromRequest(request, release);
                AddDocumentRequestSummary summary = client.addRelease(release, user);
                AddDocumentRequestStatus status = summary.getRequestStatus();
                switch(status) {
                    case SUCCESS:
                        response.setRenderParameter(RELEASE_ID, summary.getId());
                        String successMsg = "Release " + printName(release) + " added successfully";
                        SessionMessages.add(request, "request_processed", successMsg);
                        response.setRenderParameter(PAGENAME, PAGENAME_EDIT_RELEASE);
                        break;
                    case DUPLICATE:
                        setSW360SessionError(request, ErrorMessages.RELEASE_DUPLICATE);
                        response.setRenderParameter(PAGENAME, PAGENAME_EDIT_RELEASE);
                        prepareRequestForReleaseEditAfterDuplicateError(request, release);
                        break;
                    default:
                        setSW360SessionError(request, ErrorMessages.RELEASE_NOT_ADDED);
                        response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
                }
                response.setRenderParameter(COMPONENT_ID, request.getParameter(COMPONENT_ID));
            }
        } catch (TException e) {
            log.error("Error fetching release from backend!", e);
        }
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 28 with Component

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

the class RecentComponentPortlet method doView.

@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    List<Component> components = null;
    User user = UserCacheHolder.getUserFromRequest(request);
    try {
        components = thriftClients.makeComponentClient().getRecentComponentsSummary(5, user);
    } catch (TException e) {
        log.error("Could not fetch recent components from backend", e);
    }
    request.setAttribute("components", CommonUtils.nullToEmptyList(components));
    super.doView(request, response);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 29 with Component

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

the class ComponentUploadPortlet method generateAttachmentsFile.

private void generateAttachmentsFile(ResourceRequest request, ResourceResponse response) throws IOException {
    List<Iterable<String>> csvRows = new ArrayList<>();
    final List<Component> componentDetailedSummaryForExport = getComponentDetailedSummaryForExport();
    if (componentDetailedSummaryForExport != null) {
        for (Component component : componentDetailedSummaryForExport) {
            printComponentAttachments(component, csvRows);
            printReleasesAttachments(component, csvRows);
        }
    }
    ByteArrayInputStream byteArrayInputStream = CSVExport.createCSV(ComponentAttachmentCSVRecord.getCSVHeaderIterable(), csvRows);
    PortletResponseUtil.sendFile(request, response, "AttachmentInfo.csv", byteArrayInputStream, "text/csv");
}
Also used : FluentIterable(com.google.common.collect.FluentIterable) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 30 with Component

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

the class ComponentUploadPortlet method dealWithReleaseLinksContainedInRelease.

private void dealWithReleaseLinksContainedInRelease(Map<String, Component> componentsById, Map<String, Release> releasesById, Component component, Release release, List<Iterable<String>> csvRows) throws IOException {
    final Map<String, ReleaseRelationship> releaseIdToRelationship = release.getReleaseIdToRelationship();
    if (releaseIdToRelationship != null) {
        for (Map.Entry<String, ReleaseRelationship> idReleaseRelationshipEntry : releaseIdToRelationship.entrySet()) {
            final Release linkedRelease = releasesById.get(idReleaseRelationshipEntry.getKey());
            if (linkedRelease != null) {
                final ReleaseRelationship relationship = idReleaseRelationshipEntry.getValue();
                final Component linkedComponent = componentsById.get(linkedRelease.getComponentId());
                if (linkedComponent != null) {
                    printReleaseLinkEntry(component, release, linkedRelease, relationship, linkedComponent, csvRows);
                }
            }
        }
    }
}
Also used : ReleaseRelationship(org.eclipse.sw360.datahandler.thrift.ReleaseRelationship) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

Component (org.eclipse.sw360.datahandler.thrift.components.Component)38 User (org.eclipse.sw360.datahandler.thrift.users.User)30 TException (org.apache.thrift.TException)23 Release (org.eclipse.sw360.datahandler.thrift.components.Release)23 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)10 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)8 Before (org.junit.Before)7 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)6 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)5 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)5 IOException (java.io.IOException)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Test (org.junit.Test)4 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 FluentIterable (com.google.common.collect.FluentIterable)2 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2