-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load schedule for each device separately
- Loading branch information
1 parent
66a3543
commit 1721529
Showing
4 changed files
with
93 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/ru/r2cloud/web/api/device/DeviceSchedule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package ru.r2cloud.web.api.device; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.eclipsesource.json.JsonArray; | ||
import com.eclipsesource.json.JsonObject; | ||
|
||
import fi.iki.elonen.NanoHTTPD.IHTTPSession; | ||
import ru.r2cloud.device.Device; | ||
import ru.r2cloud.device.DeviceManager; | ||
import ru.r2cloud.model.ObservationRequest; | ||
import ru.r2cloud.model.Satellite; | ||
import ru.r2cloud.satellite.ObservationRequestComparator; | ||
import ru.r2cloud.satellite.SatelliteDao; | ||
import ru.r2cloud.web.AbstractHttpController; | ||
import ru.r2cloud.web.ModelAndView; | ||
import ru.r2cloud.web.NotFound; | ||
import ru.r2cloud.web.WebServer; | ||
|
||
public class DeviceSchedule extends AbstractHttpController { | ||
|
||
private final DeviceManager deviceManager; | ||
private final SatelliteDao satelliteDao; | ||
|
||
public DeviceSchedule(DeviceManager deviceManager, SatelliteDao satelliteDao) { | ||
this.deviceManager = deviceManager; | ||
this.satelliteDao = satelliteDao; | ||
} | ||
|
||
@Override | ||
public ModelAndView doGet(IHTTPSession session) { | ||
String id = WebServer.getParameter(session, "id"); | ||
Device device = deviceManager.findDeviceById(id); | ||
if (device == null) { | ||
return new NotFound(); | ||
} | ||
JsonArray result = new JsonArray(); | ||
List<ObservationRequest> request = device.findScheduledObservations(); | ||
Collections.sort(request, ObservationRequestComparator.INSTANCE); | ||
for (ObservationRequest cur : request) { | ||
Satellite satellite = satelliteDao.findById(cur.getSatelliteId()); | ||
if (satellite == null) { | ||
continue; | ||
} | ||
JsonObject curRequest = new JsonObject(); | ||
curRequest.set("id", cur.getId()); | ||
curRequest.set("start", cur.getStartTimeMillis()); | ||
curRequest.set("end", cur.getEndTimeMillis()); | ||
curRequest.set("satelliteId", cur.getSatelliteId()); | ||
curRequest.set("name", satellite.getName()); | ||
result.add(curRequest); | ||
} | ||
ModelAndView model = new ModelAndView(); | ||
model.setData(result); | ||
return model; | ||
} | ||
|
||
@Override | ||
public String getRequestMappingURL() { | ||
return "/api/v1/admin/device/schedule"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters