-
Notifications
You must be signed in to change notification settings - Fork 0
/
wmsAPI.java
900 lines (774 loc) · 36.3 KB
/
wmsAPI.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
package Controllers.wms;
import Models.global.sessionModel;
import Models.wms.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.ArrayList;
/**
* Created by georgoud on 18/9/2014.
*/
@Path("wmsapi")
public class wmsAPI {
@Context
private UriInfo context;
wmsSQL sql;
wmsReporting wrep;
public wmsAPI() {
sql = new wmsSQL();
wrep = new wmsReporting();
}
/**
* Enters a new bin to the system
*
* @param bin
* @param response
* @return
* @throws SQLException
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("registerBin/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String RegisterBin(wmsBin bin, @PathParam("applicationID") String applicationID, @Context HttpServletResponse response, @Context HttpServletRequest req, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
int cnt;
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
cnt = sql.registerBin(bin, applicationID);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("registerBinSensor/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String registerBinSensor(wmsBinSensor bs, @PathParam("applicationID") String applicationID, @Context HttpServletResponse response , @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
int cnt;
String result = "";
String key = sql.findSession(userName, session);
if (key != null&& key.equals(session))
{
wmsBinSensor testSens;
if( !sql.getBinSensorByDeviceInfoParam("hwID", bs.hwID).isEmpty())
{
cnt=-1; //--bin exists already
}
else
{
cnt = sql.registerBinSensor(bs, applicationID);
}
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
/**
* -----------------update data for a bin such as moving to a new bin, etc.
*
* @param bin
* @param response
* @return
* @throws SQLException
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("updateBin")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String updateBin(wmsBin bin, @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String result = "";
String key = sql.findSession(userName, session);
if (key != null&& key.equals(session)) {
int cnt = sql.updateBin(bin);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("updateBinSensor")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String updateBinSensor(wmsBinSensor bs, @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName, session);
if (key != null&& key.equals(session))
{
int cnt = sql.updateBinSensor(bs);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@GET
@Path("deleteSensorBin/{binSensorID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String deleteSensorBin(@PathParam("binSensorID") String binSensorID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.deleteSensorBin(binSensorID);
result = Integer.toString(cnt);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("registerVehicle/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String registerVehicle(wmsVehicle vehicle,@PathParam("applicationID") String applicationID, @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.registerVehicle(vehicle, applicationID);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@GET
@Path("getBinZone/{zoneID}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBin> getBinZone(@PathParam("zoneID") String zoneID, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
ArrayList<wmsBin> binlist=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
binlist = sql.getBinZone(zoneID, applicationID);
}
return binlist;
}
@GET
@Path("getBinsByMaterial/{zoneID}&{applicationID}&{wasteMaterial}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBin> getBinsByMaterial(@PathParam("zoneID") String zoneID, @PathParam("applicationID") String applicationID,@PathParam("wasteMaterial") String wasteMaterial, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
ArrayList<wmsBin> binlist=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
binlist = sql.getBinsByMaterial(zoneID, applicationID, wasteMaterial);
}
return binlist;
}
@GET
@Path("getBinSensors")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBinSensor> getAllBinSensors(@HeaderParam("userName") String userName,@HeaderParam("session") String session) throws IOException, SQLException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsBinSensor> bslist = sql.getAllBinSensors();
return bslist;
}
else
return null;
}
@GET
@Path("getAllBins")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBin> getAllBins(@HeaderParam("userName") String userName,@HeaderParam("session") String session) throws IOException, SQLException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsBin> bslist = sql.getAllBins();
return bslist;
}
else
return null;
}
/**
* this method should be called first: get all zones. One application per customer
*
* @param applicationID
* @return
* @throws SQLException
*/
@GET
@Path("getAllZones/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsZone> getAllZones( @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
ArrayList<wmsZone> zoneList=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session))
{
zoneList = sql.getZones(applicationID);
}
return zoneList;
}
@GET
@Path("deleteZone/{zoneID}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String deleteZone(@PathParam("zoneID") String zoneID,@PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.deleteZone(zoneID,applicationID);
result = Integer.toString(cnt);
}
return result;
}
/**
* Gets all vehicles per zone
*
* @param zoneID
* @return
* @throws SQLException
*/
@GET
@Path("getZoneVehicle/{zoneID}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsVehicle> getZoneVehicle(@PathParam("zoneID") String zoneID, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
ArrayList<wmsVehicle> vehicleList=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
vehicleList = sql.getZoneVehicle(zoneID, applicationID);
}
return vehicleList;
}
/**
* ---get all alarms from an application
*
* @param applicationID
* @return
* @throws SQLException
*/
@GET
@Path("getAlarms/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsReading> getAlarms(@PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
ArrayList<wmsReading> alarmList=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
alarmList = wrep.getAlarms(applicationID );
}
return alarmList;
}
/**
* ------if an alarm is handled, admin deletes it
*
* @param alarmID
* @return
* @throws SQLException
*/
@GET
@Path("deleteAlarm/{alarmID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String deleteAlarm(@PathParam("alarmID") String alarmID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException {
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.deleteAlarm(alarmID);
result = Integer.toString(cnt);
}
return result;
}
/**
* deletes a sensors and associated sensor
*
* @param resourceID
* @return
* @throws SQLException
*/
@GET
@Path("deleteBin/{resourceID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String deleteBin(@PathParam("resourceID") String resourceID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.deleteBin(resourceID);
result = Integer.toString(cnt);
}
return result;
}
@GET
@Path("deleteVehicle/{vehicleID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String deleteVehicle(@PathParam("vehicleID") String vehicleID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException {
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
/** NOT IMPLEMENTED YET */
/**int cnt = sql.deleteVehicle(vehicleID);
result = Integer.toString(cnt);*/
}
return result;
}
/**
* ---get vehicle position
*
* @param position
* @param response
* @return
* @throws SQLException
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("postPosition")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String postVehiclePosition(wmsPosition position, @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.postVehiclePosition(position);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@GET
@Path("getBinByDeviceInfoParam/{devParam}&{devParamValue}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBin> getBinByDeviceInfoParam(@PathParam("devParam") String devParam, @PathParam("devParamValue") String devParamValue, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
ArrayList<wmsBin> binlist=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
binlist = sql.getBinByDeviceInfoParam(devParam, devParamValue);
}
return binlist;
}
@GET
@Path("getBinSensorByDeviceInfoParam/{devParam}&{devParamValue}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBinSensor> getBinSensorByDeviceInfoParam(@PathParam("devParam") String devParam, @PathParam("devParamValue") String devParamValue, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
ArrayList<wmsBinSensor> binsenslist=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
binsenslist = sql.getBinSensorByDeviceInfoParam(devParam, devParamValue);
}
return binsenslist;
}
@GET
@Path("getBinByID/{binID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public wmsBin getBinByID(@PathParam("binID") String binID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
wmsBin bin = null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
bin = sql.getBinByID(binID);
}
return bin;
}
@GET
@Path("getBinByIDForQR/{binID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String getBinByIDForQR(@PathParam("binID") String binID, @Context HttpServletResponse response) throws SQLException, IOException {
String result;
wmsBin bin = null;
wmsReading wmr = new wmsReading();
bin = sql.getBinByID(binID);
if (bin==null)
return "Not found"; //if bin id is invalid;
//--based on the bin, construct a reading object which will contains the alarm
wmr.binID=bin.binID;
wmr.measurement="0";
wmr.alarmMessage="Πρόβλημα στον κάδο από QR";
wmr.isAlarm="1";
wmr.binTypeID=bin.binTypeID;
wmr.binTypeName="0";
wmr.latitude = bin.latitude;
wmr.longitude=bin.longitude;
wmr.hwid = bin.hwid;
int cnt = sql.insertNewReading(wmr);
result = Integer.toString(cnt);
response.setHeader("result", result);
return result;
}
@GET
@Path("getBinSensorApplication/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBinSensor> getBinSensorApplication( @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{ArrayList<wmsBinSensor> binsenslist=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
binsenslist = sql.getBinSensorApplication(applicationID);
}
return binsenslist;
}
@GET
@Path("getVehicleZone/{zoneID}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsVehicle> getVehicleZone(@PathParam("zoneID") String zoneID, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
ArrayList<wmsVehicle> vehlist=null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
vehlist = sql.getVehicleZone(zoneID, applicationID);
}
return vehlist;
}
@GET
@Path("getPositionHistory/{vehicleID}&{applicationID},&{fromDate}&{toDate} ")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsPosition> getPositionHistory(@PathParam("vehicleID") String vehicleID, @PathParam("applicationID") String ApplicationID, @PathParam("fromDate") String fromDate, @PathParam("toDate") String toDate , @HeaderParam("userName") String userName, @HeaderParam("session") String session) throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsPosition> positionList = sql.getPositionHistory(vehicleID, ApplicationID, fromDate, toDate);
return positionList;
}
else
return null;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("insertNewReading")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String insertNewReading(wmsReading wmr, @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.insertNewReading(wmr);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@GET
@Path("getBinSuperTypes/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBinSuperType> getBinSuperTypes(@PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsBinSuperType> bintypeList = sql.getBinSuperTypes(applicationID);
return bintypeList;
}
else
return null;
}
@GET
@Path("getBinTypes/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBinType> getBinTypes(@PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsBinType> bintypeList = sql.getBinTypes(applicationID);
return bintypeList;
}
else
return null;
}
@GET
@Path("getBinTypeByID/{applicationID}&{binTypeID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public wmsBinType getBinTypeByID(@PathParam("applicationID") String applicationID,@PathParam("binTypeID") String binTypeID, @HeaderParam("userName") String userName, @HeaderParam("session") String session) throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session))
{
wmsBinType bintype = sql.getBinTypeByID(applicationID, binTypeID);
return bintype;
}
else
return null;
}
@GET
@Path("getBinSuperTypeByID/{applicationID}&{binSuperTypeID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public wmsBinSuperType getBinSuperTypeByID(@PathParam("applicationID") String applicationID,@PathParam("binSuperTypeID") String binSuperTypeID, @HeaderParam("userName") String userName, @HeaderParam("session") String session) throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session))
{
wmsBinSuperType binSupertype = sql.getBinSuperTypeByID(applicationID, binSuperTypeID);
return binSupertype;
}
else
return null;
}
@GET
@Path("getBinStatusTypes/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBinStatusType> getBinStatusTypes(@PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session)throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsBinStatusType> statusList = sql.getBinStatusTypes(applicationID);
return statusList;
}
return null;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("registerZone/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String registerZone( @PathParam("applicationID") String applicationID , wmsZone zone, @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session ) throws SQLException, IOException
{ String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.registerZone(zone, applicationID);
result = Integer.toString(cnt);
//response.setHeader("result", result);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("updateZone/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String updateZone( @PathParam("applicationID") String applicationID , wmsZone zone, @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session ) throws SQLException, IOException
{ String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.updateZone(zone, applicationID);
result = Integer.toString(cnt);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("registerBinType/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String registerBinType( @Context HttpServletResponse response, wmsBinType binType, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session ) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.registerBinType(binType, applicationID);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("updateBinType/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String updateBinType(@Context HttpServletResponse response, wmsBinType binType, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName, @HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.updateBinType(binType, applicationID);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@GET
@Path("deleteBinType/{binTypeID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String deleteBinType(@PathParam("binTypeID") String binTypeID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.deleteBinType(binTypeID);
result = Integer.toString(cnt);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("registerBinSuperType/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String registerBinSuperType(@Context HttpServletResponse response, wmsBinSuperType binType, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName, @HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.registerBinSuperType(binType, applicationID);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("updateBinSuperType/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String updateBinSuperType(@Context HttpServletResponse response, wmsBinSuperType binType, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName, @HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.updateBinSuperType(binType, applicationID);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@GET
@Path("deleteBinSuperType/{binSuperTypeID}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String deleteBinSuperType(@PathParam("binSuperTypeID") String binSuperTypeID,@PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.deleteBinSuperType(binSuperTypeID, applicationID);
result = Integer.toString(cnt);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("registerStatus/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String registerStatus(wmsBinStatusType statusType,@PathParam("applicationID") String applicationID , @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.registerStatus(statusType, applicationID);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("updateStatus/{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public String updateStatus(wmsBinStatusType statusType,@PathParam("applicationID") String applicationID , @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String result = "";
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
int cnt = sql.updateStatus(statusType, applicationID);
result = Integer.toString(cnt);
response.setHeader("result", result);
}
return result;
}
/* */
/****************functions here are called from wmsReporting class */
/* */
@GET
@Path("getLastReadings/{zoneID}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsReading> getLastReadings(@PathParam("zoneID") String zoneID,@PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session)throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsReading> dataList = wrep.getLastReadings(zoneID, applicationID);
return dataList;
}
else
return null;
}
@GET
@Path("getBinActivity/{binID}&{applicationID}&{fromDate}&{toDate}")
@Produces(MediaType.APPLICATION_JSON)
public wmsReportTotal getBinActivity(@PathParam("binID") String binID,@PathParam("applicationID") String applicationID,@PathParam("fromDate") String fromDate,@PathParam("toDate") String toDate, @HeaderParam("userName") String userName,@HeaderParam("session") String session)throws SQLException, IOException {
wmsReportTotal rt =null;
/*
rt = new wmsReportTotal();
rt.averageWeight="500";
rt.totalWeight="2500";
rt.binactivity = new ArrayList<>();
for (int i=0;i<3;i++)
{
wmsBinActivity ba = new wmsBinActivity();
ba.binID=String.valueOf(i);
ba.clearedWeight = String.valueOf(i*100);
rt.binactivity.add(ba);
} */
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
rt = wrep.getBinActivity(binID, applicationID, fromDate, toDate);
}
return rt;
}
@GET
@Path("getZoneActivity/{zoneID}&{applicationID}&{fromDate}&{toDate}")
@Produces(MediaType.APPLICATION_JSON)
public wmsReportTotal getZoneActivity(@PathParam("zoneID") String zoneID,@PathParam("applicationID") String applicationID,@PathParam("fromDate") String fromDate,@PathParam("toDate") String toDate, @HeaderParam("userName") String userName,@HeaderParam("session") String session)throws SQLException, IOException {
wmsReportTotal rt =null;
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
rt = wrep.getZoneActivity(zoneID, applicationID, fromDate, toDate);
}
return rt;
}
@GET
@Path("getZoneReadings/{zoneID}&{applicationID}&{fromDate}&{toDate}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsReading> getZoneReadings(@PathParam("zoneID") String zoneID,@PathParam("applicationID") String applicationID, @PathParam("fromDate") String fromDate,@PathParam("toDate") String toDate, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsReading> dataList = wrep.getZoneReadings(zoneID, applicationID, fromDate, toDate);
return dataList;
}
return null;
}
@GET
@Path("getBinReadings/{binID}&{fromDate}&{toDate}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsReading> getBinReadings(@PathParam("binID") String binID, @PathParam("fromDate") String fromDate,@PathParam("toDate") String toDate, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException {
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
//ArrayList<wmsReading> dataList = wrep.getBinReadings(binID, fromDate, toDate,applicationID);
ArrayList<wmsReading> dataList = wrep.getViewBinReadings(binID, fromDate, toDate,applicationID);
return dataList;
}
else
return null;
}
@GET
@Path("getFilteredReadingsPerMaterial/{applicationID}&{zoneID}&{fillLevel}&{material}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsReading> getFilteredReadingsPerMaterial(@PathParam("applicationID") String applicationID,@PathParam("zoneID") String zoneID, @PathParam("fillLevel")String fillLevel, @PathParam("material")String material, @HeaderParam("userName") String userName,@HeaderParam("session") String session)throws SQLException, IOException
{
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsReading> dataList = wrep.getFilteredReadingsPerMaterial(applicationID, zoneID, fillLevel, material);
return dataList;
}
else
return null;
}
@GET
@Path("getFilledBins/{zoneID}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBin> getFilledBins(@PathParam("zoneID") String zoneID, @PathParam("applicationID") String applicationID, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsBin> binlist = wrep.getFilledBins(zoneID, applicationID);
return binlist;
}
else
return null;
}
@GET
@Path("getFilledBinsByMaterial/{zoneID}&{applicationID}&{wasteMaterial}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public ArrayList<wmsBin> getFilledBinsByMaterial(@PathParam("zoneID") String zoneID, @PathParam("applicationID") String applicationID, @PathParam("wasteMaterial") String wasteMaterial, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException
{
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
ArrayList<wmsBin> binlist = wrep.getFilledBinsByMaterial(zoneID, applicationID, wasteMaterial);
return binlist;
}
else
return null;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("redirectToPage/{pageName}")
public Response redirectToPage(@PathParam("pageName") String pageName , @Context HttpServletResponse response, @HeaderParam("userName") String userName,@HeaderParam("session") String session) throws SQLException, IOException, URISyntaxException
{
String key = sql.findSession(userName,session);
if (key!=null && key.equals(session)) {
URI location = new URI("../"+pageName+".html");
return Response.seeOther(location).build();
}
else
return Response.ok("Invalid session").build();
}
/**--------------------------------login function */
@GET
@Path("loginUser/{userName}&{paswd}&{applicationID}")
@Produces(MediaType.APPLICATION_JSON+ ";charset=utf-8")
public sessionModel loginUser(@Context HttpServletRequest req, @PathParam("userName") String userName,@PathParam("paswd") String paswd,@PathParam("applicationID") String applicationID) throws SQLException, NoSuchAlgorithmException
{
sessionModel sm = sql.loginUser(userName, paswd, applicationID);
return sm;
}
}