use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class ExtractController method getPDF.
@RequestMapping(value = "{mydevice}/watering/pdf", params = { "dtstart", "dtend" }, method = RequestMethod.POST)
public ResponseEntity<byte[]> getPDF(@PathVariable("mydevice") String mydevice, @RequestParam("dtstart") String datetimestart, @RequestParam("dtend") String datetimeend, HttpServletRequest request) {
WateringMeasure wateringMeasure = 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);
//
wateringMeasure = observationProperyService.getWateringData(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(wateringMeasure, 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 ExtractController method getXlsx.
@RequestMapping(value = "{mydevice}/{observablepropertyid}/xls", params = { "dtstart", "dtend" }, method = RequestMethod.POST)
public ResponseEntity<byte[]> getXlsx(@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);
// Create excel document
HSSFWorkbook wbook = createXlsx(observableMeasure);
wbook.write(byteArrayOutputStream);
contents = byteArrayOutputStream.toByteArray();
// generate the file
} catch (Exception exc) {
exc.printStackTrace();
return null;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
String filename = "measures.xls";
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 ExtractController method getCsv.
@RequestMapping(value = "{mydevice}/watering/csv", params = { "dtstart", "dtend" }, method = RequestMethod.POST)
public void getCsv(@PathVariable("mydevice") String mydevice, @RequestParam("dtstart") String datetimestart, @RequestParam("dtend") String datetimeend, HttpServletRequest request, HttpServletResponse response) {
response.setContentType("text/plain");
String reportName = "Watering_Measures.csv";
response.setHeader("Content-disposition", "attachment; filename=" + reportName);
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);
//
WateringMeasure wateringMeasure = observationProperyService.getWateringData(user.getUser_id(), mydevice, from, to);
//
ArrayList<String> rows = new ArrayList<String>();
rows.add("Watering Time from");
rows.add(";");
rows.add("Watering Time until");
rows.add(";");
rows.add("Total Duration");
rows.add(";");
rows.add("Watering consumption");
rows.add(";");
rows.add("Unit");
rows.add("\n");
// write table row data
for (WateringValueTime valueTime : wateringMeasure.getMeasuredata()) {
rows.add(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTimeFrom()));
rows.add(";");
rows.add(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTimeTo()));
rows.add(";");
rows.add(valueTime.getDateTimeDiff());
rows.add(";");
rows.add(valueTime.getValue().toString());
rows.add(";");
rows.add(wateringMeasure.getUnit());
rows.add("\n");
}
Iterator<String> iter = rows.iterator();
while (iter.hasNext()) {
String outputString = (String) iter.next();
response.getOutputStream().print(outputString);
}
response.getOutputStream().flush();
} catch (Exception exc) {
exc.printStackTrace();
}
}
use of com.webstart.model.Users in project FarmCloud by vratsasg.
the class ExtractController method getXlsx.
@RequestMapping(value = "{mydevice}/watering/xls", params = { "dtstart", "dtend" }, method = RequestMethod.POST)
public ResponseEntity<byte[]> getXlsx(@PathVariable("mydevice") String mydevice, @RequestParam("dtstart") String datetimestart, @RequestParam("dtend") String datetimeend, HttpServletRequest request) {
WateringMeasure wateringMeasure = 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);
//
wateringMeasure = observationProperyService.getWateringData(user.getUser_id(), mydevice, from, to);
// Create excel document
HSSFWorkbook wbook = createXlsx(wateringMeasure);
wbook.write(byteArrayOutputStream);
contents = byteArrayOutputStream.toByteArray();
// generate the file
} catch (Exception exc) {
exc.printStackTrace();
return null;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
String filename = "measures.xls";
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 ExtractController method getCsv.
@RequestMapping(value = "{mydevice}/{observablepropertyid}/csv", params = { "dtstart", "dtend" }, method = RequestMethod.POST)
public void getCsv(@PathVariable("observablepropertyid") Long observablepropertyid, @PathVariable("mydevice") String mydevice, @RequestParam("dtstart") String datetimestart, @RequestParam("dtend") String datetimeend, HttpServletRequest request, HttpServletResponse response) {
response.setContentType("text/plain");
DateTime.now().toString("yyyyMMddHHmmss");
// String reportName = String.format("Measures-%1$s.csv", DateTime.now().toString("yyyyMMddHHmmss"));
String reportName = "Measures.csv";
response.setHeader("Content-disposition", "attachment; filename=" + reportName);
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 observableMeasure = observationProperyService.getObservationData(observablepropertyid, user.getUser_id(), mydevice, from, to);
ObservableMeasure observableMeasure = observationProperyService.getObservationData(observablepropertyid, 1, mydevice, from, to);
ArrayList<String> rows = new ArrayList<String>();
rows.add("Measure date & time");
rows.add(";");
rows.add("Measure value");
rows.add(";");
rows.add("Measure unit");
rows.add("\n");
// write table row data
for (ValueTime valueTime : observableMeasure.getMeasuredata()) {
rows.add(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(valueTime.getPhenomenonDateTime()));
rows.add(";");
rows.add(valueTime.getValue().toString());
rows.add(";");
rows.add(observableMeasure.getUnit());
rows.add("\n");
}
Iterator<String> iter = rows.iterator();
while (iter.hasNext()) {
String outputString = (String) iter.next();
response.getOutputStream().print(outputString);
}
response.getOutputStream().flush();
} catch (Exception exc) {
exc.printStackTrace();
}
}
Aggregations