diff --git a/EngineeringEssentialsServices/data/allParticipatingCountries.json b/EngineeringEssentialsServices/data/allParticipatingCountries.json new file mode 100644 index 0000000..2c71498 --- /dev/null +++ b/EngineeringEssentialsServices/data/allParticipatingCountries.json @@ -0,0 +1,109 @@ +[ { + "date" : "2018-03-12", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 13, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Japan" +}, { + "date" : "2018-03-06", + "winningCountry" : "Australia", + "losingCountry" : "UnitedStates", + "winningScore" : 11, + "losingScore" : 7, + "eventType" : "Curling", + "homeCountry" : "UnitedStates", + "awayCountry" : "Australia" +}, { + "date" : "2018-03-25", + "winningCountry" : "Japan", + "losingCountry" : "India", + "winningScore" : 14, + "losingScore" : 8, + "eventType" : "Curling", + "homeCountry" : "Japan", + "awayCountry" : "India" +}, { + "date" : "2018-03-17", + "winningCountry" : "England", + "losingCountry" : "UnitedStates", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-03-12", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 11, + "losingScore" : 8, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-03-19", + "winningCountry" : "China", + "losingCountry" : "Australia", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "China" +}, { + "date" : "2018-03-16", + "winningCountry" : "Australia", + "losingCountry" : "England", + "winningScore" : 13, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "England" +}, { + "date" : "2018-03-13", + "winningCountry" : "Australia", + "losingCountry" : "Brazil", + "winningScore" : 14, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "Australia" +}, { + "date" : "2018-03-17", + "winningCountry" : "Australia", + "losingCountry" : "India", + "winningScore" : 15, + "losingScore" : 7, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "India" +}, { + "date" : "2018-03-19", + "winningCountry" : "England", + "losingCountry" : "China", + "winningScore" : 14, + "losingScore" : 8, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "England" +}, { + "date" : "2018-03-19", + "winningCountry" : "Japan", + "losingCountry" : "Australia", + "winningScore" : 10, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "Australia" +}, { + "date" : "2018-03-25", + "winningCountry" : "China", + "losingCountry" : "England", + "winningScore" : 11, + "losingScore" : 6, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "China" +} ] \ No newline at end of file diff --git a/EngineeringEssentialsServices/data/events.json b/EngineeringEssentialsServices/data/events.json new file mode 100644 index 0000000..8d72933 --- /dev/null +++ b/EngineeringEssentialsServices/data/events.json @@ -0,0 +1,901 @@ +[ { + "date" : "2018-02-09", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "India" +}, { + "date" : "2018-02-20", + "winningCountry" : "India", + "losingCountry" : "China", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "India" +}, { + "date" : "2018-02-16", + "winningCountry" : "Portugal", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-14", + "winningCountry" : "China", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "China" +}, { + "date" : "2018-02-15", + "winningCountry" : "Australia", + "losingCountry" : "India", + "winningScore" : 10, + "losingScore" : 4, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "India" +}, { + "date" : "2018-02-11", + "winningCountry" : "UnitedStates", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 2, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-04", + "winningCountry" : "Japan", + "losingCountry" : "India", + "winningScore" : 13, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-02", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 15, + "losingScore" : 8, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-19", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-23", + "winningCountry" : "England", + "losingCountry" : "India", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "India" +}, { + "date" : "2018-02-13", + "winningCountry" : "UnitedStates", + "losingCountry" : "Portugal", + "winningScore" : 11, + "losingScore" : 5, + "eventType" : "Baseball", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-07", + "winningCountry" : "England", + "losingCountry" : "Brazil", + "winningScore" : 15, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-22", + "winningCountry" : "China", + "losingCountry" : "India", + "winningScore" : 11, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "China", + "awayCountry" : "India" +}, { + "date" : "2018-02-19", + "winningCountry" : "Portugal", + "losingCountry" : "China", + "winningScore" : 10, + "losingScore" : 0, + "eventType" : "Curling", + "homeCountry" : "China", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-10", + "winningCountry" : "UnitedStates", + "losingCountry" : "Brazil", + "winningScore" : 10, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-08", + "winningCountry" : "Portugal", + "losingCountry" : "India", + "winningScore" : 15, + "losingScore" : 5, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-05", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 11, + "losingScore" : 8, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-08", + "winningCountry" : "China", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-14", + "winningCountry" : "China", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "China" +}, { + "date" : "2018-02-07", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 14, + "losingScore" : 5, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "China" +}, { + "date" : "2018-02-27", + "winningCountry" : "India", + "losingCountry" : "China", + "winningScore" : 15, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "China", + "awayCountry" : "India" +}, { + "date" : "2018-02-10", + "winningCountry" : "Portugal", + "losingCountry" : "UnitedStates", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "Curling", + "homeCountry" : "UnitedStates", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-20", + "winningCountry" : "Australia", + "losingCountry" : "England", + "winningScore" : 13, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "Australia", + "awayCountry" : "England" +}, { + "date" : "2018-02-24", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-13", + "winningCountry" : "England", + "losingCountry" : "Portugal", + "winningScore" : 10, + "losingScore" : 0, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "England" +}, { + "date" : "2018-02-25", + "winningCountry" : "India", + "losingCountry" : "China", + "winningScore" : 15, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "China" +}, { + "date" : "2018-02-12", + "winningCountry" : "UnitedStates", + "losingCountry" : "Portugal", + "winningScore" : 10, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-05", + "winningCountry" : "Brazil", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "Brazil", + "awayCountry" : "India" +}, { + "date" : "2018-02-06", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 14, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "China" +}, { + "date" : "2018-02-15", + "winningCountry" : "Australia", + "losingCountry" : "India", + "winningScore" : 11, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "India" +}, { + "date" : "2018-02-08", + "winningCountry" : "England", + "losingCountry" : "Brazil", + "winningScore" : 11, + "losingScore" : 6, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-04", + "winningCountry" : "Portugal", + "losingCountry" : "India", + "winningScore" : 13, + "losingScore" : 1, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "India" +}, { + "date" : "2018-02-24", + "winningCountry" : "England", + "losingCountry" : "Japan", + "winningScore" : 14, + "losingScore" : 0, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "England" +}, { + "date" : "2018-02-16", + "winningCountry" : "Brazil", + "losingCountry" : "Australia", + "winningScore" : 11, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "Australia", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-05", + "winningCountry" : "India", + "losingCountry" : "Australia", + "winningScore" : 14, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "India" +}, { + "date" : "2018-02-13", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 13, + "losingScore" : 6, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-04", + "winningCountry" : "UnitedStates", + "losingCountry" : "England", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-26", + "winningCountry" : "Portugal", + "losingCountry" : "UnitedStates", + "winningScore" : 11, + "losingScore" : 3, + "eventType" : "Baseball", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-19", + "winningCountry" : "England", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 3, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "England" +}, { + "date" : "2018-02-16", + "winningCountry" : "Brazil", + "losingCountry" : "Portugal", + "winningScore" : 15, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-17", + "winningCountry" : "Brazil", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 8, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-27", + "winningCountry" : "England", + "losingCountry" : "India", + "winningScore" : 15, + "losingScore" : 3, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "India" +}, { + "date" : "2018-02-07", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-13", + "winningCountry" : "Portugal", + "losingCountry" : "India", + "winningScore" : 10, + "losingScore" : 2, + "eventType" : "Curling", + "homeCountry" : "Portugal", + "awayCountry" : "India" +}, { + "date" : "2018-02-03", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 14, + "losingScore" : 8, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "China" +}, { + "date" : "2018-02-11", + "winningCountry" : "UnitedStates", + "losingCountry" : "Portugal", + "winningScore" : 14, + "losingScore" : 7, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-25", + "winningCountry" : "Portugal", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-04", + "winningCountry" : "Australia", + "losingCountry" : "Portugal", + "winningScore" : 14, + "losingScore" : 4, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-27", + "winningCountry" : "Australia", + "losingCountry" : "Portugal", + "winningScore" : 10, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-16", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 13, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-22", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 14, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "China" +}, { + "date" : "2018-02-24", + "winningCountry" : "Brazil", + "losingCountry" : "Portugal", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "Portugal", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-14", + "winningCountry" : "Australia", + "losingCountry" : "China", + "winningScore" : 12, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "China", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-20", + "winningCountry" : "Japan", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 6, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-05", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "China" +}, { + "date" : "2018-02-17", + "winningCountry" : "UnitedStates", + "losingCountry" : "Brazil", + "winningScore" : 11, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "UnitedStates", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-04", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-08", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 12, + "losingScore" : 8, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-01", + "winningCountry" : "Australia", + "losingCountry" : "Brazil", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-03", + "winningCountry" : "England", + "losingCountry" : "UnitedStates", + "winningScore" : 14, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "UnitedStates", + "awayCountry" : "England" +}, { + "date" : "2018-02-06", + "winningCountry" : "Australia", + "losingCountry" : "Japan", + "winningScore" : 10, + "losingScore" : 7, + "eventType" : "Baseball", + "homeCountry" : "Japan", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-23", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-10", + "winningCountry" : "Australia", + "losingCountry" : "Portugal", + "winningScore" : 13, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-21", + "winningCountry" : "England", + "losingCountry" : "UnitedStates", + "winningScore" : 15, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "UnitedStates", + "awayCountry" : "England" +}, { + "date" : "2018-02-27", + "winningCountry" : "Brazil", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-09", + "winningCountry" : "England", + "losingCountry" : "Japan", + "winningScore" : 15, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "Japan", + "awayCountry" : "England" +}, { + "date" : "2018-02-21", + "winningCountry" : "Portugal", + "losingCountry" : "China", + "winningScore" : 11, + "losingScore" : 3, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-12", + "winningCountry" : "Australia", + "losingCountry" : "England", + "winningScore" : 11, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "Australia", + "awayCountry" : "England" +}, { + "date" : "2018-02-02", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 13, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-24", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 14, + "losingScore" : 9, + "eventType" : "Curling", + "homeCountry" : "Japan", + "awayCountry" : "India" +}, { + "date" : "2018-02-07", + "winningCountry" : "Portugal", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 2, + "eventType" : "Curling", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-25", + "winningCountry" : "England", + "losingCountry" : "China", + "winningScore" : 15, + "losingScore" : 7, + "eventType" : "Curling", + "homeCountry" : "China", + "awayCountry" : "England" +}, { + "date" : "2018-02-20", + "winningCountry" : "Australia", + "losingCountry" : "China", + "winningScore" : 13, + "losingScore" : 7, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "China" +}, { + "date" : "2018-02-26", + "winningCountry" : "Japan", + "losingCountry" : "Australia", + "winningScore" : 14, + "losingScore" : 9, + "eventType" : "Baseball", + "homeCountry" : "Japan", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-13", + "winningCountry" : "England", + "losingCountry" : "Portugal", + "winningScore" : 14, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-08", + "winningCountry" : "Japan", + "losingCountry" : "India", + "winningScore" : 11, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "India" +}, { + "date" : "2018-02-06", + "winningCountry" : "England", + "losingCountry" : "Portugal", + "winningScore" : 14, + "losingScore" : 1, + "eventType" : "Curling", + "homeCountry" : "England", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-19", + "winningCountry" : "Brazil", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-04", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 11, + "losingScore" : 2, + "eventType" : "WaterPolo", + "homeCountry" : "Brazil", + "awayCountry" : "China" +}, { + "date" : "2018-02-17", + "winningCountry" : "Portugal", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "Portugal", + "awayCountry" : "England" +}, { + "date" : "2018-02-18", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 11, + "losingScore" : 1, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-05", + "winningCountry" : "Brazil", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "Australia", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-21", + "winningCountry" : "Japan", + "losingCountry" : "Australia", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-20", + "winningCountry" : "Japan", + "losingCountry" : "UnitedStates", + "winningScore" : 13, + "losingScore" : 6, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-20", + "winningCountry" : "UnitedStates", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "UnitedStates", + "awayCountry" : "England" +}, { + "date" : "2018-02-18", + "winningCountry" : "Portugal", + "losingCountry" : "Brazil", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "Brazil", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-18", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 12, + "losingScore" : 7, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "India" +}, { + "date" : "2018-02-11", + "winningCountry" : "India", + "losingCountry" : "Portugal", + "winningScore" : 15, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "India" +}, { + "date" : "2018-02-04", + "winningCountry" : "Brazil", + "losingCountry" : "Portugal", + "winningScore" : 15, + "losingScore" : 1, + "eventType" : "Curling", + "homeCountry" : "Portugal", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-22", + "winningCountry" : "Japan", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "UnitedStates", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-10", + "winningCountry" : "England", + "losingCountry" : "Brazil", + "winningScore" : 12, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "England" +}, { + "date" : "2018-02-26", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "China" +}, { + "date" : "2018-02-04", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 13, + "losingScore" : 7, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "India" +}, { + "date" : "2018-02-12", + "winningCountry" : "Japan", + "losingCountry" : "India", + "winningScore" : 10, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-10", + "winningCountry" : "Australia", + "losingCountry" : "Brazil", + "winningScore" : 11, + "losingScore" : 6, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-21", + "winningCountry" : "India", + "losingCountry" : "Brazil", + "winningScore" : 14, + "losingScore" : 2, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-17", + "winningCountry" : "Australia", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "England" +}, { + "date" : "2018-02-19", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 14, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-12", + "winningCountry" : "Japan", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 7, + "eventType" : "Baseball", + "homeCountry" : "Japan", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-16", + "winningCountry" : "England", + "losingCountry" : "India", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "England" +} ] \ No newline at end of file diff --git a/EngineeringEssentialsServices/data/single-event.json b/EngineeringEssentialsServices/data/single-event.json new file mode 100644 index 0000000..fc7c0e0 --- /dev/null +++ b/EngineeringEssentialsServices/data/single-event.json @@ -0,0 +1,10 @@ +{ + "eventType":"WaterPolo", + "homeCountry": "Portugal", + "awayCountry": "Australia", + "date": "2018-02-27", + "winningCountry": "Portugal", + "losingCountry": "Australia", + "winningScore": 22, + "losingScore": 4 +} \ No newline at end of file diff --git a/EngineeringEssentialsServices/pom.xml b/EngineeringEssentialsServices/pom.xml new file mode 100644 index 0000000..aecbc0a --- /dev/null +++ b/EngineeringEssentialsServices/pom.xml @@ -0,0 +1,51 @@ + + + + + + engineering-essentials + EngineeringEssentials + 1.0-SNAPSHOT + + 4.0.0 + + engineering-essentials-services + + + EngineeringEssentials + engineering-essentials-Examples + 1.0-SNAPSHOT + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example10Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example10Resource.java new file mode 100644 index 0000000..4f9558b --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example10Resource.java @@ -0,0 +1,58 @@ +package examples; + + +import model.Team; +import utility.FileHelper; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example10Resource { + + /** + * Example 10 Instructions: + * + * Modify the updateTeam method below to save the "team" that is passed in into a file with the pattern + * -team.json + * + * Use the appropriate method from FileHelper to write to the file. Then check to make sure it was successful with the GET + * method provided below + * + * URL: http://localhost:8080/events/team/{teamName} + */ + @PUT + @Path("team") + @Consumes(MediaType.APPLICATION_JSON) + public Response updateTeam(Team team) { + + return Response.ok().build(); + } + + @GET + @Path("team/{teamName}") + @Produces(MediaType.APPLICATION_JSON) + public Team getTeam(@PathParam("teamName") String teamName) throws IOException { + + return FileHelper.readTeamFromFile(teamName.toLowerCase().concat("-team.json")); + } + + +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example11Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example11Resource.java new file mode 100644 index 0000000..8ddeebe --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example11Resource.java @@ -0,0 +1,54 @@ +package examples; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example11Resource { + + /** + * Example 11 Instructions: + * + * Create a DELETE method called cancelEvent() that will update the events to cancel all events with a given + * eventType, home country, and away country. + * + * The Event Cancelled was a Baseball game where China is the Home Country and Australia is the Away Country + * + * Save the remaining events in remaining-events.json + * Return either a 200 OK or a 500 Internal Server error if it fails to delete an event + * Return the list of cancelled events in the entity. + * + * Compare the remaining-events.json file to events.json file to check that the proper events were deleted + * + */ + @DELETE + @Path("cancel/{eventType}/home/{homeCountry}/away/{awayCountry}") + @Consumes(MediaType.APPLICATION_JSON) + public Response cancelEvent() throws IOException{ + final String filename = "remaining-events.json"; + + return null; + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example12Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example12Resource.java new file mode 100644 index 0000000..993659a --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example12Resource.java @@ -0,0 +1,54 @@ +package examples; + + +import model.Event; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.text.ParseException; +import java.util.Date; +import java.util.List; + +import static utility.FileHelper.DATEFORMAT; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example12Resource { + + /** + * Example 12 Instructions: + * + * Fill in the function below to return a list of events that occur inbetween the start and end dates (inclusive) + * + * Hint: Read in the dates as Strings + * + * URL: http://localhost:8080/events/startDate/2018-03-07/endDate/2018-03-14 + */ + @GET + @Path("") + @Produces(MediaType.APPLICATION_JSON) + public List getEventsInRange() throws ParseException { + + Date startDate = DATEFORMAT.parse(""); + Date endDate = DATEFORMAT.parse(""); + + return null; + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example1Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example1Resource.java new file mode 100644 index 0000000..2110d37 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example1Resource.java @@ -0,0 +1,43 @@ +package examples; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("hello") +public class Example1Resource { + + + /** + * Example 1 Instructions: + * + * + * Run your StartApp with program Arguments: server + * Go to http://localhost:8080/hello/ok and verify your server is running. + */ + + @GET + @Path("/ok") + @Produces(MediaType.APPLICATION_JSON) + public Response getResponse() throws IOException { + return Response.status(Response.Status.OK).entity("Congratulations! You have Successfully started your Rest Server!").build(); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example2Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example2Resource.java new file mode 100644 index 0000000..daf304e --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example2Resource.java @@ -0,0 +1,38 @@ +package examples; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example2Resource { + + /** + * Example 2 Instructions: + * Modify the method below to return the String "Welcome to Engineering Essentials Services Training!" + * + * Restart the Server and visit http://localhost:8080/events/test + */ + @GET + @Path("test") + @Produces(MediaType.APPLICATION_JSON) + public String helloWorld() { + return "Hello, world!"; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example3Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example3Resource.java new file mode 100644 index 0000000..7abb6ab --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example3Resource.java @@ -0,0 +1,48 @@ +package examples; + + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("hello") +public class Example3Resource { + + /** + * Example 3 Instructions: + * + * Modify the method below so that when you restart the Server and visit the URL, + * you see "This site is now fixed." + * + * 1) You will have to change the @Path + * 2) You will have to change the string returned + * 3) Your will have to change the status returned to Response.Status.OK + * + * URL: http://localhost:8080/response/test/fixed + */ + @GET + @Path("/broken") + @Produces(MediaType.APPLICATION_JSON) + public Response getResponse() throws IOException { + String properResponse = "This site is now fixed."; + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Broken").build(); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example4Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example4Resource.java new file mode 100644 index 0000000..dcd0c5f --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example4Resource.java @@ -0,0 +1,48 @@ +package examples; + + +import model.Event; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example4Resource { + + + /** + * Example 4 Instructions: + * + * Use the appropriate method from FileHelper.java (utility folder) to read in a single event from the file + * "single-event.json" and return this event + * + * Hint: the method below is missing an annotation + * + * URL: http://localhost:8080/events/sample + */ + @Path("sample") + @Produces(MediaType.APPLICATION_JSON) + public Response getSampleEvent() { + + Event event = null; + return Response.ok().entity(event).build(); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example5Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example5Resource.java new file mode 100644 index 0000000..1626ed4 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example5Resource.java @@ -0,0 +1,50 @@ +package examples; + + +import model.Event; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example5Resource { + + + /** + * Example 5 Instructions: + * + * Add the proper @Produces Annotation to the method below + * and then use the appropriate method from FileHelper to read and return + * the list of all of the events in the events.json file + * + * URL: http://localhost:8080/events/all + */ + @GET + @Path("all") + public Response getAllEvents() throws IOException { + + List events = null; + return Response.ok().entity(events).build(); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example6Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example6Resource.java new file mode 100644 index 0000000..7463dd5 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example6Resource.java @@ -0,0 +1,46 @@ +package examples; + + +import model.Country; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example6Resource { + + /** + * Example 6 Instructions: + * Add the functionality to return a list of Countries that participated in at least 1 event + * + * URL: http://localhost:8080/events/allParticipatingCountries + * + */ + @GET + @Path("replace") + @Produces(MediaType.APPLICATION_JSON) + public Response getAllParticipatingCountries() { + + List participatingCountries = null; + return null; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example7Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example7Resource.java new file mode 100644 index 0000000..916be88 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example7Resource.java @@ -0,0 +1,52 @@ +package examples; + + +import model.Event; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example7Resource { + + /** + * Example 7 Instructions: + * + * Modify the method below to return the list of all of the events that a country participated in + * + * Note: The country name should be case insensitive ("UnitedStates" returns the same results as "UnitedStates") + * If no events are found for a country, return a message stating the country was not found + * + * URL: http://localhost:8080/events/country/{countryName} + */ + @GET + @Path("country/{countryName}") + @Produces(MediaType.APPLICATION_JSON) + public Response getEventsForCountry(@PathParam("countryName") String countryName) throws IOException { + + return null; + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example8Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example8Resource.java new file mode 100644 index 0000000..976a7a6 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example8Resource.java @@ -0,0 +1,41 @@ +package examples; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example8Resource { + + /** + * Example 8 Instructions: + * Fill in the method below so that for a given country, this endpoint returns the number of wins that country has + * + * Hint: Don't forget the @PathParam annotation + * + * URL: http://localhost:8080/events/UnitedStates/wins + * URL: http://localhost:8080/events/China/wins + * + */ + @GET + @Path("replace this") + public int getWins(String country) { + return 0; + } +} + diff --git a/EngineeringEssentialsServices/src/main/java/examples/Example9Resource.java b/EngineeringEssentialsServices/src/main/java/examples/Example9Resource.java new file mode 100644 index 0000000..75b33da --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/examples/Example9Resource.java @@ -0,0 +1,50 @@ +package examples; + +import com.fasterxml.jackson.databind.ObjectMapper; +import model.Event; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example9Resource { + + + /** + * Example 9 Instructions: + * + * Part 1: + * Create a Sample Event and save it to the test-create-event.json file using the POST method createEvent + * Return a response with Status.OK after creating the event + * + * Part 2: Add a getNewEvent method that would reads the file test-create-event.json and returns the created event + * + * URL (after part 2): http://localhost:8080/events/newEvent + */ + @Path("") + @Consumes(MediaType.APPLICATION_JSON) + public Response createEvent(Event newEvent) throws IOException{ + final String filename = "test-create-event.json"; + return null; + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/model/Country.java b/EngineeringEssentialsServices/src/main/java/model/Country.java new file mode 100644 index 0000000..3f78e5d --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/model/Country.java @@ -0,0 +1,28 @@ +package model; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public enum Country { + + UnitedStates, + England, + India, + Brazil, + Australia, + Japan, + China, + Portugal +} diff --git a/EngineeringEssentialsServices/src/main/java/model/Event.java b/EngineeringEssentialsServices/src/main/java/model/Event.java new file mode 100644 index 0000000..369b1ad --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/model/Event.java @@ -0,0 +1,137 @@ +package model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Date; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class Event { + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd", timezone="GMT-5") + private Date date; + @JsonProperty + private Country winningCountry; + @JsonProperty + private Country losingCountry; + @JsonProperty + private int winningScore; + @JsonProperty + private int losingScore; + @JsonProperty + private EventType eventType; + @JsonProperty + private Country homeCountry; + @JsonProperty + private Country awayCountry; + + + public EventType getEventType() { + return eventType; + } + + public void setEventType(EventType eventType) { + this.eventType = eventType; + } + + public Country getHomeCountry() { + return homeCountry; + } + + public void setHomeCountry(Country homeCountry) { + this.homeCountry = homeCountry; + } + + public Country getAwayCountry() { + return awayCountry; + } + + public void setAwayCountry(Country awayCountry) { + this.awayCountry = awayCountry; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public Country getLosingCountry() { + return losingCountry; + } + + public void setLosingCountry(Country losingCountry) { + this.losingCountry = losingCountry; + } + + public Country getWinningCountry() { + return winningCountry; + } + + public void setWinningCountry(Country winningCountry) { + this.winningCountry = winningCountry; + } + + public int getWinningScore() { + return winningScore; + } + + public void setWinningScore(int winningScore) { + this.winningScore = winningScore; + } + + public int getLosingScore() { + return losingScore; + } + + public void setLosingScore(int losingScore) { + this.losingScore = losingScore; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Event)) return false; + + Event event = (Event) o; + + if (getWinningScore() != event.getWinningScore()) return false; + if (getLosingScore() != event.getLosingScore()) return false; + if (!getDate().equals(event.getDate())) return false; + if (getWinningCountry() != event.getWinningCountry()) return false; + if (getLosingCountry() != event.getLosingCountry()) return false; + if (getEventType() != event.getEventType()) return false; + if (getHomeCountry() != event.getHomeCountry()) return false; + return getAwayCountry() == event.getAwayCountry(); + + } + + @Override + public int hashCode() { + int result = getDate().hashCode(); + result = 31 * result + getWinningCountry().hashCode(); + result = 31 * result + getLosingCountry().hashCode(); + result = 31 * result + getWinningScore(); + result = 31 * result + getLosingScore(); + result = 31 * result + getEventType().hashCode(); + result = 31 * result + getHomeCountry().hashCode(); + result = 31 * result + getAwayCountry().hashCode(); + return result; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/model/EventType.java b/EngineeringEssentialsServices/src/main/java/model/EventType.java new file mode 100644 index 0000000..0de8c85 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/model/EventType.java @@ -0,0 +1,22 @@ +package model; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public enum EventType { + WaterPolo, + Baseball, + Curling +} \ No newline at end of file diff --git a/EngineeringEssentialsServices/src/main/java/model/Player.java b/EngineeringEssentialsServices/src/main/java/model/Player.java new file mode 100644 index 0000000..6e22d1a --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/model/Player.java @@ -0,0 +1,70 @@ +package model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Player { + + @JsonProperty + private String name; + + @JsonProperty + private Country country; + + public Player() { + } + + public Player(String name, Country country) { + this.name = name; + this.country = country; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Country getCountry() { + return country; + } + + public void setCountry(Country country) { + this.country = country; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Player)) return false; + + Player player = (Player) o; + + if (!getName().equals(player.getName())) return false; + return getCountry() == player.getCountry(); + + } + + @Override + public int hashCode() { + int result = getName().hashCode(); + result = 31 * result + getCountry().hashCode(); + return result; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/model/Team.java b/EngineeringEssentialsServices/src/main/java/model/Team.java new file mode 100644 index 0000000..67379ef --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/model/Team.java @@ -0,0 +1,64 @@ +package model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Set; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class Team { + + @JsonProperty + private String name; + + @JsonProperty + private Set players; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getPlayers() { + return players; + } + + public void setPlayers(Set players) { + this.players = players; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Team)) return false; + + Team team = (Team) o; + + if (!getName().equals(team.getName())) return false; + return getPlayers().equals(team.getPlayers()); + + } + + @Override + public int hashCode() { + int result = getName().hashCode(); + result = 31 * result + getPlayers().hashCode(); + return result; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/server/StarterApp.java b/EngineeringEssentialsServices/src/main/java/server/StarterApp.java new file mode 100644 index 0000000..8da1636 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/server/StarterApp.java @@ -0,0 +1,103 @@ +package server; + +import examples.*; +import io.dropwizard.Application; +import io.dropwizard.Configuration; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.setup.Environment; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import solutions.Example10SolutionResource; +import solutions.Example11SolutionResource; +import solutions.Example2SolutionResource; +import solutions.Example3SolutionResource; +import solutions.Example4SolutionResource; +import solutions.Example5SolutionResource; +import solutions.Example6SolutionResource; +import solutions.Example7SolutionResource; +import solutions.Example8SolutionResource; +import solutions.Example9SolutionResource; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class StarterApp extends Application { + + /** + * + * General Instructions: + * + * This is a rough guide of how each exercise will go: + * 1) Read the prompt + * 2) Go to ResourcesTest.java and run the example test case, make sure that it fails + * - In some cases the test may not already be filled in for you, then you will have to write the test, + * - and see it fail + * 3) Implement the solution in Example<#>Resource.java + * 4) Go to ResourcesTest.java and run the test, make sure it passes + * 5) Uncomment the example resource in the 'run' method below + * 5) Restart the Server (if you get a "address-in-use bind" error, then you did not properly stop the server + * 6) Visit the URL to confirm it is working (for GET requests) + * 7) Check appropriate JSON file in "data" folder to make sure data was updated properly (for POST, PUT, DELETE) + * + * + */ + + private static final Logger LOGGER = LoggerFactory.getLogger(StarterApp.class); + + private static Example11SolutionResource restService = new Example11SolutionResource(); + + public StarterApp() { + } + + @Override + public void initialize(Bootstrap b) { + + } + + @Override + public void run(Configuration c, Environment e) throws Exception { + LOGGER.info("Registering REST resources"); + e.jersey().register(new Example1Resource()); +// e.jersey().register(new Example2Resource()); +// e.jersey().register(new Example3Resource()); +// e.jersey().register(new Example4Resource()); +// e.jersey().register(new Example5Resource()); +// e.jersey().register(new Example6Resource()); +// e.jersey().register(new Example7Resource()); +// e.jersey().register(new Example8Resource()); +// e.jersey().register(new Example9Resource()); +// e.jersey().register(new Example10Resource()); +// e.jersey().register(new Example11Resource()); +// e.jersey().register(new Example12Resource()); + LOGGER.info("Successfully started REST Service."); + } + + /** + * + * StarterApp Intellij Run Configuration: + * + * Program args: 'server' + * Working Directory: path to EngineeringEssentialsTraining + * - '...\EngineeringEssentials\EngineeringEssentialsTraining" + */ + public static void main(String[] args) throws Exception { + + StarterApp restServer = new StarterApp(); + restServer.run(args); + + System.out.println("Go to localhost:8080/hello/ok in your browser."); + } + +} \ No newline at end of file diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example10SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example10SolutionResource.java new file mode 100644 index 0000000..2a433f2 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example10SolutionResource.java @@ -0,0 +1,47 @@ +package solutions; + +import model.Team; +import utility.FileHelper; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example10SolutionResource { + + @PUT + @Path("team") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response setTeam(Team newTeam) throws IOException { + + FileHelper.writeTeamToFile(newTeam.getName().toLowerCase().concat("-team.json"), newTeam); + + return Response.ok().build(); + } + + @GET + @Path("team/{teamName}") + @Produces(MediaType.APPLICATION_JSON) + public Team getTeam(@PathParam("teamName") String teamName) throws IOException { + + return FileHelper.readTeamFromFile(teamName.toLowerCase().concat("-team.json")); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example11SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example11SolutionResource.java new file mode 100644 index 0000000..3892c5d --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example11SolutionResource.java @@ -0,0 +1,73 @@ +package solutions; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import model.Event; +import utility.FileHelper; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example11SolutionResource { + private ObjectMapper mapper = new ObjectMapper(); + + + /** + * Example 11 Instructions: + *

+ * Create a DELETE method called cancelEvent() that will update the events to remove a cancelled event based on the eventType, home country, and away country. + * The Event Cancelled was a Baseball game where China is the Home Country and Australia is the Away Country + * Save your changes in the test-delete-event.json + * Return either a 200 OK or a 500 Internal Server error if it fails to delete an event + * Return the list of cancelled events in the entity. + */ + + + @DELETE + @Path("cancel/{eventType}/home/{homeCountry}/away/{awayCountry}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response cancelEvent(@PathParam("eventType") String eventType, @PathParam("homeCountry") String home, @PathParam("awayCountry") String away) throws IOException { + final String filename = "remaining-events.json"; + List scheduledEvents = FileHelper.readAllEvents("events.json"); + List cancelled = new ArrayList<>(); + Response.ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR); + try { + for (Event event : scheduledEvents) { + if (event.getHomeCountry().name().equalsIgnoreCase(home) && + event.getAwayCountry().name().equalsIgnoreCase(away) && + event.getEventType().name().equalsIgnoreCase(eventType)) { + cancelled.add(event); + } + } + scheduledEvents.removeAll(cancelled); + FileHelper.writeEventsToFile(filename, scheduledEvents); + return Response.ok().entity(cancelled).build(); + + } catch (Exception e) { + System.out.println("Failed to cancel an event. " + e.getLocalizedMessage()); + } + return response.build(); + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example12SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example12SolutionResource.java new file mode 100644 index 0000000..ef32ba6 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example12SolutionResource.java @@ -0,0 +1,60 @@ +package solutions; + +import model.Event; +import utility.FileHelper; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static utility.FileHelper.DATEFORMAT; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example12SolutionResource { + + + + @GET + @Path("startDate/{startDate}/endDate/{endDate}") + @Produces(MediaType.APPLICATION_JSON) + public List getEventsInRange(@PathParam("startDate") String startDateStr, @PathParam("endDate") String endDateStr) throws IOException, ParseException { + + Date startDate = DATEFORMAT.parse(startDateStr); + Date endDate = DATEFORMAT.parse(endDateStr); + + List events = FileHelper.readAllEvents("events.json"); + + List eventsInRange = new ArrayList<>(); + for (Event event: events) { + if ((event.getDate().before(endDate) || event.getDate().equals(endDate)) + && (event.getDate().after(startDate) || event.getDate().equals(startDate))) { + eventsInRange.add(event); + } + } + return eventsInRange; + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example2SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example2SolutionResource.java new file mode 100644 index 0000000..b7ae697 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example2SolutionResource.java @@ -0,0 +1,36 @@ +package solutions; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example2SolutionResource { + + /** + * Example 2 Instructions: + * Modify the method below to return the String "Welcome to Engineering Essentials Services Training!" + */ + @GET + @Path("test") + @Produces(MediaType.APPLICATION_JSON) + public String helloWorld() { + return "Welcome to Engineering Essentials Services Training!"; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example3SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example3SolutionResource.java new file mode 100644 index 0000000..d99ef3d --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example3SolutionResource.java @@ -0,0 +1,44 @@ +package solutions; + + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("response") +public class Example3SolutionResource { + + /** + * Example 3 Instructions: + * + * + */ + @GET + @Path("test/fixed") + @Produces(MediaType.APPLICATION_JSON) + public Response getResponse() throws IOException { + //TODO: Modify the Path "response" and uri of the getResponse() method to be "/response/test/fixed" + //TODO: Fix the response so that it returns a 200 OK instead of an internal server error. + // TODO:Return the Response with the String entity + String entity = "This site is now fixed."; + return Response.status(Response.Status.OK).entity(entity).build(); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example4SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example4SolutionResource.java new file mode 100644 index 0000000..dcd8dc0 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example4SolutionResource.java @@ -0,0 +1,39 @@ +package solutions; + +import model.Event; +import utility.FileHelper; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example4SolutionResource { + + @GET + @Path("sample") + @Produces(MediaType.APPLICATION_JSON) + public Response getSampleEvent() throws IOException { + + Event event = FileHelper.readSingleEvent("single-event.json"); + return Response.ok().entity(event).build(); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example5SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example5SolutionResource.java new file mode 100644 index 0000000..d604564 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example5SolutionResource.java @@ -0,0 +1,44 @@ +package solutions; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import model.Event; +import utility.FileHelper; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example5SolutionResource { + private ObjectMapper mapper = new ObjectMapper(); + + @GET + @Path("all") + @Produces(MediaType.APPLICATION_JSON) + public Response getAllEvents() throws IOException { + //TODO: Return the list of all of the events in the events.json file + List events = FileHelper.readAllEvents("events.json"); + return Response.ok(events).build(); + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example6SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example6SolutionResource.java new file mode 100644 index 0000000..657c95d --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example6SolutionResource.java @@ -0,0 +1,50 @@ +package solutions; + +import model.Country; +import model.Event; +import utility.FileHelper; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example6SolutionResource { + + @GET + @Path("allParticipatingCountries") + @Produces(MediaType.APPLICATION_JSON) + public Set getAllParticipatingCountries() throws IOException { + + List events = FileHelper.readAllEvents("allParticipatingCountries.json"); + Set countries = new HashSet<>(); + + for (Event event: events) { + + countries.add(event.getAwayCountry()); + countries.add(event.getHomeCountry()); + } + + return countries; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example7SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example7SolutionResource.java new file mode 100644 index 0000000..cb5239b --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example7SolutionResource.java @@ -0,0 +1,96 @@ +package solutions; + + +import model.Event; +import utility.FileHelper; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example7SolutionResource { + + /** + * Example 7 Instructions: + *

+ * Copy over solutions from Examples 5 and 6 into this resource to help you with this example + * Return the Events for the country in the Response, must be a 200 OK response if available, include the teams in the response + * If no teams were found, return a 404 Response.Status.NOT_FOUND, and a message stating the country was not found + * If not available or exception is thrown should return a 500 Response.Status.INTERNAL_SERVER_ERROR with an explanation of what went wrong + */ + +/* + @GET + @Path("all") + @Produces(MediaType.APPLICATION_JSON) + public List getAllEvents() throws IOException { + List events = FileHelper.readAllEvents("events.json"); + return events; + } + + + @GET + @Path("allParticipatingCountries") + @Produces(MediaType.APPLICATION_JSON) + public Set getAllParticipatingCountries() throws IOException { + + events = getAllEvents(); + Set countries = new HashSet<>(); + + for (Event event: events) { + + countries.add(event.getAwayCountry()); + countries.add(event.getHomeCountry()); + } + + return countries; + } + +*/ + @GET + @Path("country/{countryName}") + @Produces(MediaType.APPLICATION_JSON) + public Response getEventsForCountry(@PathParam("countryName") String countryName) throws IOException { + List eventsForCountry = new ArrayList<>(); + List events = FileHelper.readAllEvents("events.json"); + + for (Event event : events) { + if (event.getAwayCountry().name().equalsIgnoreCase(countryName) || event.getHomeCountry().name().equalsIgnoreCase(countryName)) { + eventsForCountry.add(event); + } + } + Response.ResponseBuilder response; + try { + if (eventsForCountry.size() > 0) { + return Response.ok(eventsForCountry).build(); + } else { + return Response.ok().entity("No matches found for Country with name " + countryName).build(); + } + } catch (Exception e) { + response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e); + } + return response.build(); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example8SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example8SolutionResource.java new file mode 100644 index 0000000..ac1edd8 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example8SolutionResource.java @@ -0,0 +1,45 @@ +package solutions; + +import model.Event; +import utility.FileHelper; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import java.io.IOException; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example8SolutionResource { + + @GET + @Path("{country}/wins") + public int getWins(@PathParam("country") String country) throws IOException { + + List events = FileHelper.readAllEvents("events.json"); + + int numWins = 0; + for (Event event: events) { + if (event.getWinningCountry().name().equalsIgnoreCase(country)) { + ++numWins; + } + + } + return numWins; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/solutions/Example9SolutionResource.java b/EngineeringEssentialsServices/src/main/java/solutions/Example9SolutionResource.java new file mode 100644 index 0000000..18a408e --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/solutions/Example9SolutionResource.java @@ -0,0 +1,83 @@ +package solutions; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import model.Event; +import utility.FileHelper; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Path("events") +public class Example9SolutionResource { + + + + /** + * Example 9 Instructions: + * + * Part 1: Create a Sample Event and save it to the test-create-event.json file using the POST method createEvent + * Return either a 200 OK or a 500 Internal Server error if it fails to create the event + * URL to Visit: /events/createEvent + *

+ * Part 2: Create a getNewEvent method that would read the file test-create-event.json and return the created event + * If the event is not found, return a 404 NOT_FOUND along with an explanation + * URL to Visit: /events/new + */ + + @POST + @Path("createEvent") + @Consumes(MediaType.APPLICATION_JSON) + public Response createEvent(Event newEvent) throws IOException { + String filename = "test-create-event.json"; + + List events; + try { + events = FileHelper.readAllEvents(filename); + events.add(newEvent); + } catch (IOException e) { + // File not found + events = new ArrayList<>(); + events.add(newEvent); + } + + try { + FileHelper.writeEventsToFile(filename, events); + return Response.ok().build(); + } catch (Exception e) { + System.out.println("Failed to create a new Event"); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e).build(); + } + } + + + @GET + @Path("new") + @Produces(MediaType.APPLICATION_JSON) + public Response getNewEvent() throws IOException { + //TODO: Make this method return an Event + String filename = "test-create-event.json"; + List allCreatedEvents = FileHelper.readAllEvents(filename); + return Response.ok(allCreatedEvents).build(); + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/utility/CreateEvents.java b/EngineeringEssentialsServices/src/main/java/utility/CreateEvents.java new file mode 100644 index 0000000..cdf7525 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/utility/CreateEvents.java @@ -0,0 +1,91 @@ +package utility; + +import com.fasterxml.jackson.databind.ObjectMapper; +import model.Country; +import model.Event; +import model.EventType; +import org.joda.time.LocalDate; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +//DO NOT MODIFY THIS CLASS +public class CreateEvents { + + private static final ObjectMapper mapper = new ObjectMapper(); + + public static void main(String args[]) throws IOException { + + List events = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + + int eventIndex = ThreadLocalRandom.current().nextInt(0, EventType.values().length); + int homeCountryIndex = 0; + int awayCountryIndex = 0; + while (homeCountryIndex == awayCountryIndex) { + homeCountryIndex = ThreadLocalRandom.current().nextInt(0, Country.values().length); + awayCountryIndex = ThreadLocalRandom.current().nextInt(0, Country.values().length); + } + events.add(createEvent(EventType.values()[eventIndex], + Country.values()[homeCountryIndex], + Country.values()[awayCountryIndex])); + } + //DO NOT MODIFY FILENAME +// String filePath = CreateEvents.class.getClassLoader().getResources("resources").getPath(); + + mapper.writerWithDefaultPrettyPrinter() + .writeValue(new File("EngineeringEssentialsServices/src/main/resources/events.json"), events); + + } + + private static Event createEvent(EventType eventType, Country homeCountry, Country awayCountry) { + Event event = new Event(); + event.setAwayCountry(awayCountry); + event.setHomeCountry(homeCountry); + event.setEventType(eventType); + + int dayOfMonth = ThreadLocalRandom.current().nextInt(1, 28); + int month = 1; + int winner = ThreadLocalRandom.current().nextInt(0, 2); + int winningScore = ThreadLocalRandom.current().nextInt(10, 16); + int losingScore = ThreadLocalRandom.current().nextInt(0, 10); + event.setWinningScore(winningScore); + event.setLosingScore(losingScore); + + if (winner == 0) { + event.setWinningCountry(awayCountry); + event.setLosingCountry(homeCountry); + } else { + event.setWinningCountry(homeCountry); + event.setLosingCountry(awayCountry); + } + + + Date date = new GregorianCalendar(2018, month, dayOfMonth).getTime(); + event.setDate(date); + + return event; + } + +} diff --git a/EngineeringEssentialsServices/src/main/java/utility/CustomJsonMapper.java b/EngineeringEssentialsServices/src/main/java/utility/CustomJsonMapper.java new file mode 100644 index 0000000..c919964 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/utility/CustomJsonMapper.java @@ -0,0 +1,47 @@ +package utility; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; + +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.ext.Provider; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@Provider +@Produces(MediaType.APPLICATION_JSON) +public class CustomJsonMapper extends JacksonJaxbJsonProvider { + + private static ObjectMapper mapper = new ObjectMapper(); + + static { + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS); + mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + } + + public CustomJsonMapper() { + super(); + setMapper(mapper); + } +} \ No newline at end of file diff --git a/EngineeringEssentialsServices/src/main/java/utility/FileHelper.java b/EngineeringEssentialsServices/src/main/java/utility/FileHelper.java new file mode 100644 index 0000000..7c2323e --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/utility/FileHelper.java @@ -0,0 +1,87 @@ +package utility; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import model.Event; +import model.Team; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.List; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class FileHelper { + + public static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd"); + private static final ObjectMapper mapper = new ObjectMapper(); + + public static Event readSingleEvent(String fileName) throws IOException { + + InputStream inputStream = new FileInputStream(("data" + File.separatorChar + fileName)); +// InputStream resourceAsStream = FileHelper.class.getClassLoader().getResourceAsStream(fileName); + return mapper.readValue(inputStream, new TypeReference() {}); + } + + public static List readAllEvents(String fileName) throws IOException { + + InputStream inputStream = new FileInputStream(("data" + File.separatorChar + fileName)); +// InputStream resourceAsStream = FileHelper.class.getClassLoader().getResourceAsStream(fileName); + return mapper.readValue(inputStream, new TypeReference>() { + }); + } + + public static List readTeamsFromFile(String fileName) throws IOException { + + InputStream inputStream = new FileInputStream(("data" + File.separatorChar + fileName)); +// InputStream resourceAsStream = FileHelper.class.getClassLoader().getResourceAsStream(fileName); + return mapper.readValue(inputStream, new TypeReference>() {}); + } + + public static Team readTeamFromFile(String fileName) throws IOException { + + InputStream inputStream = new FileInputStream(("data" + File.separatorChar + fileName)); +// InputStream resourceAsStream = FileHelper.class.getClassLoader().getResourceAsStream(fileName); + return mapper.readValue(inputStream, new TypeReference() {}); + } + + public static void writeTeamsToFile(String fileName, List teams) throws IOException { + + mapper.writerWithDefaultPrettyPrinter() + .writeValue(new File("data", fileName), teams); + } + + public static void writeTeamToFile(String fileName, Team team) throws IOException { + mapper.writerWithDefaultPrettyPrinter() + .writeValue(new File("data", fileName), team); + } + + + public static void writeEventToFile(String fileName, Event event) throws IOException { + mapper.writerWithDefaultPrettyPrinter() + .writeValue(new File("data", fileName), event); + } + + public static void writeEventsToFile(String fileName, List scheduledEvents) throws IOException { + mapper.writerWithDefaultPrettyPrinter() + .writeValue(new File("data", fileName), scheduledEvents); + } +} diff --git a/EngineeringEssentialsServices/src/main/java/utility/LocalDateDeserializer.java b/EngineeringEssentialsServices/src/main/java/utility/LocalDateDeserializer.java new file mode 100644 index 0000000..c13002d --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/utility/LocalDateDeserializer.java @@ -0,0 +1,45 @@ +package utility; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +import java.io.IOException; +import java.time.LocalDate; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class LocalDateDeserializer extends JsonDeserializer { + @Override + public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { + + ObjectCodec objectCodec = jsonParser.getCodec(); + JsonNode node = objectCodec.readTree(jsonParser); + + final String dateString = node.get("date").asText(); + DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); +// final LocalDate dt = dateTimeFormatter.parseLocalDate(dateString); + + + return null; + } +} diff --git a/EngineeringEssentialsServices/src/main/java/utility/LocalDateSerializer.java b/EngineeringEssentialsServices/src/main/java/utility/LocalDateSerializer.java new file mode 100644 index 0000000..9365180 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/java/utility/LocalDateSerializer.java @@ -0,0 +1,40 @@ +package utility; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import org.apache.commons.lang3.StringUtils; +import org.joda.time.LocalDate; + +import java.io.IOException; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class LocalDateSerializer extends JsonSerializer { + + + @Override + public void serialize(LocalDate localDate, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + +// jsonGenerator.writeStartObject(); + + jsonGenerator.writeString(String.join("-", String.valueOf(localDate.getYear()), String.valueOf(localDate.getMonthOfYear()), + String.valueOf(localDate.getDayOfMonth()))); +// jsonGenerator.writeEndObject(); + } +} diff --git a/EngineeringEssentialsServices/src/main/resources/backup/allParticipatingCountries.json b/EngineeringEssentialsServices/src/main/resources/backup/allParticipatingCountries.json new file mode 100644 index 0000000..2c71498 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/resources/backup/allParticipatingCountries.json @@ -0,0 +1,109 @@ +[ { + "date" : "2018-03-12", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 13, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Japan" +}, { + "date" : "2018-03-06", + "winningCountry" : "Australia", + "losingCountry" : "UnitedStates", + "winningScore" : 11, + "losingScore" : 7, + "eventType" : "Curling", + "homeCountry" : "UnitedStates", + "awayCountry" : "Australia" +}, { + "date" : "2018-03-25", + "winningCountry" : "Japan", + "losingCountry" : "India", + "winningScore" : 14, + "losingScore" : 8, + "eventType" : "Curling", + "homeCountry" : "Japan", + "awayCountry" : "India" +}, { + "date" : "2018-03-17", + "winningCountry" : "England", + "losingCountry" : "UnitedStates", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-03-12", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 11, + "losingScore" : 8, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-03-19", + "winningCountry" : "China", + "losingCountry" : "Australia", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "China" +}, { + "date" : "2018-03-16", + "winningCountry" : "Australia", + "losingCountry" : "England", + "winningScore" : 13, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "England" +}, { + "date" : "2018-03-13", + "winningCountry" : "Australia", + "losingCountry" : "Brazil", + "winningScore" : 14, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "Australia" +}, { + "date" : "2018-03-17", + "winningCountry" : "Australia", + "losingCountry" : "India", + "winningScore" : 15, + "losingScore" : 7, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "India" +}, { + "date" : "2018-03-19", + "winningCountry" : "England", + "losingCountry" : "China", + "winningScore" : 14, + "losingScore" : 8, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "England" +}, { + "date" : "2018-03-19", + "winningCountry" : "Japan", + "losingCountry" : "Australia", + "winningScore" : 10, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "Australia" +}, { + "date" : "2018-03-25", + "winningCountry" : "China", + "losingCountry" : "England", + "winningScore" : 11, + "losingScore" : 6, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "China" +} ] \ No newline at end of file diff --git a/EngineeringEssentialsServices/src/main/resources/backup/events.json b/EngineeringEssentialsServices/src/main/resources/backup/events.json new file mode 100644 index 0000000..8d72933 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/resources/backup/events.json @@ -0,0 +1,901 @@ +[ { + "date" : "2018-02-09", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "India" +}, { + "date" : "2018-02-20", + "winningCountry" : "India", + "losingCountry" : "China", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "India" +}, { + "date" : "2018-02-16", + "winningCountry" : "Portugal", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-14", + "winningCountry" : "China", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "China" +}, { + "date" : "2018-02-15", + "winningCountry" : "Australia", + "losingCountry" : "India", + "winningScore" : 10, + "losingScore" : 4, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "India" +}, { + "date" : "2018-02-11", + "winningCountry" : "UnitedStates", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 2, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-04", + "winningCountry" : "Japan", + "losingCountry" : "India", + "winningScore" : 13, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-02", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 15, + "losingScore" : 8, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-19", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-23", + "winningCountry" : "England", + "losingCountry" : "India", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "India" +}, { + "date" : "2018-02-13", + "winningCountry" : "UnitedStates", + "losingCountry" : "Portugal", + "winningScore" : 11, + "losingScore" : 5, + "eventType" : "Baseball", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-07", + "winningCountry" : "England", + "losingCountry" : "Brazil", + "winningScore" : 15, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-22", + "winningCountry" : "China", + "losingCountry" : "India", + "winningScore" : 11, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "China", + "awayCountry" : "India" +}, { + "date" : "2018-02-19", + "winningCountry" : "Portugal", + "losingCountry" : "China", + "winningScore" : 10, + "losingScore" : 0, + "eventType" : "Curling", + "homeCountry" : "China", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-10", + "winningCountry" : "UnitedStates", + "losingCountry" : "Brazil", + "winningScore" : 10, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-08", + "winningCountry" : "Portugal", + "losingCountry" : "India", + "winningScore" : 15, + "losingScore" : 5, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-05", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 11, + "losingScore" : 8, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-08", + "winningCountry" : "China", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-14", + "winningCountry" : "China", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "China" +}, { + "date" : "2018-02-07", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 14, + "losingScore" : 5, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "China" +}, { + "date" : "2018-02-27", + "winningCountry" : "India", + "losingCountry" : "China", + "winningScore" : 15, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "China", + "awayCountry" : "India" +}, { + "date" : "2018-02-10", + "winningCountry" : "Portugal", + "losingCountry" : "UnitedStates", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "Curling", + "homeCountry" : "UnitedStates", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-20", + "winningCountry" : "Australia", + "losingCountry" : "England", + "winningScore" : 13, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "Australia", + "awayCountry" : "England" +}, { + "date" : "2018-02-24", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-13", + "winningCountry" : "England", + "losingCountry" : "Portugal", + "winningScore" : 10, + "losingScore" : 0, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "England" +}, { + "date" : "2018-02-25", + "winningCountry" : "India", + "losingCountry" : "China", + "winningScore" : 15, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "China" +}, { + "date" : "2018-02-12", + "winningCountry" : "UnitedStates", + "losingCountry" : "Portugal", + "winningScore" : 10, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-05", + "winningCountry" : "Brazil", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "Brazil", + "awayCountry" : "India" +}, { + "date" : "2018-02-06", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 14, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "China" +}, { + "date" : "2018-02-15", + "winningCountry" : "Australia", + "losingCountry" : "India", + "winningScore" : 11, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "India" +}, { + "date" : "2018-02-08", + "winningCountry" : "England", + "losingCountry" : "Brazil", + "winningScore" : 11, + "losingScore" : 6, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-04", + "winningCountry" : "Portugal", + "losingCountry" : "India", + "winningScore" : 13, + "losingScore" : 1, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "India" +}, { + "date" : "2018-02-24", + "winningCountry" : "England", + "losingCountry" : "Japan", + "winningScore" : 14, + "losingScore" : 0, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "England" +}, { + "date" : "2018-02-16", + "winningCountry" : "Brazil", + "losingCountry" : "Australia", + "winningScore" : 11, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "Australia", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-05", + "winningCountry" : "India", + "losingCountry" : "Australia", + "winningScore" : 14, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "India" +}, { + "date" : "2018-02-13", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 13, + "losingScore" : 6, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-04", + "winningCountry" : "UnitedStates", + "losingCountry" : "England", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-26", + "winningCountry" : "Portugal", + "losingCountry" : "UnitedStates", + "winningScore" : 11, + "losingScore" : 3, + "eventType" : "Baseball", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-19", + "winningCountry" : "England", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 3, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "England" +}, { + "date" : "2018-02-16", + "winningCountry" : "Brazil", + "losingCountry" : "Portugal", + "winningScore" : 15, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-17", + "winningCountry" : "Brazil", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 8, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-27", + "winningCountry" : "England", + "losingCountry" : "India", + "winningScore" : 15, + "losingScore" : 3, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "India" +}, { + "date" : "2018-02-07", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-13", + "winningCountry" : "Portugal", + "losingCountry" : "India", + "winningScore" : 10, + "losingScore" : 2, + "eventType" : "Curling", + "homeCountry" : "Portugal", + "awayCountry" : "India" +}, { + "date" : "2018-02-03", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 14, + "losingScore" : 8, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "China" +}, { + "date" : "2018-02-11", + "winningCountry" : "UnitedStates", + "losingCountry" : "Portugal", + "winningScore" : 14, + "losingScore" : 7, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-25", + "winningCountry" : "Portugal", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "England", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-04", + "winningCountry" : "Australia", + "losingCountry" : "Portugal", + "winningScore" : 14, + "losingScore" : 4, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-27", + "winningCountry" : "Australia", + "losingCountry" : "Portugal", + "winningScore" : 10, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-16", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 13, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-22", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 14, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "China" +}, { + "date" : "2018-02-24", + "winningCountry" : "Brazil", + "losingCountry" : "Portugal", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "Portugal", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-14", + "winningCountry" : "Australia", + "losingCountry" : "China", + "winningScore" : 12, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "China", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-20", + "winningCountry" : "Japan", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 6, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-05", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "China" +}, { + "date" : "2018-02-17", + "winningCountry" : "UnitedStates", + "losingCountry" : "Brazil", + "winningScore" : 11, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "UnitedStates", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-04", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-08", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 12, + "losingScore" : 8, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-01", + "winningCountry" : "Australia", + "losingCountry" : "Brazil", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-03", + "winningCountry" : "England", + "losingCountry" : "UnitedStates", + "winningScore" : 14, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "UnitedStates", + "awayCountry" : "England" +}, { + "date" : "2018-02-06", + "winningCountry" : "Australia", + "losingCountry" : "Japan", + "winningScore" : 10, + "losingScore" : 7, + "eventType" : "Baseball", + "homeCountry" : "Japan", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-23", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-10", + "winningCountry" : "Australia", + "losingCountry" : "Portugal", + "winningScore" : 13, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-21", + "winningCountry" : "England", + "losingCountry" : "UnitedStates", + "winningScore" : 15, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "UnitedStates", + "awayCountry" : "England" +}, { + "date" : "2018-02-27", + "winningCountry" : "Brazil", + "losingCountry" : "India", + "winningScore" : 12, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "India", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-09", + "winningCountry" : "England", + "losingCountry" : "Japan", + "winningScore" : 15, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "Japan", + "awayCountry" : "England" +}, { + "date" : "2018-02-21", + "winningCountry" : "Portugal", + "losingCountry" : "China", + "winningScore" : 11, + "losingScore" : 3, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-12", + "winningCountry" : "Australia", + "losingCountry" : "England", + "winningScore" : 11, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "Australia", + "awayCountry" : "England" +}, { + "date" : "2018-02-02", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 13, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "China", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-24", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 14, + "losingScore" : 9, + "eventType" : "Curling", + "homeCountry" : "Japan", + "awayCountry" : "India" +}, { + "date" : "2018-02-07", + "winningCountry" : "Portugal", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 2, + "eventType" : "Curling", + "homeCountry" : "Portugal", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-25", + "winningCountry" : "England", + "losingCountry" : "China", + "winningScore" : 15, + "losingScore" : 7, + "eventType" : "Curling", + "homeCountry" : "China", + "awayCountry" : "England" +}, { + "date" : "2018-02-20", + "winningCountry" : "Australia", + "losingCountry" : "China", + "winningScore" : 13, + "losingScore" : 7, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "China" +}, { + "date" : "2018-02-26", + "winningCountry" : "Japan", + "losingCountry" : "Australia", + "winningScore" : 14, + "losingScore" : 9, + "eventType" : "Baseball", + "homeCountry" : "Japan", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-13", + "winningCountry" : "England", + "losingCountry" : "Portugal", + "winningScore" : 14, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "England", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-08", + "winningCountry" : "Japan", + "losingCountry" : "India", + "winningScore" : 11, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "India" +}, { + "date" : "2018-02-06", + "winningCountry" : "England", + "losingCountry" : "Portugal", + "winningScore" : 14, + "losingScore" : 1, + "eventType" : "Curling", + "homeCountry" : "England", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-19", + "winningCountry" : "Brazil", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-04", + "winningCountry" : "China", + "losingCountry" : "Brazil", + "winningScore" : 11, + "losingScore" : 2, + "eventType" : "WaterPolo", + "homeCountry" : "Brazil", + "awayCountry" : "China" +}, { + "date" : "2018-02-17", + "winningCountry" : "Portugal", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 4, + "eventType" : "Baseball", + "homeCountry" : "Portugal", + "awayCountry" : "England" +}, { + "date" : "2018-02-18", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 11, + "losingScore" : 1, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-05", + "winningCountry" : "Brazil", + "losingCountry" : "Australia", + "winningScore" : 13, + "losingScore" : 0, + "eventType" : "Baseball", + "homeCountry" : "Australia", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-21", + "winningCountry" : "Japan", + "losingCountry" : "Australia", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "Curling", + "homeCountry" : "Australia", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-20", + "winningCountry" : "Japan", + "losingCountry" : "UnitedStates", + "winningScore" : 13, + "losingScore" : 6, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-20", + "winningCountry" : "UnitedStates", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "Curling", + "homeCountry" : "UnitedStates", + "awayCountry" : "England" +}, { + "date" : "2018-02-18", + "winningCountry" : "Portugal", + "losingCountry" : "Brazil", + "winningScore" : 10, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "Brazil", + "awayCountry" : "Portugal" +}, { + "date" : "2018-02-18", + "winningCountry" : "India", + "losingCountry" : "UnitedStates", + "winningScore" : 12, + "losingScore" : 7, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "India" +}, { + "date" : "2018-02-11", + "winningCountry" : "India", + "losingCountry" : "Portugal", + "winningScore" : 15, + "losingScore" : 3, + "eventType" : "WaterPolo", + "homeCountry" : "Portugal", + "awayCountry" : "India" +}, { + "date" : "2018-02-04", + "winningCountry" : "Brazil", + "losingCountry" : "Portugal", + "winningScore" : 15, + "losingScore" : 1, + "eventType" : "Curling", + "homeCountry" : "Portugal", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-22", + "winningCountry" : "Japan", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 1, + "eventType" : "Baseball", + "homeCountry" : "UnitedStates", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-10", + "winningCountry" : "England", + "losingCountry" : "Brazil", + "winningScore" : 12, + "losingScore" : 6, + "eventType" : "Curling", + "homeCountry" : "Brazil", + "awayCountry" : "England" +}, { + "date" : "2018-02-26", + "winningCountry" : "China", + "losingCountry" : "UnitedStates", + "winningScore" : 12, + "losingScore" : 5, + "eventType" : "WaterPolo", + "homeCountry" : "UnitedStates", + "awayCountry" : "China" +}, { + "date" : "2018-02-04", + "winningCountry" : "India", + "losingCountry" : "Japan", + "winningScore" : 13, + "losingScore" : 7, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "India" +}, { + "date" : "2018-02-12", + "winningCountry" : "Japan", + "losingCountry" : "India", + "winningScore" : 10, + "losingScore" : 4, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "Japan" +}, { + "date" : "2018-02-10", + "winningCountry" : "Australia", + "losingCountry" : "Brazil", + "winningScore" : 11, + "losingScore" : 6, + "eventType" : "Baseball", + "homeCountry" : "Brazil", + "awayCountry" : "Australia" +}, { + "date" : "2018-02-21", + "winningCountry" : "India", + "losingCountry" : "Brazil", + "winningScore" : 14, + "losingScore" : 2, + "eventType" : "WaterPolo", + "homeCountry" : "India", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-17", + "winningCountry" : "Australia", + "losingCountry" : "England", + "winningScore" : 12, + "losingScore" : 9, + "eventType" : "WaterPolo", + "homeCountry" : "Australia", + "awayCountry" : "England" +}, { + "date" : "2018-02-19", + "winningCountry" : "Brazil", + "losingCountry" : "Japan", + "winningScore" : 14, + "losingScore" : 8, + "eventType" : "WaterPolo", + "homeCountry" : "Japan", + "awayCountry" : "Brazil" +}, { + "date" : "2018-02-12", + "winningCountry" : "Japan", + "losingCountry" : "UnitedStates", + "winningScore" : 10, + "losingScore" : 7, + "eventType" : "Baseball", + "homeCountry" : "Japan", + "awayCountry" : "UnitedStates" +}, { + "date" : "2018-02-16", + "winningCountry" : "England", + "losingCountry" : "India", + "winningScore" : 13, + "losingScore" : 2, + "eventType" : "Baseball", + "homeCountry" : "India", + "awayCountry" : "England" +} ] \ No newline at end of file diff --git a/EngineeringEssentialsServices/src/main/resources/backup/single-event.json b/EngineeringEssentialsServices/src/main/resources/backup/single-event.json new file mode 100644 index 0000000..fc7c0e0 --- /dev/null +++ b/EngineeringEssentialsServices/src/main/resources/backup/single-event.json @@ -0,0 +1,10 @@ +{ + "eventType":"WaterPolo", + "homeCountry": "Portugal", + "awayCountry": "Australia", + "date": "2018-02-27", + "winningCountry": "Portugal", + "losingCountry": "Australia", + "winningScore": 22, + "losingScore": 4 +} \ No newline at end of file diff --git a/EngineeringEssentialsServices/src/test/java/resources/ResourcesTest.java b/EngineeringEssentialsServices/src/test/java/resources/ResourcesTest.java new file mode 100644 index 0000000..c55c864 --- /dev/null +++ b/EngineeringEssentialsServices/src/test/java/resources/ResourcesTest.java @@ -0,0 +1,216 @@ +package resources; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import examples.*; +import model.*; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.junit.Assert; +import org.junit.Test; +import utility.FileHelper; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.text.ParseException; +import java.util.*; + +import static model.Country.UnitedStates; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static utility.FileHelper.DATEFORMAT; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class ResourcesTest extends JerseyTest { + private static ObjectMapper mapper = new ObjectMapper(); + + + @Override + protected Application configure() { + return new ResourceConfig( + Example2Resource.class, + Example3Resource.class, + Example4Resource.class, + Example5Resource.class, + Example6Resource.class, + Example7Resource.class, + Example8Resource.class, + Example9Resource.class, + Example10Resource.class, + Example11Resource.class, + Example12Resource.class + ); + } + + @Test + public void testExample2() { + String response = target().path("events/test").request().get(String.class); + assertEquals("Welcome to Engineering Essentials Services Training!", response); + } + + @Test + public void testExample3() { + String entity = "This site is now fixed."; + Response expected = Response.ok().entity(entity).build(); + + Response response = target().path("response/test/fixed").request().get(); + String stringResponse = target().path("response/test/fixed").request().get(String.class); + assertEquals(expected.getStatus(), response.getStatus()); + assertEquals(expected.getEntity(), stringResponse); + } + + @Test + public void testExample4() throws ParseException { + Event event = new Event(); + + /** + * Use the setter methods to create an identical event to single-event.json + * and assert that they are equal + * + */ + + Date date = DATEFORMAT.parse("2018-02-27"); + event.setDate(date); + + Event response = target().path("events/sample").request().get(Event.class); + +// assertEquals(); + Assert.fail("Remove this line once you write the test"); + + } + + @Test + public void testExample5() throws IOException { + List events = FileHelper.readAllEvents("events.json"); + + Response response = target().path("events/all").request().get(); + List responseEvents = mapper.convertValue(response.readEntity(List.class), new TypeReference>() { + }); + + assertEquals(events.size(), responseEvents.size()); + assertEquals(events, responseEvents); + } + + @Test + public void testExample6() { + + // Add a test to make sure that all the participating countries are returned correctly + // The only country not participating is Portugal + Set checkParticipatingCountries = EnumSet.complementOf(EnumSet.of(Country.Portugal)); + + + Assert.fail("Remove this line once you write the test"); + } + + @Test + public void testExample7() { + + List china = target().path("/events/country/China").request().get(List.class); + List brazil = target().path("events/country/brazil").request().get(List.class); + List brazilUppercase = target().path("events/country/BraZil").request().get(List.class); + List us = target().path("events/country/UnitedStates").request().get(List.class); + String response = target().path("events/country/Canada").request().get(String.class); + + assertEquals(23, china.size()); + assertEquals(28, brazil.size()); + assertEquals(28, brazilUppercase.size()); + assertEquals(25, us.size()); + assertEquals(response, "No matches found for Country with name Canada"); + } + + @Test + public void testExample8() { + + int expNumWinsEngland = 15; + int expNumWinsUnitedStates = 8; + int expNumWinsChina = 15; + + // Fill in the Jersey get requests + int actualNumWinsEngland = 0; + int actualNumWinsUnitedStates = 0; + int actualNumWinsChina = 0; + + assertEquals(expNumWinsEngland, actualNumWinsEngland); + assertEquals(expNumWinsUnitedStates, actualNumWinsUnitedStates); + assertEquals(expNumWinsChina, actualNumWinsChina); + } + + @Test + public void testExample9() throws ParseException, IOException { + + Event event = new Event(); + event.setAwayCountry(Country.Japan); + event.setHomeCountry(UnitedStates); + event.setWinningCountry(UnitedStates); + event.setLosingCountry(Country.Japan); + event.setWinningScore(10); + event.setLosingScore(4); + event.setEventType(EventType.Baseball); + + Date date = DATEFORMAT.parse("2018-02-22"); + event.setDate(date); + + Response postEvent = target().path("events/createEvent").request().post(Entity.json(event)); + List getNewEvents = target().path("events/new").request().get(List.class); + + // To make sure that the event was created + assertEquals(1, getNewEvents.size()); + + target().path("events/createEvent").request().post(Entity.json(event)); + List getNewEvents2 = target().path("events/new").request().get(List.class); + + // To make sure that a new event was added, rather than overwriting the existing one, test not idempotent + assertTrue(getNewEvents2.size() >= 2); + assertEquals(postEvent.getStatus(), 200); + } + + @Test + public void testExample10() { + + // Add some players + Set players = new HashSet<>(); + + // Add players to the team and set a team name + Team team = new Team(); + + // Make sure to test doing the PUT operation twice, and make sure the result is the same both times + + Assert.fail("Remove this line once you write the test"); + } + + @Test + public void testExample11() throws ParseException, IOException { + + List allEvents = FileHelper.readAllEvents("events.json"); + + List cancelledEvents = target().path("events/cancel/Baseball/home/China/away/Australia").request().delete(List.class); + + assertTrue(cancelledEvents.size() < allEvents.size()); + assertEquals(1, cancelledEvents.size()); + } + + @Test + public void testExample12() { + + // Check that the number of events between Feb 09 2018 and Feb 12 2018 (inclusive) is 14 + + List eventsInRange = target().path("/events/startDate/2018-02-09/endDate/2018-02-12").request().get(List.class); + assertEquals(14, eventsInRange.size()); + } +} \ No newline at end of file diff --git a/EngineeringEssentialsServices/src/test/java/resources/ResourcesTestSolutions.java b/EngineeringEssentialsServices/src/test/java/resources/ResourcesTestSolutions.java new file mode 100644 index 0000000..549ebc8 --- /dev/null +++ b/EngineeringEssentialsServices/src/test/java/resources/ResourcesTestSolutions.java @@ -0,0 +1,222 @@ +package resources; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import model.*; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.junit.Test; +import solutions.*; +import utility.FileHelper; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.text.ParseException; +import java.util.*; + +import static model.Country.*; +import static org.junit.Assert.*; +import static utility.FileHelper.DATEFORMAT; + +/** + * Copyright 2018 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class ResourcesTestSolutions extends JerseyTest { + private static ObjectMapper mapper = new ObjectMapper(); + + + @Override + protected Application configure() { + return new ResourceConfig( + Example2SolutionResource.class, + Example3SolutionResource.class, + Example4SolutionResource.class, + Example5SolutionResource.class, + Example6SolutionResource.class, + Example7SolutionResource.class, + Example8SolutionResource.class, + Example9SolutionResource.class, + Example10SolutionResource.class, + Example11SolutionResource.class, + Example12SolutionResource.class + ); + } + + @Test + public void testExample2() { + String response = target().path("events/test").request().get(String.class); + assertEquals("Welcome to Engineering Essentials Services Training!", response); + } + + @Test + public void testExample3() { + String entity = "This site is now fixed."; + Response expected = Response.ok().entity(entity).build(); + + Response response = target().path("response/test/fixed").request().get(); + String stringResponse = target().path("response/test/fixed").request().get(String.class); + assertEquals(expected.getStatus(), response.getStatus()); + assertEquals(expected.getEntity(), stringResponse); + } + + @Test + public void testExample4() throws ParseException { + Event event = new Event(); + event.setAwayCountry(Country.Australia); + event.setHomeCountry(Portugal); + event.setWinningCountry(Portugal); + event.setLosingCountry(Country.Australia); + event.setWinningScore(22); + event.setLosingScore(4); + event.setEventType(EventType.WaterPolo); + + Date date = DATEFORMAT.parse("2018-02-27"); + event.setDate(date); + + Event response = target().path("events/sample").request().get(Event.class); + assertEquals(event, response); + } + + @Test + public void testExample5() throws IOException { + List events = FileHelper.readAllEvents("events.json"); + + Response response = target().path("events/all").request().get(); + List responseEvents = mapper.convertValue(response.readEntity(List.class), new TypeReference>() { + }); + + assertEquals(events.size(), responseEvents.size()); + assertEquals(events, responseEvents); + } + + @Test + public void testExample6() { + + Set checkParticipatingCountries = EnumSet.complementOf(EnumSet.of(Country.Portugal)); + Set getParticipatingCountries = target().path("events/allParticipatingCountries").request().get(Set.class); + + assertEquals(checkParticipatingCountries.size(), getParticipatingCountries.size()); + assertFalse(getParticipatingCountries.contains(Portugal)); + + } + + @Test + public void testExample7() { + + List china = target().path("/events/country/China").request().get(List.class); + List brazil = target().path("events/country/brazil").request().get(List.class); + List brazilUppercase = target().path("events/country/BraZil").request().get(List.class); + List us = target().path("events/country/UnitedStates").request().get(List.class); + String response = target().path("events/country/Canada").request().get(String.class); + + assertEquals(23, china.size()); + assertEquals(28, brazil.size()); + assertEquals(28, brazilUppercase.size()); + assertEquals(25, us.size()); + assertEquals(response, "No matches found for Country with name Canada"); + } + + @Test + public void testExample8() { + + int expNumWinsEngland = 15; + int expNumWinsUnitedStates = 8; + int expNumWinsChina = 15; + + int actualNumWinsEngland = target().path("events/England/wins").request().get(int.class); + int actualNumWinsUnitedStates = target().path("events/UnitedStates/wins").request().get(int.class); + int actualNumWinsChina = target().path("events/China/wins").request().get(int.class); + + assertEquals(expNumWinsEngland, actualNumWinsEngland); + assertEquals(expNumWinsUnitedStates, actualNumWinsUnitedStates); + assertEquals(expNumWinsChina, actualNumWinsChina); + } + + @Test + public void testExample9() throws ParseException, IOException { + + Event event = new Event(); + event.setAwayCountry(Country.Japan); + event.setHomeCountry(UnitedStates); + event.setWinningCountry(UnitedStates); + event.setLosingCountry(Country.Japan); + event.setWinningScore(10); + event.setLosingScore(4); + event.setEventType(EventType.Baseball); + + Date date = DATEFORMAT.parse("2018-02-22"); + event.setDate(date); + + Response postEvent = target().path("events/createEvent").request().post(Entity.json(event)); + List getNewEvents = target().path("events/new").request().get(List.class); + + // To make sure that the event was created + assertEquals(1, getNewEvents.size()); + + target().path("events/createEvent").request().post(Entity.json(event)); + List getNewEvents2 = target().path("events/new").request().get(List.class); + + // To make sure that a new event was added, rather than overwriting the existing one + assertEquals(2, getNewEvents2.size()); + assertEquals(postEvent.getStatus(), 200); + + } + + @Test + public void testExample10() { + + Set players = new HashSet<>(); + players.add(new Player("Anna Conda", India)); + players.add(new Player("Linda Book", India)); + + Team ballers = new Team(); + ballers.setName("Smallers"); + ballers.setPlayers(players); + + Response putTeam = target().path("events/team").request().put(Entity.json(ballers)); + assertEquals(200, putTeam.getStatus()); + + Team getBallers = target().path("events/team/Smallers").request().get(Team.class); + + target().path("events/team").request().put(Entity.json(ballers)); + Team getBallers2 = target().path("events/team/Smallers").request().get(Team.class); + + assertEquals(ballers, getBallers); + assertEquals(getBallers, getBallers2); + } + + @Test + public void testExample11() throws ParseException, IOException { + List allEvents = FileHelper.readAllEvents("events.json"); + + List cancelledEvents = target().path("events/cancel/Baseball/home/China/away/Australia").request().delete(List.class); + + assertTrue(cancelledEvents.size() < allEvents.size()); + assertEquals(1, cancelledEvents.size()); + + } + + @Test + public void testExample12() { + + // Check that the number of events between Feb 09 2018 and Feb 12 2018 (inclusive) is 14 + + List eventsInRange = target().path("/events/startDate/2018-02-09/endDate/2018-02-12").request().get(List.class); + assertEquals(14, eventsInRange.size()); + } + +} \ No newline at end of file diff --git a/StockTicker.js b/StockTicker.js new file mode 100644 index 0000000..7a341bf --- /dev/null +++ b/StockTicker.js @@ -0,0 +1,197 @@ +/** + * Copyright 2019 Goldman Sachs. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + + +/* Display a stock ticker that provides typeahead (aka autocomplete) capability. + * This requires making an AJAX HTTP request (asynchronous JavaScript and XML request) to + * your service and prefetching the list of all available stock tickers or making an async + * query every time the input changes (AsyncTypeahead). If you don't have a route defined + * in your services/API that returns all stock tickers as a JSON object, create one! + * + * You can use promises(axios), + * fetch, jQuery...there are many libraries to help you do this. The data you will + * receive will be in a JSON format. + * https://hashnode.com/post/5-best-libraries-for-making-ajax-calls-in-react-cis8x5f7k0jl7th53z68s41k1 + * fetch: https://davidwalsh.name/fetch + * axios: https://github.com/mzabriskie/axios (you will need to install this package) + * jquery: http://api.jquery.com/jquery.getjson/ (you will need to install the jquery package) + * + * Feel free to choose among of the many open source options for your typeahead select box. + * We recommend react-select or react-bootstrap-typeahead. react-boostrap-typeahead is included + * in your package.json. + * + * react-select: + * https://www.npmjs.com/package/react-select + * http://jedwatson.github.io/react-select/ + * https://github.com/JedWatson/react-select + * + * react-boostrap-typeahead + * https://www.npmjs.com/package/react-bootstrap-typeahead + * http://ericgio.github.io/react-bootstrap-typeahead/ + * https://github.com/ericgio/react-bootstrap-typeahead/blob/master/example/examples/BasicBehaviorsExample.react.js (note this is not ES2015) + */ + +import React from 'react'; +import Select from 'react-select'; +//import {Typeahead} from 'react-bootstrap-typeahead'; + + +//UNCOMMENT this line if you are using the react-bootstrap-typeeahead component + +/* If you chose to use react-boostrap-typeahead, look at AsyncTypeahead for a component that + * provides auto-complete suggestions as you type. This would require adding a search handler + * method for an onSearch prop. + * https://github.com/ericgio/react-bootstrap-typeahead/blob/master/example/examples/AsyncExample.react.js + */ +const options = [ + { value: 'goldman sachs', label: 'Goldman Sachs' }, + { value: 'jpmorgan chase', label: 'JPMorgan Chase' }, + { value: 'morgan stanley', label: 'Morgan Stanley' }, + { value: 'marcus', label: 'Marcus' } + ]; + +class StockTicker extends React.Component { + state = { + selectedOption: null, + } + handleChange = (selectedOption) => { + this.setState({ selectedOption }); + console.log(`Option selected:`, selectedOption); + } + /** + * TODO + * Prefetch the data required to display options fo the typeahead component. Initialize a state array with + * this data and pass it via props to the typeahead component that will be rendered. + * https://github.com/ericgio/react-bootstrap-typeahead/blob/master/docs/Data.md + * e.g. + * options : [ + * GS, + * AAPL, + * FB, + * ] + * If you are having difficulty with this, you may hard code the options array from the company data provided for the + * services. + */ + + constructor(props) { + super(props); + this.state = { + showcompanyinfo: false, //TODO: Use this boolean to determine if the company information should be rendered + company : { + symbol: 'GS', + name: 'Goldman Sachs', + city: 'SDCM', + state: 'NJ', + sector: '', + industry: 'IB' + } + /** + * TODO + * Add any additional state to pass via props to the typeahead component. + */ + }; + this.handleChange = this.handleChange.bind(this); + } + + handleChange(event) { + if (event.length > 0) { + /** + * TODO + * Make a request to your service to GET company information for the selected company and set it in state. + * The information you will need to determine the URL will be contained in the 'event[0]' object, + * e.g. event[0] (event[0].symbol if your options are an array of objects) provides you the symbol selected. + * The URL will be on your localhost (e.g. http://localhost:8000/service_path/some_param) where + * your service is running. Your service MUST be running for the request to work (you can add a catch function + * to handle errors). If you successfully retrieve this information, you can set the state objects + * and render it. + */ + this.setState({showcompanyinfo: true}); + this.props.onChange(event); + //this.props.onChange(..); Call this.props.onChange with the selected symbol to propagate it + // to the App component, which will handle it via its own onChane prop, + // ultimately used to fetch the data for the LineChart component. + + } + else { + this.setState({showinfo: false}); + this.props.onChange(undefined); + } + } + + + render() { + const { selectedOption } = this.state; + /** + * TODO + * Render a typeahead component that uses the data prefetched from your service to display a list of companies or + * ticker symbols. The props you use can be stored as state objects. + * On change should fetch the company information and display Company, Ticker Symbol, City, State/Country, Sector, and Industry information. + * https://github.com/ericgio/react-bootstrap-typeahead/blob/master/docs/Props.md + */ + + return ( + +

+

Stock Ticker

+ + { +