View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.repository;
17  
18  import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
19  import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
20  import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
21  import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
22  import org.kuali.ole.logger.DocStoreLogger;
23  import org.kuali.ole.pojo.OleException;
24  import org.springframework.beans.factory.annotation.Required;
25  
26  import javax.jcr.RepositoryException;
27  
28  import java.io.File;
29  import java.io.FileNotFoundException;
30  import java.io.IOException;
31  
32  /**
33   * Created by IntelliJ IDEA.
34   * User: pvsubrah
35   * Date: 9/13/11
36   * Time: 10:27 AM
37   * To change this template use File | Settings | File Templates.
38   * <p/>
39   * Singleton instance of this class is created by Spring.
40   */
41  public class DocumentStoreManager {
42      DocStoreLogger docStoreLogger = new DocStoreLogger(this.getClass().getName());
43      /**
44       * Singleton instance of  CheckinManager initialized by Spring DI.
45       */
46      private CheckinManager checkinManager;
47      /**
48       * Singleton instance of  CheckoutManager initialized by Spring DI.
49       */
50      private CheckoutManager checkoutManager;
51      /**
52       * Singleton instance of  DeleteManager initialized by Spring DI.
53       */
54      private DeleteManager deleteManager;
55      /**
56       * Singleton instance of  RequestHandler initialized by Spring DI.
57       */
58      private RequestHandler requestHandler;
59  
60      @Required
61      public void setCheckinManager(CheckinManager checkinManager) {
62          this.checkinManager = checkinManager;
63      }
64  
65      @Required
66      public void setCheckoutManager(CheckoutManager checkoutManager) {
67          this.checkoutManager = checkoutManager;
68      }
69  
70      @Required
71      public void setDeleteManager(DeleteManager deleteManager) {
72          this.deleteManager = deleteManager;
73      }
74  
75      @Required
76      public void setRequestHandler(RequestHandler requestHandler) {
77          this.requestHandler = requestHandler;
78      }
79  
80      public Response processDeleteRequest(String requestString) throws Exception {
81          Response response = null;
82          Request request = requestHandler.toObject(requestString);
83          response = deleteManager.deleteDocs(request);
84          return response;
85  
86      }
87  
88      public String checkOut(String uuid, String userId, String action) {
89          try {
90              return checkoutManager.checkOut(uuid, userId, action);
91          } catch (OleException e) {
92              docStoreLogger.log(e.getMessage());
93              return "Error in checking out the file. Please refer to the logs for more details!";
94          } catch (RepositoryException e) {
95              docStoreLogger.log(e.getMessage());
96              return "Error in checking out the file. Please refer to the logs for more details!";
97          } catch (FileNotFoundException e) {
98              docStoreLogger.log(e.getMessage());
99              return "Error in checking out the file. Please refer to the logs for more details!";
100         }
101     }
102 
103 
104     public String updateRecord(RequestDocument updateContent) throws OleException {
105         return checkinManager.updateContent(updateContent);
106     }
107 
108     public File checkOutMultiPart(Request request) throws Exception {
109         return checkoutManager.checkOutMultiPart(request);
110     }
111 
112     public void addReference(String uuidFile1, String uuidFile2, String userId, String action) {
113     }
114 
115     /*  public CheckinManager getCheckinManager() {
116         if (null == checkinManager) {
117             checkinManager = new CheckinManager();
118         }
119         return checkinManager;
120     }*/
121 
122     public String checkOutBinary(String uuid, String userId, String action, String docFormat) throws IOException {
123         try {
124             return checkoutManager.checkOutBinary(uuid, userId, action, docFormat);
125         } catch (OleException e) {
126             docStoreLogger.log(e.getMessage());
127             return "Error in checking out the file. Please refer to the logs for more details!";
128         } catch (RepositoryException e) {
129             docStoreLogger.log(e.getMessage());
130             return "Error in checking out the file. Please refer to the logs for more details!";
131         } catch (FileNotFoundException e) {
132             docStoreLogger.log(e.getMessage());
133             return "Error in checking out the file. Please refer to the logs for more details!";
134         }
135     }
136 }