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