Newer
Older
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
package org.josast.AmsatServer;
import org.josast.AmsatServer.dao.DatabaseSIDSBeanDAO;
import org.josast.AmsatServer.entity.Classement;
import org.josast.AmsatServer.entity.DatabaseSIDSBean;
import org.josast.AmsatServer.exceptions.SIDSDataNotFound;
import org.josast.influxdb.EntrySatDB;
import org.josast.influxdb.InfluxdbUVSQsatDB;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@RestController
public class AmsatDatabaseAPI {
@Autowired
private DatabaseSIDSBeanDAO SIDSBeanDAOimp;
public AmsatDatabaseAPI() {
// TODO Auto-generated constructor stub
}
/**
* Interpret SIDS POST request and store the SIDS data in dataBase
*
* @param noradID
* @param source
* @param timestamp
* @param frame
* @param locator
* @param longitude
* @param latitude
* @param version
* @return message with ID of the data stored
*/
@ApiOperation(value = "Send data to the Amsat-F database. The protocole follow the SIDS protocole describe in sids document ")
@PostMapping("/api/V2/SIDS")
@ResponseBody
public String postSIDS(
@ApiParam(
name = "noradID",
type = "long",
value = "Norad Identifer, exemple 46287 for Amicalsat",
example = "46287",
required = true)
@RequestParam(name = "noradID") int noradID,
@ApiParam(
name = "source",
type = "String",
value = "Provider callsign",
example = "46287",
required = true)
@RequestParam(name = "source") String source,
@RequestParam(name = "timestamp") String timestamp,
@RequestParam(name = "frame") String frame,
@RequestParam(name = "locator") String locator,
@RequestParam(name = "longitude") String longitude,
@RequestParam(name = "latitude") String latitude,
@RequestParam(name = "version") String version) {
DatabaseSIDSBean SIDSBeanimp = new DatabaseSIDSBean();
SIDSBeanimp.setNoradID(noradID);
SIDSBeanimp.setSource(source);
SIDSBeanimp.setFrame(frame);
SIDSBeanimp.setTimestamp(timestamp);
SIDSBeanimp.setLongitude(longitude);
SIDSBeanimp.setLatitude(latitude);
SIDSBeanimp.setVersion(version);
DatabaseSIDSBean SIDSBeanimpS = SIDSBeanDAOimp.save(SIDSBeanimp);
try {
switch(noradID) {
// Entry Sat
case 44429:
EntrySatDB App = EntrySatDB.getInstance();
// App.addEntrySatData(source, frame);
App.addEntrySatData(source, frame, fromISO8601UTC(timestamp));
break;
// UVSQsat
case 99760:
case 99999:
InfluxdbUVSQsatDB appDb = InfluxdbUVSQsatDB.getInstance();
appDb.store(frame, source);
break;
default:
//Do nothing or something else..
break;
}
}
catch (Exception e )
{
System.err.println(e.getStackTrace());
e.printStackTrace();
}
return "SIDS frame registred with ID : " + SIDSBeanimpS.getId();
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
}
@ApiOperation(value = "Return all SIDS data registred in the database")
@GetMapping("/api/V2/database/sidsData")
public List<DatabaseSIDSBean> retrieveAllSIDS() {
return SIDSBeanDAOimp.findAll();
}
@ApiOperation(value = "Return number of SIDS data in the database")
@GetMapping("/api/V2/database/sidsDatacount")
public long retrieveSIDSCount() {
return SIDSBeanDAOimp.count();
}
@ApiOperation(value = "retreive data from the database between two dates ")
@GetMapping("/api/V2/database/sidsDataDate")
@ResponseBody
public String handlerSIDS(
@ApiParam(
name = "noradID",
type = "long",
value = "Norad Identifer, exemple 46287 for Amicalsat",
example = "46287",
required = true)
@RequestParam(name = "noradID") int noradID,
@ApiParam(
name = "startTimeStamp",
type = "date represented by string with format UTC (see ISO 8601) ",
value = "Start date for the request",
example = "2020-10-10T09:30:06Z",
required = true)
@RequestParam(name = "startTimeStamp") String startTimeStamp,
@ApiParam(
name = "endTimeStamp",
type = "date represented by string with format UTC (see ISO 8601) ",
value = "End date for the request",
example = "2020-10-10T09:30:06Z",
required = true)
@RequestParam(name = "endTimeStamp") String endTimeStamp)
{
Object[][] listFrame = SIDSBeanDAOimp.findSatelliteDataFromTo(noradID,startTimeStamp,endTimeStamp);
DatabaseSIDSBean[] sb =new DatabaseSIDSBean[listFrame.length];
for (int i=0;i<listFrame.length;i++)
{
DatabaseSIDSBean sbo = new DatabaseSIDSBean();
Object[] o= listFrame[i];
BigInteger bi = (BigInteger)o[0];
sbo.setId(bi.longValue());
sbo.setNoradID((int) o[1]);
sbo.setAzimuth((double) o[2]);
sbo.setElevation((double) o[3]);
bi = (BigInteger)o[4];
sbo.setfDown(bi.longValue());
sbo.setFrame((String) o[5]);
sbo.setLatitude((String) o[6]);
sbo.setLongitude((String) o[7]);
sbo.setSource((String) o[8]);
sbo.setTimestamp((String) o[9]);
sbo.setTncPort((int) o[10] );
sbo.setVersion((String) o[11]) ;
sb[i]=sbo;
}
JSONArray json = new JSONArray (sb);
return json.toString();
}
@ApiOperation(value = "Return last SIDS data received")
@GetMapping("/api/V2/database/lastSidsData")
public DatabaseSIDSBean retrievelastSidsTest() {
DatabaseSIDSBean SidsBean = SIDSBeanDAOimp.findTopByOrderByIdDesc();
if (SidsBean == null)
throw new SIDSDataNotFound(" Last record not found ");
return SidsBean;
}
@ApiOperation(value = "Return all contributor sorted for a Satellite")
@GetMapping("/api/V2/database/classement/{NoradId}")
public List<Classement> retrieveClassementByNoradID(
@PathVariable String NoradId) {
System.out.println("Classement" + NoradId);
Object[][] SidsBean = SIDSBeanDAOimp
.findAllActiveUsersNativeByNoradId(Long.parseLong(NoradId));
List<Classement> list = new ArrayList<Classement>();
if (SidsBean == null)
throw new SIDSDataNotFound(" findAllActiveUsersNative ");
System.out.println(SidsBean.length);
// System.out.println(" value " +(String) SidsBean[0][0] +" "+
// (BigInteger) SidsBean[0][1]);
for (int i = 0; i < SidsBean.length; i++) {
Classement c = new Classement((String) SidsBean[i][0],
(BigInteger) SidsBean[i][1]);
list.add(c);
}
//
System.out.println(list.size());
return list;
}
@ApiOperation(value = "Return all contributor sorted")
@GetMapping("/api/V2/database/classementall/")
public List<Classement> retrieveClassement() {
Object[][] SidsBean = SIDSBeanDAOimp.findAllActiveUsersNative();
List<Classement> list = new ArrayList<Classement>();
if (SidsBean == null)
throw new SIDSDataNotFound(" findAllActiveUsersNative ");
for (int i = 0; i < SidsBean.length; i++) {
Classement c = new Classement((String) SidsBean[i][0],
(BigInteger) SidsBean[i][1]);
list.add(c);
}
return list;
}
private Date fromISO8601UTC(String dateStr) {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(tz);
try {
return df.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}