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          }
92          catch (OleException e) {
93              docStoreLogger.log(e.getMessage());
94              return "Error in checking out the file. Please refer to the logs for more details!";
95          }
96          catch (RepositoryException e) {
97              docStoreLogger.log(e.getMessage());
98              return "Error in checking out the file. Please refer to the logs for more details!";
99          }
100         catch (FileNotFoundException e) {
101             docStoreLogger.log(e.getMessage());
102             return "Error in checking out the file. Please refer to the logs for more details!";
103         }
104     }
105 
106 
107     public String updateRecord(RequestDocument updateContent) throws OleException {
108         return checkinManager.updateContent(updateContent);
109     }
110 
111     public File checkOutMultiPart(Request request) throws Exception {
112         return checkoutManager.checkOutMultiPart(request);
113     }
114 
115     public void addReference(String uuidFile1, String uuidFile2, String userId, String action) {
116     }
117 
118     /*  public CheckinManager getCheckinManager() {
119         if (null == checkinManager) {
120             checkinManager = new CheckinManager();
121         }
122         return checkinManager;
123     }*/
124 
125     public String checkOutBinary(String uuid, String userId, String action, String docFormat) throws IOException {
126         try {
127             return checkoutManager.checkOutBinary(uuid, userId, action, docFormat);
128         }
129 
130         catch (OleException e) {
131             docStoreLogger.log(e.getMessage());
132             return "Error in checking out the file. Please refer to the logs for more details!";
133         }
134         catch (RepositoryException e) {
135             docStoreLogger.log(e.getMessage());
136             return "Error in checking out the file. Please refer to the logs for more details!";
137         }
138         catch (FileNotFoundException e) {
139             docStoreLogger.log(e.getMessage());
140             return "Error in checking out the file. Please refer to the logs for more details!";
141         }
142     }
143 }