@RequestMapping(
      method = RequestMethod.PUT,
      value = "/eu.trentorise.smartcampus.journeyplanner.sync.BasicRecurrentJourney/{clientId}")
  public @ResponseBody void updateRecurrentJourney(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      @RequestBody BasicRecurrentJourney recurrent,
      @PathVariable String clientId)
      throws InvocationException, AcServiceException {
    try {
      User user = getUser(request);
      String userId = getUserId(user);
      if (userId == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
      }

      String objectClientId = recurrent.getClientId();
      if (!clientId.equals(objectClientId)) {
        response.setStatus(HttpServletResponse.SC_CONFLICT);
        return;
      }
      DomainObject res =
          getObjectByClientId(
              clientId, "smartcampus.services.journeyplanner.RecurrentJourneyObject");
      if (res != null) {
        String objectId = checkUser(res, userId);
        if (objectId == null) {
          response.setStatus(HttpServletResponse.SC_FORBIDDEN);
          return;
        }

        Map<String, Object> pars = new HashMap<String, Object>();
        pars.put("newJourney", recurrent.getData());
        pars.put("newName", recurrent.getName());
        pars.put("newMonitor", recurrent.isMonitor());
        domainClient.invokeDomainOperation(
            "updateRecurrentJourney",
            "smartcampus.services.journeyplanner.RecurrentJourneyObject",
            objectId,
            pars,
            userId,
            "vas_journeyplanner_subscriber");
      } else {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      }
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }
  @RequestMapping(
      method = RequestMethod.POST,
      value = "/eu.trentorise.smartcampus.journeyplanner.sync.BasicRecurrentJourney")
  public @ResponseBody void saveRecurrentJourney(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      @RequestBody BasicRecurrentJourney recurrent)
      throws InvocationException, AcServiceException {
    try {
      User user = getUser(request);
      String userId = getUserId(user);
      if (userId == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
      }

      logger.info("-" + userId + "~AppConsume~monitor");

      Map<String, Object> pars = new HashMap<String, Object>();
      pars.put("recurrentJourney", recurrent.getData());
      pars.put("name", recurrent.getName());
      String clientId = recurrent.getClientId();
      if (clientId == null) {
        clientId = new ObjectId().toString();
      }
      pars.put("clientId", clientId);
      pars.put("userId", userId);
      pars.put("monitor", recurrent.isMonitor());
      domainClient.invokeDomainOperation(
          "saveRecurrentJourney",
          "smartcampus.services.journeyplanner.RecurrentJourneyFactory",
          "smartcampus.services.journeyplanner.RecurrentJourneyFactory.0",
          pars,
          userId,
          "vas_journeyplanner_subscriber");
      storage.storeObject(recurrent);
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }
  @RequestMapping(
      method = RequestMethod.GET,
      value = "/eu.trentorise.smartcampus.journeyplanner.sync.BasicRecurrentJourney/{clientId}")
  public @ResponseBody BasicRecurrentJourney getRecurrentJourney(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      @PathVariable String clientId)
      throws InvocationException {
    try {
      User user = getUser(request);
      String userId = getUserId(user);
      if (userId == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return null;
      }

      DomainObject obj =
          getObjectByClientId(
              clientId, "smartcampus.services.journeyplanner.RecurrentJourneyObject");
      if (obj == null) {
        return null;
      }
      if (checkUser(obj, userId) == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return null;
      }

      ObjectMapper mapper = new ObjectMapper();
      mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
      Map<String, Object> content = obj.getContent();
      RecurrentJourney recurrent = mapper.convertValue(content.get("data"), RecurrentJourney.class);
      BasicRecurrentJourney recurrentJourney = new BasicRecurrentJourney();
      String objectClientId = (String) content.get("clientId");
      if (!clientId.equals(objectClientId)) {
        response.setStatus(HttpServletResponse.SC_CONFLICT);
        return null;
      }
      recurrentJourney.setData(recurrent);
      recurrentJourney.setClientId(clientId);
      recurrentJourney.setName((String) obj.getContent().get("name"));
      recurrentJourney.setMonitor((Boolean) obj.getContent().get("monitor"));
      recurrentJourney.setUser((String) obj.getContent().get("userId"));

      return recurrentJourney;
    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return null;
  }
  @RequestMapping(
      method = RequestMethod.GET,
      value = "/eu.trentorise.smartcampus.journeyplanner.sync.BasicRecurrentJourney")
  public @ResponseBody List<BasicRecurrentJourney> getRecurrentJourneys(
      HttpServletRequest request, HttpServletResponse response, HttpSession session)
      throws InvocationException {
    try {
      User user = getUser(request);
      String userId = getUserId(user);
      if (userId == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return null;
      }

      Map<String, Object> pars = new TreeMap<String, Object>();
      pars.put("userId", userId);
      List<String> res =
          domainClient.searchDomainObjects(
              "smartcampus.services.journeyplanner.RecurrentJourneyObject",
              pars,
              "vas_journeyplanner_subscriber");

      List<BasicRecurrentJourney> journeys = new ArrayList<BasicRecurrentJourney>();
      ObjectMapper mapper = new ObjectMapper();
      mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
      for (String r : res) {
        DomainObject obj = new DomainObject(r);
        RecurrentJourney recurrent =
            mapper.convertValue(obj.getContent().get("data"), RecurrentJourney.class);
        BasicRecurrentJourney recurrentJourney = new BasicRecurrentJourney();
        String clientId = (String) obj.getContent().get("clientId");
        recurrentJourney.setData(recurrent);
        recurrentJourney.setClientId(clientId);
        recurrentJourney.setName((String) obj.getContent().get("name"));
        recurrentJourney.setMonitor((Boolean) obj.getContent().get("monitor"));
        recurrentJourney.setUser((String) obj.getContent().get("userId"));

        journeys.add(recurrentJourney);
      }

      return journeys;

    } catch (Exception e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return null;
  }