Search in sources :

Example 1 with DocumentState

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

the class ProjectPortlet method prepareProjectEdit.

private void prepareProjectEdit(RenderRequest request) {
    User user = UserCacheHolder.getUserFromRequest(request);
    String id = request.getParameter(PROJECT_ID);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
    Project project;
    Set<Project> usingProjects;
    request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());
    if (id != null) {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            project = client.getProjectByIdForEdit(id, user);
            usingProjects = client.searchLinkingProjects(id, user);
        } catch (TException e) {
            log.error("Something went wrong with fetching the project", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
            return;
        }
        request.setAttribute(PROJECT, project);
        request.setAttribute(DOCUMENT_ID, id);
        setAttachmentsInRequest(request, project.getAttachments());
        try {
            putDirectlyLinkedProjectsInRequest(request, project, user);
            putDirectlyLinkedReleasesInRequest(request, project);
        } catch (TException e) {
            log.error("Could not fetch linked projects or linked releases in projects view.", e);
            return;
        }
        request.setAttribute(USING_PROJECTS, usingProjects);
        Map<RequestedAction, Boolean> permissions = project.getPermissions();
        DocumentState documentState = project.getDocumentState();
        addEditDocumentMessage(request, permissions, documentState);
    } else {
        if (request.getAttribute(PROJECT) == null) {
            project = new Project();
            project.setBusinessUnit(user.getDepartment());
            request.setAttribute(PROJECT, project);
            setAttachmentsInRequest(request, project.getAttachments());
            try {
                putDirectlyLinkedProjectsInRequest(request, project, user);
                putDirectlyLinkedReleasesInRequest(request, project);
            } catch (TException e) {
                log.error("Could not put empty linked projects or linked releases in projects view.", e);
            }
            request.setAttribute(USING_PROJECTS, Collections.emptySet());
            SessionMessages.add(request, "request_processed", "New Project");
        }
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction)

Example 2 with DocumentState

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

the class LicenseDatabaseHandler method getLicenseForOrganisationWithOwnModerationRequests.

public License getLicenseForOrganisationWithOwnModerationRequests(String id, String organisation, User user) throws SW360Exception {
    List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
    License license = getLicenseForOrganisation(id, organisation);
    DocumentState documentState;
    if (moderationRequestsForDocumentId.isEmpty()) {
        documentState = CommonUtils.getOriginalDocumentState();
    } else {
        final String email = user.getEmail();
        Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
        if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
            ModerationRequest moderationRequest = moderationRequestOptional.get();
            license = moderator.updateLicenseFromModerationRequest(license, moderationRequest.getLicenseAdditions(), moderationRequest.getLicenseDeletions(), organisation);
            for (Todo todo : license.getTodos()) {
                // remove other organisations from whitelist of todo
                todo.setWhitelist(SW360Utils.filterBUSet(organisation, todo.whitelist));
            }
            documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
        } else {
            documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
        }
    }
    license.setPermissions(makePermission(license, user).getPermissionMap());
    license.setDocumentState(documentState);
    return license;
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 3 with DocumentState

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

the class CommonUtils method getModeratedDocumentState.

@NotNull
public static DocumentState getModeratedDocumentState(ModerationRequest moderationRequest) {
    DocumentState documentState = new DocumentState().setIsOriginalDocument(false);
    documentState.setModerationState(moderationRequest.getModerationState());
    return documentState;
}
Also used : DocumentState(org.eclipse.sw360.datahandler.thrift.DocumentState) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with DocumentState

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

the class CommonUtils method getOriginalDocumentState.

@NotNull
public static DocumentState getOriginalDocumentState() {
    DocumentState documentState = new DocumentState().setIsOriginalDocument(true);
    documentState.unsetModerationState();
    return documentState;
}
Also used : DocumentState(org.eclipse.sw360.datahandler.thrift.DocumentState) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with DocumentState

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

the class ComponentDatabaseHandler method getComponentForEdit.

public Component getComponentForEdit(String id, User user) throws SW360Exception {
    List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
    Component component = getComponent(id, user);
    DocumentState documentState;
    if (moderationRequestsForDocumentId.isEmpty()) {
        documentState = CommonUtils.getOriginalDocumentState();
    } else {
        final String email = user.getEmail();
        Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
        if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
            ModerationRequest moderationRequest = moderationRequestOptional.get();
            component = moderator.updateComponentFromModerationRequest(component, moderationRequest.getComponentAdditions(), moderationRequest.getComponentDeletions());
            documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
        } else {
            documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
        }
    }
    component.setPermissions(makePermission(component, user).getPermissionMap());
    component.setDocumentState(documentState);
    return component;
}
Also used : ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Aggregations

ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)4 TException (org.apache.thrift.TException)3 RequestedAction (org.eclipse.sw360.datahandler.thrift.users.RequestedAction)3 User (org.eclipse.sw360.datahandler.thrift.users.User)3 DocumentState (org.eclipse.sw360.datahandler.thrift.DocumentState)2 NotNull (org.jetbrains.annotations.NotNull)2 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)1