11
11
12
12
import java .awt .event .ActionListener ;
13
13
import java .beans .PropertyVetoException ;
14
+ import java .time .LocalDate ;
15
+ import java .time .temporal .ChronoField ;
14
16
import java .util .ArrayList ;
15
17
import java .util .Calendar ;
16
18
import java .util .List ;
21
23
*/
22
24
@ Service ("ParcelTrackingService" )
23
25
public class ParcelTrackingServiceImpl implements ParcelTrackingService {
26
+ /**
27
+ * Get an instance of the StudyFee proxy
28
+ *
29
+ * @return
30
+ * @throws PropertyVetoException
31
+ */
32
+ private Smsij01sMntGenDespatchInfo getProxyInstance () throws PropertyVetoException {
33
+ Smsij01sMntGenDespatchInfo despatchProxy = new Smsij01sMntGenDespatchInfo ();
34
+ despatchProxy .clear ();
35
+ despatchProxy .setInCsfClientServerCommunicationsClientVersionNumber ((short ) 3 );
36
+ despatchProxy .setInCsfClientServerCommunicationsClientRevisionNumber ((short ) 1 );
37
+ despatchProxy .setInCsfClientServerCommunicationsAction ("D" );
38
+ despatchProxy .setInCsfClientServerCommunicationsClientDevelopmentPhase ("C" );
39
+ despatchProxy .setInSecurityWsPrinterCode ("MYUNISA" );
40
+ return despatchProxy ;
41
+ }
24
42
25
43
@ Override
26
44
public ParcelTrackingInfo trackAndTraceParcel (Integer studentNumber ) throws OperationFailedException {
27
45
try {
28
- //ParcelTrackingInfo parcelTrackingInfo = new ParcelTrackingInfo();
29
- // ParcelTrackingDisplayForm parcelTrackingDisplayForm = (ParcelTrackingDisplayForm) form;
30
- // ActionMessages messages = new ActionMessages();
31
- //
32
- // messages = (ActionMessages) parcelTrackingDisplayForm.validate(mapping, request);
33
- //
34
- // eventTrackingService = (EventTrackingService) ComponentManager.get(EventTrackingService.class);
35
- // toolManager = (ToolManager) ComponentManager.get(ToolManager.class);
36
-
37
- int tmpStudentNr = 0 ;
38
-
39
- // if (!messages.isEmpty()) {
40
- // addErrors(request, messages);
41
- // return mapping.findForward("TrackandTraceInput");
42
- // }
43
- tmpStudentNr = studentNumber ;
44
- /** Current Year */
45
-
46
- short currentYear ;
47
-
48
- if (Calendar .getInstance ().get (Calendar .MONTH ) < 11 ) {
49
- currentYear = new Integer (Calendar .getInstance ().get (Calendar .YEAR )).shortValue ();
50
-
51
- //System.out.println( "year "+currentYear);
52
- } else {
53
- currentYear = new Integer (Calendar .getInstance ().get (Calendar .YEAR )).shortValue ();
54
- //System.out.println(currentYear);
55
- }
46
+ Integer currentYear = Calendar .getInstance ().get (Calendar .YEAR );
47
+ //LocalDate.now().get(ChronoField.YEAR);
56
48
57
- Smsij01sMntGenDespatchInfo despatchProxy = new Smsij01sMntGenDespatchInfo ();
49
+ Smsij01sMntGenDespatchInfo despatchProxy = getProxyInstance ();
58
50
final AtomicReference <OperationFailedException > exceptionReference = new AtomicReference <>();
59
51
final ActionListener exceptionListener = e -> exceptionReference .set (new OperationFailedException (e .getActionCommand ()));
60
- //operListener opl = new operListener();
61
52
despatchProxy .addExceptionListener (exceptionListener );
62
- despatchProxy .clear ();
53
+ //Populate fields
54
+ despatchProxy .setInStudentAnnualRecordMkStudentNr (studentNumber );
55
+ despatchProxy .setInStudentAnnualRecordMkAcademicYear (currentYear .shortValue ());
63
56
64
- despatchProxy .setInCsfClientServerCommunicationsClientVersionNumber ((short ) 3 );
65
- despatchProxy .setInCsfClientServerCommunicationsClientRevisionNumber ((short ) 1 );
66
- despatchProxy .setInCsfClientServerCommunicationsAction ("D" );
67
- despatchProxy .setInCsfClientServerCommunicationsClientDevelopmentPhase ("C" );
68
- despatchProxy .setInStudentAnnualRecordMkStudentNr (tmpStudentNr );
69
- despatchProxy .setInStudentAnnualRecordMkAcademicYear (currentYear );
70
- despatchProxy .setInSecurityWsPrinterCode ("MYUNISA" );
71
-
72
- //System.out.println(tmpStudentNr);
73
57
despatchProxy .execute ();
74
58
if (exceptionReference .get () != null ) {
75
59
throw exceptionReference .get ();
76
60
}
77
61
return buildResponse (despatchProxy , currentYear );
78
62
} catch (PropertyVetoException ex ) {
79
63
throw new OperationFailedException (ex );
80
- //ActionMessages messages = new ActionMessages();
81
- //messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
82
- // "errors.exceptionhappened", "An unepxected Error has happened, please close this tool and log on again"));
83
- //return mapping.findForward("displayforward");
84
64
}
85
65
}
86
66
87
- private ParcelTrackingInfo buildResponse (Smsij01sMntGenDespatchInfo despatchProxy , short currentYear ) throws OperationFailedException {
67
+ private ParcelTrackingInfo buildResponse (Smsij01sMntGenDespatchInfo despatchProxy , Integer currentYear ) throws OperationFailedException {
88
68
ParcelTrackingInfo parcelTrackingInfo = new ParcelTrackingInfo ();
89
69
String errorMessage = despatchProxy .getOutCsfStringsString500 ();
90
70
if (StringUtils .hasText (errorMessage )) {
91
71
throw new OperationFailedException (errorMessage );
92
- // messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
93
- // "error.coolgenerror", Errormsg));
94
- // addErrors(request, messages);
95
- // return mapping.findForward("TrackandTraceInput");
96
72
}
97
73
StudentInfo student = new StudentInfo ();
98
74
student .setStudentNumber (String .valueOf (despatchProxy .getOutStudentAnnualRecordMkStudentNr ()));
99
75
student .setStudentName ((String .valueOf (despatchProxy .getOutWsStudentMkTitle ()) + " " + String .valueOf (despatchProxy .getOutWsStudentFirstNames () + " " + String .valueOf (despatchProxy .getOutWsStudentSurname ()))));
100
76
parcelTrackingInfo .setStudentInfo (student );
101
77
102
- int count = despatchProxy .getOutLuGroupCount ();//count gives total no. of records belongs to that student
103
78
List records = new ArrayList <>();
104
79
105
-
106
- for (int i = 0 ; i < count ; i ++) {
107
-
80
+ for (int i = 0 ; i < despatchProxy .getOutLuGroupCount (); i ++) {
108
81
109
82
if (!("" .equals (despatchProxy .getOutGWsTrackAndTraceNumber (i )))) {
110
83
//DateFormat strDate = new SimpleDateFormat("dd-MM-yyyy");
@@ -132,10 +105,8 @@ private ParcelTrackingInfo buildResponse(Smsij01sMntGenDespatchInfo despatchProx
132
105
tempday = Integer .toString (day );
133
106
}
134
107
135
-
136
108
int year = tmpDate .get (Calendar .YEAR );
137
- if (currentYear == (new Integer (year ).shortValue ()) ||
138
- ((currentYear - 1 ) == (new Integer (year ).shortValue ()) && month > 10 )) {
109
+ if (currentYear == year || ((currentYear - 1 ) == year && month > 10 )) {
139
110
//set date in array list
140
111
TrackAndTraceRecordInfo trackAndTraceRecord = new TrackAndTraceRecordInfo ();
141
112
if (despatchProxy .getOutGWsTrackAndTraceNumber (i ).substring (0 , 1 ).equals ("C" ) ||
@@ -160,13 +131,11 @@ private ParcelTrackingInfo buildResponse(Smsij01sMntGenDespatchInfo despatchProx
160
131
}
161
132
}
162
133
parcelTrackingInfo .setTraceRecordInfoList (records );
163
- parcelTrackingInfo .setStudentuser (false );
164
- //request.setAttribute("records", records);
165
- //parcelTrackingDisplayForm1.setTrackRecords(records);
134
+ parcelTrackingInfo .setStudentuser (true );
135
+
136
+ //TODO Unisa tool logs some event.
166
137
//eventTrackingService.post(
167
138
// eventTrackingService.newEvent(EventTrackingTypes.EVENT_TRACKANDTRACE_VIEW, toolManager.getCurrentPlacement().getContext(), false));
168
-
169
- //return mapping.findForward("displayforward");
170
139
return parcelTrackingInfo ;
171
140
}
172
141
@@ -178,4 +147,4 @@ private boolean isInteger(String i) {
178
147
return false ;
179
148
}
180
149
}
181
- }
150
+ }
0 commit comments