View Javadoc
1   /**
2    * Copyright 2005-2015 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.kcb.service.impl;
17  
18  import java.util.Collection;
19  import java.util.List;
20  
21  import org.kuali.rice.core.api.criteria.QueryByCriteria;
22  import org.kuali.rice.kcb.bo.Message;
23  import org.kuali.rice.kcb.service.MessageService;
24  import org.kuali.rice.krad.data.DataObjectService;
25  import org.kuali.rice.krad.data.PersistenceOption;
26  
27  import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
28  
29  /**
30   * MessageService implementation 
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   *
34   */
35  public class MessageServiceImpl implements MessageService {
36  
37      private DataObjectService dataObjectService;
38      /**
39       * @see org.kuali.rice.kcb.service.MessageService#deleteMessage(org.kuali.rice.kcb.bo.Message)
40       */
41      public void deleteMessage(Message message) {
42          dataObjectService.delete(message);
43      }
44  
45      /**
46       * @see org.kuali.rice.kcb.service.MessageService#getMessage(java.lang.Long)
47       */
48      public Message getMessage(Long id) {
49          return dataObjectService.find(Message.class, id);
50      }
51  
52      /**
53       * @see org.kuali.rice.kcb.service.MessageService#getAllMessages()
54       */
55      public Collection<Message> getAllMessages() {
56          return dataObjectService.findMatching(Message.class, QueryByCriteria.Builder.create().build()).getResults();
57      }
58  
59      /**
60       * @see org.kuali.rice.kcb.service.MessageService#saveMessage(org.kuali.rice.kcb.bo.Message)
61       */
62      public Message saveMessage(Message message) {
63          return dataObjectService.save(message);
64      }
65  
66      /**
67       * @see org.kuali.rice.kcb.service.MessageService#getMessageByOriginId(java.lang.String)
68       */
69      public Message getMessageByOriginId(String originId) {
70          QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
71          criteria.setPredicates(equal(Message.ORIGINID_FIELD, originId));
72          List<Message> messages = dataObjectService.findMatching(Message.class, criteria.build()).getResults();
73  
74          if (messages.isEmpty()) {
75              return null;
76          }
77  
78          return messages.get(0);
79      }
80  
81      /**
82       * Sets the data object service.
83       * @param dataObjectService persits data to the datasource.
84       */
85      public void setDataObjectService(DataObjectService dataObjectService) {
86          this.dataObjectService = dataObjectService;
87      }
88  }