Clover Coverage Report - KS Admin 1.1.0-M10-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
75   175   13   7.5
6   126   0.17   10
10     1.3  
1    
 
  MessageServiceImpl       Line # 25 75 0% 13 91 0% 0.0
 
No Tests
 
1    package org.kuali.student.admin.messages.service.impl;
2   
3    import java.util.ArrayList;
4    import java.util.Collection;
5    import java.util.HashMap;
6    import java.util.Iterator;
7    import java.util.List;
8    import java.util.Map;
9   
10    import javax.jws.WebService;
11    import javax.jws.soap.SOAPBinding;
12   
13    import org.kuali.rice.kns.service.BusinessObjectService;
14    import org.kuali.rice.kns.service.KNSServiceLocator;
15    import org.kuali.student.core.enumerationmanagement.bo.EnumeratedValue;
16    import org.kuali.student.core.messages.bo.MessageEntity;
17    import org.kuali.student.core.messages.dto.LocaleKeyList;
18    import org.kuali.student.core.messages.dto.Message;
19    import org.kuali.student.core.messages.dto.MessageGroupKeyList;
20    import org.kuali.student.core.messages.dto.MessageList;
21    import org.kuali.student.core.messages.service.MessageService;
22   
23    @WebService(endpointInterface = "org.kuali.student.core.messages.service.MessageService", serviceName = "MessageService", portName = "MessageService", targetNamespace = "http://student.kuali.org/wsdl/messages")
24    @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
 
