Search in sources :

Example 6 with DocumentState

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

the class ComponentDatabaseHandler method getReleaseForEdit.

public Release getReleaseForEdit(String id, User user) throws SW360Exception {
    List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
    Release release = getRelease(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();
            release = releaseModerator.updateReleaseFromModerationRequest(release, moderationRequest.getReleaseAdditions(), moderationRequest.getReleaseDeletions());
            documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
        } else {
            documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
        }
    }
    vendorRepository.fillVendor(release);
    release.setPermissions(makePermission(release, user).getPermissionMap());
    release.setDocumentState(documentState);
    ensureEccInformationIsSet(release);
    return release;
}
Also used : ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 7 with DocumentState

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

the class ProjectDatabaseHandler method getProjectForEdit.

public Project getProjectForEdit(String id, User user) throws SW360Exception {
    List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
    Project project = getProjectById(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();
            project = moderator.updateProjectFromModerationRequest(project, moderationRequest.getProjectAdditions(), moderationRequest.getProjectDeletions());
            documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
        } else {
            documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
        }
    }
    project.setPermissions(makePermission(project, user).getPermissionMap());
    project.setDocumentState(documentState);
    return project;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 8 with DocumentState

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

the class ComponentPortlet method prepareReleaseEdit.

private void prepareReleaseEdit(RenderRequest request, RenderResponse response) throws PortletException {
    String id = request.getParameter(COMPONENT_ID);
    String releaseId = request.getParameter(RELEASE_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_RELEASE);
    if (isNullOrEmpty(id) && isNullOrEmpty(releaseId)) {
        throw new PortletException("Component or Release ID not set!");
    }
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        Release release;
        if (!isNullOrEmpty(releaseId)) {
            release = client.getReleaseByIdForEdit(releaseId, user);
            request.setAttribute(RELEASE, release);
            request.setAttribute(DOCUMENT_ID, releaseId);
            setAttachmentsInRequest(request, release.getAttachments());
            putDirectlyLinkedReleaseRelationsInRequest(request, release);
            Map<RequestedAction, Boolean> permissions = release.getPermissions();
            DocumentState documentState = release.getDocumentState();
            setUsingDocs(request, releaseId, user, client);
            addEditDocumentMessage(request, permissions, documentState);
            if (isNullOrEmpty(id)) {
                id = release.getComponentId();
            }
        } else {
            release = (Release) request.getAttribute(RELEASE);
            if (release == null) {
                release = new Release();
                release.setComponentId(id);
                release.setClearingState(ClearingState.NEW_CLEARING);
                request.setAttribute(RELEASE, release);
                putDirectlyLinkedReleaseRelationsInRequest(request, release);
                setAttachmentsInRequest(request, release.getAttachments());
                setUsingDocs(request, null, user, client);
                SessionMessages.add(request, "request_processed", "New Release");
            }
        }
        Component component = client.getComponentById(id, user);
        addComponentBreadcrumb(request, response, component);
        if (!isNullOrEmpty(release.getId())) {
            // Otherwise the link is meaningless
            addReleaseBreadcrumb(request, response, release);
        }
        request.setAttribute(COMPONENT, component);
        request.setAttribute(IS_USER_AT_LEAST_ECC_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.ECC_ADMIN, user) ? "Yes" : "No");
    } catch (TException e) {
        log.error("Error fetching release from backend!", e);
        setSW360SessionError(request, ErrorMessages.ERROR_GETTING_RELEASE);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction)

Example 9 with DocumentState

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

the class ComponentPortlet method prepareComponentEdit.

private void prepareComponentEdit(RenderRequest request) {
    String id = request.getParameter(COMPONENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_COMPONENT);
    if (id != null) {
        try {
            ComponentService.Iface client = thriftClients.makeComponentClient();
            Component component = client.getComponentByIdForEdit(id, user);
            request.setAttribute(COMPONENT, component);
            request.setAttribute(DOCUMENT_ID, id);
            setAttachmentsInRequest(request, component.getAttachments());
            Map<RequestedAction, Boolean> permissions = component.getPermissions();
            DocumentState documentState = component.getDocumentState();
            addEditDocumentMessage(request, permissions, documentState);
            Set<String> releaseIds = SW360Utils.getReleaseIds(component.getReleases());
            setUsingDocs(request, user, client, releaseIds);
        } catch (TException e) {
            log.error("Error fetching component from backend!", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_COMPONENT);
        }
    } else {
        if (request.getAttribute(COMPONENT) == null) {
            Component component = new Component();
            request.setAttribute(COMPONENT, component);
            setUsingDocs(request, user, null, component.getReleaseIds());
            setAttachmentsInRequest(request, component.getAttachments());
            SessionMessages.add(request, "request_processed", "New Component");
        }
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction)

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