001/*
002 * (C) Copyright 2006-2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Remi Cattiau
018 */
019package org.nuxeo.ecm.platform.relations.api;
020
021import org.nuxeo.ecm.core.api.CoreSession;
022import org.nuxeo.ecm.core.api.DocumentModel;
023import org.nuxeo.ecm.platform.relations.api.exceptions.RelationAlreadyExistsException;
024
025/**
026 * Create relations between documents
027 *
028 * @since 5.9.2
029 */
030public interface DocumentRelationManager {
031
032    /**
033     * Add link between two document
034     *
035     * @param from the document to link from
036     * @param to the document to link to
037     * @param predicate is the type of link
038     * @param inverse if to is related to from ( the event will still be generated with from document )
039     * @throws RelationAlreadyExistsException
040     */
041    void addRelation(CoreSession session, DocumentModel from, DocumentModel to, String predicate, boolean inverse);
042
043    /**
044     * Add link between two document
045     *
046     * @param from the document to link from
047     * @param to the node to link to
048     * @param predicate is the type of link
049     * @param inverse if to is related to from ( the event will still be generated with from document )
050     * @throws RelationAlreadyExistsException
051     */
052    void addRelation(CoreSession session, DocumentModel from, Node to, String predicate, boolean inverse);
053
054    /**
055     * Add link between two document
056     *
057     * @param from the document to link from
058     * @param to the node to link to
059     * @param predicate is the type of link
060     * @throws RelationAlreadyExistsException
061     */
062    void addRelation(CoreSession session, DocumentModel from, Node to, String predicate);
063
064    /**
065     * Add link between two document
066     *
067     * @param from the document to link from
068     * @param to the node to link to
069     * @param predicate is the type of link
070     * @param inverse if to is related to from ( the event will still be generated with from document )
071     * @param includeStatementsInEvents will add the statement to the events RelationEvents.BEFORE_RELATION_CREATION and
072     *            RelationEvents.AFTER_RELATION_CREATION
073     * @throws RelationAlreadyExistsException
074     */
075    void addRelation(CoreSession session, DocumentModel from, Node to, String predicate, boolean inverse,
076            boolean includeStatementsInEvents);
077
078    /**
079     * Add link between two document
080     *
081     * @param from the document to link from
082     * @param to the node to link to
083     * @param predicate is the type of link
084     * @param inverse if to is related to from ( the event will still be generated with from document )
085     * @param includeStatementsInEvents will add the statement to the events RelationEvents.BEFORE_RELATION_CREATION and
086     *            RelationEvents.AFTER_RELATION_CREATION
087     * @param comment of the relation
088     * @throws RelationAlreadyExistsException
089     */
090    void addRelation(CoreSession session, DocumentModel from, Node to, String predicate, boolean inverse,
091            boolean includeStatementsInEvents, String comment);
092
093    /**
094     * @param from document
095     * @param to document
096     * @param predicate relation type
097     */
098    void deleteRelation(CoreSession session, DocumentModel from, DocumentModel to, String predicate);
099
100    /**
101     * @param statement to delete
102     */
103    void deleteRelation(CoreSession session, Statement statement);
104
105    /**
106     * @param stmt to delete
107     * @param includeStatementsInEvents add the current statement in event RelationEvents.BEFORE_RELATION_REMOVAL and
108     *            RelationEvents.AFTER_RELATION_REMOVAL
109     */
110    void deleteRelation(CoreSession session, Statement stmt, boolean includeStatementsInEvents);
111
112    /**
113     * @param from document
114     * @param to document
115     * @param predicate relation type
116     * @param includeStatementsInEvents add the current statement in event RelationEvents.BEFORE_RELATION_REMOVAL and
117     *            RelationEvents.AFTER_RELATION_REMOVAL
118     */
119    void deleteRelation(CoreSession session, DocumentModel from, DocumentModel to, String predicate,
120            boolean includeStatementsInEvents);
121
122}