Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@grtsantu(Tanmoy) ,Please review Spring data assignment + Spring REST & BOOT +JUnit Tests #39

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
775db46
Assignment for the first Session-JMP
RahulMuj Apr 14, 2016
4a40496
Assignment for first session-JMP
RahulMuj Apr 14, 2016
b952186
Pending Tasks Assignment- 1st session-JMP
RahulMuj Apr 18, 2016
24c19cc
@Tanmoy - Spring Data Assignment
RahulMuj May 15, 2016
5b6fb3e
@Tanmoy - Spring Data Assignment
RahulMuj May 15, 2016
0cff674
@Tanmoy - Spring Data Assignment
RahulMuj May 15, 2016
c979485
@Tanmoy - Spring Data Assignment
RahulMuj May 15, 2016
8521e22
@Tanmoy - Spring Data Assignment
RahulMuj May 15, 2016
a3305e5
@Tanmoy - Spring Data Assignment
RahulMuj May 15, 2016
d58a152
@Tanmoy - Spring Data Assignment
RahulMuj May 15, 2016
b2db99e
Covering Test Scenarios for REST Service
RahulMuj May 24, 2016
f849b75
Exception Class to handle HTTP Exceptions.
RahulMuj May 24, 2016
1914ab4
Implementation for REST Controller and making REST services available
RahulMuj May 24, 2016
5da3415
Setting up SpringBoot Main Class
RahulMuj May 24, 2016
6ff659e
Refactor & Clean Code
RahulMuj May 25, 2016
9db417e
Refactor & Clean Code
RahulMuj May 25, 2016
58c9d67
Writing Unit Tests for Police Force & DayTime Service -Assignment Task 3
RahulMuj May 25, 2016
8af06bf
Writing Unit Tests for Police Force & DayTime Service -Assignment Task 3
RahulMuj May 25, 2016
2750600
Integration Test For File Writer Functionality
RahulMuj May 25, 2016
01347fe
Writing Unit Tests for Police Force & DayTime Service
RahulMuj May 25, 2016
3b5f98f
Integration Test For File Writer Functionality
RahulMuj May 25, 2016
226c9cc
Writing Unit Tests for Police Force & DayTime Service
RahulMuj May 25, 2016
4d438e9
Writing Unit Tests for Police Force & DayTime Service
RahulMuj May 25, 2016
8f62acc
Writing Unit Tests for Police Force & DayTime Service
RahulMuj May 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/main/java/com/epam/AccidentTrackingMainApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.epam;

import com.epam.db.HsqlInit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import java.sql.Connection;

/**
* Created by rahul.mujnani on 5/21/2016.
*/
//@SpringBootApplication
@Configuration
@ImportResource("classpath*:/spring-config.xml")
public class AccidentTrackingMainApplication {

static HsqlInit hsqlInit;
static Connection connection;
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication();
ApplicationContext ctx = SpringApplication.run(AccidentTrackingMainApplication.class, args);
//initDB(ctx);
}

