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.classifications2; 20 21 import java.util.Collection; 22 import java.util.Map; 23 24 /** 25 * 26 * @author Thomas Scheffler (yagee) 27 * @version $Revision$ $Date$ 28 * @since 2.0 29 */ 30 public interface MCRCategLinkService { 31 32 /** 33 * Checks if a categories id refered by objects. 34 * 35 * @param category 36 * a subtree rooted at a MCRCategory for which links should be counted 37 * @return true if the classification is used 38 */ 39 Map<MCRCategoryID, Boolean> hasLinks(MCRCategory category); 40 41 /** 42 * Checks if the category with the given id is liked with an object 43 * 44 * @return 45 * true if is linked otherwise false 46 */ 47 boolean hasLink(MCRCategory classif); 48 49 /** 50 * Counts links to a collection of categories. 51 * 52 * @param category 53 * a subtree rooted at a MCRCategory for which links should be counted 54 * @param childrenOnly 55 * if only direct children of category should be queried (query may be more optimized) 56 * @return a Map with MCRCategoryID as key and the number of links as value 57 */ 58 Map<MCRCategoryID, Number> countLinks(MCRCategory category, boolean childrenOnly); 59 60 /** 61 * Counts links to a collection of categories. 62 * 63 * @param category 64 * a subtree rooted at a MCRCategory for which links should be counted 65 * @param type 66 * restrict links that refer to object of this type 67 * @param childrenOnly 68 * if only direct children of category should be queried (query may be more optimized) 69 * @return a Map with MCRCategoryID as key and the number of links as value 70 */ 71 Map<MCRCategoryID, Number> countLinksForType(MCRCategory category, String type, boolean childrenOnly); 72 73 /** 74 * Delete all links that refer to the given {@link MCRCategLinkReference}. 75 * 76 * @param id 77 * an Object ID 78 * @see #deleteLinks(Collection) 79 */ 80 void deleteLink(MCRCategLinkReference id); 81 82 /** 83 * Delete all links that refer to the given collection of category links. 84 * 85 * @param ids 86 * a collection of {@link MCRCategLinkReference} 87 * @see #deleteLink(MCRCategLinkReference) 88 */ 89 void deleteLinks(Collection<MCRCategLinkReference> ids); 90 91 /** 92 * Returns a list of linked Object IDs. 93 * 94 * @param id 95 * ID of the category 96 * @return Collection of Object IDs, empty Collection when no links exist 97 */ 98 Collection<String> getLinksFromCategory(MCRCategoryID id); 99 100 /** 101 * Checks if a given reference is in a specific category. 102 * 103 * @param reference 104 * reference, e.g. to a MCRObject 105 * @return true if the reference is in the category 106 */ 107 boolean isInCategory(MCRCategLinkReference reference, MCRCategoryID id); 108 109 /** 110 * Returns a list of linked Object IDs restricted by the specified type. 111 * 112 * @param id 113 * ID of the category 114 * @param type 115 * restrict links that refer to object of this type 116 * @return Collection of Object IDs 117 */ 118 Collection<String> getLinksFromCategoryForType(MCRCategoryID id, String type); 119 120 /** 121 * Returns a list of linked categories. 122 * 123 * @param reference 124 * reference, e.g. to a MCRObject 125 * @return list of MCRCategoryID of linked categories 126 */ 127 Collection<MCRCategoryID> getLinksFromReference(MCRCategLinkReference reference); 128 129 /** 130 * Return a collection of all category link references for the given type 131 */ 132 Collection<MCRCategLinkReference> getReferences(String type); 133 134 /** 135 * Return a collection of all link types. 136 * 137 */ 138 Collection<String> getTypes(); 139 140 /** 141 * Returns a collection of all links for the given type. 142 * 143 */ 144 Collection<MCRCategoryLink> getLinks(String type); 145 146 /** 147 * Add links between categories and Objects. 148 * 149 * Implementors must assure that ancestor (parent) axis categories are 150 * implicit linked by this method. 151 * 152 * @param objectReference 153 * reference to a Object 154 * @param categories 155 * a collection of categoryIDs to be linked to 156 * @see #countLinks(MCRCategory, boolean) 157 * @see #countLinksForType(MCRCategory, String, boolean) 158 */ 159 void setLinks(MCRCategLinkReference objectReference, Collection<MCRCategoryID> categories); 160 161 }