Commit ca06d5c4 by jorgecacs

First commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>demo_mcs</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="demo_mcs-0.0.1-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="demo_mcs"/>
<property name="java-output-path" value="/demo_mcs/target/classes"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.5"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
Window
\ No newline at end of file
disabled=06target
eclipse.preferences.version=1
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rshk.demo.mcs</groupId>
<artifactId>demo_mcs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>RshkMcs</name>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>default-war</id>
<phase>prepare-package</phase>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.rshka.mcs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Customer {
@JsonProperty(value = "customer_id", required = true)
private int id;
@JsonProperty(value = "customer_name", required = true)
private String name;
@JsonProperty(value = "customer_address", required = true)
private String address;
@JsonProperty(value = "customer_number", required = true)
private String phoneNumber;
@JsonProperty(value = "customer_document", required = true)
private String document;
}
package com.rshka.mcs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ErrorMcs {
@JsonProperty(value = "code", required = true)
private String code;
@JsonProperty(value = "message", required = true)
private String message;
}
package com.rshka.mcs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class GetCustomerRespData {
@JsonProperty(value = "data")
private Customer data;
}
package com.rshka.mcs.beans;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class GetCustomersRespData {
@JsonProperty(value = "data")
private List<Customer> data;
}
package com.rshka.mcs.beans;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class PostCustomerData implements Serializable {
@JsonProperty(value = "data")
private Integer data;
}
package com.rshka.mcs.configuration;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class AppConfiguration extends WebMvcConfigurationSupport {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(false).setName("testdb")
.setType(EmbeddedDatabaseType.H2).addDefaultScripts().setScriptEncoding("UTF-8").ignoreFailedDrops(true)
.build();
}
@Bean
public NamedParameterJdbcTemplate namedParamJdbcTemplate() {
NamedParameterJdbcTemplate namedParamJdbcTemplate = new NamedParameterJdbcTemplate(dataSource());
return namedParamJdbcTemplate;
}
}
package com.rshka.mcs.controllers;
import java.util.List;
import java.util.logging.ErrorManager;
import org.h2.util.New;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rshka.mcs.beans.Customer;
import com.rshka.mcs.beans.ErrorMcs;
import com.rshka.mcs.beans.GetCustomerRespData;
import com.rshka.mcs.beans.GetCustomersRespData;
import com.rshka.mcs.beans.PostCustomerData;
import com.rshka.mcs.service.CustomerService;
@RestController
@RequestMapping(value = "/customer")
public class CustomerController {
@Autowired
private CustomerService customerService;
@RequestMapping(value = "/{document}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getCustomer(@PathVariable(value = "document") String document) {
try {
Customer customer = customerService.getCustomer(document);
return new ResponseEntity<GetCustomerRespData>(new GetCustomerRespData(customer), HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<ErrorMcs>(new ErrorMcs("FTL_PF_1000", e.getMessage()),
HttpStatus.UNPROCESSABLE_ENTITY);
}
}
@RequestMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getCustomerList() {
try {
List<Customer> customer = customerService.getCustomers();
return new ResponseEntity<GetCustomersRespData>(new GetCustomersRespData(customer), HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<ErrorMcs>(new ErrorMcs("FTL_PF_1000", e.getMessage()),
HttpStatus.UNPROCESSABLE_ENTITY);
}
}
@RequestMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity save(@RequestBody Customer customer) {
try {
Integer id = customerService.saveCustomer(customer);
return new ResponseEntity<PostCustomerData>(new PostCustomerData(id), HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<ErrorMcs>(new ErrorMcs("FTL_PF_1000", e.getMessage()),
HttpStatus.UNPROCESSABLE_ENTITY);
}
}
}
package com.rshka.mcs.dao;
import java.util.List;
import com.rshka.mcs.beans.Customer;
public interface CustomerDao {
Customer getCustomer(String document);
List<Customer> getCustomers();
int saveCustomer(Customer customer);
}
package com.rshka.mcs.dao;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import com.rshka.mcs.beans.Customer;
import com.rshka.mcs.mapper.CustomerMapper;
public class CustomerDaoImpl implements CustomerDao {
private final String CUSTOMER_TABLE = "CUSTOMER";
private final String SCHEMA_NAME = "";
private final String SELECT_CUSTOMER_QUERY = "select * from customer where document_number = ?";
private final String SELECT_CUSTOMERS_QUERY = "select * from customer";
private final String INSERT_CUSTOMER_QUERY = "insert into customer(document_number, name, address, phone) values (?, ?, ?, ?)";
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* Return a customer by the specified document
*/
public Customer getCustomer(String document) {
try {
Customer c = jdbcTemplate.queryForObject(SELECT_CUSTOMER_QUERY, new Object[] { document },
new CustomerMapper());
return c;
} catch (EmptyResultDataAccessException e) {
e.printStackTrace();
throw e;
} catch (DataAccessException e) {
e.printStackTrace();
throw e;
}
}
/**
* Return a customer list.
*/
public List<Customer> getCustomers() {
try {
List<Customer> customerList = jdbcTemplate.query(SELECT_CUSTOMERS_QUERY, new CustomerMapper());
return customerList;
} catch (DataAccessException e) {
e.printStackTrace();
throw e;
}
}
/**
* Insert the customer provided.
*/
public int saveCustomer(Customer customer) {
try {
SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate);
insert.withTableName(CUSTOMER_TABLE).usingGeneratedKeyColumns("id");
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("name", customer.getName());
parameters.addValue("document", customer.getDocument());
parameters.addValue("address", customer.getAddress());
parameters.addValue("phone", customer.getPhoneNumber());
Number id = insert.executeAndReturnKey(parameters);
return id.intValue();
} catch (DataAccessException e) {
e.printStackTrace();
throw e;
}
}
}
package com.rshka.mcs.mapper;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.rshka.mcs.beans.Customer;
public class CustomerMapper implements RowMapper<Customer> {
public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {
Customer customer = new Customer();
customer.setAddress(rs.getString("address"));
customer.setDocument(rs.getString("document"));
customer.setName(rs.getString("name"));
customer.setPhoneNumber(rs.getString("phone"));
return customer;
}
}
package com.rshka.mcs.service;
import java.util.List;
import com.rshka.mcs.beans.Customer;
public interface CustomerService {
Customer getCustomer(String document);
List<Customer> getCustomers();
int saveCustomer(Customer customer);
}
package com.rshka.mcs.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.rshka.mcs.beans.Customer;
import com.rshka.mcs.dao.CustomerDao;
@Repository
public class CustomerServiceImpl implements CustomerService {
@Autowired
private CustomerDao customerDao;
public Customer getCustomer(String document) {
return customerDao.getCustomer(document);
}
public List<Customer> getCustomers() {
return customerDao.getCustomers();
}
public int saveCustomer(Customer customer) {
return customerDao.saveCustomer(customer);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>demo_mcs</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
\ No newline at end of file
Manifest-Version: 1.0
Built-By: jorgecaceresflores
Build-Jdk: 1.8.0_232
Created-By: Maven Integration for Eclipse
#Generated by Maven Integration for Eclipse
#Wed Jan 15 21:27:27 PYST 2020
version=0.0.1-SNAPSHOT
groupId=com.rshk.demo.mcs
m2e.projectName=demo_mcs
m2e.projectLocation=/Users/jorgecaceresflores/Documents/workspace-sts-3.9.11.RELEASE/demo_mcs
artifactId=demo_mcs
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rshk.demo.mcs</groupId>
<artifactId>demo_mcs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>RshkMcs</name>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>default-war</id>
<phase>prepare-package</phase>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment