001 /* 002 * Copyright 2005-2007 The Kuali Foundation 003 * 004 * 005 * Licensed under the Educational Community License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.opensource.org/licenses/ecl2.php 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.kuali.rice.kew.edl.dao.impl; 018 019 import java.util.ArrayList; 020 import java.util.Iterator; 021 import java.util.List; 022 023 import org.apache.ojb.broker.query.Criteria; 024 import org.apache.ojb.broker.query.QueryByCriteria; 025 import org.kuali.rice.kew.edl.bo.EDocLiteAssociation; 026 import org.kuali.rice.kew.edl.bo.EDocLiteDefinition; 027 import org.kuali.rice.kew.edl.bo.EDocLiteStyle; 028 import org.kuali.rice.kew.edl.dao.EDocLiteDAO; 029 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; 030 031 032 public class EDocLiteDAOOjbImpl extends PersistenceBrokerDaoSupport implements EDocLiteDAO { 033 034 public void saveEDocLiteStyle(EDocLiteStyle styleData) { 035 this.getPersistenceBrokerTemplate().store(styleData); 036 } 037 038 public void saveEDocLiteDefinition(EDocLiteDefinition edocLiteData) { 039 this.getPersistenceBrokerTemplate().store(edocLiteData); 040 } 041 042 public void saveEDocLiteAssociation(EDocLiteAssociation assoc) { 043 this.getPersistenceBrokerTemplate().store(assoc); 044 } 045 046 public EDocLiteStyle getEDocLiteStyle(String styleName) { 047 Criteria criteria = new Criteria(); 048 criteria.addEqualTo("name", styleName); 049 criteria.addEqualTo("activeInd", Boolean.TRUE); 050 return (EDocLiteStyle) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteStyle.class, criteria)); 051 } 052 053 public EDocLiteDefinition getEDocLiteDefinition(String defName) { 054 Criteria criteria = new Criteria(); 055 criteria.addEqualTo("name", defName); 056 criteria.addEqualTo("activeInd", Boolean.TRUE); 057 return (EDocLiteDefinition) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteDefinition.class, criteria)); 058 } 059 060 public EDocLiteAssociation getEDocLiteAssociation(String docTypeName) { 061 Criteria criteria = new Criteria(); 062 criteria.addEqualTo("edlName", docTypeName); 063 criteria.addEqualTo("activeInd", Boolean.TRUE); 064 return (EDocLiteAssociation) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteAssociation.class, criteria)); 065 } 066 067 /** 068 * Returns names of all active Styles 069 */ 070 public List<String> getEDocLiteStyleNames() { 071 List<EDocLiteStyle> styles = getEDocLiteStyles(); 072 List<String> styleNames = new ArrayList<String>(styles.size()); 073 for (EDocLiteStyle style: styles) { 074 styleNames.add(style.getName()); 075 } 076 return styleNames; 077 } 078 079 /** 080 * Returns all active Styles 081 */ 082 public List<EDocLiteStyle> getEDocLiteStyles() { 083 Criteria criteria = new Criteria(); 084 criteria.addEqualTo("activeInd", Boolean.TRUE); 085 Iterator it = this.getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(EDocLiteStyle.class, criteria)); 086 List<EDocLiteStyle> styles = new ArrayList<EDocLiteStyle>(); 087 while (it.hasNext()) { 088 styles.add((EDocLiteStyle) it.next()); 089 } 090 return styles; 091 } 092 093 public List getEDocLiteDefinitions() { 094 Criteria criteria = new Criteria(); 095 criteria.addEqualTo("activeInd", Boolean.TRUE); 096 Iterator it = this.getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(EDocLiteDefinition.class, criteria)); 097 List defs = new ArrayList(); 098 while (it.hasNext()) { 099 defs.add(((EDocLiteDefinition) it.next()).getName()); 100 } 101 return defs; 102 } 103 104 public List getEDocLiteAssociations() { 105 Criteria criteria = new Criteria(); 106 criteria.addEqualTo("activeInd", Boolean.TRUE); 107 Iterator it = this.getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(EDocLiteAssociation.class, criteria)); 108 List assocs = new ArrayList(); 109 while (it.hasNext()) { 110 assocs.add(it.next()); 111 } 112 return assocs; 113 } 114 115 public List search(EDocLiteAssociation edocLite) { 116 Criteria crit = new Criteria(); 117 if (edocLite.getActiveInd() != null) { 118 crit.addEqualTo("activeInd", edocLite.getActiveInd()); 119 } 120 if (edocLite.getDefinition() != null) { 121 crit.addLike("UPPER(definition)", "%"+edocLite.getDefinition().toUpperCase()+"%"); 122 } 123 if (edocLite.getEdlName() != null) { 124 crit.addLike("UPPER(edlName)", "%"+edocLite.getEdlName().toUpperCase()+"%"); 125 } 126 if (edocLite.getStyle() != null) { 127 crit.addLike("UPPER(style)", "%"+edocLite.getStyle().toUpperCase()+"%"); 128 } 129 return (List)this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(EDocLiteAssociation.class, crit)); 130 } 131 132 public EDocLiteAssociation getEDocLiteAssociation(Long associationId) { 133 Criteria crit = new Criteria(); 134 crit.addEqualTo("edocLiteAssocId", associationId); 135 return (EDocLiteAssociation)this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteAssociation.class, crit)); 136 } 137 }