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
26 changes: 26 additions & 0 deletions configurationapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<skipTests>true</skipTests>
</properties>

<dependencies>
Expand All @@ -39,6 +40,24 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>

</dependencies>

<build>
Expand All @@ -47,6 +66,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
<finalName>configurationapp</finalName>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* The Company Privacy & Copy Right message goes here
*/
package com.att.dao.configurations;

import com.att.data.configurations.ConfigValue;
Expand All @@ -8,6 +11,7 @@
import java.util.List;
import java.util.Map;


@Service
public class ConfigurationDao {
private class IdProvider {
Expand All @@ -33,16 +37,40 @@ public ConfigurationDao() {
currentConfigurations = new HashMap<>();
}

public List<ConfigValue> getConfigurationsForYearMonth(String yearMonth) {
return new ArrayList<>();
}
public List<ConfigValue> getConfigurationsForYearMonth(String yearMonth) {
if(currentConfigurations.containsKey(yearMonth)) {
return currentConfigurations.get(yearMonth);
}
return null;
}

public void addConfiguration(String yearMonth, ConfigValue value) {
public ConfigValue addConfiguration(String yearMonth, ConfigValue value) {
int newId = idProvider.getNextId();
value.setConfigId(newId);
if(currentConfigurations.containsKey(yearMonth)) {
currentConfigurations.get(yearMonth).add(value);
} else {
List<ConfigValue> configValues = new ArrayList<ConfigValue>();
configValues.add(value);
currentConfigurations.put(yearMonth, configValues);
}
return value;

}

public void removeAllConfigurationsForYearMonth(String yearMonth) {
if(currentConfigurations.containsKey(yearMonth)) {
currentConfigurations.get(yearMonth).clear();
}
}

public void removeConfigurationsForYearMonth(int configId, String yearMonth) {
if(currentConfigurations.containsKey(yearMonth)) {
ConfigValue configValueSelected = currentConfigurations.get(yearMonth)
.stream()
.filter(c -> c.getConfigId() == configId)
.findFirst()
.get();
currentConfigurations.get(yearMonth).remove(configValueSelected);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.att.data.configurations;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
* Data Model
*/
public class ConfigValue {

@NotNull
@NotEmpty
private String configName;
private int configId;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.att.exceptionHandling;

import com.att.web.configuarations.ConfigurationController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
* Created by Achille on 10/5/2018.
*/
public class ConfigurationException extends Exception{

private static final long serialVersionUID = 1L;
private int code;
private String message;

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

@Override
public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.att.exceptionHandling;

import com.att.web.configuarations.ConfigurationController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
* Created by Achille on 10/5/2018.
*/
@ControllerAdvice
public class ErrorHandlingController {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationController.class);

@ExceptionHandler(Exception.class)
public ResponseEntity<ExceptionResponse> generalException(Exception excception) {
ExceptionResponse ex = new ExceptionResponse();
ex.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
ex.setDescription(excception.getMessage());
LOGGER.error(excception.getMessage(),excception.getStackTrace());
return new ResponseEntity<ExceptionResponse>(ex, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(ConfigurationException.class)
public ResponseEntity<ExceptionResponse> configurationlException(Exception excception) {
ExceptionResponse ex = new ExceptionResponse();
ex.setCode(HttpStatus.BAD_REQUEST.value());
ex.setDescription(excception.getMessage());
LOGGER.error(excception.getMessage(),excception.getStackTrace());

return new ResponseEntity<ExceptionResponse>(ex, HttpStatus.BAD_REQUEST);
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.att.exceptionHandling;

/**
* Created by Achille on 10/5/2018.
*/
public class ExceptionResponse extends Exception {


private static final long serialVersionUID = 1L;
private int code;

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

private String description;

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.att.restapi.configurations;

/**
* Created by Achille on 10/5/2018.
*/
import com.att.web.configuarations.ConfigurationController;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@PropertySource("classpath:swagger.properties")
@ComponentScan(basePackageClasses = ConfigurationController.class)
@Configuration
public class SwaggerConfig {

private static final String SWAGGER_API_VERSION = "1.0";
private static final String LICENSE_TEXT = "License";
private static final String title = "ConfigurationController REST API";
private static final String description = "RESTful API for ConfigurationController";

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(title)
.description(description)
.license(LICENSE_TEXT)
.version(SWAGGER_API_VERSION)
.build();
}

@Bean
public Docket productsApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.pathMapping("/")
.select()
.paths(PathSelectors.regex("/api.*"))
.build();
}
}
Loading