diff --git a/.gitignore b/.gitignore index 6246bc2..fca2d05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea *.iml -node_modules \ No newline at end of file +node_modules +/target/ diff --git a/WebContent/META-INF/MANIFEST.MF b/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/WebContent/WEB-INF/lib/aopalliance-1.0.jar b/WebContent/WEB-INF/lib/aopalliance-1.0.jar new file mode 100644 index 0000000..578b1a0 Binary files /dev/null and b/WebContent/WEB-INF/lib/aopalliance-1.0.jar differ diff --git a/WebContent/WEB-INF/lib/commons-logging-1.1.3.jar b/WebContent/WEB-INF/lib/commons-logging-1.1.3.jar new file mode 100644 index 0000000..ab51254 Binary files /dev/null and b/WebContent/WEB-INF/lib/commons-logging-1.1.3.jar differ diff --git a/WebContent/WEB-INF/lib/json-simple-1.1.1.jar b/WebContent/WEB-INF/lib/json-simple-1.1.1.jar new file mode 100644 index 0000000..66347a6 Binary files /dev/null and b/WebContent/WEB-INF/lib/json-simple-1.1.1.jar differ diff --git a/WebContent/WEB-INF/lib/jstl-1.2.jar b/WebContent/WEB-INF/lib/jstl-1.2.jar new file mode 100644 index 0000000..0fd275e Binary files /dev/null and b/WebContent/WEB-INF/lib/jstl-1.2.jar differ diff --git a/WebContent/WEB-INF/lib/spring-aop-4.0.3.RELEASE.jar b/WebContent/WEB-INF/lib/spring-aop-4.0.3.RELEASE.jar new file mode 100644 index 0000000..9cf4b92 Binary files /dev/null and b/WebContent/WEB-INF/lib/spring-aop-4.0.3.RELEASE.jar differ diff --git a/WebContent/WEB-INF/lib/spring-beans-4.0.3.RELEASE.jar b/WebContent/WEB-INF/lib/spring-beans-4.0.3.RELEASE.jar new file mode 100644 index 0000000..47485a4 Binary files /dev/null and b/WebContent/WEB-INF/lib/spring-beans-4.0.3.RELEASE.jar differ diff --git a/WebContent/WEB-INF/lib/spring-context-4.0.3.RELEASE.jar b/WebContent/WEB-INF/lib/spring-context-4.0.3.RELEASE.jar new file mode 100644 index 0000000..7e8bd16 Binary files /dev/null and b/WebContent/WEB-INF/lib/spring-context-4.0.3.RELEASE.jar differ diff --git a/WebContent/WEB-INF/lib/spring-core-4.0.3.RELEASE.jar b/WebContent/WEB-INF/lib/spring-core-4.0.3.RELEASE.jar new file mode 100644 index 0000000..12e99f6 Binary files /dev/null and b/WebContent/WEB-INF/lib/spring-core-4.0.3.RELEASE.jar differ diff --git a/WebContent/WEB-INF/lib/spring-expression-4.0.3.RELEASE.jar b/WebContent/WEB-INF/lib/spring-expression-4.0.3.RELEASE.jar new file mode 100644 index 0000000..6030380 Binary files /dev/null and b/WebContent/WEB-INF/lib/spring-expression-4.0.3.RELEASE.jar differ diff --git a/WebContent/WEB-INF/lib/spring-web-4.0.3.RELEASE.jar b/WebContent/WEB-INF/lib/spring-web-4.0.3.RELEASE.jar new file mode 100644 index 0000000..ceef695 Binary files /dev/null and b/WebContent/WEB-INF/lib/spring-web-4.0.3.RELEASE.jar differ diff --git a/WebContent/WEB-INF/lib/spring-webmvc-4.0.3.RELEASE.jar b/WebContent/WEB-INF/lib/spring-webmvc-4.0.3.RELEASE.jar new file mode 100644 index 0000000..4f895da Binary files /dev/null and b/WebContent/WEB-INF/lib/spring-webmvc-4.0.3.RELEASE.jar differ diff --git a/WebContent/WEB-INF/spring/webcontext/DispatcherServlet-context.xml b/WebContent/WEB-INF/spring/webcontext/DispatcherServlet-context.xml new file mode 100644 index 0000000..94f5970 --- /dev/null +++ b/WebContent/WEB-INF/spring/webcontext/DispatcherServlet-context.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/views/flight.jsp b/WebContent/WEB-INF/views/flight.jsp new file mode 100644 index 0000000..daf34ea --- /dev/null +++ b/WebContent/WEB-INF/views/flight.jsp @@ -0,0 +1,37 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + +Welcome + + + + +
+
+
+

