View Javadoc
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.sword.application;
20  
21  import java.util.List;
22  import java.util.concurrent.TimeUnit;
23  import java.util.stream.Stream;
24  
25  import org.apache.logging.log4j.LogManager;
26  import org.apache.logging.log4j.Logger;
27  import org.mycore.datamodel.metadata.MCRMetadataManager;
28  import org.mycore.datamodel.metadata.MCRObjectID;
29  import org.mycore.sword.MCRSwordContainerHandler;
30  import org.swordapp.server.SwordError;
31  
32  /**
33   * Interface to tell the MyCoRe SwordV2 which MyCoRe Objects will be visible to sword and in which collections they are.
34   *
35   * @author Sebastian Hofmann (mcrshofm)
36   */
37  public abstract class MCRSwordCollectionProvider implements MCRSwordLifecycle {
38  
39      protected static Logger LOGGER = LogManager.getLogger(MCRSwordCollectionProvider.class);
40  
41      private MCRSwordContainerHandler mcrSwordContainerHandler;
42  
43      private MCRSwordMediaHandler mcrSwordMediaHandler;
44  
45      protected MCRSwordCollectionProvider() {
46          mcrSwordContainerHandler = new MCRSwordContainerHandler();
47          mcrSwordMediaHandler = new MCRSwordMediaHandler();
48      }
49  
50      /**
51       * tells the SwordV2 impl if the Collection is visible for the current User.
52       *
53       * @return true if the collection should be provided.
54       */
55      public abstract boolean isVisible();
56  
57      /**
58       * tells which packaging is supported by the collection.
59       *
60       * @return a list of supported packacking
61       */
62      public abstract List<String> getSupportedPagacking();
63  
64      /**
65       * @return a supplier which tells the MyCoRe Sword implementation which objects can be exposed to a collection
66       */
67      public abstract MCRSwordObjectIDSupplier getIDSupplier();
68  
69      public MCRSwordContainerHandler getContainerHandler() {
70          return mcrSwordContainerHandler;
71      }
72  
73      public abstract MCRSwordIngester getIngester();
74  
75      public abstract MCRSwordMetadataProvider getMetadataProvider();
76  
77      /**
78       * @return the {@link MCRSwordMediaHandler} which will be used for this collection
79       */
80      public MCRSwordMediaHandler getMediaHandler() {
81          return mcrSwordMediaHandler;
82      }
83  
84      public abstract MCRSwordAuthHandler getAuthHandler();
85  
86      public Stream<String> getDerivateIDsofObject(final String mcrObjectId) throws SwordError {
87          final List<MCRObjectID> derivateIds = MCRMetadataManager.getDerivateIds(MCRObjectID.getInstance(mcrObjectId),
88              10, TimeUnit.SECONDS);
89          return derivateIds.stream().map(MCRObjectID::toString);
90      }
91  
92      @Override
93      public void init(MCRSwordLifecycleConfiguration lifecycleConfiguration) {
94          getIngester().init(lifecycleConfiguration);
95          getMetadataProvider().init(lifecycleConfiguration);
96          getMediaHandler().init(lifecycleConfiguration);
97          getContainerHandler().init(lifecycleConfiguration);
98      }
99  
100     @Override
101     public void destroy() {
102         getIngester().destroy();
103         getMetadataProvider().destroy();
104         getMediaHandler().destroy();
105         getContainerHandler().destroy();
106     }
107 }