9e7ba6635fb2c48dde7edcaf157ba16e812eb9a8
[vfc/nfvo/wfengine.git] /
1 /*******************************************************************************
2  * Copyright (c) 2012-2013 University of Stuttgart.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.backend;
13
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.nio.file.attribute.FileTime;
17 import java.util.Collection;
18 import java.util.Date;
19 import java.util.SortedSet;
20
21 import javax.ws.rs.core.MediaType;
22
23 import org.eclipse.winery.common.RepositoryFileReference;
24 import org.eclipse.winery.common.ids.GenericId;
25 import org.eclipse.winery.common.ids.Namespace;
26 import org.eclipse.winery.common.ids.definitions.TOSCAComponentId;
27 import org.eclipse.winery.common.ids.elements.TOSCAElementId;
28 import org.eclipse.winery.common.interfaces.IWineryRepositoryCommon;
29
30 /**
31  * Enables access to the winery repository via Ids defined in package
32  * {@link org.eclipse.winery.common.ids}
33  * 
34  * In contrast to {@link org.eclipse.winery.repository.backend.IRepository},
35  * this is NOT dependent on a particular storage format for the properties.
36  * These two classes exist to make the need for reengineering explicit.
37  * 
38  * This is a first attempt to offer methods via GenericId. It might happen, that
39  * methods, where GenericIds make sense, are simply added to "IWineryRepository"
40  * instead of being added here.
41  * 
42  * The ultimate goal is to get rid of this class and to have
43  * IWineryRepositoryCommon only.
44  * 
45  * Currently, this class is used internally only
46  */
47 interface IGenericRepository extends IWineryRepositoryCommon {
48         
49         /**
50          * Flags the given TOSCA element as existing. The resources itself create
51          * appropriate data files.
52          * 
53          * Pre-Condition: !exists(id)<br/>
54          * Post-Condition: exists(id)
55          * 
56          * Typically, the given TOSCA element is created if a configuration is asked
57          * for
58          * 
59          * @param id
60          * @return
61          */
62         public boolean flagAsExisting(GenericId id);
63         
64         /**
65          * Checks whether the associated TOSA element exists
66          * 
67          * @param id the id to check
68          * @return true iff the TOSCA element belonging to the given ID exists
69          */
70         public boolean exists(GenericId id);
71         
72         /**
73          * Deletes the referenced object from the repository
74          * 
75          * @param ref
76          */
77         public void forceDelete(RepositoryFileReference ref) throws IOException;
78         
79         /**
80          * @param ref reference to check
81          * @return true if the file associated with the given reference exists
82          */
83         public boolean exists(RepositoryFileReference ref);
84         
85         /**
86          * Puts the given content to the given file. Replaces existing content.
87          * 
88          * If the parent of the reference does not exist, it is created.
89          * 
90          * @param ref the reference to the file. Must not be null.
91          * @param content the content to put into the file. Must not be null.
92          * @param mediaType the media type of the file. Must not be null.
93          * 
94          * @throws IOException if something goes wrong
95          */
96         public void putContentToFile(RepositoryFileReference ref, String content, MediaType mediaType) throws IOException;
97         
98         /**
99          * Puts the given content to the given file. Replaces existing content.
100          * 
101          * If the parent of the reference does not exist, it is created.
102          * 
103          * @param ref the reference to the file
104          * @param content the content to put into the file
105          * @throws IOException if something goes wrong
106          */
107         public void putContentToFile(RepositoryFileReference ref, InputStream inputStream, MediaType mediaType) throws IOException;
108         
109         /**
110          * Creates an opened inputStream of the contents referenced by ref. The
111          * stream has to be closed by the caller.
112          * 
113          * @param ref the reference to the file
114          * @return an inputstream
115          * @throws IOException if something goes wrong
116          */
117         public InputStream newInputStream(RepositoryFileReference ref) throws IOException;
118         
119         /**
120          * Returns the size of the file referenced by ref
121          * 
122          * @param ref a refernce to the file stored in the repository
123          * @return the size in bytes
124          * @throws IOException if something goes wrong
125          */
126         long getSize(RepositoryFileReference ref) throws IOException;
127         
128         /**
129          * Returns the last modification time of the entry.
130          * 
131          * @param ref the reference to the file
132          * @return the time of the last modification
133          * @throws IOException if something goes wrong
134          */
135         FileTime getLastModifiedTime(RepositoryFileReference ref) throws IOException;
136         
137         /**
138          * Returns the mimetype belonging to the reference.
139          * 
140          * @param ref the reference to the file
141          * @return the mimetype as string
142          * @throws IOException if something goes wrong
143          * @throws IllegalStateException if an internal error occurs, which is not
144          *             an IOException
145          */
146         String getMimeType(RepositoryFileReference ref) throws IOException;
147         
148         /**
149          * @return the last change date of the file belonging to the given
150          *         reference. NULL if the associated file does not exist.
151          */
152         Date getLastUpdate(RepositoryFileReference ref);
153         
154         /**
155          * Returns all components available of the given id type
156          * 
157          * @param idClass class of the Ids to search for
158          * @return empty set if no ids are available
159          */
160         public <T extends TOSCAComponentId> SortedSet<T> getAllTOSCAComponentIds(Class<T> idClass);
161         
162         /**
163          * Returns the set of <em>all</em> ids nested in the given reference
164          * 
165          * The generated Ids are linked as child to the id associated to the given
166          * reference
167          * 
168          * Required for getting plans nested in a service template: plans are nested
169          * below the PlansOfOneServiceTemplateId
170          * 
171          * @param ref a reference to the TOSCA element to be checked. The path
172          *            belonging to this element is checked.
173          * @param idClass
174          * @return the set of Ids nested in the given reference. Empty set if there
175          *         are no or the reference itself does not exist.
176          */
177         public <T extends TOSCAElementId> SortedSet<T> getNestedIds(GenericId ref, Class<T> idClass);
178         
179         /**
180          * Returns the set of files nested in the given reference
181          */
182         public SortedSet<RepositoryFileReference> getContainedFiles(GenericId id);
183         
184         /**
185          * Returns all namespaces used by all known TOSCA components
186          */
187         public Collection<Namespace> getUsedNamespaces();
188         
189 }