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

Homework2 for task 1 and 2 #41

Open
wants to merge 27 commits into
base: memory-session
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
50635b5
Add more data for multithreading homework
Apr 20, 2016
1ed90cd
Create .travis.yml
Apr 24, 2016
419b78f
Update .travis.yml
Apr 24, 2016
011a3a5
init commit
grtsantu Apr 25, 2016
09b575f
init commit
grtsantu Apr 25, 2016
3da74ea
init commit 2
grtsantu Apr 25, 2016
d09c034
code cleanup
grtsantu Apr 25, 2016
d826e84
code cleanup
grtsantu Apr 25, 2016
b7152f4
Merge pull request #17 from grtsantu/master
Apr 26, 2016
7a49e90
ReportGenerator class with tests; add integration test (week4)
enyalux Apr 29, 2016
5547c59
Add instructions for Hometask 4.
enyalux Apr 29, 2016
90240e8
Merge pull request #23 from enyalux/week4-homework
May 2, 2016
90a428f
Loaded tables to hsqlbd database
May 4, 2016
0a2cb32
Trying to put test together - problem with dependencies - not all of …
May 5, 2016
5dbd812
Integration test is working now. Updated readme
May 8, 2016
be80f7f
Sample ServiceInterface for Spring Data assignment
grephari May 9, 2016
a250711
Sample ServiceInterfaceIMpl for Spring Data assignment
grephari May 9, 2016
c6916cd
Added dependencies for Spring Data assignment
grephari May 9, 2016
fe6f21b
Merge pull request #31 from grephari/springdata-hometask
May 9, 2016
c9474c2
Fix typo
alexeymatyas May 11, 2016
f42422c
Merge pull request #33 from alexeymatyas/patch-1
May 11, 2016
190eeb1
Homework 5 for spring
oceanhhy May 13, 2016
df27e2b
Implementatin for AccidentDBServiceImpl and the repository
oceanhhy May 16, 2016
50022f5
Commit repository and AccidentDBServiceImpl
oceanhhy May 16, 2016
61c8bff
Update
oceanhhy May 16, 2016
45aab1d
Add test for homework 5 and update after review
oceanhhy May 17, 2016
ca48fcb
Homework2 for task 1 and 2
oceanhhy May 18, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.iml
target/*
/target/
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: java
jdk:
- oraclejdk8
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ In pull request mark your mentor (@mentorName) so it can review it.
To complite task one you need to fix DataProcessorTest unit tests.
All methods in DataProcessor with "7" in a name should be implemented using Java 7, when other should be done with Java 8 streaming api.

<<<<<<< HEAD
## Hometask 4
In the code what you did on Hometask 3 please create tests to achieve at least 50% test coverage in your new classes. Use IDE plugin to measure. At least 1 integration test is required. Try to use BDD approach.

Recommendations will be :
1. write unit test for getContactNumber (JUnit)
2. write unit tests for your service from hometask3 (Mockito/PowerMock: you have to mock all external/additional services which you use in your solution). This part depends on your own solution.
3. write integration test for your file writing functionality ( don't use any mocks here)


##Hometask 5

In this task, instead of csv files, you will use HSQLDB as datasource.
To initialize homework - run HsqlInitTest.runThisTestToBuildHSQLDBLocally()
It will create database files in root folder of your project - jmpdb.*

After that run test AccidentsControllerIntegrationTest.testFindOne.
It will connect to your local database and get one accident by Id.

As you can see AccidentControllerBasicImpl is quite dummy :)
Improve it with some framework - Spring Data with JPA or Spring JDBC - up to you.
=======

## Homework 2

Expand Down Expand Up @@ -76,4 +98,5 @@ Install AppDynamic and use it to monitor any applications' memory. Provide scree



>>>>>>> 1d430cda92356da89b7dcec5d3f6764ce937bb48

121 changes: 120 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<<<<<<< HEAD
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.epam</groupId>
<artifactId>java-mentoring-program</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.4.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.10.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.12.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
</dependency>

</dependencies>


</project>
=======
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand Down Expand Up @@ -54,4 +172,5 @@
</dependencies>


</project>
</project>
>>>>>>> 1d430cda92356da89b7dcec5d3f6764ce937bb48
23 changes: 23 additions & 0 deletions src/main/java/com/epam/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.epam;

import com.epam.data.AccidentsDataLoader;
import com.epam.data.RoadAccident;

import java.io.IOException;
import java.util.List;


/**
* Created by Tkachi on 2016/4/3.
*/
public class Main {

private static final String ACCIDENTS_CSV = "src/main/resources/DfTRoadSafety_Accidents_2010.csv";


public static void main(String[] args) throws IOException {
AccidentsDataLoader accidentsDataLoader = new AccidentsDataLoader();
List<RoadAccident> accidents = accidentsDataLoader.loadRoadAccidents(ACCIDENTS_CSV);
}

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


import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AccidentsDataLoader {

private static final String DISTRICT_AUTHORITY_CSV = "src/main/resources/disrict_authority.csv";
private static final String ACCIDENT_SEVERITY_CSV = "src/main/resources/accident_severity.csv";
private static final String LIGHT_CONDITIONS_CSV = "src/main/resources/light_conditions.csv";
private static final String POLICE_FORCE_CSV = "src/main/resources/police_force.csv";
private static final String ROAD_SURFACE_CSV = "src/main/resources/road_surface.csv";
private static final String WEATHER_CONDITIONS_CSV = "src/main/resources/weather_conditions.csv";
private Map<Integer, String> districtAuthorities;
private Map<Integer, String> accidentSeverity;
private Map<Integer, String> lightConditions;
private Map<Integer, String> policeForce;
private Map<Integer, String> roadSurface;
private Map<Integer, String> weatherConditions;

private void loadAdditionalTables() {
districtAuthorities = loadIntToStrignMap(DISTRICT_AUTHORITY_CSV);
accidentSeverity = loadIntToStrignMap(ACCIDENT_SEVERITY_CSV);
lightConditions = loadIntToStrignMap(LIGHT_CONDITIONS_CSV);
policeForce = loadIntToStrignMap(POLICE_FORCE_CSV);
roadSurface = loadIntToStrignMap(ROAD_SURFACE_CSV);
weatherConditions = loadIntToStrignMap(WEATHER_CONDITIONS_CSV);
}


private Map<Integer, String> loadIntToStrignMap(String filepath) {
Map<Integer, String> resultMap = new HashMap<>();

try {
Reader reader = new FileReader(filepath);
Iterable<CSVRecord> records = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
for (CSVRecord record : records) {
Integer key = Integer.valueOf(record.get(0));
String value = record.get(1);
resultMap.put(key, value);
}
} catch (IOException e) {
e.printStackTrace();
}
return resultMap;
}

public List<RoadAccident> loadRoadAccidents(String filepath) {
loadAdditionalTables();

List<RoadAccident> roadAccidentList = new ArrayList<>();
try {
Reader reader = new FileReader(filepath);
Iterable<CSVRecord> records = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
for (CSVRecord record : records) {
RoadAccident roadAccident = parseOneRecord(record);
if (roadAccident != null) {
roadAccidentList.add(roadAccident);
}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.printf("Loaded %d accidents information \n", roadAccidentList.size());
return roadAccidentList;
}

private RoadAccident parseOneRecord(CSVRecord record) {
try {
String accidentId = record.get("Accident_Index");
RoadAccident roadAccident = new RoadAccidentBuilder(accidentId)
.withLongitude(Float.valueOf(record.get("Longitude")))
.withLatitude(Float.valueOf(record.get("Latitude")))
.withPoliceForce(policeForce.get(record.get("Police_Force")))
.withAccidentSeverity(accidentSeverity.get(record.get("Accident_Severity")))
.withNumberOfVehicles(Integer.valueOf(record.get("Number_of_Vehicles")))
.withNumberOfCasualties(Integer.valueOf(record.get("Number_of_Casualties")))
.withDate(LocalDate.parse(record.get("Date"), DateTimeFormatter.ofPattern("dd/MM/yyyy")))
.withTime(LocalTime.parse(record.get("Time"), DateTimeFormatter.ofPattern("H:mm")))
.withDistrictAuthority(districtAuthorities.get(Integer.valueOf(record.get("Local_Authority_(District)"))))
.withLightConditions(lightConditions.get(Integer.valueOf(record.get("Light_Conditions"))))
.withWeatherConditions(weatherConditions.get(Integer.valueOf(record.get("Weather_Conditions"))))
.withRoadSurfaceConditions(roadSurface.get(Integer.valueOf(record.get("Road_Surface_Conditions"))))
.build();
return roadAccident;
} catch (DateTimeParseException timeException) {
System.out.println("Some data quality issue with one of records - screw it, have plenty more");
return null;
}
}


public Map<Integer, String> getWeatherConditions() {
return weatherConditions;
}

}
Loading