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
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.backend;
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;
21 import javax.ws.rs.core.MediaType;
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;
31 * Enables access to the winery repository via Ids defined in package
32 * {@link org.eclipse.winery.common.ids}
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.
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.
42 * The ultimate goal is to get rid of this class and to have
43 * IWineryRepositoryCommon only.
45 * Currently, this class is used internally only
47 interface IGenericRepository extends IWineryRepositoryCommon {
50 * Flags the given TOSCA element as existing. The resources itself create
51 * appropriate data files.
53 * Pre-Condition: !exists(id)<br/>
54 * Post-Condition: exists(id)
56 * Typically, the given TOSCA element is created if a configuration is asked
62 public boolean flagAsExisting(GenericId id);
65 * Checks whether the associated TOSA element exists
67 * @param id the id to check
68 * @return true iff the TOSCA element belonging to the given ID exists
70 public boolean exists(GenericId id);
73 * Deletes the referenced object from the repository
77 public void forceDelete(RepositoryFileReference ref) throws IOException;
80 * @param ref reference to check
81 * @return true if the file associated with the given reference exists
83 public boolean exists(RepositoryFileReference ref);
86 * Puts the given content to the given file. Replaces existing content.
88 * If the parent of the reference does not exist, it is created.
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.
94 * @throws IOException if something goes wrong
96 public void putContentToFile(RepositoryFileReference ref, String content, MediaType mediaType) throws IOException;
99 * Puts the given content to the given file. Replaces existing content.
101 * If the parent of the reference does not exist, it is created.
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
107 public void putContentToFile(RepositoryFileReference ref, InputStream inputStream, MediaType mediaType) throws IOException;
110 * Creates an opened inputStream of the contents referenced by ref. The
111 * stream has to be closed by the caller.
113 * @param ref the reference to the file
114 * @return an inputstream
115 * @throws IOException if something goes wrong
117 public InputStream newInputStream(RepositoryFileReference ref) throws IOException;
120 * Returns the size of the file referenced by ref
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
126 long getSize(RepositoryFileReference ref) throws IOException;
129 * Returns the last modification time of the entry.
131 * @param ref the reference to the file
132 * @return the time of the last modification
133 * @throws IOException if something goes wrong
135 FileTime getLastModifiedTime(RepositoryFileReference ref) throws IOException;
138 * Returns the mimetype belonging to the reference.
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
146 String getMimeType(RepositoryFileReference ref) throws IOException;
149 * @return the last change date of the file belonging to the given
150 * reference. NULL if the associated file does not exist.
152 Date getLastUpdate(RepositoryFileReference ref);
155 * Returns all components available of the given id type
157 * @param idClass class of the Ids to search for
158 * @return empty set if no ids are available
160 public <T extends TOSCAComponentId> SortedSet<T> getAllTOSCAComponentIds(Class<T> idClass);
163 * Returns the set of <em>all</em> ids nested in the given reference
165 * The generated Ids are linked as child to the id associated to the given
168 * Required for getting plans nested in a service template: plans are nested
169 * below the PlansOfOneServiceTemplateId
171 * @param ref a reference to the TOSCA element to be checked. The path
172 * belonging to this element is checked.
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.
177 public <T extends TOSCAElementId> SortedSet<T> getNestedIds(GenericId ref, Class<T> idClass);
180 * Returns the set of files nested in the given reference
182 public SortedSet<RepositoryFileReference> getContainedFiles(GenericId id);
185 * Returns all namespaces used by all known TOSCA components
187 public Collection<Namespace> getUsedNamespaces();