Search in sources :

Example 1 with Users

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Featureofinterest(com.webstart.model.Featureofinterest) HelperCls(com.webstart.Helpers.HelperCls) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Users(com.webstart.model.Users) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ResponseEntity(org.springframework.http.ResponseEntity) ObservableMeasure(com.webstart.DTO.ObservableMeasure) com.itextpdf.text(com.itextpdf.text) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 2 with Users

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;
}
Also used : Users(com.webstart.model.Users) ParserException(jdk.nashorn.internal.runtime.ParserException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with Users

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Users(com.webstart.model.Users) ParserException(jdk.nashorn.internal.runtime.ParserException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with Users

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);
}
Also used : ParserException(jdk.nashorn.internal.runtime.ParserException) ResponseEntity(org.springframework.http.ResponseEntity) Featureofinterest(com.webstart.model.Featureofinterest) HelperCls(com.webstart.Helpers.HelperCls) Users(com.webstart.model.Users) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) ParserException(jdk.nashorn.internal.runtime.ParserException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with Users

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";
    }
}
Also used : Users(com.webstart.model.Users) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Users (com.webstart.model.Users)30 ResponseEntity (org.springframework.http.ResponseEntity)18 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 ParserException (jdk.nashorn.internal.runtime.ParserException)12 Featureofinterest (com.webstart.model.Featureofinterest)9 HelperCls (com.webstart.Helpers.HelperCls)8 DateTime (org.joda.time.DateTime)8 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)8 LocalDateTime (org.joda.time.LocalDateTime)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ArrayList (java.util.ArrayList)4 JSONObject (org.json.simple.JSONObject)4 HttpHeaders (org.springframework.http.HttpHeaders)4 ObservableMeasure (com.webstart.DTO.ObservableMeasure)3 WateringMeasure (com.webstart.DTO.WateringMeasure)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 com.itextpdf.text (com.itextpdf.text)2 WateringValueTime (com.webstart.DTO.WateringValueTime)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2