Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
33 changes: 32 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand All @@ -25,12 +27,17 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.flywaydb</groupId>
Expand All @@ -49,6 +56,22 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

</dependencies>

<build>
Expand All @@ -57,6 +80,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<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>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.zoomcare.candidatechallenge.constants;

/**
* Message values for application
*/
public final class ApplicationConstants {

/** Personalized message for employee not found error **/
public static final String EMPLOYEE_NOT_FOUND = "Employee ID %d not found";

/** Personalized message for employee ID required **/
public static final String EMPLOYEE_ID_REQUIRED = "Employee ID required";

}
12 changes: 12 additions & 0 deletions src/main/java/com/zoomcare/candidatechallenge/dao/EmployeeDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.zoomcare.candidatechallenge.dao;

import org.springframework.data.repository.CrudRepository;

import com.zoomcare.candidatechallenge.model.Employee;

/**
* DAO for employee
*/
public interface EmployeeDAO extends CrudRepository<Employee, Long> {

}
46 changes: 46 additions & 0 deletions src/main/java/com/zoomcare/candidatechallenge/dto/EmployeeDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.zoomcare.candidatechallenge.dto;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
* DTO to return employee
*/
@JsonInclude(Include.NON_NULL)
public abstract class EmployeeDTO {

/** Employee ID */
private Long id;

/** Properties map **/
private Map<String, String> properties;

public EmployeeDTO() {
properties = new HashMap<>();
}

public EmployeeDTO(Long id, Map<String, String> properties) {
this.id = id;
this.properties = properties;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Map<String, String> getProperties() {
return properties;
}

public void setProperties(Map<String, String> properties) {
this.properties = properties;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.zoomcare.candidatechallenge.dto;

import java.util.Map;

/**
* DTO to return employee with supervisor information
*/
public class EmployeeInfoDTO extends EmployeeDTO {

/** Supervisor information **/
private EmployeeInfoDTO supervisor;

/** Error message **/
private String error;

public EmployeeInfoDTO() {
super();
}

public EmployeeInfoDTO(String error) {
this.error = error;
this.setProperties(null);
}

public EmployeeInfoDTO(Long id, EmployeeInfoDTO supervisor, Map<String, String> properties) {
super(id, properties);
this.supervisor = supervisor;
}

public String toString() {
return String.format("EmployeeInfo[id: %d, supervisor: %d]", getId(), null != supervisor ? supervisor.getId() : null);
}

public EmployeeInfoDTO getSupervisor() {
return supervisor;
}

public void setSupervisor(EmployeeInfoDTO supervisor) {
this.supervisor = supervisor;
}

public String getError() {
return error;
}

public void setError(String error) {
this.error = error;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.zoomcare.candidatechallenge.dto;

import java.util.Map;

/**
* DTO to create organization estructure
*/
public class OrganizationStructureDTO extends EmployeeDTO {

/** Supervisor ID **/
private Long supervisor;

public OrganizationStructureDTO() {
super();
}

public OrganizationStructureDTO(Long id, Map<String, String> properties, Long supervisor) {
super(id, properties);
this.supervisor = supervisor;
}

@Override
public String toString() {
return String.format("OrganizationStructure[id; %d, supervidor: %d]", getId(), supervisor);
}

public Long getSupervisor() {
return supervisor;
}

public void setSupervisor(Long supervisor) {
this.supervisor = null != supervisor ? supervisor : -1l;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.zoomcare.candidatechallenge.dto;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* DTO to create top level list organization
*/
public class TopLevelListDTO extends EmployeeDTO {

/** underling employees **/
private List<TopLevelListDTO> underling;

public TopLevelListDTO() {
super();
underling = new ArrayList<>();
}

public TopLevelListDTO(Long id, Map<String, String> properties, List<TopLevelListDTO> underling) {
super(id, properties);
this.underling = underling;
}

public String toString() {
return String.format("TopLevelLis[id: %d, underling: %d]", getId(), underling.size());
}

public List<TopLevelListDTO> getUnderling() {
return underling;
}

public void setUnderling(List<TopLevelListDTO> underling) {
this.underling = underling;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.zoomcare.candidatechallenge.exception;

import org.springframework.http.HttpStatus;

/**
* Exception to report data required
*/
public class DataRequiredException extends EmployeeException {

private static final long serialVersionUID = 1L;

public DataRequiredException(String message) {
super();
this.message = message;
this.httpStatus = HttpStatus.BAD_REQUEST;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.zoomcare.candidatechallenge.exception;

import org.springframework.http.HttpStatus;

/**
* Basic exception for employee operations
*/
public class EmployeeException extends Exception {

private static final long serialVersionUID = 1L;

/** Error message **/
protected String message;

/** Status response **/
protected HttpStatus httpStatus;

public EmployeeException() {
super();
}

public EmployeeException(String message, HttpStatus httpStatus) {
super();
this.message = message;
this.httpStatus = httpStatus;
}

public String getMessage() {
return message;
}

public HttpStatus getHttpStatus() {
return httpStatus;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zoomcare.candidatechallenge.exception;

import org.springframework.http.HttpStatus;

import com.zoomcare.candidatechallenge.constants.ApplicationConstants;

public class EmployeeNotFoundException extends EmployeeException {

private static final long serialVersionUID = 1L;

public EmployeeNotFoundException(Long emplooyeeId) {
super();
message = String.format(ApplicationConstants.EMPLOYEE_NOT_FOUND, emplooyeeId);
httpStatus = HttpStatus.NOT_FOUND;
}

}
Loading