Skip to content

Commit dc30578

Browse files
committed
initial
0 parents  commit dc30578

22 files changed

+498
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.iml
2+
target
3+
.idea

connector/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<artifactId>toptal-program-connector</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<parent>
11+
<groupId>co.kukurin</groupId>
12+
<artifactId>toptal-program</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
</parent>
15+
16+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package co.kukurin.toptal;
2+
3+
import co.kukurin.toptal.validation.MyAnnotation;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import org.hibernate.validator.constraints.Length;
8+
9+
import javax.validation.constraints.NotNull;
10+
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
@Getter
14+
public class TopTalentData {
15+
16+
@MyAnnotation(value = 10)
17+
@NotNull
18+
private String name;
19+
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package co.kukurin.toptal.validation;
2+
3+
import javax.validation.Constraint;
4+
import javax.validation.Payload;
5+
import java.lang.annotation.*;
6+
7+
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Documented
10+
@Constraint(validatedBy = { MyAnnotationValidator.class })
11+
public @interface MyAnnotation {
12+
13+
String message() default "String length does not match expected";
14+
15+
Class<?>[] groups() default {};
16+
17+
Class<? extends Payload>[] payload() default {};
18+
19+
int value();
20+
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package co.kukurin.toptal.validation;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
import javax.validation.ConstraintValidator;
6+
import javax.validation.ConstraintValidatorContext;
7+
8+
@Component
9+
public class MyAnnotationValidator implements ConstraintValidator<MyAnnotation, String> {
10+
11+
private int expectedLength;
12+
13+
@Override
14+
public void initialize(MyAnnotation myAnnotation) {
15+
this.expectedLength = myAnnotation.value();
16+
}
17+
18+
@Override
19+
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
20+
return s == null || s.length() == this.expectedLength;
21+
}
22+
}

pom.xml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>co.kukurin</groupId>
7+
<artifactId>toptal-program</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
11+
<name>TopTalProgram</name>
12+
<description>Sample Spring application.</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.4.1.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<modules>
22+
<module>connector</module>
23+
<module>service</module>
24+
</modules>
25+
26+
<properties>
27+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
28+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
29+
<java.version>1.8</java.version>
30+
</properties>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-data-jpa</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-jdbc</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-data-rest</artifactId>
46+
</dependency>
47+
48+
<!-- In-memory H2 database / development -->
49+
<dependency>
50+
<groupId>com.h2database</groupId>
51+
<artifactId>h2</artifactId>
52+
</dependency>
53+
54+
<!-- MySQL database / production -->
55+
<dependency>
56+
<groupId>mysql</groupId>
57+
<artifactId>mysql-connector-java</artifactId>
58+
<version>5.1.39</version>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-starter-test</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.projectlombok</groupId>
69+
<artifactId>lombok</artifactId>
70+
</dependency>
71+
72+
</dependencies>
73+
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.springframework.boot</groupId>
78+
<artifactId>spring-boot-maven-plugin</artifactId>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
83+
</project>

service/pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<artifactId>toptal-program-service</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<parent>
11+
<groupId>co.kukurin</groupId>
12+
<artifactId>toptal-program</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<relativePath>../pom.xml</relativePath>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>co.kukurin</groupId>
20+
<artifactId>toptal-program-connector</artifactId>
21+
<version>1.0-SNAPSHOT</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>io.rest-assured</groupId>
26+
<artifactId>rest-assured</artifactId>
27+
<version>3.0.2</version>
28+
<scope>test</scope>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>io.rest-assured</groupId>
33+
<artifactId>spring-mock-mvc</artifactId>
34+
<version>3.0.2</version>
35+
<scope>test</scope>
36+
</dependency>
37+
38+
</dependencies>
39+
40+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package co.kukurin;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
6+
7+
@SpringBootApplication
8+
@EnableJpaRepositories
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(Application.class, args);
13+
}
14+
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package co.kukurin;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
5+
@Configuration
6+
public class DataSourceConfig {
7+
8+
// alternate example of data source config bound to the dev profile
9+
// does essentially the same job as in application-dev.yaml.
10+
11+
// @Profile("dev")
12+
// @Bean
13+
// public DataSource embeddedDataSource() {
14+
// return new EmbeddedDatabaseBuilder()
15+
// .setType(EmbeddedDatabaseType.H2)
16+
// .addScript("classpath:schema.sql")
17+
// .addScript("classpath:data-h2.sql")
18+
// .build();
19+
// }
20+
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package co.kukurin.toptal;
2+
3+
import lombok.Value;
4+
import org.springframework.validation.ObjectError;
5+
6+
import java.util.List;
7+
8+
@Value
9+
public class ErrorResponse {
10+
11+
public static final int GENERIC_ERROR_CODE = 0;
12+
public static final int VALIDATION_ERROR_CODE = 1;
13+
14+
public static final ErrorResponse GENERIC_ERROR = new ErrorResponse(GENERIC_ERROR_CODE, "Unknown server exception");
15+
16+
private Integer errorCode;
17+
private String errorMessage;
18+
19+
public static ErrorResponse fromValidationErrors(List<ObjectError> validationErrors) {
20+
return validationErrors.stream()
21+
.map(ObjectError::getDefaultMessage)
22+
.findFirst()
23+
.map(error -> new ErrorResponse(ErrorResponse.VALIDATION_ERROR_CODE, error))
24+
.orElse(ErrorResponse.GENERIC_ERROR);
25+
}
26+
27+
}

0 commit comments

Comments
 (0)