Coverage Report - org.kuali.student.core.messages.service.impl.MessageServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageServiceImpl
77%
38/49
50%
13/26
2.7
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.core.messages.service.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.jws.WebService;
 21  
 import javax.jws.soap.SOAPBinding;
 22  
 
 23  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 24  
 import org.kuali.student.common.messages.dto.LocaleKeyList;
 25  
 import org.kuali.student.common.messages.dto.Message;
 26  
 import org.kuali.student.common.messages.dto.MessageGroupKeyList;
 27  
 import org.kuali.student.common.messages.dto.MessageList;
 28  
 import org.kuali.student.common.messages.service.MessageService;
 29  
 import org.kuali.student.core.messages.dao.MessageManagementDAO;
 30  
 import org.kuali.student.core.messages.entity.MessageEntity;
 31  
 import org.slf4j.Logger;
 32  
 import org.slf4j.LoggerFactory;
 33  
 import org.springframework.transaction.annotation.Transactional;
 34  
 
 35  
 @WebService(endpointInterface = "org.kuali.student.common.messages.service.MessageService", serviceName = "MessageService", portName = "MessageService", targetNamespace = "http://student.kuali.org/wsdl/messages")
 36  
 @Transactional(readOnly=true,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 37  
 @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
 38  
 public class MessageServiceImpl implements MessageService{
 39  
     
 40  1
         final static Logger logger = LoggerFactory.getLogger(MessageServiceImpl.class);
 41  
         
 42  
         private MessageManagementDAO messageDAO;
 43  
         
 44  2
         public MessageServiceImpl() {
 45  2
         }
 46  
         
 47  
     public MessageManagementDAO getMessageDAO() {
 48  0
         return messageDAO;
 49  
     }
 50  
 
 51  
     public void setMessageDAO(MessageManagementDAO messageDAO) {
 52  1
         this.messageDAO = messageDAO;
 53  1
     }
 54  
 
 55  
         public LocaleKeyList getLocales() {
 56  
         
 57  1
                 List<String> locales = this.messageDAO.getLocales();
 58  
                 
 59  1
                 LocaleKeyList keyList = new LocaleKeyList();
 60  1
                 keyList.setLocales(locales);
 61  
   
 62  1
                 return keyList;
 63  
         }
 64  
         
 65  
         public MessageGroupKeyList getMessageGroups() {
 66  1
                 List<String> groups = this.messageDAO.getMessageGroups();
 67  
                 
 68  1
                 MessageGroupKeyList keyList = new MessageGroupKeyList();
 69  1
                 keyList.setMessageGroupKeys(groups);
 70  
 
 71  1
                 return keyList;
 72  
         }
 73  
 
 74  
         public Message getMessage(String localeKey, String messageGroupKey, String messageKey) {
 75  4
                 Message message = null;
 76  4
                 if(localeKey == null || messageGroupKey == null || messageKey == null){
 77  0
                         return null;
 78  
                 }
 79  
                 else{
 80  4
                         MessageEntity messageEntity = this.messageDAO.getMessage(localeKey, messageGroupKey, messageKey);
 81  4
                         if(messageEntity != null){
 82  3
                                 message = new Message();
 83  3
                                 MessageAssembler.toMessage(messageEntity,message); 
 84  
                         }
 85  
                 }
 86  4
                 return message;
 87  
         }
 88  
 
 89  
         public MessageList getMessages(String localeKey, String messageGroupKey) {
 90  3
                 if(localeKey == null || messageGroupKey == null){
 91  0
                         return new MessageList();
 92  
                 }
 93  
                 else{
 94  3
                         List<MessageEntity> messages =  this.messageDAO.getMessages(localeKey, messageGroupKey);
 95  
                 
 96  3
                 MessageList messageList = new MessageList();
 97  3
                 List<Message> messageDTOs =  MessageAssembler.toMessageList(messages,Message.class);
 98  3
                 messageList.setMessages(messageDTOs);
 99  3
                         return messageList;
 100  
                 }
 101  
         }
 102  
 
 103  
         public MessageList getMessagesByGroups(String localeKey, MessageGroupKeyList messageGroupKeyList) {
 104  2
                 if(localeKey == null || messageGroupKeyList == null){
 105  0
                         return new MessageList();
 106  
                 }
 107  
                 else{
 108  2
                         List<MessageEntity> messages =  this.messageDAO.getMessagesByGroups(localeKey, messageGroupKeyList.getMessageGroupKeys());
 109  2
                     MessageList messageList = new MessageList();
 110  2
                     List<Message> messageDTOs =  MessageAssembler.toMessageList(messages,Message.class);
 111  2
                     messageList.setMessages(messageDTOs);
 112  2
                         return messageList;
 113  
                 }
 114  
         }
 115  
 
 116  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 117  
         public Message updateMessage(String localeKey, String messageGroupKey, String messageKey, Message messageInfo) {
 118  
                 
 119  1
                 if(localeKey == null || messageGroupKey == null || messageKey == null || messageInfo == null){
 120  0
                         return null;
 121  
                 }
 122  
                 else{
 123  1
                     MessageEntity messageEntity = new MessageEntity();    
 124  1
                     MessageAssembler.toMessageEntity( messageInfo, messageEntity);
 125  1
                     messageEntity =  messageDAO.updateMessage(localeKey, messageGroupKey, messageKey, messageEntity);
 126  1
                     MessageAssembler.toMessage( messageEntity,messageInfo);
 127  1
                     return messageInfo;
 128  
                 }        
 129  
         }
 130  
 
 131  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 132  
         public Message addMessage(Message messageInfo) {
 133  0
                 if(messageInfo != null)        {
 134  0
                         MessageEntity messageEntity = new MessageEntity();    
 135  0
                         MessageAssembler.toMessageEntity(messageInfo, messageEntity);
 136  0
                         messageEntity =  messageDAO.addMessage(messageEntity);
 137  0
                         MessageAssembler.toMessage(messageEntity, messageInfo);
 138  
                 }
 139  0
                 return messageInfo;
 140  
         }
 141  
     
 142  
 }