Search in sources :

Example 56 with Component

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

the class ComponentPortlet method getFilteredComponentList.

private List<Component> getFilteredComponentList(PortletRequest request) throws IOException {
    List<Component> componentList;
    Map<String, Set<String>> filterMap = new HashMap<>();
    for (Component._Fields filteredField : componentFilteredFields) {
        String parameter = request.getParameter(filteredField.toString());
        if (!isNullOrEmpty(parameter) && !(filteredField.equals(Component._Fields.COMPONENT_TYPE) && parameter.equals(PortalConstants.NO_FILTER))) {
            Set<String> values = CommonUtils.splitToSet(parameter);
            if (filteredField.equals(Component._Fields.NAME)) {
                values = values.stream().map(v -> v + "*").collect(Collectors.toSet());
            }
            filterMap.put(filteredField.getFieldName(), values);
        }
        request.setAttribute(filteredField.getFieldName(), nullToEmpty(parameter));
    }
    try {
        final User user = UserCacheHolder.getUserFromRequest(request);
        int limit = CustomFieldHelper.loadAndStoreStickyViewSize(request, user, CUSTOM_FIELD_COMPONENTS_VIEW_SIZE);
        ComponentService.Iface componentClient = thriftClients.makeComponentClient();
        request.setAttribute(PortalConstants.TOTAL_ROWS, componentClient.getTotalComponentsCount(user));
        if (filterMap.isEmpty()) {
            componentList = componentClient.getRecentComponentsSummary(limit, user);
        } else {
            componentList = componentClient.refineSearch(null, filterMap);
        }
    } catch (TException e) {
        log.error("Could not search components in backend ", e);
        componentList = Collections.emptyList();
    }
    return componentList;
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 57 with Component

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

the class ComponentPortlet method prepareComponentEdit.

private void prepareComponentEdit(RenderRequest request) {
    String id = request.getParameter(COMPONENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_COMPONENT);
    if (id != null) {
        try {
            ComponentService.Iface client = thriftClients.makeComponentClient();
            Component component = client.getComponentByIdForEdit(id, user);
            request.setAttribute(COMPONENT, component);
            request.setAttribute(DOCUMENT_ID, id);
            setAttachmentsInRequest(request, component.getAttachments());
            Map<RequestedAction, Boolean> permissions = component.getPermissions();
            DocumentState documentState = component.getDocumentState();
            addEditDocumentMessage(request, permissions, documentState);
            Set<String> releaseIds = SW360Utils.getReleaseIds(component.getReleases());
            setUsingDocs(request, user, client, releaseIds);
        } catch (TException e) {
            log.error("Error fetching component from backend!", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_COMPONENT);
        }
    } else {
        if (request.getAttribute(COMPONENT) == null) {
            Component component = new Component();
            request.setAttribute(COMPONENT, component);
            setUsingDocs(request, user, null, component.getReleaseIds());
            setAttachmentsInRequest(request, component.getAttachments());
            SessionMessages.add(request, "request_processed", "New Component");
        }
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction)

Example 58 with Component

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

the class ComponentPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) {
    String id = request.getParameter(COMPONENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    if (!isNullOrEmpty(id)) {
        try {
            ComponentService.Iface client = thriftClients.makeComponentClient();
            Component component = client.getComponentById(id, user);
            request.setAttribute(COMPONENT, component);
            request.setAttribute(DOCUMENT_ID, id);
            request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_COMPONENT);
            setAttachmentsInRequest(request, component.getAttachments());
            Set<String> releaseIds = SW360Utils.getReleaseIds(component.getReleases());
            setUsingDocs(request, user, client, releaseIds);
            request.setAttribute(IS_USER_ALLOWED_TO_MERGE, PermissionUtils.isUserAtLeast(UserGroup.ADMIN, user));
            // get vulnerabilities
            putVulnerabilitiesInRequestComponent(request, id, user);
            request.setAttribute(VULNERABILITY_VERIFICATION_EDITABLE, PermissionUtils.isUserAtLeast(UserGroup.SECURITY_ADMIN, user));
            addComponentBreadcrumb(request, response, component);
        } catch (TException e) {
            log.error("Error fetching component from backend!", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_COMPONENT);
        }
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 59 with Component

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

the class ComponentPortlet method updateComponent.

// ! Actions
@UsedAsLiferayAction
public void updateComponent(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String id = request.getParameter(COMPONENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        if (id != null) {
            Component component = client.getComponentByIdForEdit(id, user);
            ComponentPortletUtils.updateComponentFromRequest(request, component);
            String ModerationRequestCommentMsg = request.getParameter(MODERATION_REQUEST_COMMENT);
            user.setCommentMadeDuringModerationRequest(ModerationRequestCommentMsg);
            RequestStatus requestStatus = client.updateComponent(component, user);
            setSessionMessage(request, requestStatus, "Component", "update", component.getName());
            cleanUploadHistory(user.getEmail(), id);
            response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
            response.setRenderParameter(COMPONENT_ID, request.getParameter(COMPONENT_ID));
        } else {
            Component component = new Component();
            ComponentPortletUtils.updateComponentFromRequest(request, component);
            AddDocumentRequestSummary summary = client.addComponent(component, user);
            AddDocumentRequestStatus status = summary.getRequestStatus();
            switch(status) {
                case SUCCESS:
                    String successMsg = "Component " + component.getName() + " added successfully";
                    SessionMessages.add(request, "request_processed", successMsg);
                    response.setRenderParameter(COMPONENT_ID, summary.getId());
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    break;
                case DUPLICATE:
                    setSW360SessionError(request, ErrorMessages.COMPONENT_DUPLICATE);
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    prepareRequestForEditAfterDuplicateError(request, component);
                    break;
                default:
                    setSW360SessionError(request, ErrorMessages.COMPONENT_NOT_ADDED);
                    response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
            }
        }
    } catch (TException e) {
        log.error("Error fetching component from backend!", e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 60 with Component

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

the class ComponentPortlet method generateComponentMergeWizardStep1Response.

private void generateComponentMergeWizardStep1Response(ActionRequest request, JsonGenerator jsonGenerator) throws IOException, TException {
    User sessionUser = UserCacheHolder.getUserFromRequest(request);
    String componentTargetId = request.getParameter(COMPONENT_TARGET_ID);
    String componentSourceId = request.getParameter(COMPONENT_SOURCE_ID);
    ComponentService.Iface cClient = thriftClients.makeComponentClient();
    Component componentTarget = cClient.getComponentById(componentTargetId, sessionUser);
    Component componentSource = cClient.getComponentById(componentSourceId, sessionUser);
    jsonGenerator.writeStartObject();
    // adding common title
    jsonGenerator.writeRaw("\"componentTarget\":" + JSON_THRIFT_SERIALIZER.toString(componentTarget) + ",");
    jsonGenerator.writeRaw("\"componentSource\":" + JSON_THRIFT_SERIALIZER.toString(componentSource));
    jsonGenerator.writeEndObject();
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User)

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