View Javadoc

1   /**
2    * Copyright 2005-2014 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.rice.edl.impl.extract.dao.impl;
17  
18  import java.util.List;
19  
20  import org.apache.ojb.broker.query.Criteria;
21  import org.apache.ojb.broker.query.QueryByCriteria;
22  import org.kuali.rice.edl.impl.extract.Dump;
23  import org.kuali.rice.edl.impl.extract.Fields;
24  import org.kuali.rice.edl.impl.extract.dao.ExtractDAO;
25  import org.kuali.rice.kew.notes.Note;
26  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
27  
28  
29  public class ExtractDAOOjbImpl extends PersistenceBrokerDaoSupport implements ExtractDAO {
30  
31  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ExtractDAOOjbImpl.class);
32  
33  	public Dump getDumpByDocumentId(String docId) {
34  		LOG.debug("finding Document Extract by documentId " + docId);
35          Criteria crit = new Criteria();
36          crit.addEqualTo("docId", docId);
37          return (Dump) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(Dump.class, crit));
38  	}
39  
40  	public List getFieldsByDocumentId(String docId) {
41  		LOG.debug("finding Extract Fileds by documentId " + docId);
42  	    Criteria crit = new Criteria();
43  	    crit.addEqualTo("documentId", docId);
44  	    QueryByCriteria query = new QueryByCriteria(Fields.class, crit);
45  	    query.addOrderByAscending("docId");
46  	    return (List) getPersistenceBrokerTemplate().getCollectionByQuery(query);
47      }
48  
49  	public void saveDump(Dump dump) {
50          LOG.debug("check for null values in Extract document");
51          checkNull(dump.getDocId() , "Document ID");
52          checkNull(dump.getDocCreationDate(), "Creation Date");
53          checkNull(dump.getDocCurrentNodeName(), "Current Node Name");
54          checkNull(dump.getDocModificationDate(), "Modification Date");
55          checkNull(dump.getDocRouteStatusCode(), "Route Status Code");
56          checkNull(dump.getDocInitiatorId(), "Initiator ID");
57          checkNull(dump.getDocTypeName(), "Doc Type Name");
58          LOG.debug("saving EDocLite document: routeHeader " + dump.getDocId());
59          getPersistenceBrokerTemplate().store(dump);
60  	}
61  
62  	public void saveField(Fields field) {
63          LOG.debug("saving EDocLite Extract fields");
64          checkNull(field.getDocId() , "Document ID");
65          checkNull(field.getFieldValue(), "Field Value");
66          checkNull(field.getFiledName(), "Field Name");
67          LOG.debug("saving Fields: routeHeader " + field.getFieldId());
68  	    getPersistenceBrokerTemplate().store(field);
69  	}
70  
71      private void checkNull(Object value, String valueName) throws RuntimeException {
72          if (value == null) {
73              throw new RuntimeException("Null value for " + valueName);
74          }
75      }
76  
77  	public void deleteDump(String documentId) {
78          LOG.debug("deleting record form Extract Dump table");
79          Criteria crit = new Criteria();
80          crit.addEqualTo("docId", documentId);
81          getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(Note.class, crit));
82  	}
83  }