001    /**
002     * Copyright 2005-2014 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.List;
020    
021    import org.kuali.rice.core.api.criteria.QueryByCriteria;
022    import org.kuali.rice.kcb.bo.Message;
023    import org.kuali.rice.kcb.service.MessageService;
024    import org.kuali.rice.krad.data.DataObjectService;
025    import org.kuali.rice.krad.data.PersistenceOption;
026    
027    import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
028    
029    /**
030     * MessageService implementation 
031     * 
032     * @author Kuali Rice Team (rice.collab@kuali.org)
033     *
034     */
035    public class MessageServiceImpl implements MessageService {
036    
037        private DataObjectService dataObjectService;
038        /**
039         * @see org.kuali.rice.kcb.service.MessageService#deleteMessage(org.kuali.rice.kcb.bo.Message)
040         */
041        public void deleteMessage(Message message) {
042            dataObjectService.delete(message);
043        }
044    
045        /**
046         * @see org.kuali.rice.kcb.service.MessageService#getMessage(java.lang.Long)
047         */
048        public Message getMessage(Long id) {
049            return dataObjectService.find(Message.class, id);
050        }
051    
052        /**
053         * @see org.kuali.rice.kcb.service.MessageService#getAllMessages()
054         */
055        public Collection<Message> getAllMessages() {
056            return dataObjectService.findMatching(Message.class, QueryByCriteria.Builder.create().build()).getResults();
057        }
058    
059        /**
060         * @see org.kuali.rice.kcb.service.MessageService#saveMessage(org.kuali.rice.kcb.bo.Message)
061         */
062        public Message saveMessage(Message message) {
063            return dataObjectService.save(message);
064        }
065    
066        /**
067         * @see org.kuali.rice.kcb.service.MessageService#getMessageByOriginId(java.lang.String)
068         */
069        public Message getMessageByOriginId(String originId) {
070            QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
071            criteria.setPredicates(equal(Message.ORIGINID_FIELD, originId));
072            List<Message> messages = dataObjectService.findMatching(Message.class, criteria.build()).getResults();
073    
074            if (messages.isEmpty()) {
075                return null;
076            }
077    
078            return messages.get(0);
079        }
080    
081        /**
082         * Sets the data object service.
083         * @param dataObjectService persits data to the datasource.
084         */
085        public void setDataObjectService(DataObjectService dataObjectService) {
086            this.dataObjectService = dataObjectService;
087        }
088    }