1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.registration.client.service.impl.util;
18
19 import org.codehaus.jackson.map.ObjectMapper;
20 import org.codehaus.jackson.type.TypeReference;
21 import org.kuali.student.enrollment.registration.client.service.dto.ConflictCourseResult;
22 import org.kuali.student.enrollment.registration.client.service.dto.RegistrationValidationConflictCourseResult;
23 import org.kuali.student.enrollment.registration.client.service.dto.RegistrationValidationMaxCreditResult;
24 import org.kuali.student.enrollment.registration.client.service.dto.RegistrationValidationResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import java.io.IOException;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36
37
38 public class RegistrationValidationResultsUtil {
39 public static final Logger LOGGER = LoggerFactory.getLogger(RegistrationValidationResultsUtil.class);
40
41 private RegistrationValidationResultsUtil() {
42 }
43
44 public static String marshallSimpleMessage(String messageKey) {
45 return marshallResult(new RegistrationValidationResult(messageKey));
46 }
47
48 public static String marshallConflictCourseMessage(String messageKey, List<ConflictCourseResult> conflictingCourses) {
49 return marshallResult(new RegistrationValidationConflictCourseResult(messageKey, conflictingCourses));
50 }
51
52 public static String marshallMaxCreditMessage(String messageKey, String maxCredits) {
53 return marshallResult(new RegistrationValidationMaxCreditResult(messageKey, maxCredits));
54 }
55
56 public static String marshallResult(RegistrationValidationResult result) {
57 ObjectMapper mapper = new ObjectMapper();
58 String json = null;
59 try {
60 json = mapper.writeValueAsString(result);
61 } catch (IOException ex) {
62 LOGGER.error("Unable to marshall result object", ex);
63 }
64 return json;
65 }
66
67 public static Map<String, Object> unmarshallResult(String result) {
68 ObjectMapper mapper = new ObjectMapper();
69 try {
70 TypeReference<HashMap<String, Object>> typeRef
71 = new TypeReference<HashMap<String, Object>>() {
72 };
73
74 return mapper.readValue(result, typeRef);
75 } catch (IOException e) {
76 LOGGER.error("Unable to marshall result object", e);
77 }
78 return null;
79 }
80
81 }