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;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.student.enrollment.registration.client.service.StaticUserDateClientService;
21 import org.kuali.student.enrollment.registration.client.service.impl.util.StaticUserDateUtil;
22 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import javax.ws.rs.core.Response;
27 import javax.ws.rs.core.Response.ResponseBuilder;
28 import java.util.Map;
29
30
31
32
33
34
35
36
37
38 public class StaticUserDateClientServiceImpl implements StaticUserDateClientService {
39
40 public static final Logger LOGGER = LoggerFactory.getLogger(ScheduleOfClassesClientServiceImpl.class);
41
42 @Override
43 public Response setStaticDate(String userId, String date) {
44 ResponseBuilder response;
45
46 try {
47 StaticUserDateUtil.putDateInMap(userId, date);
48 response = Response.ok();
49 } catch (InvalidParameterException ex) {
50 LOGGER.warn("Unable to set static date for userId {} / date {} ... invalid parameters.", userId, date, ex);
51 response = Response.status(Response.Status.BAD_REQUEST);
52 } catch (Exception ex) {
53 LOGGER.warn("Unable to set static date to {} for userId {}: {}", date, userId, ex.getMessage(), ex);
54 response = Response.serverError();
55 }
56
57 return response.build();
58 }
59
60 @Override
61 public Response getStaticDate(String userId) {
62 return getStaticDate(userId, null);
63 }
64
65 @Override
66 public Response getStaticDate(String userId, String date) {
67 ResponseBuilder builder = null;
68 Response response = null;
69
70
71
72
73
74 if (StringUtils.isNotEmpty(date)) {
75 Response updateResponse = setStaticDate(userId, date);
76 if (updateResponse.getStatus() != Response.Status.OK.getStatusCode()) {
77 response = updateResponse;
78 }
79 }
80
81 if (response == null) {
82 try {
83 builder = Response.ok(StaticUserDateUtil.getDateFromMap(userId));
84 } catch (InvalidParameterException ex) {
85 LOGGER.warn("Unable to get static date for userId {} ... invalid parameters.", userId, ex);
86 builder = Response.status(Response.Status.BAD_REQUEST);
87 } catch (Exception ex) {
88 LOGGER.warn("Unable to get static date for userId {}: {}", userId, ex.getMessage(), ex);
89 builder = Response.serverError();
90 } finally {
91 if (builder == null) {
92 builder = Response.serverError();
93 }
94 response = builder.build();
95 }
96 }
97
98 return response;
99 }
100
101 @Override
102 public Response clearStaticDate(String userId) {
103 ResponseBuilder response;
104
105 try {
106 StaticUserDateUtil.removeDateFromMap(userId);
107 response = Response.ok();
108 } catch (InvalidParameterException ex) {
109 LOGGER.warn("Unable to remove static date for userId {} ... invalid parameters.", userId, ex);
110 response = Response.status(Response.Status.BAD_REQUEST);
111 } catch (Exception ex) {
112 LOGGER.warn("Unable to remove static date from map for userId {}: {}", userId, ex.getMessage(), ex);
113 response = Response.serverError();
114 }
115
116 return response.build();
117 }
118
119 @Override
120 public Response getStaticDates() {
121 ResponseBuilder response;
122
123 try {
124 response = Response.ok(StaticUserDateUtil.getDatesFromMap());
125 } catch (Exception ex) {
126 LOGGER.warn("Unable to get static date map: {}", ex.getMessage(), ex);
127 response = Response.serverError();
128 }
129 return response.build();
130 }
131
132 public void setRegUserMap(Map<String, String> regUserMap) {
133 StaticUserDateUtil.loadMap(regUserMap);
134 }
135 }