use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class ExtractController method getPDF.
@RequestMapping(value = "{mydevice}/{observablepropertyid}/pdf", params = { "dtstart", "dtend" }, method = RequestMethod.POST)
public ResponseEntity<byte[]> getPDF(@PathVariable("observablepropertyid") Long observablePropertyId, @PathVariable("mydevice") String mydevice, @RequestParam("dtstart") String datetimestart, @RequestParam("dtend") String datetimeend, HttpServletRequest request) {
ObservableMeasure observableMeasure = null;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] contents;
try {
Users user = (Users) request.getSession().getAttribute("current_user");
// DateTime Convertable
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 = observationProperyService.getObservationData(observablePropertyId, user.getUser_id(), mydevice, from, to);
//
com.itextpdf.text.Document doc = new com.itextpdf.text.Document();
// Do this BEFORE document.open()
PdfWriter.getInstance(doc, byteArrayOutputStream);
doc.open();
// Whatever function that you use to create your PDF
doc = createPDF(observableMeasure, datetimestart, datetimeend, doc);
doc.close();
contents = byteArrayOutputStream.toByteArray();
// generate the file
} catch (Exception exc) {
exc.printStackTrace();
return null;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/pdf"));
String filename = "measures.pdf";
headers.setContentDispositionFormData(filename, filename);
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(contents, headers, HttpStatus.OK);
return response;
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class HomeController method getAutomaticWaterTimes.
@RequestMapping(value = "{coordinator}/automaticwater/dates", method = RequestMethod.GET)
@ResponseBody
public AutomaticWater getAutomaticWaterTimes(@PathVariable("coordinator") String coordinator, HttpServletRequest request) {
AutomaticWater automaticWater;
try {
Users users = (Users) request.getSession().getAttribute("current_user");
automaticWater = featureofInterestService.getAutomaticWater(users.getUser_id(), coordinator);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return automaticWater;
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class HomeController method saveAutomacticWatering.
@RequestMapping(value = "/automaticwater/dates", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity saveAutomacticWatering(HttpServletRequest request, @RequestBody AutomaticWater automaticWatering) {
try {
Users user = (Users) request.getSession().getAttribute("current_user");
if (user == null) {
return new ResponseEntity(HttpStatus.UNAUTHORIZED);
}
int userid = user.getUser_id();
featureofInterestService.setAutomaticWateringTime(automaticWatering, userid);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity(HttpStatus.OK);
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class HomeController method getTotalMeasuresCounter.
@RequestMapping(value = "/{mydevice}/{observablePropertyId}/measures/counter", params = { "dtstart", "dtend" }, method = RequestMethod.GET)
public ResponseEntity<Long> getTotalMeasuresCounter(@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);
}
Long sentData = 0L;
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);
sentData = observationProperyService.getObservationsCounter(observablePropertyId, users.getUser_id(), mydevice, from, to);
} catch (ParserException parseExc) {
parseExc.printStackTrace();
new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception e) {
e.printStackTrace();
new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<Long>(sentData, HttpStatus.OK);
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class IndexController method validate.
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String validate(@RequestParam("username_n") String username, @RequestParam("password_n") String password, Model model, HttpServletRequest request) {
Users users = usersService.findUser(username, password);
if (users == null) {
model.addAttribute("alert_message", "Wrong Username/Password!");
model.addAttribute("alert_class", "alert alert-danger");
return "index";
} else {
request.getSession().setAttribute("current_user", users);
users = (Users) request.getSession().getAttribute("current_user");
model.addAttribute("current_user", users);
return "home";
}
}
Aggregations