Search in sources :

Example 46 with User

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

the class ModerationPortlet method renderEditViewForId.

private void renderEditViewForId(RenderRequest request, RenderResponse response, String id) throws IOException, PortletException, TException {
    if (id != null) {
        ModerationRequest moderationRequest = null;
        User user = UserCacheHolder.getUserFromRequest(request);
        try {
            ModerationService.Iface client = thriftClients.makeModerationClient();
            moderationRequest = client.getModerationRequestById(id);
            boolean actionsAllowed = moderationRequest.getModerators().contains(user.getEmail()) && ModerationPortletUtils.isOpenModerationRequest(moderationRequest);
            request.setAttribute(PortalConstants.MODERATION_ACTIONS_ALLOWED, actionsAllowed);
            if (actionsAllowed) {
                SessionMessages.add(request, "request_processed", "You have assigned yourself to this moderation request.");
                client.setInProgress(id, user);
            }
            request.setAttribute(PortalConstants.MODERATION_REQUEST, moderationRequest);
            addModerationBreadcrumb(request, response, moderationRequest);
        } catch (TException e) {
            log.error("Error fetching moderation  details from backend", e);
        }
        if (moderationRequest != null) {
            switch(moderationRequest.getDocumentType()) {
                case COMPONENT:
                    renderComponentModeration(request, response, moderationRequest, user);
                    break;
                case RELEASE:
                    VendorService.Iface vendorClient = thriftClients.makeVendorClient();
                    Release additions = moderationRequest.getReleaseAdditions();
                    if (additions.isSetVendorId()) {
                        additions.setVendor(vendorClient.getByID(additions.getVendorId()));
                    }
                    Release deletions = moderationRequest.getReleaseDeletions();
                    if (deletions.isSetVendorId()) {
                        deletions.setVendor(vendorClient.getByID(deletions.getVendorId()));
                    }
                    renderReleaseModeration(request, response, moderationRequest, user);
                    break;
                case PROJECT:
                    renderProjectModeration(request, response, moderationRequest, user);
                    break;
                case LICENSE:
                    renderLicenseModeration(request, response, moderationRequest, user);
                    break;
                case USER:
                    renderUserModeration(request, response, moderationRequest, user);
                    break;
            }
        }
    }
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) TException(org.apache.thrift.TException) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) User(org.eclipse.sw360.datahandler.thrift.users.User) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 47 with User

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

the class UserPreferencesPortlet method savePreferences.

@UsedAsLiferayAction
public void savePreferences(ActionRequest request, ActionResponse response) throws IOException, PortletException {
    User sessionUser = UserCacheHolder.getUserFromRequest(request);
    UserService.Iface userClient = thriftClients.makeUserClient();
    try {
        // reload user to prevent couchdb update conflict
        User user = userClient.getByEmail(sessionUser.getEmail());
        PortletUtils.setFieldValue(request, user, User._Fields.WANTS_MAIL_NOTIFICATION, User.metaDataMap.get(User._Fields.WANTS_MAIL_NOTIFICATION), "");
        if (user.isWantsMailNotification()) {
            // if !wantsMailNotification, all the other checkboxes are disabled and therefore not submitted
            Map<String, Boolean> preferences = new HashMap<>();
            SW360Constants.NOTIFICATION_EVENTS_KEYS.forEach(k -> {
                String value = request.getParameter(User._Fields.NOTIFICATION_PREFERENCES.toString() + k);
                if (value != null) {
                    preferences.put(k, Boolean.TRUE);
                }
            });
            user.setNotificationPreferences(preferences);
        }
        userClient.updateUser(user);
        request.setAttribute(PortalConstants.SW360_USER, user);
    } catch (TException e) {
        log.error("An error occurred while updating the user record", e);
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) UserService(org.eclipse.sw360.datahandler.thrift.users.UserService) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 48 with User

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

the class ProjectPortlet method serveProjectSearchResults.

private void serveProjectSearchResults(ResourceRequest request, ResourceResponse response, String searchText) throws IOException, PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    List<Project> searchResult;
    try {
        ProjectService.Iface client = thriftClients.makeProjectClient();
        if (isNullOrEmpty(searchText)) {
            searchResult = client.getAccessibleProjectsSummary(user);
        } else {
            searchResult = client.searchByName(searchText, user);
        }
    } catch (TException e) {
        log.error("Error searching projects", e);
        searchResult = Collections.emptyList();
    }
    request.setAttribute(PortalConstants.PROJECT_SEARCH, searchResult);
    include("/html/projects/ajax/searchProjectsAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 49 with User

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

the class ProjectPortlet method removeProject.

private RequestStatus removeProject(PortletRequest request) {
    String projectId = request.getParameter(PortalConstants.PROJECT_ID);
    String encodedDeleteComment = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
    final User user = UserCacheHolder.getUserFromRequest(request);
    if (encodedDeleteComment != null) {
        String deleteComment = new String(Base64.getDecoder().decode(encodedDeleteComment));
        user.setCommentMadeDuringModerationRequest(deleteComment);
    }
    try {
        deleteUnneededAttachments(user.getEmail(), projectId);
        ProjectService.Iface client = thriftClients.makeProjectClient();
        return client.deleteProject(projectId, user);
    } catch (TException e) {
        log.error("Error deleting project from backend", e);
    }
    return RequestStatus.FAILURE;
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 50 with User

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

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);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
    request.setAttribute(DOCUMENT_ID, id);
    request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());
    if (id != null) {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(id, user);
            project = getWithFilledClearingStateSummary(project, user);
            request.setAttribute(PROJECT, project);
            setAttachmentsInRequest(request, project.getAttachments());
            List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, user);
            request.setAttribute(PROJECT_LIST, mappedProjectLinks);
            putDirectlyLinkedReleasesInRequest(request, project);
            Set<Project> usingProjects = client.searchLinkingProjects(id, user);
            request.setAttribute(USING_PROJECTS, usingProjects);
            putReleasesAndProjectIntoRequest(request, id, user);
            putVulnerabilitiesInRequest(request, id, user);
            request.setAttribute(VULNERABILITY_RATINGS_EDITABLE, PermissionUtils.makePermission(project, user).isActionAllowed(RequestedAction.WRITE));
            addProjectBreadcrumb(request, response, project);
        } 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) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)169 TException (org.apache.thrift.TException)100 Release (org.eclipse.sw360.datahandler.thrift.components.Release)58 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)44 Test (org.junit.Test)30 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)27 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)26 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)20 ResponseEntity (org.springframework.http.ResponseEntity)20 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)19 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)18 IOException (java.io.IOException)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)16 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)13 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)12 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)12 Before (org.junit.Before)12 ArrayList (java.util.ArrayList)11