Search in sources :

Example 1 with AddDocumentRequestSummary

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

the class Sw360ProjectService method createProject.

public Project createProject(Project project, User sw360User) throws TException {
    ProjectService.Iface sw360ProjectClient = getThriftProjectClient();
    AddDocumentRequestSummary documentRequestSummary = sw360ProjectClient.addProject(project, sw360User);
    if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.SUCCESS) {
        project.setId(documentRequestSummary.getId());
        return project;
    } else if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.DUPLICATE) {
        throw new DataIntegrityViolationException("sw360 project with name '" + project.getName() + "' already exists.");
    }
    return null;
}
Also used : AddDocumentRequestSummary(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 2 with AddDocumentRequestSummary

use of org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary 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 3 with AddDocumentRequestSummary

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

the class ComponentPortlet method updateComponent.

// ! Actions
@UsedAsLiferayAction
public void updateComponent(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String id = request.getParameter(COMPONENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        if (id != null) {
            Component component = client.getComponentByIdForEdit(id, user);
            ComponentPortletUtils.updateComponentFromRequest(request, component);
            String ModerationRequestCommentMsg = request.getParameter(MODERATION_REQUEST_COMMENT);
            user.setCommentMadeDuringModerationRequest(ModerationRequestCommentMsg);
            RequestStatus requestStatus = client.updateComponent(component, user);
            setSessionMessage(request, requestStatus, "Component", "update", component.getName());
            cleanUploadHistory(user.getEmail(), id);
            response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
            response.setRenderParameter(COMPONENT_ID, request.getParameter(COMPONENT_ID));
        } else {
            Component component = new Component();
            ComponentPortletUtils.updateComponentFromRequest(request, component);
            AddDocumentRequestSummary summary = client.addComponent(component, user);
            AddDocumentRequestStatus status = summary.getRequestStatus();
            switch(status) {
                case SUCCESS:
                    String successMsg = "Component " + component.getName() + " added successfully";
                    SessionMessages.add(request, "request_processed", successMsg);
                    response.setRenderParameter(COMPONENT_ID, summary.getId());
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    break;
                case DUPLICATE:
                    setSW360SessionError(request, ErrorMessages.COMPONENT_DUPLICATE);
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    prepareRequestForEditAfterDuplicateError(request, component);
                    break;
                default:
                    setSW360SessionError(request, ErrorMessages.COMPONENT_NOT_ADDED);
                    response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
            }
        }
    } catch (TException e) {
        log.error("Error fetching component from backend!", e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 4 with AddDocumentRequestSummary

use of org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary 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)

Example 5 with AddDocumentRequestSummary

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

the class Sw360ComponentService method createComponent.

public Component createComponent(Component component, User sw360User) throws TException {
    ComponentService.Iface sw360ComponentClient = getThriftComponentClient();
    AddDocumentRequestSummary documentRequestSummary = sw360ComponentClient.addComponent(component, sw360User);
    if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.SUCCESS) {
        component.setId(documentRequestSummary.getId());
        return component;
    } else if (documentRequestSummary.getRequestStatus() == AddDocumentRequestStatus.DUPLICATE) {
        throw new DataIntegrityViolationException("sw360 component with name '" + component.getName() + "' already exists.");
    }
    return null;
}
Also used : AddDocumentRequestSummary(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Aggregations

TException (org.apache.thrift.TException)3 AddDocumentRequestSummary (org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary)3 User (org.eclipse.sw360.datahandler.thrift.users.User)3 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)3 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)1