Search in sources :

Example 21 with Users

use of com.webstart.model.Users in project FarmCloud by vratsasg.

the class HomeController method getObsProperties.

@RequestMapping(value = "/observableproperties", method = RequestMethod.GET)
public ResponseEntity<String> getObsProperties(HttpServletRequest request) {
    JSONObject obj = new JSONObject();
    Users users = (Users) request.getSession().getAttribute("current_user");
    if (users == null) {
        return new ResponseEntity(HttpStatus.UNAUTHORIZED);
    }
    obj = observationProperyService.getAllObsPropeties();
    return new ResponseEntity<String>(obj.toJSONString(), HttpStatus.CREATED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JSONObject(org.json.simple.JSONObject) Users(com.webstart.model.Users)

Example 22 with Users

use of com.webstart.model.Users in project FarmCloud by vratsasg.

the class HomeController method getProfile.

@RequestMapping(value = "/features/profile", method = RequestMethod.GET)
public ResponseEntity<String> getProfile(HttpServletRequest request) {
    Users users = (Users) request.getSession().getAttribute("current_user");
    if (users == null) {
        return new ResponseEntity(HttpStatus.UNAUTHORIZED);
    }
    JSONObject obj = featureofInterestService.findCropInfo(users.getUser_id());
    return new ResponseEntity<String>(obj.toJSONString(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JSONObject(org.json.simple.JSONObject) Users(com.webstart.model.Users)

Example 23 with Users

use of com.webstart.model.Users in project FarmCloud by vratsasg.

the class HomeController method setIrrigationDates.

@RequestMapping(value = "/{mydevice}/irrigation/times", params = { "dtfrom", "dtto" }, method = RequestMethod.POST)
public ResponseEntity<?> setIrrigationDates(@PathVariable("mydevice") String mydevice, @RequestParam("dtfrom") String datefrom, @RequestParam("dtto") String dateto, HttpServletRequest request) {
    Users users = (Users) request.getSession().getAttribute("current_user");
    try {
        AutomaticWater automaticWater = new AutomaticWater(datefrom, dateto, new BigDecimal(0), mydevice);
        boolean sentData = featureofInterestService.setDeviceIrrigaDate(users.getUser_id(), mydevice, datefrom, dateto);
        Featureofinterest featureofinterest = this.featureofInterestService.getFeatureofinterestByIdentifier(mydevice);
        usersService.createNewNotification(users.getUser_id(), String.format("New irrigation event from: %1$s until %2$s for end device %3$s ", automaticWater.getFromtime(), automaticWater.getUntiltime(), featureofinterest.getName()), NotificationTypeEnum.IRRIGATION.getValue());
        if (!sentData)
            return new ResponseEntity(HttpStatus.BAD_REQUEST);
    } catch (Exception e) {
        e.printStackTrace();
        return new ResponseEntity(HttpStatus.BAD_REQUEST);
    }
    return new ResponseEntity(HttpStatus.OK);
}
Also used : Featureofinterest(com.webstart.model.Featureofinterest) ResponseEntity(org.springframework.http.ResponseEntity) Users(com.webstart.model.Users) BigDecimal(java.math.BigDecimal) ParserException(jdk.nashorn.internal.runtime.ParserException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 24 with Users

use of com.webstart.model.Users in project FarmCloud by vratsasg.

the class HomeController method getStationCoords.

@RequestMapping(value = "/station/coords", method = RequestMethod.GET)
public ResponseEntity<String> getStationCoords(HttpServletRequest request) {
    String jsonresult = null;
    try {
        Users users = (Users) request.getSession().getAttribute("current_user");
        List<FeatureidIdentifier> results = featureofInterestService.findByUserAndType(users.getUser_id(), FeatureTypeEnum.STATION.getValue());
        jsonresult = featureofInterestService.findByFeatureofinterestid(results.get(0).getFeatureinterestid());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new ResponseEntity<String>(jsonresult, 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 25 with Users

use of com.webstart.model.Users in project FarmCloud by vratsasg.

the class HomeController method getMeasuresByObsProperty.

@RequestMapping(value = "/measures/lastdate", method = RequestMethod.GET)
public ResponseEntity<String> getMeasuresByObsProperty(HttpServletRequest request) {
    JSONArray obj = new JSONArray();
    Users users = (Users) request.getSession().getAttribute("current_user");
    String sentData = null;
    try {
        sentData = observationProperyService.getLastObservationsDate(users.getUser_id());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return new ResponseEntity<String>(sentData, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JSONArray(org.json.simple.JSONArray) 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