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.documenthandler;
17  
18  import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
19  import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.*;
20  import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkInstanceOlemlRecordProcessor;
21  
22  import javax.jcr.Node;
23  import javax.jcr.RepositoryException;
24  import java.util.ArrayList;
25  
26  /**
27   * Class to WorkInstanceOleMLContentHandler.
28   *
29   * @author Rajesh Chowdary K
30   * @created Feb 24, 2012
31   */
32  public class WorkInstanceOleMLContentHandler {
33      private WorkInstanceOlemlRecordProcessor olemlProcessor = new WorkInstanceOlemlRecordProcessor();
34  
35      /**
36       * Method to alter the pre ingest operations for the given Instance OleML Content Manipulations.
37       * Manipulates content to insert hodlings Identifier and Instance Identifier
38       *
39       * @param document
40       * @param fileNodeUUID
41       * @param parentNode
42       * @throws RepositoryException
43       */
44      public void doInstanceOleMLContentManipulations(RequestDocument document, final String fileNodeUUID,
45                                                      final Node parentNode) throws RepositoryException {
46          if (document.getContent().getContentObject() instanceof OleHoldings) { // holdings
47              ((OleHoldings) document.getContent().getContentObject()).setHoldingsIdentifier(fileNodeUUID);
48              document.getContent()
49                      .setContent(olemlProcessor.toXML((OleHoldings) document.getContent().getContentObject()));
50          }
51          else if (document.getContent().getContentObject() instanceof SourceHoldings) { // source holdings.
52              ((SourceHoldings) document.getContent().getContentObject()).setHoldingsIdentifier(fileNodeUUID);
53              document.getContent()
54                      .setContent(olemlProcessor.toXML((SourceHoldings) document.getContent().getContentObject()));
55          }
56          else if (document.getContent().getContentObject() instanceof Item) { // item
57              ((Item) document.getContent().getContentObject()).setItemIdentifier(fileNodeUUID);
58              document.getContent().setContent(olemlProcessor.toXML((Item) document.getContent().getContentObject()));
59          }
60          else if (document.getContent().getContentObject() instanceof Instance) { // instance
61              Instance inst = ((Instance) document.getContent().getContentObject());
62              inst.setInstanceIdentifier(parentNode.getIdentifier());
63              InstanceCollection instanceCollection = new InstanceCollection();
64              ArrayList<Instance> oleinsts = new ArrayList<Instance>();
65              oleinsts.add(inst);
66              instanceCollection.setInstance((oleinsts));
67              document.getContent().setContent(olemlProcessor.toXML(instanceCollection));
68          }
69      }
70  }