${greeting}

+

${tagline}

+
+
+
+ +

Flight Information for the request

+
+
+

${info}

+
+
+ + + \ No newline at end of file diff --git a/WebContent/WEB-INF/views/search.jsp b/WebContent/WEB-INF/views/search.jsp new file mode 100644 index 0000000..2bdbb73 --- /dev/null +++ b/WebContent/WEB-INF/views/search.jsp @@ -0,0 +1,18 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> + + + + + Welcome + + + + + + + +
Login + Register +
+ + \ No newline at end of file diff --git a/WebContent/WEB-INF/views/welcome.jsp b/WebContent/WEB-INF/views/welcome.jsp new file mode 100644 index 0000000..32a6bb0 --- /dev/null +++ b/WebContent/WEB-INF/views/welcome.jsp @@ -0,0 +1,50 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + +Welcome + + +
+
+
+

${greeting}

+

${tagline}

+
+
+
+
+
+ + + + + + + + + + + + + + + +
+
+ +

Flight Information for the request

+
+
+

${info}

+
+
+ + + + \ No newline at end of file diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..c252d0e --- /dev/null +++ b/WebContent/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + DispatcherServlet + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + + /WEB-INF/spring/webcontext/DispatcherServlet-context.xml + + + + + + DispatcherServlet + / + + + \ No newline at end of file diff --git a/flight-sample.json b/flight-sample.json new file mode 100644 index 0000000..00c65bb --- /dev/null +++ b/flight-sample.json @@ -0,0 +1,148 @@ +[ + { + "flightNumber": "2005", + "carrier": "UA", + "origin": "IAH", + "departure": "2018-01-31T05:10:00", + "destination": "ORD", + "arrival": "2018-01-31T07:57:00", + "aircraft": "Airbus A320", + "distance": 925, + "travelTime": "02:47", + "status": "Arrived at Gate" + + }, + { + "flightNumber": "0638", + "carrier": "UA", + "origin": "IAH", + "departure": "2018-01-31T07:45:00", + "destination": "ORD", + "arrival": "2018-01-31T10:18:00", + "aircraft": "Boeing 737-900", + "distance": 925, + "travelTime": "02:33", + "status": "Arrived at Gate" + }, + { + "flightNumber": "1160", + "carrier": "UA", + "origin": "IAH", + "departure": "2018-01-31T12:05:00", + "destination": "ORD", + "arrival": "2018-01-31T14:38:00", + "aircraft": "Boeing 737-800", + "distance": 925, + "travelTime": "02:41", + "status": "Arrived at Gate" + }, + { + "flightNumber": "1256", + "carrier": "UA", + "origin": "IAH", + "departure": "2018-01-31T14:22:00", + "destination": "ORD", + "arrival": "2018-01-31T17:01:00", + "aircraft": "Boeing 737-800", + "distance": 925, + "travelTime": "02:41", + "status": "On Time" + }, + { + "flightNumber": "2153", + "carrier": "UA", + "origin": "IAH", + "departure": "2018-01-31T16:24:00", + "destination": "ORD", + "arrival": "2018-01-31T19:27:00", + "aircraft": "Boeing 737-800", + "distance": 925, + "travelTime": "02:47", + "status": "On Time" + }, + { + "flightNumber": "2155", + "carrier": "UA", + "origin": "IAH", + "departure": "2018-01-31T18:10:00", + "destination": "ORD", + "arrival": "2018-01-31T20:49:00", + "aircraft": "Boeing 737-900", + "distance": 925, + "travelTime": "02:39", + "status": "On Time" + }, + { + "flightNumber": "2131", + "carrier": "UA", + "origin": "IAH", + "departure": "2018-01-31T19:49:00", + "destination": "ORD", + "arrival": "2018-01-31T22:00:00", + "aircraft": "Boeing 737-900", + "distance": 925, + "travelTime": "02:31", + "status": "On Time" + }, + { + "flightNumber": "2043", + "carrier": "UA", + "origin": "ORD", + "departure": "2018-01-31T06:08:00", + "destination": "IAH", + "arrival": "2018-01-31T08:42:00", + "aircraft": "Boeing 737-800", + "distance": 925, + "travelTime": "02:34", + "status": "Arrived at Gate" + }, + { + "flightNumber": "0748", + "carrier": "UA", + "origin": "ORD", + "departure": "2018-01-31T08:10:00", + "destination": "IAH", + "arrival": "2018-01-31T10:44:00", + "aircraft": "Boeing 737-900", + "distance": 925, + "travelTime": "02:34", + "status": "Arrived at Gate" + }, + { + "flightNumber": "2166", + "carrier": "UA", + "origin": "ORD", + "departure": "2018-01-31T10:15:00", + "destination": "IAH", + "arrival": "2018-01-31T12:53:00", + "aircraft": "Airbus A320", + "distance": 925, + "travelTime": "02:34", + "status": "Arrived at Gate" + }, + { + "flightNumber": "2171", + "carrier": "UA", + "origin": "ORD", + "departure": "2018-01-31T12:45:00", + "destination": "IAH", + "arrival": "2018-01-31T15:34:00", + "aircraft": "Airbus A320", + "distance": 925, + "travelTime": "02:39", + "status": "On Time" + }, + { + "flightNumber": "1128", + "carrier": "UA", + "origin": "ORD", + "departure": "2018-01-31T14:05:00", + "destination": "IAH", + "arrival": "2018-01-31T16:52:00", + "aircraft": "Boeing 737-800", + "distance": 925, + "travelTime": "02:41", + "status": "On Time" + } + +] diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8370601 --- /dev/null +++ b/pom.xml @@ -0,0 +1,72 @@ + + 4.0.0 + com.flight + simpleFlightSearch + 0.0.1-SNAPSHOT + SearchFlights + war + + + + org.springframework + spring-webmvc + 4.3.9.RELEASE + + + org.springframework + spring-web + 4.3.9.RELEASE + + + org.slf4j + jcl-over-slf4j + 1.7.12 + + + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + javax.servlet + jstl + 1.2 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + + + + + maven-compiler-plugin + 3.6.1 + + 1.7 + 1.7 + + + + maven-war-plugin + 3.0.0 + + WebContent + + + + ${project.artifactId} + + \ No newline at end of file diff --git a/src/main/java/com/flight/simpleFlightSearch/controller/FlightSearchController.java b/src/main/java/com/flight/simpleFlightSearch/controller/FlightSearchController.java new file mode 100644 index 0000000..1971002 --- /dev/null +++ b/src/main/java/com/flight/simpleFlightSearch/controller/FlightSearchController.java @@ -0,0 +1,68 @@ +package com.flight.simpleFlightSearch.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.simple.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.view.RedirectView; + +import com.flight.simpleFlightSearch.model.FlightInfo; +import com.flight.simpleFlightSearch.service.FlightService; + +//import jbr.springmvc.model.Login; +//import jbr.springmvc.model.User; +//import jbr.springmvc.service.UserService; +@Controller +@Component +public class FlightSearchController { + @Autowired + FlightService flightService; +// @RequestMapping(value = "/search", method = RequestMethod.GET) +// public ModelAndView showLogin(HttpServletRequest request, HttpServletResponse response) { +// ModelAndView mav = new ModelAndView("login"); +// //mav.addObject("login", new Login()); +// return mav; +// } + String num =""; + JSONObject status= null; + @RequestMapping(value = "/", method = RequestMethod.GET) + public String welcome(Model model) + { + model.addAttribute("greeting","Welcome to Flight Search Application"); + model.addAttribute("Welcome aboard!! ", num); + model.addAttribute("info", "Please enter a valid Flight Number"); + return "welcome"; + } + + @RequestMapping(value = "/flight", method = RequestMethod.GET) + public String searchflight(Model model) { + if (null != status) + { + String information = status.entrySet().toString(); + model.addAttribute("info", status.entrySet().toString()); + } + else + model.addAttribute("info", "Invalid Flight number"); + return "flight"; + } + + @RequestMapping(value = "/search", method = RequestMethod.GET) + public RedirectView search(@RequestParam(value="flightNum") String fNum, Model model) { + num = fNum; + status = flightService.flightDataFromJson(num); + if (null != status) + return new RedirectView("flight"); + else return new RedirectView("welcome"); + } + +} \ No newline at end of file diff --git a/src/main/java/com/flight/simpleFlightSearch/model/FlightInfo.java b/src/main/java/com/flight/simpleFlightSearch/model/FlightInfo.java new file mode 100644 index 0000000..6a26d38 --- /dev/null +++ b/src/main/java/com/flight/simpleFlightSearch/model/FlightInfo.java @@ -0,0 +1,32 @@ +package com.flight.simpleFlightSearch.model; + +public class FlightInfo { + private String flightNumber; + private String Origin; + private String destination; + private String date; + public String getFlightNumber() { + return flightNumber; + } + public void setFlightNumber(String flightNumber) { + this.flightNumber = flightNumber; + } + public String getOrigin() { + return Origin; + } + public void setOrigin(String origin) { + Origin = origin; + } + public String getDestination() { + return destination; + } + public void setDestination(String destination) { + this.destination = destination; + } + public String getDate() { + return date; + } + public void setDate(String date) { + this.date = date; + } + } diff --git a/src/main/java/com/flight/simpleFlightSearch/service/FlightService.java b/src/main/java/com/flight/simpleFlightSearch/service/FlightService.java new file mode 100644 index 0000000..5283324 --- /dev/null +++ b/src/main/java/com/flight/simpleFlightSearch/service/FlightService.java @@ -0,0 +1,9 @@ +package com.flight.simpleFlightSearch.service; + +import org.json.simple.JSONObject; + + +public interface FlightService { + + public JSONObject flightDataFromJson(String numberFl); +} diff --git a/src/main/java/com/flight/simpleFlightSearch/service/impl/FlightServiceImpl.java b/src/main/java/com/flight/simpleFlightSearch/service/impl/FlightServiceImpl.java new file mode 100644 index 0000000..3e85bcf --- /dev/null +++ b/src/main/java/com/flight/simpleFlightSearch/service/impl/FlightServiceImpl.java @@ -0,0 +1,62 @@ +package com.flight.simpleFlightSearch.service.impl; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; + +import org.json.simple.parser.ParseException; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +import com.flight.simpleFlightSearch.service.FlightService; + + + +@Service +public class FlightServiceImpl implements FlightService{ + + + public JSONObject flightDataFromJson(String numberFl) + { + JSONParser jsonParser = new JSONParser(); + JSONObject myList = null; + + try (FileReader reader = new FileReader("//Users//Chinthy//git//simpleFlightSearch//flight-docs//flight-sample.json")) + { + //Read JSON file + Object obj = jsonParser.parse(reader); + + JSONArray flightList = (JSONArray) obj; + + Iterator iterator = flightList.iterator(); + while (iterator.hasNext()) { + JSONObject jsonObject1 = ((JSONObject) iterator.next()); + Iterator > it = jsonObject1.entrySet().iterator(); + while(it.hasNext()) { + + if(it.next().getValue().equals(numberFl)) + { + myList = jsonObject1; + System.out.println("iterator element : "+jsonObject1.entrySet()); + } + } + } + + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return myList; + } +} + diff --git a/src/main/webapp/WEB-INF/spring/webcontext/DispatcherServlet-context.xml b/src/main/webapp/WEB-INF/spring/webcontext/DispatcherServlet-context.xml new file mode 100644 index 0000000..81548e6 --- /dev/null +++ b/src/main/webapp/WEB-INF/spring/webcontext/DispatcherServlet-context.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..c252d0e --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + DispatcherServlet + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + + /WEB-INF/spring/webcontext/DispatcherServlet-context.xml + + + + + + DispatcherServlet + / + + + \ No newline at end of file