Coverage Report - org.kuali.rice.ken.service.impl.NotificationContentTypeServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
NotificationContentTypeServiceImpl
0%
0/45
0%
0/12
2.143
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.ken.service.impl;
 17  
 
 18  
 import java.util.Collection;
 19  
 import java.util.HashMap;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.apache.ojb.broker.query.Criteria;
 23  
 import org.apache.ojb.broker.query.QueryByCriteria;
 24  
 import org.apache.ojb.broker.query.QueryFactory;
 25  
 import org.kuali.rice.core.dao.GenericDao;
 26  
 import org.kuali.rice.ken.bo.Notification;
 27  
 import org.kuali.rice.ken.bo.NotificationContentType;
 28  
 import org.kuali.rice.ken.service.NotificationContentTypeService;
 29  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 30  
 
 31  
 
 32  
 /**
 33  
  * NotificationContentTypeService implementation - uses the businessObjectDao to get at the underlying data in the stock DBMS.
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  */
 36  
 public class NotificationContentTypeServiceImpl implements NotificationContentTypeService {
 37  
     private GenericDao businessObjectDao;
 38  
 
 39  
     /**
 40  
      * Constructs a NotificationContentTypeServiceImpl.java.
 41  
      * @param businessObjectDao
 42  
      */
 43  0
     public NotificationContentTypeServiceImpl(GenericDao businessObjectDao) {
 44  0
         this.businessObjectDao = businessObjectDao;
 45  0
     }
 46  
 
 47  
     /**
 48  
      * @see org.kuali.rice.ken.service.NotificationContentTypeService#getNotificationContentType(java.lang.String)
 49  
      */
 50  
     public NotificationContentType getNotificationContentType(String name) {
 51  0
         Criteria c = new Criteria();
 52  0
         c.addEqualTo("name", name);
 53  0
         c.addEqualTo("current", true);
 54  0
         Collection<NotificationContentType> coll = businessObjectDao.findMatching(NotificationContentType.class, c);
 55  0
         if (coll.size() == 0) {
 56  0
             return null;
 57  
         } else {
 58  0
             return coll.iterator().next();
 59  
         }
 60  
     }
 61  
 
 62  
     protected int findHighestContentTypeVersion(String name) {
 63  
         // there's probably a better way...'report'? or direct SQL
 64  0
         Map<String, Object> fields = new HashMap<String, Object>(2);
 65  0
         fields.put("name", name);
 66  0
         Collection<NotificationContentType> types = businessObjectDao.findMatchingOrderBy(NotificationContentType.class, fields, "version", false);
 67  0
         if (types.size() > 0) {
 68  0
             return types.iterator().next().getVersion();
 69  
         }
 70  0
         return -1;
 71  
     }
 72  
 
 73  
     /**
 74  
      * @see org.kuali.rice.ken.service.NotificationContentTypeService#saveNotificationContentType(org.kuali.rice.ken.bo.NotificationContentType)
 75  
      */
 76  
     public void saveNotificationContentType(NotificationContentType contentType) {
 77  0
         NotificationContentType previous = getNotificationContentType(contentType.getName());
 78  0
         if (previous != null) {
 79  0
             previous.setCurrent(false);
 80  0
             businessObjectDao.save(previous);
 81  
         }
 82  0
         int lastVersion = findHighestContentTypeVersion(contentType.getName());
 83  
         NotificationContentType next;
 84  0
         if (contentType.getId() == null) {
 85  0
             next = contentType; 
 86  
         } else {
 87  0
             next = new NotificationContentType();
 88  0
             next.setName(contentType.getName());
 89  0
             next.setDescription(contentType.getDescription());
 90  0
             next.setNamespace(contentType.getNamespace());
 91  0
             next.setXsd(contentType.getXsd());
 92  0
             next.setXsl(contentType.getXsl());
 93  
         }
 94  
 
 95  0
         next.setVersion(lastVersion + 1);
 96  0
         next.setCurrent(true);
 97  0
         businessObjectDao.save(next);
 98  
         
 99  
         // update all the old references
 100  0
         if (previous != null) {
 101  0
             Collection<Notification> ns = getNotificationsOfContentType(previous);
 102  0
             for (Notification n: ns) {
 103  0
                 n.setContentType(next);
 104  0
                 businessObjectDao.save(n);
 105  
             }
 106  
         }
 107  0
     }
 108  
 
 109  
     protected Collection<Notification> getNotificationsOfContentType(NotificationContentType ct) {
 110  0
         Map<String, Object> fields = new HashMap<String, Object>(1);
 111  0
         fields.put("contentType", ct.getId());
 112  0
         return businessObjectDao.findMatching(Notification.class, fields);
 113  
     }
 114  
     /**
 115  
      * @see org.kuali.rice.ken.service.NotificationContentTypeService#getAllCurrentContentTypes()
 116  
      */
 117  
     public Collection<NotificationContentType> getAllCurrentContentTypes() {
 118  0
         Criteria c = new Criteria();
 119  0
         c.addEqualTo("current", true);
 120  0
         return businessObjectDao.findMatching(NotificationContentType.class, c);
 121  
     }
 122  
     
 123  
     /**
 124  
      * @see org.kuali.rice.ken.service.NotificationContentTypeService#getAllContentTypes()
 125  
      */
 126  
     public Collection<NotificationContentType> getAllContentTypes() {
 127  0
         return businessObjectDao.findAll(NotificationContentType.class);
 128  
     }
 129  
 }