1
2
3
4
5
6
7
8
9
10
11
12
13 package org.kuali.student.r2.common.class1.search;
14
15 import org.kuali.student.r2.common.dto.ContextInfo;
16 import org.kuali.student.r2.common.exceptions.MissingParameterException;
17 import org.kuali.student.r2.common.exceptions.OperationFailedException;
18 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
19 import org.kuali.student.r2.common.util.RichTextHelper;
20 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
21 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
22 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
23 import org.kuali.student.r2.core.search.util.SearchRequestHelper;
24 import org.kuali.student.r2.core.search.util.SearchResultCreatorHelper;
25
26 import javax.persistence.Query;
27 import java.text.DateFormat;
28 import java.text.ParseException;
29 import java.text.SimpleDateFormat;
30
31
32
33
34
35
36 public class ApptWindowCountsSearchImpl
37 extends SearchServiceAbstractHardwiredImpl {
38
39 public static final String CREATE_TIME = "createTime";
40 public static final String FIRST_SLOT = "firstSlot";
41 public static final String LAST_SLOT = "lastSlot";
42 public static final String NUM_APPTS = "numAppts";
43 public static final String NUM_SLOTS = "numSlots";
44
45
46
47
48 public static final TypeInfo SEARCH_TYPE;
49
50 static {
51 TypeInfo info = new TypeInfo();
52 info.setKey("kuali.search.type.appt.appointmentCountsForWindowId");
53 info.setName("Appointment Counts for Window Id");
54 info.setDescr(new RichTextHelper().fromPlain("Gets summary counts fo slots and appointmetns for an appointment window"));
55 DateFormat mmddyyyy = new SimpleDateFormat("MM/dd/yyyy");
56 try {
57 info.setEffectiveDate(mmddyyyy.parse("01/01/2012"));
58 } catch (ParseException ex) {
59 throw new RuntimeException("bad code");
60 }
61 SEARCH_TYPE = info;
62 }
63
64
65
66 public static final TypeInfo APPT_WINDOW_ID;
67
68 static {
69 TypeInfo info = new TypeInfo();
70 info.setKey("windowId");
71 info.setName("Appointment Window Id");
72 info.setDescr(new RichTextHelper().fromPlain("The appointment window id for which you want to get the counts"));
73 DateFormat mmddyyyy = new SimpleDateFormat("MM/dd/yyyy");
74 try {
75 info.setEffectiveDate(mmddyyyy.parse("01/01/2012"));
76 } catch (ParseException ex) {
77 throw new RuntimeException("bad code");
78 }
79 APPT_WINDOW_ID = info;
80 }
81
82
83
84 public static final TypeInfo[] SEARCH_PARAMETERS = {APPT_WINDOW_ID};
85
86 @Override
87 public TypeInfo getSearchType() {
88 return SEARCH_TYPE;
89 }
90
91 @Override
92 public SearchResultInfo search(SearchRequestInfo searchRequestInfo, ContextInfo contextInfo)
93 throws MissingParameterException,
94 OperationFailedException,
95 PermissionDeniedException {
96 if (!searchRequestInfo.getSearchKey().equals(SEARCH_TYPE.getKey())) {
97 throw new OperationFailedException("Unsupported search type: " + searchRequestInfo.getSearchKey());
98 }
99 SearchRequestHelper requestHelper = new SearchRequestHelper(searchRequestInfo);
100
101
102 String windowId = requestHelper.getParamAsString(APPT_WINDOW_ID.getKey());
103 SearchResultCreatorHelper creatorHelper = new SearchResultCreatorHelper();
104 creatorHelper.getHeaders().add(CREATE_TIME);
105 creatorHelper.getHeaders().add(FIRST_SLOT);
106 creatorHelper.getHeaders().add(LAST_SLOT);
107 creatorHelper.getHeaders().add(NUM_APPTS);
108 creatorHelper.getHeaders().add(NUM_SLOTS);
109 Query query = this.getGenericEntityDao().getEm().createNamedQuery("AppointmentWindowEntity.appointmentWindowCounts");
110 query.setParameter("windowId", windowId);
111 creatorHelper.processQuery(query);
112 return creatorHelper.getSearchResult();
113 }
114 }