Search in sources :

Example 16 with Users

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

Example 17 with Users

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);
}
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 18 with Users

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

Example 19 with Users

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

Example 20 with Users

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

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