001/*
002 * (C) Copyright 2006-2011 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 *     Anahide Tchertchian
018 *     Florent Guillaume
019 */
020package org.nuxeo.ecm.platform.relations.api;
021
022import java.io.InputStream;
023import java.io.OutputStream;
024import java.io.Serializable;
025import java.util.List;
026import java.util.Map;
027import java.util.Set;
028
029import org.nuxeo.ecm.core.api.CoreSession;
030
031/**
032 * RelationService common interface.
033 */
034public interface RelationManager extends Serializable {
035
036    /**
037     * Gets a registered graph by name.
038     * <p>
039     * A {@link CoreSession} should be passed to provide a context in which to store relations when using a "core"
040     * graph.
041     *
042     * @param name string name of the graph used at registration
043     * @param session the core session
044     * @return the graph
045     * @throws RuntimeException if the graph is not found
046     * @since 5.5
047     */
048    Graph getGraph(String name, CoreSession session);
049
050    /**
051     * Gets a registered graph by name.
052     *
053     * @param name string name of the graph used at registration
054     * @return the graph
055     * @throws RuntimeException if the graph is not found
056     */
057    Graph getGraphByName(String name);
058
059    /**
060     * Gets a transient graph.
061     *
062     * @param type The graph type.
063     * @return the graph.
064     */
065    Graph getTransientGraph(String type);
066
067    /**
068     * Gets a resource given a namespace and a serializable object.
069     * <p>
070     * There can be several resources with different namespaces associated to an incoming object. A document can for
071     * instance be used to refer to itself as a precise version as well as to the set of all versions.
072     * <p>
073     * Context can hold any object useful for the adapters, like a {@link CoreSession}.
074     *
075     * @since 5.2-M1
076     */
077    Resource getResource(String namespace, Serializable object, Map<String, Object> context);
078
079    /**
080     * Computes all resources corresponding to the given object.
081     * <p>
082     * Context can hold any object useful for the adapters, like a {@link CoreSession}.
083     *
084     * @since 5.2-M1
085     * @return the resources as a set
086     */
087    Set<Resource> getAllResources(Serializable object, Map<String, Object> context);
088
089    /**
090     * Gets an object representing this resource given a namespace.
091     * <p>
092     * Context can hold any object useful for the adapters, like a {@link CoreSession}.
093     *
094     * @since 5.2-M1
095     */
096    Serializable getResourceRepresentation(String namespace, Resource resource, Map<String, Object> context);
097
098    /**
099     * Gets the list containing the graph names.
100     *
101     * @since 5.2-GA
102     */
103    List<String> getGraphNames();
104
105    /**
106     * @see org.nuxeo.ecm.platform.relations.api.Graph#add
107     * @deprecated since 5.5, use the Graph API directly
108     */
109    @Deprecated
110    void add(String graphName, List<Statement> statements);
111
112    /**
113     * @see org.nuxeo.ecm.platform.relations.api.Graph#remove
114     * @deprecated since 5.5, use the Graph API directly
115     */
116    @Deprecated
117    void remove(String graphName, List<Statement> statements);
118
119    /**
120     * @see org.nuxeo.ecm.platform.relations.api.Graph#getStatements
121     * @deprecated since 5.5, use the Graph API directly
122     */
123    @Deprecated
124    List<Statement> getStatements(String graphName);
125
126    /**
127     * @see org.nuxeo.ecm.platform.relations.api.Graph#getStatements
128     * @deprecated since 5.5, use the Graph API directly
129     */
130    @Deprecated
131    List<Statement> getStatements(String graphName, Statement statement);
132
133    /**
134     * @see org.nuxeo.ecm.platform.relations.api.Graph#getSubjects
135     * @deprecated since 5.5, use the Graph API directly
136     */
137    @Deprecated
138    List<Node> getSubjects(String graphName, Node predicate, Node object);
139
140    /**
141     * @see org.nuxeo.ecm.platform.relations.api.Graph#getPredicates
142     * @deprecated since 5.5, use the Graph API directly
143     */
144    @Deprecated
145    List<Node> getPredicates(String graphName, Node subject, Node object);
146
147    /**
148     * @see org.nuxeo.ecm.platform.relations.api.Graph#getObjects
149     * @deprecated since 5.5, use the Graph API directly
150     */
151    @Deprecated
152    List<Node> getObjects(String graphName, Node subject, Node predicate);
153
154    /**
155     * @see org.nuxeo.ecm.platform.relations.api.Graph#hasStatement
156     * @deprecated since 5.5, use the Graph API directly
157     */
158    @Deprecated
159    boolean hasStatement(String graphName, Statement statement);
160
161    /**
162     * @see org.nuxeo.ecm.platform.relations.api.Graph#hasResource
163     * @deprecated since 5.5, use the Graph API directly
164     */
165    @Deprecated
166    boolean hasResource(String graphName, Resource resource);
167
168    /**
169     * @see org.nuxeo.ecm.platform.relations.api.Graph#size
170     * @deprecated since 5.5, use the Graph API directly
171     */
172    @Deprecated
173    Long size(String graphName);
174
175    /**
176     * @see org.nuxeo.ecm.platform.relations.api.Graph#clear
177     * @deprecated since 5.5, use the Graph API directly
178     */
179    @Deprecated
180    void clear(String graphName);
181
182    /**
183     * @see org.nuxeo.ecm.platform.relations.api.Graph#query
184     * @deprecated since 5.5, use the Graph API directly
185     */
186    @Deprecated
187    QueryResult query(String graphName, String queryString, String language, String baseURI);
188
189    /**
190     * @see org.nuxeo.ecm.platform.relations.api.Graph#read
191     * @deprecated since 5.5, use the Graph API directly
192     */
193    @Deprecated
194    boolean read(String graphName, InputStream in, String lang, String base);
195
196    /**
197     * @see org.nuxeo.ecm.platform.relations.api.Graph#write
198     * @deprecated since 5.5, use the Graph API directly
199     */
200    @Deprecated
201    boolean write(String graphName, OutputStream out, String lang, String base);
202
203}