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.common.document.content.instance.*;
19  import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
20  import org.kuali.ole.docstore.common.document.content.instance.xstream.InstanceOlemlRecordProcessor;
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 InstanceOlemlRecordProcessor olemlProcessor = new InstanceOlemlRecordProcessor();
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          } else if (document.getContent().getContentObject() instanceof SourceHoldings) { // source holdings.
51              ((SourceHoldings) document.getContent().getContentObject()).setHoldingsIdentifier(fileNodeUUID);
52              document.getContent()
53                      .setContent(olemlProcessor.toXML((SourceHoldings) document.getContent().getContentObject()));
54          } else if (document.getContent().getContentObject() instanceof Item) { // item
55              ((Item) document.getContent().getContentObject()).setItemIdentifier(fileNodeUUID);
56              document.getContent().setContent(olemlProcessor.toXML((Item) document.getContent().getContentObject()));
57          } else if (document.getContent().getContentObject() instanceof Instance) { // instance
58              Instance inst = ((Instance) document.getContent().getContentObject());
59              inst.setInstanceIdentifier(parentNode.getIdentifier());
60              InstanceCollection instanceCollection = new InstanceCollection();
61              ArrayList<Instance> oleinsts = new ArrayList<Instance>();
62              oleinsts.add(inst);
63              instanceCollection.setInstance((oleinsts));
64              document.getContent().setContent(olemlProcessor.toXML(instanceCollection));
65          }
66      }
67  }