Package org.nuxeo.ecm.core.api

Examples of org.nuxeo.ecm.core.api.CoreSession


    @Path("documentCommentList")
    public Object documentCommentList(@QueryParam("docRef") String ref)
            throws Exception {
        // build freemarker arguments map
        Map<String, Object> args = new HashMap<String, Object>();
        CoreSession session = ctx.getCoreSession();
        IdRef docRef = new IdRef(ref);
        DocumentModel doc = session.getDocument(docRef);
        args.put("doc", doc);
        return Response.ok(getView("document_comments_template").args(args)).header(
                "docRef", ref).build();
    }
View Full Code Here


    @POST
    @Path("addComment")
    public Object addComment() throws ClientException {
        try {
            HttpServletRequest request = ctx.getRequest();
            CoreSession session = ctx.getCoreSession();
            // Create pending comment
            DocumentModel myComment = session.createDocumentModel("Comment");
            // Set comment properties
            myComment.setProperty("comment", "author",
                    ctx.getPrincipal().getName());
            myComment.setProperty("comment", "text",
                    request.getParameter("commentContent"));
            myComment.setProperty("comment", "creationDate",
                    Calendar.getInstance());
            // Retrieve document to comment
            String docToCommentRef = request.getParameter("docToCommentRef");
            DocumentModel docToComment = session.getDocument(new IdRef(
                    docToCommentRef));
            String commentParentRef = request.getParameter("commentParentRef");
            // Create comment
            CommentableDocument commentableDoc = null;
            if (docToComment != null) {
                commentableDoc = docToComment.getAdapter(CommentableDocument.class);
            }
            DocumentModel newComment;
            if (commentParentRef != null) {
                // if exists retrieve comment parent
                DocumentModel commentParent = session.getDocument(new IdRef(
                        commentParentRef));
                newComment = commentableDoc.addComment(commentParent, myComment);
            } else {
                newComment = commentableDoc.addComment(myComment);
            }
View Full Code Here

     */
    @POST
    @Path("docLike")
    public Object docLike(@FormParam("docRef") String docRef) throws Exception {
        // Get document
        CoreSession session = ctx.getCoreSession();
        DocumentModel docToLike = session.getDocument(new IdRef(docRef));
        // Get Like Services
        LikeService likeService = Framework.getLocalService(LikeService.class);
        // Get user name
        String userName = ctx.getPrincipal().getName();
        if (likeService.hasUserLiked(userName, docToLike)) {
View Full Code Here

        if (!DELETE_TRANSITION.equals(ctx.getProperty(TRANSTION_EVENT_OPTION_TRANSITION))) {
            return;
        }

        CoreSession session = ctx.getCoreSession();

        SocialDocument socialDocument = toSocialDocument(document);
        cleanProxy(session, socialDocument);
    }
View Full Code Here

        if (document.getParentRef() == null) {
            return;
        }

        CoreSession session = ctx.getCoreSession();
        DocumentModel documentParent = session.getDocument(document.getParentRef());
        SocialWorkspace sws = getSocialWorkspaceService().getSocialWorkspace(
                documentParent);

        if (sws == null) {
            return;
        }

        document.addFacet(SOCIAL_DOCUMENT_FACET);
        if (DOCUMENT_MOVED.equals(eventName)) {
            session.saveDocument(document);
        }
    }
View Full Code Here

    }

    @Override
    public SocialWorkspace getSocialWorkspace(DocumentModel doc) {
        try {
            CoreSession session = doc.getCoreSession();
            if (session != null) {
                List<DocumentModel> parents = session.getParentDocuments(doc.getRef());
                for (DocumentModel parent : parents) {
                    if (isSocialWorkspace(parent)) {
                        return toSocialWorkspace(parent);
                    }
                }
View Full Code Here

    @Override
    public void handleSocialWorkspaceCreation(
            final SocialWorkspace socialWorkspace, final Principal principal) {
        createBaseRelationshipsWithSocialWorkspace(socialWorkspace, principal);
        CoreSession session = socialWorkspace.getDocument().getCoreSession();
        try {
            new UnrestrictedSessionRunner(session) {
                @Override
                public void run() throws ClientException {
                    SocialWorkspace unrestrictedSocialWorkspace = toSocialWorkspace(session.getDocument(new IdRef(
                            socialWorkspace.getId())));
                    initializeSocialWorkspaceRights(unrestrictedSocialWorkspace);
                    initializeNewsItemsRootRights(unrestrictedSocialWorkspace);
                    if (unrestrictedSocialWorkspace.isPublic()) {
                        makeSocialWorkspacePublic(unrestrictedSocialWorkspace);
View Full Code Here

    }

    private void initializeSocialWorkspaceRights(SocialWorkspace socialWorkspace) {
        try {
            DocumentModel doc = socialWorkspace.getDocument();
            CoreSession session = doc.getCoreSession();
            ACP acp = doc.getACP();
            ACL acl = acp.getOrCreateACL(SOCIAL_WORKSPACE_ACL_NAME);
            addSocialWorkspaceACL(acl, socialWorkspace);
            doc.setACP(acp, true);
            doc.putContextData(ScopeType.REQUEST,
                    SocialWorkspaceListener.DO_NOT_PROCESS, true);
            doc = session.saveDocument(doc);
            socialWorkspace.setDocument(doc);
        } catch (ClientException e) {
            throw new ClientRuntimeException(e);
        }
    }
View Full Code Here

    }

    private static void initializeNewsItemsRootRights(
            SocialWorkspace socialWorkspace) {
        try {
            CoreSession session = socialWorkspace.getDocument().getCoreSession();
            PathRef newsItemsRootPath = new PathRef(
                    socialWorkspace.getNewsItemsRootPath());
            DocumentModel newsItemsRoot = session.getDocument(newsItemsRootPath);

            ACP acp = newsItemsRoot.getACP();
            ACL acl = acp.getOrCreateACL(NEWS_ITEMS_ROOT_ACL_NAME);
            acl.add(new ACE(socialWorkspace.getAdministratorsGroupName(),
                    EVERYTHING, true));
            acl.add(new ACE(socialWorkspace.getMembersGroupName(), READ));
            acl.add(ACE.BLOCK);
            newsItemsRoot.setACP(acp, true);
            session.saveDocument(newsItemsRoot);
        } catch (ClientException e) {
            throw new ClientRuntimeException(e);
        }
    }
View Full Code Here

            DocumentModel doc = socialWorkspace.getDocument();
            doc.setPropertyValue(SOCIAL_WORKSPACE_IS_PUBLIC_PROPERTY, true);
            doc.putContextData(ScopeType.REQUEST,
                    SocialWorkspaceListener.DO_NOT_PROCESS, true);

            CoreSession session = doc.getCoreSession();
            makePublicSectionReadable(session, socialWorkspace);
            makePublicDashboardReadable(session, socialWorkspace);
            doc = session.saveDocument(doc);
            session.save();
            socialWorkspace.setDocument(doc);
        } catch (ClientException e) {
            throw new ClientRuntimeException(e);
        }
    }
View Full Code Here

TOP

Related Classes of org.nuxeo.ecm.core.api.CoreSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.