001/*
002 * (C) Copyright 2006-2014 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Remi Cattiau
016 */
017package org.nuxeo.ecm.platform.relations.api;
018
019import org.nuxeo.ecm.core.api.CoreSession;
020import org.nuxeo.ecm.core.api.DocumentModel;
021import org.nuxeo.ecm.platform.relations.api.exceptions.RelationAlreadyExistsException;
022
023/**
024 * Create relations between documents
025 *
026 * @since 5.9.2
027 */
028public interface DocumentRelationManager {
029
030    /**
031     * Add link between two document
032     *
033     * @param from the document to link from
034     * @param to the document to link to
035     * @param predicate is the type of link
036     * @param inverse if to is related to from ( the event will still be generated with from document )
037     * @throws RelationAlreadyExistsException
038     */
039    void addRelation(CoreSession session, DocumentModel from, DocumentModel to, String predicate, boolean inverse);
040
041    /**
042     * Add link between two document
043     *
044     * @param from the document to link from
045     * @param to the node to link to
046     * @param predicate is the type of link
047     * @param inverse if to is related to from ( the event will still be generated with from document )
048     * @throws RelationAlreadyExistsException
049     */
050    void addRelation(CoreSession session, DocumentModel from, Node to, String predicate, boolean inverse);
051
052    /**
053     * Add link between two document
054     *
055     * @param from the document to link from
056     * @param to the node to link to
057     * @param predicate is the type of link
058     * @throws RelationAlreadyExistsException
059     */
060    void addRelation(CoreSession session, DocumentModel from, Node to, String predicate);
061
062    /**
063     * Add link between two document
064     *
065     * @param from the document to link from
066     * @param to the node to link to
067     * @param predicate is the type of link
068     * @param inverse if to is related to from ( the event will still be generated with from document )
069     * @param includeStatementsInEvents will add the statement to the events RelationEvents.BEFORE_RELATION_CREATION and
070     *            RelationEvents.AFTER_RELATION_CREATION
071     * @throws RelationAlreadyExistsException
072     */
073    void addRelation(CoreSession session, DocumentModel from, Node to, String predicate, boolean inverse,
074            boolean includeStatementsInEvents);
075
076    /**
077     * Add link between two document
078     *
079     * @param from the document to link from
080     * @param to the node to link to
081     * @param predicate is the type of link
082     * @param inverse if to is related to from ( the event will still be generated with from document )
083     * @param includeStatementsInEvents will add the statement to the events RelationEvents.BEFORE_RELATION_CREATION and
084     *            RelationEvents.AFTER_RELATION_CREATION
085     * @param comment of the relation
086     * @throws RelationAlreadyExistsException
087     */
088    void addRelation(CoreSession session, DocumentModel from, Node to, String predicate, boolean inverse,
089            boolean includeStatementsInEvents, String comment);
090
091    /**
092     * @param from document
093     * @param to document
094     * @param predicate relation type
095     */
096    void deleteRelation(CoreSession session, DocumentModel from, DocumentModel to, String predicate);
097
098    /**
099     * @param statement to delete
100     */
101    void deleteRelation(CoreSession session, Statement statement);
102
103    /**
104     * @param stmt to delete
105     * @param includeStatementsInEvents add the current statement in event RelationEvents.BEFORE_RELATION_REMOVAL and
106     *            RelationEvents.AFTER_RELATION_REMOVAL
107     */
108    void deleteRelation(CoreSession session, Statement stmt, boolean includeStatementsInEvents);
109
110    /**
111     * @param from document
112     * @param to document
113     * @param predicate relation type
114     * @param includeStatementsInEvents add the current statement in event RelationEvents.BEFORE_RELATION_REMOVAL and
115     *            RelationEvents.AFTER_RELATION_REMOVAL
116     */
117    void deleteRelation(CoreSession session, DocumentModel from, DocumentModel to, String predicate,
118            boolean includeStatementsInEvents);
119
120}