001/** 002 * Copyright 2005-2017 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 */ 016package org.kuali.rice.ken.service.impl; 017 018import org.kuali.rice.core.api.criteria.QueryByCriteria; 019import org.kuali.rice.ken.bo.NotificationChannelBo; 020import org.kuali.rice.ken.service.NotificationChannelService; 021import org.kuali.rice.krad.data.DataObjectService; 022 023import java.util.Collection; 024import java.util.List; 025 026import static org.kuali.rice.core.api.criteria.PredicateFactory.equal; 027import static org.kuali.rice.core.api.criteria.PredicateFactory.isNotNull; 028 029/** 030 * NotificationChannelService implementation - uses the businessObjectDao to get at data in the underlying database. 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033public class NotificationChannelServiceImpl implements NotificationChannelService { 034 private DataObjectService dataObjectService; 035 036 /** 037 * Constructs a NotificationChannelServiceImpl.java. 038 * @param dataObjectService service persists data to datasource. 039 */ 040 public NotificationChannelServiceImpl(DataObjectService dataObjectService) { 041 this.dataObjectService = dataObjectService; 042 } 043 044 /** 045 * @see org.kuali.rice.ken.service.NotificationChannelService#getNotificationChannel(java.lang.String) 046 */ 047 @Override 048 public NotificationChannelBo getNotificationChannel(String id) { 049 050 return dataObjectService.find(NotificationChannelBo.class, Long.valueOf(id)); 051 } 052 053 /** 054 * @see org.kuali.rice.ken.service.NotificationChannelService#getNotificationChannelByName(java.lang.String) 055 */ 056 @Override 057 public NotificationChannelBo getNotificationChannelByName(String name) { 058 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create(); 059 060 criteria.setPredicates(equal("name", name)); 061 List<NotificationChannelBo> found = dataObjectService.findMatching(NotificationChannelBo.class, criteria.build()).getResults(); 062 assert(found.size() <= 1); 063 064 return ((found.isEmpty() ? null : found.get(0))); 065 } 066 067 /** 068 * @see org.kuali.rice.ken.service.NotificationChannelService#getSubscribableChannels() 069 */ 070 @Override 071 public Collection getSubscribableChannels() { 072 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create(); 073 criteria.setPredicates(equal("subscribable", Boolean.TRUE)); 074 criteria.setOrderByAscending("name"); 075 076 return dataObjectService.findMatching(NotificationChannelBo.class, criteria.build()).getResults(); 077 } 078 079 /** 080 * @see org.kuali.rice.ken.service.NotificationChannelService#getAllNotificationChannels() 081 */ 082 @Override 083 public Collection getAllNotificationChannels() { 084 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create(); 085 criteria.setOrderByAscending("name"); 086 087 return dataObjectService.findMatching(NotificationChannelBo.class, criteria.build()).getResults(); 088 } 089}