1 /* 2 * This file is part of *** M y C o R e *** 3 * See http://www.mycore.de/ for details. 4 * 5 * MyCoRe is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * MyCoRe is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 package org.mycore.datamodel.common; 20 21 import java.io.IOException; 22 import java.util.Collection; 23 import java.util.Date; 24 import java.util.List; 25 import java.util.concurrent.TimeUnit; 26 27 import org.mycore.common.MCRCache; 28 import org.mycore.common.MCRPersistenceException; 29 import org.mycore.common.content.MCRContent; 30 import org.mycore.datamodel.ifs2.MCRMetadataVersion; 31 import org.mycore.datamodel.metadata.MCRObject; 32 import org.mycore.datamodel.metadata.MCRObjectID; 33 34 /** 35 * Provides an abstract class for persistence managers of MCRObject and MCRDerivate xml 36 * metadata to extend, with methods to perform CRUD operations on object metadata. 37 * 38 * The default xml metadata manager is {@link MCRDefaultXMLMetadataManager}. If you wish to use 39 * another manager implementation instead, change the following property accordingly: 40 * 41 * MCR.Metadata.Manager.Class=org.mycore.datamodel.common.MCRDefaultXMLMetadataManager 42 * 43 * Xml metadata managers have a default class they will instantiate for every store. 44 * If you wish to use a different default class, change the following property 45 * accordingly. For example, when using the MCRDefaultXMLMetadataManager: 46 * 47 * MCR.Metadata.Store.DefaultClass=org.mycore.datamodel.ifs2.MCRVersioningMetadataStore 48 * 49 * The following directory will be used by xml metadata managers to keep up-to-date 50 * store contents in. This directory will be created if it does not exist yet. 51 * 52 * MCR.Metadata.Store.BaseDir=/path/to/metadata/dir 53 * 54 * For each project and type, subdirectories will be created below this path, 55 * for example %MCR.Metadata.Store.BaseDir%/DocPortal/document/. 56 * 57 * If an SVN-based store is configured, then the following property will be used to 58 * store and manage local SVN repositories: 59 * 60 * MCR.Metadata.Store.SVNBase=file:///path/to/local/svndir/ 61 * 62 * It is also possible to change individual properties per project and object type 63 * and overwrite the defaults, for example 64 * 65 * MCR.IFS2.Store.Class=org.mycore.datamodel.ifs2.MCRVersioningMetadataStore 66 * MCR.IFS2.Store.SVNRepositoryURL=file:///use/other/location/for/document/versions/ 67 * MCR.IFS2.Store.SlotLayout=2-2-2-2 68 * 69 * See documentation of MCRStore, MCRMetadataStore and the MCRXMLMetadataManager 70 * extensions (e.g. MCRDefaultXMLMetadataManager) for details. 71 * 72 * @author Christoph Neidahl (OPNA2608) 73 */ 74 public interface MCRXMLMetadataManagerAdapter { 75 76 /** 77 * Reads configuration properties, checks and creates base directories and builds the singleton. 78 */ 79 void reload(); 80 81 /** 82 * Try to validate a store. 83 * 84 * @param base The base ID of a to-be-validated store 85 */ 86 void verifyStore(String base); 87 88 /** 89 * Stores metadata of a new MCRObject in the persistent store. 90 * 91 * @param mcrid the MCRObjectID 92 * @param xml the xml metadata of the MCRObject 93 * @param lastModified the date of last modification to set 94 * @throws MCRPersistenceException the object couldn't be created due persistence problems 95 */ 96 void create(MCRObjectID mcrid, MCRContent xml, Date lastModified) 97 throws MCRPersistenceException; 98 99 /** 100 * Delete metadata in store. 101 * 102 * @param mcrid the MCRObjectID 103 * @throws MCRPersistenceException if an error occurs during the deletion 104 */ 105 void delete(MCRObjectID mcrid) throws MCRPersistenceException; 106 107 /** 108 * Updates metadata of existing MCRObject in the persistent store. 109 * 110 * @param mcrid the MCRObjectID 111 * @param xml the xml metadata of the MCRObject 112 * @param lastModified the date of last modification to set 113 */ 114 void update(MCRObjectID mcrid, MCRContent xml, Date lastModified) 115 throws MCRPersistenceException; 116 117 /** 118 * Retrieves the (latest) content of a metadata object. 119 * 120 * @param mcrid 121 * the id of the object to be retrieved 122 * @return a {@link MCRContent} representing the {@link MCRObject} or 123 * <code>null</code> if there is no such object 124 * @throws IOException 125 */ 126 MCRContent retrieveContent(MCRObjectID mcrid) throws IOException; 127 128 /** 129 * Retrieves the content of a specific revision of a metadata object. 130 * 131 * @param mcrid 132 * the id of the object to be retrieved 133 * @param revision 134 * the revision to be returned, specify -1 if you want to 135 * retrieve the latest revision (includes deleted objects also) 136 * @return a {@link MCRContent} representing the {@link MCRObject} of the 137 * given revision or <code>null</code> if there is no such object 138 * with the given revision 139 * @throws IOException 140 */ 141 MCRContent retrieveContent(MCRObjectID mcrid, String revision) throws IOException; 142 143 /** 144 * Lists all versions of this metadata object available in the 145 * subversion repository. 146 * 147 * @param id 148 * the id of the object to be retrieved 149 * @return {@link List} with all {@link MCRMetadataVersion} of 150 * the given object or null if the id is null or the metadata 151 * store doesn't support versioning 152 */ 153 List<? extends MCRAbstractMetadataVersion<?>> listRevisions(MCRObjectID id) throws IOException; 154 155 /** 156 * This method returns the highest stored ID number for a given MCRObjectID 157 * base, or 0 if no object is stored for this type and project. 158 * 159 * @param project 160 * the project ID part of the MCRObjectID base 161 * @param type 162 * the type ID part of the MCRObjectID base 163 * @exception MCRPersistenceException 164 * if a persistence problem is occurred 165 * @return the highest stored ID number as a String 166 */ 167 int getHighestStoredID(String project, String type); 168 169 /** 170 * Checks if an object with the given MCRObjectID exists in the store. 171 * 172 * @param mcrid 173 * the MCRObjectID to check 174 * @return true if the ID exists, or false if it doesn't 175 * @throws MCRPersistenceException if an error occurred in the store 176 */ 177 boolean exists(MCRObjectID mcrid) throws MCRPersistenceException; 178 179 /** 180 * Lists all MCRObjectIDs stored for the given base, which is {project}_{type} 181 * 182 * @param base 183 * the MCRObjectID base, e.g. DocPortal_document 184 * @return List of Strings with all MyCoRe identifiers found in the metadata stores for the given base 185 */ 186 List<String> listIDsForBase(String base); 187 188 /** 189 * Lists all MCRObjectIDs stored for the given object type, for all projects 190 * 191 * @param type 192 * the MCRObject type, e.g. document 193 * @return List of Strings with all MyCoRe identifiers found in the metadata store for the given type 194 */ 195 List<String> listIDsOfType(String type); 196 197 /** 198 * Lists all MCRObjectIDs of all types and projects stored in any metadata store 199 * 200 * @return List of Strings with all MyCoRe identifiers found in the metadata store 201 */ 202 List<String> listIDs(); 203 204 /** 205 * Returns all stored object types of MCRObjects/MCRDerivates. 206 * 207 * @return Collection of Strings with all object types 208 * @see MCRObjectID#getTypeId() 209 */ 210 Collection<String> getObjectTypes(); 211 212 /** 213 * Returns all used base ids of MCRObjects/MCRDerivates. 214 * 215 * @return Collection of Strings with all object base identifier 216 * @see MCRObjectID#getBase() 217 */ 218 Collection<String> getObjectBaseIds(); 219 220 /** 221 * Returns an enhanced list of object ids and their last modified date 222 * 223 * @param ids MCRObject ids 224 * @throws IOException 225 */ 226 List<MCRObjectIDDate> retrieveObjectDates(List<String> ids) throws IOException; 227 228 /** 229 * Returns the time when the xml data of a MCRObject was last modified. 230 * 231 * @param id 232 * the MCRObjectID of an object 233 * @return the last modification data of the object 234 * @throws IOException thrown while retrieving the object from the store 235 */ 236 long getLastModified(MCRObjectID id) throws IOException; 237 238 /** 239 * 240 * 241 * @param id 242 * @param expire 243 * @param unit 244 * @return 245 */ 246 MCRCache.ModifiedHandle getLastModifiedHandle(MCRObjectID id, long expire, TimeUnit unit); 247 }