001    /**
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.edl.impl.extract.dao.impl;
017    
018    import java.util.List;
019    
020    import org.apache.ojb.broker.query.Criteria;
021    import org.apache.ojb.broker.query.QueryByCriteria;
022    import org.kuali.rice.edl.impl.extract.Dump;
023    import org.kuali.rice.edl.impl.extract.Fields;
024    import org.kuali.rice.edl.impl.extract.dao.ExtractDAO;
025    import org.kuali.rice.kew.notes.Note;
026    import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
027    
028    
029    public class ExtractDAOOjbImpl extends PersistenceBrokerDaoSupport implements ExtractDAO {
030    
031            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ExtractDAOOjbImpl.class);
032    
033            public Dump getDumpByDocumentId(String docId) {
034                    LOG.debug("finding Document Extract by documentId " + docId);
035            Criteria crit = new Criteria();
036            crit.addEqualTo("docId", docId);
037            return (Dump) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(Dump.class, crit));
038            }
039    
040            public List getFieldsByDocumentId(String docId) {
041                    LOG.debug("finding Extract Fileds by documentId " + docId);
042                Criteria crit = new Criteria();
043                crit.addEqualTo("documentId", docId);
044                QueryByCriteria query = new QueryByCriteria(Fields.class, crit);
045                query.addOrderByAscending("docId");
046                return (List) getPersistenceBrokerTemplate().getCollectionByQuery(query);
047        }
048    
049            public void saveDump(Dump dump) {
050            LOG.debug("check for null values in Extract document");
051            checkNull(dump.getDocId() , "Document ID");
052            checkNull(dump.getDocCreationDate(), "Creation Date");
053            checkNull(dump.getDocCurrentNodeName(), "Current Node Name");
054            checkNull(dump.getDocModificationDate(), "Modification Date");
055            checkNull(dump.getDocRouteStatusCode(), "Route Status Code");
056            checkNull(dump.getDocInitiatorId(), "Initiator ID");
057            checkNull(dump.getDocTypeName(), "Doc Type Name");
058            LOG.debug("saving EDocLite document: routeHeader " + dump.getDocId());
059            getPersistenceBrokerTemplate().store(dump);
060            }
061    
062            public void saveField(Fields field) {
063            LOG.debug("saving EDocLite Extract fields");
064            checkNull(field.getDocId() , "Document ID");
065            checkNull(field.getFieldValue(), "Field Value");
066            checkNull(field.getFiledName(), "Field Name");
067            LOG.debug("saving Fields: routeHeader " + field.getFieldId());
068                getPersistenceBrokerTemplate().store(field);
069            }
070    
071        private void checkNull(Object value, String valueName) throws RuntimeException {
072            if (value == null) {
073                throw new RuntimeException("Null value for " + valueName);
074            }
075        }
076    
077            public void deleteDump(String documentId) {
078            LOG.debug("deleting record form Extract Dump table");
079            Criteria crit = new Criteria();
080            crit.addEqualTo("docId", documentId);
081            getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(Note.class, crit));
082            }
083    }