Search in sources :

Example 41 with Release

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

the class ComponentPortlet method serveNewTableRowLinkedRelease.

private void serveNewTableRowLinkedRelease(ResourceRequest request, ResourceResponse response, String[] linkedIds) throws IOException, PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    List<ReleaseLink> linkedReleases = new ArrayList<>();
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        for (Release release : client.getReleasesById(new HashSet<>(Arrays.asList(linkedIds)), user)) {
            final Vendor vendor = release.getVendor();
            final String vendorName = vendor != null ? vendor.getShortname() : "";
            ReleaseLink linkedRelease = new ReleaseLink(release.getId(), vendorName, release.getName(), release.getVersion(), SW360Utils.printFullname(release), !nullToEmptyMap(release.getReleaseIdToRelationship()).isEmpty());
            linkedRelease.setReleaseRelationship(ReleaseRelationship.CONTAINED);
            linkedReleases.add(linkedRelease);
        }
    } catch (TException e) {
        log.error("Error getting releases!", e);
        throw new PortletException("cannot get releases " + Arrays.toString(linkedIds), e);
    }
    request.setAttribute(RELEASE_LIST, linkedReleases);
    include("/html/utils/ajax/linkedReleasesRelationAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor)

Example 42 with Release

use of org.eclipse.sw360.datahandler.thrift.components.Release 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 43 with Release

use of org.eclipse.sw360.datahandler.thrift.components.Release 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 44 with Release

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

the class FossologyAwarePortlet method serveFossologyStatus.

protected void serveFossologyStatus(ResourceRequest request, ResourceResponse response) throws IOException {
    DataTablesParameters parameters = DataTablesParser.parametersFrom(request);
    Release release = getReleaseForFossologyStatus(request);
    Map<String, FossologyStatus> fossologyStatus = getFossologyStatus(release);
    JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
    JSONArray data = JSONFactoryUtil.createJSONArray();
    for (Map.Entry<String, FossologyStatus> entry : fossologyStatus.entrySet()) {
        JSONObject row = JSONFactoryUtil.createJSONObject();
        row.put("0", entry.getKey());
        row.put("1", ThriftEnumUtils.enumToString(entry.getValue()));
        data.put(row);
    }
    jsonResponse.put("attachment", getFossologyUploadableAttachment(release));
    jsonResponse.put("data", data);
    jsonResponse.put("draw", parameters.getDraw());
    jsonResponse.put("recordsTotal", fossologyStatus.size());
    jsonResponse.put("recordsFiltered", fossologyStatus.size());
    writeJSON(request, response, jsonResponse);
}
Also used : DataTablesParameters(org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) CommonUtils.nullToEmptyMap(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 45 with Release

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

the class FossologyAwarePortlet method getReleaseForFossologyStatus.

protected Release getReleaseForFossologyStatus(ResourceRequest request) {
    String releaseId = request.getParameter(RELEASE_ID);
    String clearingTeam = request.getParameter(CLEARING_TEAM);
    boolean cached = Boolean.parseBoolean(request.getParameter("cached"));
    if (!isNullOrEmpty(releaseId) && !isNullOrEmpty(clearingTeam)) {
        try {
            final Release release;
            if (!cached) {
                FossologyService.Iface client = thriftClients.makeFossologyClient();
                release = client.getStatusInFossology(releaseId, UserCacheHolder.getUserFromRequest(request), clearingTeam);
            } else {
                ComponentService.Iface client = thriftClients.makeComponentClient();
                release = client.getReleaseById(releaseId, UserCacheHolder.getUserFromRequest(request));
            }
            if (release != null) {
                return release;
            } else {
                log.error("no response from backend!");
            }
        } catch (TException e) {
            log.error("Could not release status in fossology", e);
        }
    }
    log.error("Could not get release from request");
    return null;
}
Also used : TException(org.apache.thrift.TException) FossologyService(org.eclipse.sw360.datahandler.thrift.fossology.FossologyService) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

Release (org.eclipse.sw360.datahandler.thrift.components.Release)93 User (org.eclipse.sw360.datahandler.thrift.users.User)39 TException (org.apache.thrift.TException)34 Test (org.junit.Test)22 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)20 Component (org.eclipse.sw360.datahandler.thrift.components.Component)18 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)13 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)13 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)11 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)10 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)9 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)7 Before (org.junit.Before)7 Collectors (java.util.stream.Collectors)6 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)6 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)6 IOException (java.io.IOException)5 java.util (java.util)5