Commit fa0e4bf6 authored by ccottier's avatar ccottier

read, create, and delete operations working

parents
File added
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/nisum-workshop.iml" filepath="$PROJECT_DIR$/.idea/nisum-workshop.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nisum</groupId>
<artifactId>nisum-workshop</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>nisum-workshop</name>
<url>http://maven.apache.org</url>
<properties>
<spring-version>5.2.13.RELEASE</spring-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- renders views-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.5.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.165</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<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>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>mytomcat7</server>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
File added
package com.nisum;
import com.nisum.config.AppConfig;
import com.nisum.helper.EmployeeHelper;
import com.nisum.model.Employee;
import com.nisum.model.JobRole;
import com.nisum.model.impl.Contractor;
import com.nisum.model.impl.EmployeeImp;
import com.nisum.model.impl.JobRoleImp;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
// traditionalApplicationFlow();
// applicationContextXmlConfig();
// applicationContextAnnotation();
}
public static void applicationContextAnnotation() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
EmployeeHelper employeeHelper = ctx.getBean(EmployeeHelper.class);
Employee emp1 = employeeHelper.createSoftwareEngineerEmployee("Vlad", "Rez");
Employee emp2 = employeeHelper.createSoftwareEngineerEmployee("John", "Smith");
List<Employee> employeeList = Arrays.asList(emp1, emp2);
employeeHelper.displayTeam(employeeList);
}
public static void applicationContextXmlConfig() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("application-context.xml");
Employee emp1 = ctx.getBean("employeeJohn", EmployeeImp.class);
Employee emp2 = ctx.getBean("employeeWalter", EmployeeImp.class);
Employee emp3 = ctx.getBean("employeeJane", EmployeeImp.class);
List<Employee> employeeList = Arrays.asList(emp1, emp2, emp3);
String techTeam = employeeList.stream().map(employee ->
String.format("%s - %s", employee.getDisplayName(), employee.getJobRole().getTitle()))
.collect(Collectors.joining("\n"));
System.out.println(techTeam);
Contractor contractor1 = ctx.getBean("jobRoleContractor", Contractor.class);
Contractor contractor2 = ctx.getBean("jobRoleContractor", Contractor.class);
JobRole contractor3 = ctx.getBean("jobRoleContractor", Contractor.class);
JobRoleImp jobRoleImp = ctx.getBean("jobRoleSoftwareEngineerI", JobRoleImp.class);
jobRoleImp.setTitle("Sales");
String techTeam2 = employeeList.stream().map(employee ->
String.format("%s - %s", employee.getDisplayName(), employee.getJobRole().getTitle()))
.collect(Collectors.joining("\n"));
System.out.println(techTeam2);
contractor1.setTitle("Accounting");
System.out.printf("\n%s\n%s", contractor1.getTitle(), contractor2.getTitle());
}
public static void traditionalApplicationFlow() {
// Traditional Application Flow
JobRoleImp jobRole1 = new JobRoleImp("Software Engineer I");
JobRoleImp jobRole2 = new JobRoleImp("Software Engineer II");
JobRoleImp jobRole3 = new JobRoleImp("Tech Lead");
EmployeeImp employee1 = new EmployeeImp();
employee1.setFirstName("John");
employee1.setLastName("Smith");
employee1.setJobRole(jobRole1);
EmployeeImp employee2 = new EmployeeImp();
employee2.setFirstName("Walter");
employee2.setLastName("Bell");
employee2.setJobRole(jobRole2);
EmployeeImp employee3 = new EmployeeImp();
employee3.setFirstName("Jane");
employee3.setLastName("Doe");
employee3.setJobRole(jobRole3);
System.out.printf("\n%s %s %s\n",
employee1.getDisplayName(),
employee2.getDisplayName(),
employee3.getDisplayName());
}
}
package com.nisum.config;
import com.nisum.helper.EmployeeHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("com.nisum")
public class AppConfig {
@Bean
public EmployeeHelper employeeHelper() {
return new EmployeeHelper();
}
}
package com.nisum.controller;
import com.nisum.model.impl.EmployeeImp;
import com.nisum.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.PathVariable;
import com.nisum.dto.EmployeeDto;
import java.util.Collection;
@Controller
public class EmployeeController {
@Autowired
EmployeeService employeeService;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(Model model) {
Collection<EmployeeImp> employeeList = employeeService.getAllEmployees();
model.addAttribute("employees", employeeList);
return "index";
}
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String newEmployee(Model model) {
model.addAttribute("employee", new EmployeeDto());
return "new";
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String createEmployee(@ModelAttribute("employee") EmployeeDto employeeDto,
BindingResult bindingResult) {
employeeService.createEmployee(employeeDto);
return "redirect:/";
}
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
public String editEmployee(@PathVariable("id") int id, Model model) {
employeeService.deleteEmployee(id);
return "redirect:/";
}
}
package com.nisum.dao;
import java.util.Collection;
import java.util.Optional;
public interface Dao<T> {
Optional<T> getById(int id);
Collection<T> getAll();
void save(T t);
void update(T t);
void delete(T t);
}
package com.nisum.dao.impl;
import com.nisum.dao.Dao;
import com.nisum.model.impl.EmployeeImp;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import java.util.Collection;
import java.util.Optional;
@Repository
@Qualifier("EmployeeDao")
@Transactional
public class EmployeeDao implements Dao<EmployeeImp> {
@PersistenceContext
private EntityManager entityManager;
@Override
public Optional<EmployeeImp> getById(int id) {
return Optional.of(entityManager.find(EmployeeImp.class, id));
}
@Override
public Collection<EmployeeImp> getAll() {
TypedQuery<EmployeeImp> typedQuery = entityManager.createQuery("SELECT e FROM employee e", EmployeeImp.class);
return typedQuery.getResultList();
}
@Override
public void save(EmployeeImp employeeImp) {
entityManager.persist(employeeImp);
}
@Override
public void update(EmployeeImp employeeImp) {
}
@Override
public void delete(EmployeeImp employeeImp) {
entityManager.remove(entityManager.contains(employeeImp) ? employeeImp : entityManager.merge(employeeImp));
}
}
package com.nisum.dto;
public class EmployeeDto {
String firstName;
String lastName;
String jobTitle;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public String[] get(){
return new String[]{firstName,lastName,jobTitle};
}
}
\ No newline at end of file
package com.nisum.helper;
import com.nisum.model.Employee;
import com.nisum.model.impl.EmployeeImp;
import com.nisum.model.impl.JobRoleImp;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class EmployeeHelper {
public EmployeeImp createSoftwareEngineerEmployee(String fName, String lName) {
EmployeeImp employeeImp = new EmployeeImp();
employeeImp.setFirstName(fName);
employeeImp.setLastName(lName);
employeeImp.setJobRole(new JobRoleImp("Software Engineer"));
return employeeImp;
}
public void displayTeam(List<Employee> employeeList) {
String techTeam = employeeList.stream().map(employee ->
String.format("%s - %s", employee.getDisplayName(), employee.getJobRole().getTitle())).collect(Collectors.joining("\n"));
System.out.println(techTeam);
}
}
package com.nisum.model;
public interface Employee {
String getFirstName();
String getLastName();
String getDisplayName();
JobRole getJobRole();
}
package com.nisum.model;
public interface JobRole {
String getTitle();
}
package com.nisum.model.impl;
public class Contractor extends JobRoleImp {
public Contractor(String s) {
super(String.format("%s Contractor", s));
}
}
package com.nisum.model.impl;
import com.nisum.model.Employee;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
@Table
@Entity(name="employee")
public class EmployeeImp implements Employee {
@Id
@GeneratedValue
private Integer id;
private String firstName;
private String lastName;
@Transient
private JobRoleImp jobRole;
public EmployeeImp() {
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getDisplayName() {
return String.format("%s%s",
this.firstName.toUpperCase().charAt(0),
this.lastName.toUpperCase());
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public JobRoleImp getJobRole() {
return jobRole;
}
public void setJobRole(JobRoleImp jobRole) {
this.jobRole = jobRole;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void set(String[] settings){
setFirstName(settings[0]);
setLastName(settings[1]);
setJobRole(new JobRoleImp(settings[2]));
}
}
package com.nisum.model.impl;
import com.nisum.model.JobRole;
public class JobRoleImp implements JobRole {
private String title;
public JobRoleImp(String title) {
this.title = title;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
}
package com.nisum.service;
import com.nisum.dao.Dao;
import com.nisum.model.Employee;
import com.nisum.model.impl.EmployeeImp;
import com.nisum.dto.EmployeeDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.Collection;
@Service
public class EmployeeService {
@Autowired
@Qualifier(value = "EmployeeDao")
private Dao employeeDao;
public Collection<EmployeeImp> getAllEmployees() {
return employeeDao.getAll();
}
public void createEmployee(EmployeeDto employeeDto){
EmployeeImp newEmployee = new EmployeeImp();
newEmployee.set(employeeDto.get());
employeeDao.save(newEmployee);
}
public void deleteEmployee(int id){
Optional<EmployeeImp> employee = employeeDao.getById(id);
if (employee.isPresent()) {
employeeDao.delete(employee.get());
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="jobRoleSoftwareEngineerI" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Software Engineer I"/>
</bean>
<bean id="jobRoleSoftwareEngineerII" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Software Engineer II"/>
</bean>
<bean id="jobRoleTechLead" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Tech Lead"/>
</bean>
<bean id="jobRoleContractor" scope="prototype" class="com.nisum.model.impl.Contractor">
<constructor-arg value="Software Engineer"/>
</bean>
<bean id="employeeJohn" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="John"/>
<property name="lastName" value="Smith"/>
<property name="jobRole" ref="jobRoleSoftwareEngineerI"/>
</bean>
<bean id="employeeWalter" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="Walter"/>
<property name="lastName" value="Bell"/>
<property name="jobRole" ref="jobRoleSoftwareEngineerII"/>
</bean>
<bean id="employeeJane" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="Jane"/>
<property name="lastName" value="Doe"/>
<property name="jobRole" ref="jobRoleTechLead"/>
</bean>
</beans>
\ No newline at end of file
INSERT INTO public.employee values (1, 'Vlad', 'Rez')
INSERT INTO public.employee values (2, 'John', 'Smith')
INSERT INTO public.employee values (3, 'Jane', 'Doe')
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc ="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven/>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Where to look for to get @Component -->
<context:component-scan base-package="com.nisum.controller" />
</beans>
\ No newline at end of file
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Employee Service</title>
</head>
<body>
Hello Web
<table>
<c:forEach var="employee" items="${employees}">
<tr>
<td>
<c:out value="EMP: ${employee.displayName}">
</c:out>
<a href="/delete/${employee.id}">Delete</a>
</td>
</tr>
</c:forEach>
</table>
<a href="/new">Create New</a>
</body>
</html>
\ No newline at end of file
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<title>New Employee</title>
</head>
<body>
<h1>Create Employee</h1>
<%--the <form:form> tag plays an important role here;
it's very similar to the regular HTLM <form> tag but the modelAttribute attribute is the key which specifies a name
of the model object that backs this form:--%>
<form:form action="/create" method="POST" modelAttribute="employee">
<table>
<tr>
<td><form:label path="firstName">First Name</form:label></td>
<td><form:input path="firstName"/></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name</form:label></td>
<td><form:input path="lastName"/></td>
</tr>
<tr>
<td><form:label path="jobTitle">Job Title</form:label></td>
<td><form:input path="jobTitle"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</form:form>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--resource visible to all other web components-->
<mvc:annotation-driven/>
<!-- Same as @ComponentScan("com.nisum")-->
<context:component-scan base-package="com.nisum" />
<!-- serves static resources-->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- creates an embedded database instance as a bean -->
<jdbc:embedded-database id="dataSource" type="H2" />
<!-- creates a H2 database bean to be managed by the application context-->
<bean id="h2Server" class="org.h2.tools.Server" factory-method="createTcpServer" init-method="start" destroy-method="stop" depends-on="h2WebServer">
<constructor-arg value="-tcp,-tcpAllowOthers,-tcpPort,9093"/>
</bean>
<!-- creates a H2 webserver bean to be managed by the application context to access web based UI for sql commands-->
<bean id="h2WebServer" class="org.h2.tools.Server" factory-method="createWebServer" init-method="start" destroy-method="stop">
<constructor-arg value="-web,-webAllowOthers,-webPort,8082"/>
</bean>
<!-- Container managed entity manager, sets up instantiation of a EntityManager, an Entity Manger is basically a connection to a database -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="EmpPU" />
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" >
<list>
<value>com.nisum.model</value>
</list>
</property>
<property name="persistenceProvider">
<bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
</property>
<property name="jpaProperties">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<entry key="hibernate.hbm2ddl.auto" value="create" />
<entry key="hibernate.hbm2ddl.import_files" value="employee_data.sql" />
<entry key="hibernate.show_sql" value="true" />
<entry key="hibernate.enable_lazy_load_no_trans" value="true"/>
</map>
</property>
</bean>
<!-- Bean for a single JPA EntityManagerFactory (see above entityManagerFactory)-->
<bean id="transactionManager" scope="session" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- Enable Annotation based Transaction Management, To make the @Transactional annotation work -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets, basically provides parameters to the entire web application-->
<!--see https://docs.spring.io/spring-framework/docs/3.0.0.M3/reference/html/ch19s02.html-->
<context-param>
<!--param gives the location of the root context.-->
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/web-context.xml</param-value>
</context-param>
<!-- root web-application-context for the web-application and puts it in the ServletContext-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- specifies which java servlet should be invoked for a url-->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
package com.nisum;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="jobRoleSoftwareEngineerI" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Software Engineer I"/>
</bean>
<bean id="jobRoleSoftwareEngineerII" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Software Engineer II"/>
</bean>
<bean id="jobRoleTechLead" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Tech Lead"/>
</bean>
<bean id="jobRoleContractor" scope="prototype" class="com.nisum.model.impl.Contractor">
<constructor-arg value="Software Engineer"/>
</bean>
<bean id="employeeJohn" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="John"/>
<property name="lastName" value="Smith"/>
<property name="jobRole" ref="jobRoleSoftwareEngineerI"/>
</bean>
<bean id="employeeWalter" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="Walter"/>
<property name="lastName" value="Bell"/>
<property name="jobRole" ref="jobRoleSoftwareEngineerII"/>
</bean>
<bean id="employeeJane" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="Jane"/>
<property name="lastName" value="Doe"/>
<property name="jobRole" ref="jobRoleTechLead"/>
</bean>
</beans>
\ No newline at end of file
INSERT INTO public.employee values (1, 'Vlad', 'Rez')
INSERT INTO public.employee values (2, 'John', 'Smith')
INSERT INTO public.employee values (3, 'Jane', 'Doe')
\ No newline at end of file
#Generated by Maven
#Tue Mar 30 14:26:57 CDT 2021
groupId=com.nisum
artifactId=nisum-workshop
version=1.0-SNAPSHOT
com/nisum/model/impl/EmployeeImp.class
com/nisum/model/JobRole.class
com/nisum/config/AppConfig.class
com/nisum/dao/impl/EmployeeDao.class
com/nisum/model/Employee.class
com/nisum/model/impl/JobRoleImp.class
com/nisum/service/EmployeeService.class
com/nisum/dto/EmployeeDto.class
com/nisum/helper/EmployeeHelper.class
com/nisum/App.class
com/nisum/dao/Dao.class
com/nisum/controller/EmployeeController.class
com/nisum/model/impl/Contractor.class
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/dto/EmployeeDto.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/model/JobRole.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/model/impl/EmployeeImp.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/App.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/dao/impl/EmployeeDao.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/service/EmployeeService.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/config/AppConfig.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/model/impl/Contractor.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/controller/EmployeeController.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/dao/Dao.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/model/Employee.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/model/impl/JobRoleImp.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/main/java/com/nisum/helper/EmployeeHelper.java
/Users/ccottier/Documents/assignments/nisum-workshop/src/test/java/com/nisum/AppTest.java
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="jobRoleSoftwareEngineerI" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Software Engineer I"/>
</bean>
<bean id="jobRoleSoftwareEngineerII" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Software Engineer II"/>
</bean>
<bean id="jobRoleTechLead" class="com.nisum.model.impl.JobRoleImp">
<constructor-arg value="Tech Lead"/>
</bean>
<bean id="jobRoleContractor" scope="prototype" class="com.nisum.model.impl.Contractor">
<constructor-arg value="Software Engineer"/>
</bean>
<bean id="employeeJohn" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="John"/>
<property name="lastName" value="Smith"/>
<property name="jobRole" ref="jobRoleSoftwareEngineerI"/>
</bean>
<bean id="employeeWalter" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="Walter"/>
<property name="lastName" value="Bell"/>
<property name="jobRole" ref="jobRoleSoftwareEngineerII"/>
</bean>
<bean id="employeeJane" class="com.nisum.model.impl.EmployeeImp">
<property name="firstName" value="Jane"/>
<property name="lastName" value="Doe"/>
<property name="jobRole" ref="jobRoleTechLead"/>
</bean>
</beans>
\ No newline at end of file
INSERT INTO public.employee values (1, 'Vlad', 'Rez')
INSERT INTO public.employee values (2, 'John', 'Smith')
INSERT INTO public.employee values (3, 'Jane', 'Doe')
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc ="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven/>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Where to look for to get @Component -->
<context:component-scan base-package="com.nisum.controller" />
</beans>
\ No newline at end of file
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Employee Service</title>
</head>
<body>
Hello Web
<table>
<c:forEach var="employee" items="${employees}">
<tr>
<td>
<c:out value="EMP: ${employee.displayName}">
</c:out>
<a href="/delete/${employee.id}">Delete</a>
</td>
</tr>
</c:forEach>
</table>
<a href="/new">Create New</a>
</body>
</html>
\ No newline at end of file
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<title>New Employee</title>
</head>
<body>
<h1>Create Employee</h1>
<%--the <form:form> tag plays an important role here;
it's very similar to the regular HTLM <form> tag but the modelAttribute attribute is the key which specifies a name
of the model object that backs this form:--%>
<form:form action="/create" method="POST" modelAttribute="employee">
<table>
<tr>
<td><form:label path="firstName">First Name</form:label></td>
<td><form:input path="firstName"/></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name</form:label></td>
<td><form:input path="lastName"/></td>
</tr>
<tr>
<td><form:label path="jobTitle">Job Title</form:label></td>
<td><form:input path="jobTitle"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</form:form>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--resource visible to all other web components-->
<mvc:annotation-driven/>
<!-- Same as @ComponentScan("com.nisum")-->
<context:component-scan base-package="com.nisum" />
<!-- serves static resources-->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- creates an embedded database instance as a bean -->
<jdbc:embedded-database id="dataSource" type="H2" />
<!-- creates a H2 database bean to be managed by the application context-->
<bean id="h2Server" class="org.h2.tools.Server" factory-method="createTcpServer" init-method="start" destroy-method="stop" depends-on="h2WebServer">
<constructor-arg value="-tcp,-tcpAllowOthers,-tcpPort,9093"/>
</bean>
<!-- creates a H2 webserver bean to be managed by the application context to access web based UI for sql commands-->
<bean id="h2WebServer" class="org.h2.tools.Server" factory-method="createWebServer" init-method="start" destroy-method="stop">
<constructor-arg value="-web,-webAllowOthers,-webPort,8082"/>
</bean>
<!-- Container managed entity manager, sets up instantiation of a EntityManager, an Entity Manger is basically a connection to a database -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="EmpPU" />
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" >
<list>
<value>com.nisum.model</value>
</list>
</property>
<property name="persistenceProvider">
<bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
</property>
<property name="jpaProperties">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<entry key="hibernate.hbm2ddl.auto" value="create" />
<entry key="hibernate.hbm2ddl.import_files" value="employee_data.sql" />
<entry key="hibernate.show_sql" value="true" />
<entry key="hibernate.enable_lazy_load_no_trans" value="true"/>
</map>
</property>
</bean>
<!-- Bean for a single JPA EntityManagerFactory (see above entityManagerFactory)-->
<bean id="transactionManager" scope="session" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- Enable Annotation based Transaction Management, To make the @Transactional annotation work -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets, basically provides parameters to the entire web application-->
<!--see https://docs.spring.io/spring-framework/docs/3.0.0.M3/reference/html/ch19s02.html-->
<context-param>
<!--param gives the location of the root context.-->
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/web-context.xml</param-value>
</context-param>
<!-- root web-application-context for the web-application and puts it in the ServletContext-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- specifies which java servlet should be invoked for a url-->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="1" failures="0" name="com.nisum.AppTest" time="0.002" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="java.vm.version" value="15.0.2+7"/>
<property name="sun.boot.library.path" value="/usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home/lib"/>
<property name="maven.multiModuleProjectDirectory" value="/Users/ccottier/Documents/assignments/nisum-workshop"/>
<property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="java.vendor.url" value="https://openjdk.java.net/"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="path.separator" value=":"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="user.country" value="US"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/Users/ccottier/Documents/assignments/nisum-workshop"/>
<property name="java.vm.compressedOopsMode" value="Zero based"/>
<property name="java.runtime.version" value="15.0.2+7"/>
<property name="os.arch" value="x86_64"/>
<property name="java.io.tmpdir" value="/var/folders/7p/ljyg1wqs3nj3yb6800dmr28r0000gp/T/"/>
<property name="line.separator" value="
"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Mac OS X"/>
<property name="classworlds.conf" value="/usr/local/Cellar/maven/3.6.3_1/libexec/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.library.path" value="/Users/ccottier/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."/>
<property name="maven.conf" value="/usr/local/Cellar/maven/3.6.3_1/libexec/conf"/>
<property name="jdk.debug" value="release"/>
<property name="java.class.version" value="59.0"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="10.15.7"/>
<property name="library.jansi.path" value="/usr/local/Cellar/maven/3.6.3_1/libexec/lib/jansi-native"/>
<property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="user.home" value="/Users/ccottier"/>
<property name="user.timezone" value="America/Chicago"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.specification.version" value="15"/>
<property name="user.name" value="ccottier"/>
<property name="java.class.path" value="/usr/local/Cellar/maven/3.6.3_1/libexec/boot/plexus-classworlds-2.6.0.jar"/>
<property name="java.vm.specification.version" value="15"/>
<property name="sun.arch.data.model" value="64"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher clean install tomcat7:run"/>
<property name="java.home" value="/usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="java.version" value="15.0.2"/>
<property name="java.vendor" value="N/A"/>
<property name="maven.home" value="/usr/local/Cellar/maven/3.6.3_1/libexec"/>
<property name="file.separator" value="/"/>
<property name="java.version.date" value="2021-01-19"/>
<property name="java.vendor.url.bug" value="https://bugreport.java.com/bugreport/"/>
<property name="sun.io.unicode.encoding" value="UnicodeBig"/>
<property name="sun.cpu.endian" value="little"/>
<property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
</properties>
<testcase classname="com.nisum.AppTest" name="testApp" time="0.002"/>
</testsuite>
\ No newline at end of file
-------------------------------------------------------------------------------
Test set: com.nisum.AppTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.
2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.
3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.FileHandler.prefix = manager.
4host-manager.org.apache.juli.FileHandler.level = FINE
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.FileHandler.prefix = host-manager.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.FileHandler
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE
# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users>
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->
</tomcat-users>
This diff is collapsed.
This diff is collapsed.
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