001    /**
002     * Copyright 2005-2015 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.kcb.service.impl;
017    
018    import java.util.Collection;
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.kuali.rice.kcb.bo.Message;
023    import org.kuali.rice.kcb.service.MessageService;
024    
025    /**
026     * MessageService implementation 
027     * 
028     * @author Kuali Rice Team (rice.collab@kuali.org)
029     *
030     */
031    public class MessageServiceImpl extends BusinessObjectServiceImpl implements MessageService {
032        /**
033         * @see org.kuali.rice.kcb.service.MessageService#deleteMessage(org.kuali.rice.kcb.bo.Message)
034         */
035        public void deleteMessage(Message message) {
036            dao.delete(message);
037        }
038    
039        /**
040         * @see org.kuali.rice.kcb.service.MessageService#getMessage(java.lang.Long)
041         */
042        public Message getMessage(Long id) {
043            Map<String, Object> fields = new HashMap<String, Object>(1);
044            fields.put(Message.ID_FIELD, id);
045            Message m = (Message) dao.findByPrimaryKey(Message.class, fields);
046            return m;
047        }
048    
049        /**
050         * @see org.kuali.rice.kcb.service.MessageService#getAllMessages()
051         */
052        public Collection<Message> getAllMessages() {
053            return dao.findAll(Message.class);
054        }
055    
056        /**
057         * @see org.kuali.rice.kcb.service.MessageService#saveMessage(org.kuali.rice.kcb.bo.Message)
058         */
059        public void saveMessage(Message message) {
060            dao.save(message);
061        }
062    
063        /**
064         * @see org.kuali.rice.kcb.service.MessageService#getMessageByOriginId(java.lang.String)
065         */
066        public Message getMessageByOriginId(String originId) {
067            Map<String, Object> fields = new HashMap<String, Object>(1);
068            fields.put(Message.ORIGINID_FIELD, originId);
069            Collection<Message> messages = dao.findMatching(Message.class, fields);
070            if (messages.size() == 0) {
071                return null;
072            }
073            return messages.iterator().next();
074        }
075    }