private static void initDB(ApplicationContext ctx){
hsqlInit = new HsqlInit();
connection = hsqlInit.initDatabase();
}

}
18 changes: 18 additions & 0 deletions src/main/java/com/epam/data/RoadAccident.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class RoadAccident {
private int numberOfCasualties;
private LocalDate date;
private LocalTime time;

public void setDayOfWeek(java.time.DayOfWeek dayOfWeek) {
DayOfWeek = dayOfWeek;
}

private DayOfWeek DayOfWeek;
private String districtAuthority;
private String lightConditions;
private String weatherConditions;
Expand Down Expand Up @@ -146,4 +152,16 @@ public String getRoadSurfaceConditions() {
public void setRoadSurfaceConditions(String roadSurfaceConditions) {
this.roadSurfaceConditions = roadSurfaceConditions;
}

public String toString() {
return "RoadAccident:" +
"\nid:" + this.accidentId +
"\ndistrictAuthority:" + this.districtAuthority+
"\npoliceForce:" + this.policeForce +
"\nroadSurfaceConditions:" + this.roadSurfaceConditions +
"\nweatherConditions:" + this.weatherConditions;



}
}
187 changes: 95 additions & 92 deletions src/main/java/com/epam/data/RoadAccidentBuilder.java
Original file line number Diff line number Diff line change
@@ -1,92 +1,95 @@
package com.epam.data;

import java.time.LocalDate;
import java.time.LocalTime;

/**
* Created by Tkachi on 2016/3/31.
*/
public class RoadAccidentBuilder {
String accidentId;
float longitude;
float latitude;
String policeForce;
String accidentSeverity;
int numberOfVehicles;
int numberOfCasualties;
LocalDate date;
LocalTime time;
String districtAuthority;
String lightConditions;
String weatherConditions;
String roadSurfaceConditions;


public RoadAccidentBuilder(String accidentId){
this.accidentId = accidentId;
}

public RoadAccidentBuilder withLongitude(float longitude) {
this.longitude = longitude;
return this;
}

public RoadAccidentBuilder withLatitude(float latitude) {
this.latitude = latitude;
return this;
}

public RoadAccidentBuilder withPoliceForce(String policeForce) {
this.policeForce = policeForce;
return this;
}

public RoadAccidentBuilder withAccidentSeverity(String accidentSeverity) {
this.accidentSeverity = accidentSeverity;
return this;
}

public RoadAccidentBuilder withNumberOfVehicles(int numberOfVehicles) {
this.numberOfVehicles = numberOfVehicles;
return this;
}

public RoadAccidentBuilder withNumberOfCasualties(int numberOfCasualties) {
this.numberOfCasualties = numberOfCasualties;
return this;
}

public RoadAccidentBuilder withDate(LocalDate date) {
this.date = date;
return this;
}

public RoadAccidentBuilder withTime(LocalTime time) {
this.time = time;
return this;
}

public RoadAccidentBuilder withDistrictAuthority(String districtAuthority) {
this.districtAuthority = districtAuthority;
return this;
}

public RoadAccidentBuilder withLightConditions(String lightConditions) {
this.lightConditions = lightConditions;
return this;
}

public RoadAccidentBuilder withWeatherConditions(String weatherConditions) {
this.weatherConditions = weatherConditions;
return this;
}

public RoadAccidentBuilder withRoadSurfaceConditions(String roadSurfaceConditions) {
this.roadSurfaceConditions = roadSurfaceConditions;
return this;
}

public RoadAccident build(){
return new RoadAccident(this);
}
}
package com.epam.data;

import java.time.LocalDate;
import java.time.LocalTime;

/**
* Created by Tkachi on 2016/3/31.
*/
public class RoadAccidentBuilder {
String accidentId;
float longitude;
float latitude;
String policeForce;
String accidentSeverity;
int numberOfVehicles;
int numberOfCasualties;
LocalDate date;
LocalTime time;
String districtAuthority;
String lightConditions;
String weatherConditions;
String roadSurfaceConditions;


public RoadAccidentBuilder(String accidentId){
this.accidentId = accidentId;
}

public RoadAccidentBuilder() {
}

public RoadAccidentBuilder withLongitude(float longitude) {
this.longitude = longitude;
return this;
}

public RoadAccidentBuilder withLatitude(float latitude) {
this.latitude = latitude;
return this;
}

public RoadAccidentBuilder withPoliceForce(String policeForce) {
this.policeForce = policeForce;
return this;
}

public RoadAccidentBuilder withAccidentSeverity(String accidentSeverity) {
this.accidentSeverity = accidentSeverity;
return this;
}

public RoadAccidentBuilder withNumberOfVehicles(int numberOfVehicles) {
this.numberOfVehicles = numberOfVehicles;
return this;
}

public RoadAccidentBuilder withNumberOfCasualties(int numberOfCasualties) {
this.numberOfCasualties = numberOfCasualties;
return this;
}

public RoadAccidentBuilder withDate(LocalDate date) {
this.date = date;
return this;
}

public RoadAccidentBuilder withTime(LocalTime time) {
this.time = time;
return this;
}

public RoadAccidentBuilder withDistrictAuthority(String districtAuthority) {
this.districtAuthority = districtAuthority;
return this;
}

public RoadAccidentBuilder withLightConditions(String lightConditions) {
this.lightConditions = lightConditions;
return this;
}

public RoadAccidentBuilder withWeatherConditions(String weatherConditions) {
this.weatherConditions = weatherConditions;
return this;
}

public RoadAccidentBuilder withRoadSurfaceConditions(String roadSurfaceConditions) {
this.roadSurfaceConditions = roadSurfaceConditions;
return this;
}

public RoadAccident build(){
return new RoadAccident(this);
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/epam/data/TimeOfDay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.epam.data;
import java.time.LocalTime;

import java.time.LocalTime;



/**
* Created by rahul.mujnani on 5/3/2016.
*/
public class TimeOfDay {

public enum TimeCategory{
MORNING, AFTERNOON, EVENING, NIGHT, INVALID_TIME;
}

public static String getTimeOfDay(LocalTime localtime){
if (localtime.getHour() < 6) return TimeCategory.NIGHT.toString();
else if (localtime.getHour() < 12) return TimeCategory.MORNING.toString();
else if (localtime.getHour() < 18) return TimeCategory.AFTERNOON.toString();
else if (localtime.getHour() < 24) return TimeCategory.EVENING.toString();
else return TimeCategory.INVALID_TIME.toString();

}
}
43 changes: 43 additions & 0 deletions src/main/java/com/epam/dbrepositories/AccidentRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.epam.dbrepositories;

import com.epam.data.RoadAccident;
import com.epam.entities.Accident;;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Vector;

public interface AccidentRepository extends CrudRepository<Accident, String> {

/*Find RoadAccident for the given Id*/
Accident findOne(String accidentId);

/*Find RoadAccident for the Given Road Surface Condition*/
@Query(value = "SELECT acdnt.accidentIndex,acdnt.roadSurfaceCondition FROM Accident acdnt" +
" WHERE acdnt.roadSurfaceCondition.code=:road_surface")
Vector<Object> findByRoadSurfaceCondition(@Param("road_surface") Integer road_surface);

/*Find RoadAccident for the Given Weather Condition*/
@Query(value = "SELECT acdnt.accidentIndex,acdnt.weatherCondition FROM Accident acdnt " +
"WHERE acdnt.weatherCondition.code=:weather_Condition and acdnt.Date LIKE CONCAT('%',:date,'%')")
Vector<Object> findAccidentsByWeatherConditionAndYear(@Param("weather_Condition") Integer weatherCondition,
@Param("date") String date);

/*Find RoadAccident for the Given Date*/
@Query(value = "SELECT acdnt.accidentIndex,acdnt.Time FROM Accident acdnt WHERE acdnt.Date =:date")
Vector<String> findAccidentsByDate(@Param("date") String date);

/*Update RoadAccident for the Given accidentId*/
@Transactional
@Modifying
@Query(value = "update Accident acdnt set acdnt.Time=:time " +
"WHERE acdnt.accidentIndex=:accidentId")
Integer updateTime(@Param("time") String time, @Param("accidentId") String accidentId);

}
20 changes: 20 additions & 0 deletions src/main/java/com/epam/dbservice/AccidentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.epam.dbservice;

import java.util.Date;

import com.epam.data.RoadAccident;
import com.epam.entities.Accident;

public interface AccidentService {

Accident findOne(String accidentId);

Iterable<RoadAccident> getAllAccidentsByRoadCondition(Integer label);

Iterable<RoadAccident> getAllAccidentsByWeatherConditionAndYear(Integer weatherCondition, String year);

Iterable<RoadAccident> getAllAccidentsByDate(Date date);

Boolean update(RoadAccident roadAccident);

}
Loading