Search in sources :

Example 11 with UsedAsLiferayAction

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

the class LicensesPortlet method updateWhiteList.

@UsedAsLiferayAction
public void updateWhiteList(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    // we get a list of todoDatabaseIds and Booleans and we have to update the whiteList of each todo if it changed
    String licenseId = request.getParameter(LICENSE_ID);
    String[] whiteList = request.getParameterValues("whiteList");
    // As empty arrays are not passed as parameters
    if (whiteList == null)
        whiteList = new String[0];
    final User user = UserCacheHolder.getUserFromRequest(request);
    String moderationComment = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
    if (moderationComment != null) {
        user.setCommentMadeDuringModerationRequest(moderationComment);
    }
    try {
        LicenseService.Iface client = thriftClients.makeLicenseClient();
        RequestStatus requestStatus = client.updateWhitelist(licenseId, ImmutableSet.copyOf(whiteList), user);
        setSessionMessage(request, requestStatus, "License", "update");
    } catch (TException e) {
        log.error("Error updating whitelist!", e);
    }
    response.setRenderParameter(LICENSE_ID, licenseId);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "Todos");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 12 with UsedAsLiferayAction

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

the class LicensesPortlet method editExternalLink.

@UsedAsLiferayAction
public void editExternalLink(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String licenseId = request.getParameter(LICENSE_ID);
    String remoteLink = request.getParameter(License._Fields.EXTERNAL_LICENSE_LINK.name());
    if (!Strings.isNullOrEmpty(licenseId)) {
        try {
            User user = UserCacheHolder.getUserFromRequest(request);
            LicenseService.Iface client = thriftClients.makeLicenseClient();
            final License license = client.getByID(licenseId, user.getDepartment());
            license.setExternalLicenseLink(CommonUtils.nullToEmptyString(remoteLink));
            final RequestStatus requestStatus = client.updateLicense(license, user, user);
            renderRequestStatus(request, response, requestStatus);
        } catch (TException e) {
            log.error("Error updating license", e);
        }
    }
    response.setRenderParameter(LICENSE_ID, licenseId);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "Details");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 13 with UsedAsLiferayAction

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

the class LicensesPortlet method addTodo.

@UsedAsLiferayAction
public void addTodo(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String licenseID = request.getParameter(LICENSE_ID);
    String[] obligationIds = request.getParameterValues("obligations");
    String todoText = request.getParameter("todoText");
    String[] bools = request.getParameterValues("bools");
    Todo todo = new Todo();
    // add temporary id
    todo.setId(TMP_TODO_ID_PREFIX + UUID.randomUUID().toString());
    if (obligationIds != null) {
        for (String obligationId : obligationIds) {
            if (obligationId != null && !obligationId.isEmpty()) {
                todo.addToObligationDatabaseIds(obligationId);
            }
        }
    } else {
        todo.setObligationDatabaseIds(Collections.emptySet());
    }
    todo.setText(todoText);
    User user = UserCacheHolder.getUserFromRequest(request);
    String moderationComment = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
    if (moderationComment != null) {
        user.setCommentMadeDuringModerationRequest(moderationComment);
    }
    todo.addToWhitelist(user.getDepartment());
    if (bools != null) {
        List<String> theBools = Arrays.asList(bools);
        todo.setDevelopment(theBools.contains("development"));
        todo.setDistribution(theBools.contains("distribution"));
    } else {
        todo.setDevelopment(false);
        todo.setDistribution(false);
    }
    try {
        LicenseService.Iface client = thriftClients.makeLicenseClient();
        RequestStatus requestStatus = client.addTodoToLicense(todo, licenseID, user);
        setSessionMessage(request, requestStatus, "License", "update");
    } catch (TException e) {
        log.error("Error updating license details from backend", e);
    }
    response.setRenderParameter(LICENSE_ID, licenseID);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "Todos");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 14 with UsedAsLiferayAction

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

the class LicensesPortlet method changeText.

@UsedAsLiferayAction
public void changeText(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String licenseId = request.getParameter(LICENSE_ID);
    String text = request.getParameter(License._Fields.TEXT.name());
    if (!isNullOrEmpty(licenseId)) {
        try {
            User user = UserCacheHolder.getUserFromRequest(request);
            LicenseService.Iface client = thriftClients.makeLicenseClient();
            final License license = client.getByID(licenseId, user.getDepartment());
            license.setText(CommonUtils.nullToEmptyString(text));
            final RequestStatus requestStatus = client.updateLicense(license, user, user);
            renderRequestStatus(request, response, requestStatus);
        } catch (TException e) {
            log.error("Error updating license", e);
        }
    }
    response.setRenderParameter(LICENSE_ID, licenseId);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "LicenseText");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 15 with UsedAsLiferayAction

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

the class ProjectPortlet method update.

@UsedAsLiferayAction
public void update(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String id = request.getParameter(PROJECT_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    RequestStatus requestStatus;
    try {
        ProjectService.Iface client = thriftClients.makeProjectClient();
        if (id != null) {
            Project project = client.getProjectByIdForEdit(id, user);
            ProjectPortletUtils.updateProjectFromRequest(request, project);
            String ModerationRequestCommentMsg = request.getParameter(MODERATION_REQUEST_COMMENT);
            user.setCommentMadeDuringModerationRequest(ModerationRequestCommentMsg);
            requestStatus = client.updateProject(project, user);
            setSessionMessage(request, requestStatus, "Project", "update", printName(project));
            cleanUploadHistory(user.getEmail(), id);
            response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
            response.setRenderParameter(PROJECT_ID, request.getParameter(PROJECT_ID));
        } else {
            // Add project
            Project project = new Project();
            ProjectPortletUtils.updateProjectFromRequest(request, project);
            AddDocumentRequestSummary summary = client.addProject(project, user);
            AddDocumentRequestStatus status = summary.getRequestStatus();
            switch(status) {
                case SUCCESS:
                    String successMsg = "Project " + printName(project) + " added successfully";
                    SessionMessages.add(request, "request_processed", successMsg);
                    response.setRenderParameter(PROJECT_ID, summary.getId());
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    break;
                case DUPLICATE:
                    setSW360SessionError(request, ErrorMessages.PROJECT_DUPLICATE);
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    prepareRequestForEditAfterDuplicateError(request, project, user);
                    break;
                default:
                    setSW360SessionError(request, ErrorMessages.PROJECT_NOT_ADDED);
                    response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
            }
        }
    } catch (TException e) {
        log.error("Error updating project in backend!", e);
        setSW360SessionError(request, ErrorMessages.DEFAULT_ERROR_MESSAGE);
    }
}
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)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