use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class HomeController method saveWateringProfile.
@RequestMapping(value = "/wateringprofile/minmax", method = RequestMethod.POST)
@ResponseBody
public HttpStatus saveWateringProfile(@RequestBody List<FeatureObsProp> featureObsPropList, HttpServletRequest request) {
Users users = (Users) request.getSession().getAttribute("current_user");
if (users == null) {
return HttpStatus.UNAUTHORIZED;
}
try {
List<FeatureMinMaxValue> featureMinMaxValuesList = new ArrayList<FeatureMinMaxValue>();
for (FeatureObsProp featureObsProp : featureObsPropList) {
featureMinMaxValuesList.addAll(featureObsProp.getFeatureObsproplist());
}
observationProperyService.setObservationMinmaxValues(featureMinMaxValuesList);
} catch (Exception e) {
e.printStackTrace();
return HttpStatus.INTERNAL_SERVER_ERROR;
}
return HttpStatus.OK;
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class HomeController method getStationMinMaxValues.
@RequestMapping(value = "/wateringprofile/minmax", method = RequestMethod.GET)
public ResponseEntity<String> getStationMinMaxValues(HttpServletRequest request) {
String jsonInString = null;
try {
Users users = (Users) request.getSession().getAttribute("current_user");
jsonInString = featureofInterestService.findMinMaxbyUserId(users.getUser_id());
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>("false", HttpStatus.EXPECTATION_FAILED);
}
return new ResponseEntity<String>(jsonInString, HttpStatus.OK);
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class HomeController method getFeatureEndDevices.
@RequestMapping(value = "/enddevices", method = RequestMethod.GET)
public ResponseEntity<String> getFeatureEndDevices(HttpServletRequest request) {
String jsonresult = null;
try {
Users users = (Users) request.getSession().getAttribute("current_user");
List<FeatureidIdentifier> results = featureofInterestService.findByUserAndType(users.getUser_id(), FeatureTypeEnum.END_DEVICE.getValue());
ObjectMapper mapper = new ObjectMapper();
jsonresult = mapper.writeValueAsString(results);
} catch (Exception e) {
e.printStackTrace();
}
return new ResponseEntity<String>(jsonresult, HttpStatus.OK);
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class HomeController method getMeasuresByObsProperty.
@RequestMapping(value = "/{mydevice}/{observablePropertyId}/measures", params = { "dtstart", "dtend" }, method = RequestMethod.GET)
public ResponseEntity<String> getMeasuresByObsProperty(@PathVariable("observablePropertyId") Long observablePropertyId, @PathVariable("mydevice") String mydevice, @RequestParam("dtstart") String datetimestart, @RequestParam("dtend") String datetimeend, HttpServletRequest request) {
Users users = (Users) request.getSession().getAttribute("current_user");
if (users == null) {
return new ResponseEntity(HttpStatus.UNAUTHORIZED);
}
String sentData = null;
try {
Featureofinterest featureofinterest = featureofInterestService.getFeatureofinterestByIdentifier(mydevice);
DateTimeFormatter dtfInput = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
HelperCls.ConvertToDateTime convertable = new HelperCls.ConvertToDateTime();
DateTime from = convertable.GetUTCDateTime(datetimestart, dtfInput, featureofinterest.getTimezone(), StatusTimeConverterEnum.TO_UTC);
DateTime to = convertable.GetUTCDateTime(datetimeend, dtfInput, featureofinterest.getTimezone(), StatusTimeConverterEnum.TO_UTC);
ObservableMeasure observableMeasure = observationProperyService.getObservationData(observablePropertyId, users.getUser_id(), mydevice, from, to);
if (observableMeasure == null) {
sentData = "{\"unit\":\"\",\"measuredata\":[]}";
} else {
ObjectMapper mapper = new ObjectMapper();
// Object to JSON in String
sentData = mapper.writeValueAsString(observableMeasure);
}
} catch (Exception e) {
e.printStackTrace();
new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<String>(sentData, HttpStatus.OK);
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class HomeController method getLastWateringMeasures.
@RequestMapping(value = "/{mydevice}/watering/last", method = RequestMethod.GET)
public ResponseEntity<?> getLastWateringMeasures(@PathVariable("mydevice") String mydevice, HttpServletRequest request) {
Users users = (Users) request.getSession().getAttribute("current_user");
// AutomaticWater sentData = null;
ResponseEntity<AutomaticWater> sentData;
try {
sentData = observationProperyService.getLastWateringObsbyIdentifier(users.getUser_id(), mydevice);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST);
}
return sentData;
}
Aggregations