Search in sources :

Example 1 with CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT

use of org.eclipse.sw360.portal.common.PortalConstants.CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT in project sw360 by eclipse.

the class ModerationPortlet method renderClearingRequest.

private void renderClearingRequest(RenderRequest request, RenderResponse response, String pageName) throws PortletException {
    final String clearingId = request.getParameter(CLEARING_REQUEST_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    if (CommonUtils.isNullEmptyOrWhitespace(clearingId)) {
        throw new PortletException("Clearing request ID not set!");
    }
    try {
        ModerationService.Iface client = thriftClients.makeModerationClient();
        ClearingRequest clearingRequest;
        if (PAGENAME_EDIT_CLEARING_REQUEST.equals(pageName)) {
            clearingRequest = client.getClearingRequestByIdForEdit(clearingId, user);
        } else {
            clearingRequest = client.getClearingRequestById(clearingId, user);
        }
        clearingRequest.setComments(Lists.reverse(CommonUtils.nullToEmptyList(clearingRequest.getComments())));
        boolean isPrimaryRoleOfUserAtLeastClearingExpert = PermissionUtils.isUserAtLeast(UserGroup.CLEARING_EXPERT, user);
        request.setAttribute(CLEARING_REQUEST, clearingRequest);
        request.setAttribute(WRITE_ACCESS_USER, false);
        request.setAttribute(IS_CLEARING_EXPERT, isPrimaryRoleOfUserAtLeastClearingExpert);
        Integer approvedReleaseCount = 0;
        if (CommonUtils.isNotNullEmptyOrWhitespace(clearingRequest.getProjectId())) {
            ProjectService.Iface projectClient = thriftClients.makeProjectClient();
            Project project = projectClient.getProjectById(clearingRequest.getProjectId(), UserCacheHolder.getUserFromRequest(request));
            DocumentPermissions<Project> projectPermission = makePermission(project, user);
            ImmutableSet<UserGroup> clearingExpertRoles = ImmutableSet.of(UserGroup.CLEARING_EXPERT);
            ImmutableSet<UserGroup> adminRoles = ImmutableSet.of(UserGroup.ADMIN, UserGroup.SW360_ADMIN);
            request.setAttribute(IS_CLEARING_EXPERT, isPrimaryRoleOfUserAtLeastClearingExpert || projectPermission.isUserOfOwnGroupHasRole(clearingExpertRoles, UserGroup.CLEARING_EXPERT) || projectPermission.isUserOfOwnGroupHasRole(adminRoles, UserGroup.ADMIN));
            request.setAttribute(WRITE_ACCESS_USER, projectPermission.isActionAllowed(RequestedAction.WRITE));
            String babl = CommonUtils.nullToEmptyMap(project.getAdditionalData()).get("BA BL");
            if (CommonUtils.isNotNullEmptyOrWhitespace(babl)) {
                project.setBusinessUnit(babl);
            }
            request.setAttribute(PROJECT, project);
            List<Project> projects = getWithFilledClearingStateSummary(projectClient, Lists.newArrayList(project), user);
            Project projWithCsSummary = projects.get(0);
            if (null != projWithCsSummary && null != projWithCsSummary.getReleaseClearingStateSummary()) {
                ReleaseClearingStateSummary summary = projWithCsSummary.getReleaseClearingStateSummary();
                approvedReleaseCount = summary.getApproved() + summary.getReportAvailable();
            }
        }
        if (clearingRequest.getTimestampOfDecision() > 1) {
            Integer criticalCount = client.getCriticalClearingRequestCount();
            request.setAttribute(CRITICAL_CR_COUNT, criticalCount);
        }
        String dateLimit = CommonUtils.nullToEmptyString(ModerationPortletUtils.loadPreferredClearingDateLimit(request, user));
        request.setAttribute(CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT, dateLimit);
        request.setAttribute(APPROVED_RELEASE_COUNT, approvedReleaseCount);
        addClearingBreadcrumb(request, response, clearingId);
    } catch (TException e) {
        log.error("Error fetching clearing request from backend!", e);
        setSW360SessionError(request, ErrorMessages.ERROR_GETTING_CLEARING_REQUEST);
    }
}
Also used : WrappedException.wrapTException(org.eclipse.sw360.datahandler.common.WrappedException.wrapTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ClearingRequest(org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) UserGroup(org.eclipse.sw360.datahandler.thrift.users.UserGroup) ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReleaseClearingStateSummary(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary)

Example 2 with CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT

use of org.eclipse.sw360.portal.common.PortalConstants.CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT in project sw360 by eclipse.

the class ProjectPortlet method prepareStandardView.

private void prepareStandardView(RenderRequest request) throws IOException {
    User user = UserCacheHolder.getUserFromRequest(request);
    ProjectService.Iface projectClient = thriftClients.makeProjectClient();
    ModerationService.Iface modClient = thriftClients.makeModerationClient();
    try {
        Set<String> organizations = projectClient.getGroups();
        request.setAttribute(PortalConstants.ORGANIZATIONS, organizations);
        String dateLimit = CommonUtils.nullToEmptyString(ModerationPortletUtils.loadPreferredClearingDateLimit(request, UserCacheHolder.getUserFromRequest(request)));
        request.setAttribute(CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT, dateLimit);
        Integer criticalCount = modClient.getCriticalClearingRequestCount();
        request.setAttribute(CRITICAL_CR_COUNT, criticalCount);
    } catch (TException e) {
        log.error("Error in getting the projectList from backend ", e);
    }
    request.setAttribute(IS_USER_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.SW360_ADMIN, user) ? YES : NO);
    for (Project._Fields filteredField : projectFilteredFields) {
        String parameter = request.getParameter(filteredField.toString());
        request.setAttribute(filteredField.getFieldName(), nullToEmpty(parameter));
    }
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) WrappedException.wrapTException(org.eclipse.sw360.datahandler.common.WrappedException.wrapTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 3 with CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT

use of org.eclipse.sw360.portal.common.PortalConstants.CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT in project sw360 by eclipse.

the class ProjectPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    User user = UserCacheHolder.getUserFromRequest(request);
    String id = request.getParameter(PROJECT_ID);
    setDefaultRequestAttributes(request);
    request.setAttribute(DOCUMENT_ID, id);
    if (id != null) {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(id, user);
            project = getWithFilledClearingStateSummary(project, user);
            Map<String, String> sortedAdditionalData = getSortedMap(project.getAdditionalData(), true);
            project.setAdditionalData(sortedAdditionalData);
            fillVendor(project);
            request.setAttribute(PROJECT, project);
            request.setAttribute(PARENT_PROJECT_PATH, project.getId());
            setAttachmentsInRequest(request, project);
            List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, user);
            request.setAttribute(PROJECT_LIST, mappedProjectLinks);
            List<ProjectLink> allSubProjectLinks = createLinkedProjects(project, Function.identity(), true, user);
            request.setAttribute(ALL_SUB_PROJECT_LINK, allSubProjectLinks);
            putDirectlyLinkedReleasesInRequest(request, project);
            Set<Project> usingProjects = client.searchLinkingProjects(id, user);
            request.setAttribute(USING_PROJECTS, usingProjects);
            int allUsingProjectCount = client.getCountByProjectId(id);
            request.setAttribute(ALL_USING_PROJECTS_COUNT, allUsingProjectCount);
            putReleasesAndProjectIntoRequest(request, id, user);
            putVulnerabilitiesInRequest(request, id, user);
            putAttachmentUsagesInRequest(request, id);
            request.setAttribute(WRITE_ACCESS_USER, PermissionUtils.makePermission(project, user).isActionAllowed(RequestedAction.WRITE));
            PortletUtils.setCustomFieldsDisplay(request, user, project);
            addProjectBreadcrumb(request, response, project);
            request.setAttribute(IS_USER_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.SW360_ADMIN, user) ? YES : NO);
            request.setAttribute(IS_PROJECT_MEMBER, SW360Utils.isModeratorOrCreator(project, user));
            String dateLimit = CommonUtils.nullToEmptyString(ModerationPortletUtils.loadPreferredClearingDateLimit(request, UserCacheHolder.getUserFromRequest(request)));
            request.setAttribute(CUSTOM_FIELD_PREFERRED_CLEARING_DATE_LIMIT, dateLimit);
            ModerationService.Iface modClient = thriftClients.makeModerationClient();
            Integer criticalCount = modClient.getCriticalClearingRequestCount();
            request.setAttribute(IS_CLEARING_REQUEST_DISABLED_FOR_PROJECT_BU, false);
            Set<String> groupsWithCrDisabled = Stream.of(PortalConstants.DISABLE_CLEARING_REQUEST_FOR_PROJECT_WITH_GROUPS.toLowerCase().split(",")).collect(Collectors.toSet());
            if (CommonUtils.isNotEmpty(groupsWithCrDisabled) && groupsWithCrDisabled.contains(project.getBusinessUnit().toLowerCase()) && Objects.isNull(project.getClearingRequestId())) {
                request.setAttribute(IS_CLEARING_REQUEST_DISABLED_FOR_PROJECT_BU, true);
            }
            request.setAttribute(CRITICAL_CR_COUNT, criticalCount);
            request.setAttribute(LIST_VULNERABILITY_WITH_VIEW_SIZE_FRIENDLY_URL, ProjectPortletUtils.createProjectPortletUrlWithViewSizeFriendlyUrl(request, id));
        } catch (SW360Exception sw360Exp) {
            setSessionErrorBasedOnErrorCode(request, sw360Exp.getErrorCode());
        } catch (TException e) {
            log.error("Error fetching project from backend!", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
        }
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) WrappedException.wrapTException(org.eclipse.sw360.datahandler.common.WrappedException.wrapTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService)

Aggregations

TException (org.apache.thrift.TException)3 WrappedException.wrapTException (org.eclipse.sw360.datahandler.common.WrappedException.wrapTException)3 ModerationService (org.eclipse.sw360.datahandler.thrift.moderation.ModerationService)3 User (org.eclipse.sw360.datahandler.thrift.users.User)3 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)2 ReleaseClearingStateSummary (org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStateSummary)1 ClearingRequest (org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest)1 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)1 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)1 UserGroup (org.eclipse.sw360.datahandler.thrift.users.UserGroup)1