Package org.nuxeo.ecm.directory

Examples of org.nuxeo.ecm.directory.Session


        if (kind == null) {
            throw new ClientRuntimeException("Type cannot be null");
        }

        DirectoryService directoryService = Framework.getLocalService(DirectoryService.class);
        Session relationshipsDirectory = null;
        try {
            relationshipsDirectory = directoryService.open(RELATIONSHIP_DIRECTORY_NAME);
            // try to get an existing entry
            Map<String, Serializable> relationship = new HashMap<String, Serializable>();
            relationship.put(RELATIONSHIP_FIELD_ACTOR, actorId);
            relationship.put(RELATIONSHIP_FIELD_TARGET, targetId);
            relationship.put(RELATIONSHIP_FIELD_KIND, kind.toString());

            DocumentModelList relationships = relationshipsDirectory.query(relationship);
            if (relationships.isEmpty()) {
                relationshipsDirectory.createEntry(new HashMap<String, Object>(
                        relationship));
                return true;
            } else {
                return false;
            }
        } catch (ClientException e) {
            throw new ClientRuntimeException("Unable to create a new relation",
                    e);
        } finally {
            if (relationshipsDirectory != null) {
                try {
                    relationshipsDirectory.close();
                } catch (DirectoryException e) {
                    log.error("Error while trying to close relationships directory");
                    log.debug("Exception occurred", e);
                }
            }
View Full Code Here


    @Override
    public Boolean removeRelation(String actorId, String targetId,
            RelationshipKind kind) {
        DirectoryService directoryService = Framework.getLocalService(DirectoryService.class);
        Session relationshipDirectory = null;
        try {
            relationshipDirectory = directoryService.open(RELATIONSHIP_DIRECTORY_NAME);

            Map<String, Serializable> filter = new HashMap<String, Serializable>();
            filter.put(RELATIONSHIP_FIELD_ACTOR, actorId);
            if (!StringUtils.isBlank(targetId)) {
                filter.put(RELATIONSHIP_FIELD_TARGET, targetId);
            }
            if (!(kind == null || kind.isEmpty())) {
                filter.put(RELATIONSHIP_FIELD_KIND, kind.toString());
            }

            DocumentModelList relations = relationshipDirectory.query(filter,
                    filter.keySet());
            if (relations.isEmpty()) {
                log.warn("Trying to delete a relationship that doesn't exists");
                return false;
            } else {
                for (DocumentModel relation : relations) {
                    relationshipDirectory.deleteEntry(relation.getId());
                }
                return true;
            }
        } catch (ClientException e) {
            throw new ClientRuntimeException("Unable to remove a relationship",
                    e);
        } finally {
            if (relationshipDirectory != null) {
                try {
                    relationshipDirectory.close();
                } catch (DirectoryException e) {
                    log.error("Error while trying to close relationships directory");
                    log.debug("Exception occurred", e);
                }
            }
View Full Code Here

    }

    protected DocumentModelList queryRelationshipsDirectory(
            Map<String, Serializable> filter, Boolean withFulltext) {
        DirectoryService directoryService = Framework.getLocalService(DirectoryService.class);
        Session relationshipsDirectory = null;
        try {
            relationshipsDirectory = directoryService.open(RELATIONSHIP_DIRECTORY_NAME);

            Set<String> fulltextFields = new HashSet<String>();
            fulltextFields.add(RELATIONSHIP_FIELD_KIND);
            if (withFulltext) {
                fulltextFields.addAll(filter.keySet());
            }

            return relationshipsDirectory.query(filter, fulltextFields,
                    getRelationshipsOrderBy());
        } catch (ClientException e) {
            throw new ClientRuntimeException(
                    "Unable to query through relationships directory", e);
        } finally {
            if (relationshipsDirectory != null) {
                try {
                    relationshipsDirectory.close();
                } catch (DirectoryException e) {
                    log.error("Error while trying to close relationships directory");
                    log.debug("Exception occurred", e);
                }
            }
View Full Code Here

TOP

Related Classes of org.nuxeo.ecm.directory.Session

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.