@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; }