Search in sources :

Example 1 with UsedAsLiferayAction

use of org.eclipse.sw360.portal.common.UsedAsLiferayAction 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 2 with UsedAsLiferayAction

use of org.eclipse.sw360.portal.common.UsedAsLiferayAction in project sw360portal by sw360.

the class ScheduleAdminPortlet method scheduleCveSearch.

@UsedAsLiferayAction
public void scheduleCveSearch(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    try {
        User user = UserCacheHolder.getUserFromRequest(request);
        RequestSummary requestSummary = new ThriftClients().makeScheduleClient().scheduleService(ThriftClients.CVESEARCH_SERVICE);
        setSessionMessage(request, requestSummary.getRequestStatus(), "Task", "schedule");
    } catch (TException e) {
        log.error(e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 3 with UsedAsLiferayAction

use of org.eclipse.sw360.portal.common.UsedAsLiferayAction in project sw360portal by sw360.

the class ScheduleAdminPortlet method unscheduleAllServices.

@UsedAsLiferayAction
public void unscheduleAllServices(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    try {
        User user = UserCacheHolder.getUserFromRequest(request);
        RequestStatus requestStatus = new ThriftClients().makeScheduleClient().unscheduleAllServices(user);
        setSessionMessage(request, requestStatus, "Every task", "unschedule");
    } catch (TException e) {
        log.error(e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 4 with UsedAsLiferayAction

use of org.eclipse.sw360.portal.common.UsedAsLiferayAction in project sw360portal by sw360.

the class SignupPortlet method createAccount.

@UsedAsLiferayAction
public void createAccount(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    Registrant registrant = new Registrant(request);
    SignupPortletUtils.updateUserFromRequest(request, registrant);
    User newUser = null;
    if (registrant.validateUserData(request)) {
        newUser = createUser(registrant, request);
    }
    if (null != newUser) {
        boolean success = createUserModerationRequest(newUser, request);
        if (success) {
            response.setRenderParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_SUCCESS);
        }
    } else {
        String message = (String) ((LinkedHashMap) request.getPortletSession().getAttributeMap().get("com.liferay.portal.kernel.servlet.SessionMessages")).get("requestProcessed");
        setSW360SessionError(request, message);
        request.setAttribute(PortalConstants.USER, registrant);
        log.info("Could not create user");
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 5 with UsedAsLiferayAction

use of org.eclipse.sw360.portal.common.UsedAsLiferayAction 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)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)18 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)18 TException (org.apache.thrift.TException)13 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)8 CSVRecord (org.apache.commons.csv.CSVRecord)4 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)3 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)3 AttachmentService (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentService)2 VendorService (org.eclipse.sw360.datahandler.thrift.vendors.VendorService)2 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)1 FossologyHostFingerPrint (org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint)1 FossologyService (org.eclipse.sw360.datahandler.thrift.fossology.FossologyService)1 UserService (org.eclipse.sw360.datahandler.thrift.users.UserService)1 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)1