25    public class MessageServiceImpl implements MessageService {
26   
27    private BusinessObjectService businessObjectService;
28   
 
29  0 toggle public Message addMessage(Message messageInfo) {
30  0 MessageEntity entity = toMessageEntity(messageInfo);
31  0 getBusinessObjectService().save(entity);
32   
33  0 return toMessage(entity);
34    }
35   
 
36  0 toggle @SuppressWarnings("unchecked")
37    public LocaleKeyList getLocales() {
38  0 List<String> keyList = new ArrayList<String>();
39  0 Map<String, Object> criteria = new HashMap<String,Object>();
40   
41  0 criteria.put(EnumeratedValue.ENUMERATION_KEY, MessageEntity.LOCALE_ENUMERATION);
42  0 BusinessObjectService boService = KNSServiceLocator.getBusinessObjectService();
43  0 Collection<EnumeratedValue> values = boService.findMatching(EnumeratedValue.class, criteria);
44   
45  0 Iterator<EnumeratedValue> iterator = values.iterator();
46  0 while(iterator.hasNext()) {
47  0 EnumeratedValue value = iterator.next();
48  0 keyList.add(value.getCode());
49    }
50   
51  0 LocaleKeyList localeKeyList = new LocaleKeyList();
52  0 localeKeyList.setLocales(keyList);
53   
54  0 return localeKeyList;
55    }
56   
 
57  0 toggle public Message getMessage(String localeKey, String messageGroupKey, String messageKey) {
58  0 Map<String, Object> queryMap = new HashMap<String, Object>();
59  0 queryMap.put("locale", localeKey);
60  0 queryMap.put("groupName", messageGroupKey);
61  0 queryMap.put("messageId", messageKey);
62   
63  0 MessageEntity entity = (MessageEntity) getBusinessObjectService().findByPrimaryKey(MessageEntity.class, queryMap);
64   
65  0 return toMessage(entity);
66    }
67   
 
68  0 toggle @SuppressWarnings("unchecked")
69    public MessageGroupKeyList getMessageGroups() {
70  0 List<String> keyList = new ArrayList<String>();
71  0 Map<String, Object> criteria = new HashMap<String,Object>();
72   
73  0 criteria.put(EnumeratedValue.ENUMERATION_KEY, MessageEntity.GROUP_NAME_ENUMERATION);
74  0 BusinessObjectService boService = KNSServiceLocator.getBusinessObjectService();
75  0 Collection<EnumeratedValue> values = boService.findMatching(EnumeratedValue.class, criteria);
76   
77  0 Iterator<EnumeratedValue> iterator = values.iterator();
78  0 while(iterator.hasNext()) {
79  0 EnumeratedValue value = iterator.next();
80  0 keyList.add(value.getCode());
81    }
82   
83  0 MessageGroupKeyList messageGroupKeyList = new MessageGroupKeyList();
84  0 messageGroupKeyList.setMessageGroupKeys(keyList);
85   
86  0 return messageGroupKeyList;
87    }
88   
 
89  0 toggle @SuppressWarnings("unchecked")
90    public MessageList getMessages(String localeKey, String messageGroupKey) {
91   
92  0 Map<String,String> fieldValues = new HashMap<String,String>();
93  0 fieldValues.put("locale", localeKey);
94  0 fieldValues.put("groupName", messageGroupKey);
95   
96  0 List<MessageEntity> messageEntityList = (List<MessageEntity>) getBusinessObjectService().findMatching(MessageEntity.class, fieldValues);
97   
98  0 List<Message> messages = new ArrayList<Message>();
99   
100  0 for(MessageEntity messageEntity: messageEntityList){
101  0 messages.add(toMessage(messageEntity));
102    }
103   
104  0 MessageList messageList = new MessageList();
105  0 messageList.setMessages(messages);
106   
107  0 return messageList;
108   
109    }
110   
 
111  0 toggle public MessageList getMessagesByGroups(String localeKey, MessageGroupKeyList messageGroupKeyList) {
112   
113  0 List<Message> messages = new ArrayList<Message>();
114   
115  0 for(String messageGroupKey: messageGroupKeyList.getMessageGroupKeys()){
116  0 messages.addAll(getMessages(localeKey, messageGroupKey).getMessages());
117    }
118   
119  0 MessageList messageList = new MessageList();
120  0 messageList.setMessages(messages);
121   
122  0 return messageList;
123   
124    }
125   
 
126  0 toggle public Message updateMessage(String localeKey, String messageGroupKey, String messageKey, Message messageInfo) {
127   
128  0 Map<String,String> primaryKeys = new HashMap<String,String>();
129  0 primaryKeys.put("locale", localeKey);
130  0 primaryKeys.put("groupName", messageGroupKey);
131  0 primaryKeys.put("messageId", messageKey);
132   
133  0 MessageEntity entity = (MessageEntity) getBusinessObjectService().findByPrimaryKey(MessageEntity.class, primaryKeys);
134   
135  0 entity.setMessageId(messageInfo.getId());
136  0 entity.setLocale(messageInfo.getLocale());
137  0 entity.setGroupName(messageInfo.getGroupName());
138  0 entity.setValue(messageInfo.getValue());
139   
140  0 getBusinessObjectService().save(entity);
141   
142  0 return toMessage(entity);
143   
144    }
145   
 
146  0 toggle protected MessageEntity toMessageEntity(Message message) {
147  0 MessageEntity result = new MessageEntity();
148   
149  0 result.setMessageId(message.getId());
150  0 result.setLocale(message.getLocale());
151  0 result.setGroupName(message.getGroupName());
152  0 result.setValue(message.getValue());
153   
154  0 return result;
155    }
156   
 
157  0 toggle protected Message toMessage(MessageEntity entity) {
158  0 Message result = new Message();
159   
160  0 result.setGroupName(entity.getGroupName());
161  0 result.setId(entity.getMessageId());
162  0 result.setLocale(entity.getLocale());
163  0 result.setValue(entity.getValue());
164   
165  0 return result;
166    }
167   
 
168  0 toggle protected BusinessObjectService getBusinessObjectService() {
169  0 if (businessObjectService == null) {
170  0 businessObjectService = KNSServiceLocator.getBusinessObjectService();
171    }
172  0 return businessObjectService;
173    }
174   
175    }