Skip to content

Completed the exercise :) #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
db2bbcf
chore: Start setting to the application and tomcat
simaomenezes Apr 8, 2024
4696add
feat: Created a new attribute for the User - email, add new attribute…
simaomenezes Apr 9, 2024
30e3a46
chore: Created method to the table company
simaomenezes Apr 9, 2024
09072ba
chore: Add setting and route to the company page list
simaomenezes Apr 9, 2024
60fc62a
feat: Add called to the page comapny
simaomenezes Apr 9, 2024
a90d5cf
feat: Created class to the company list
simaomenezes Apr 9, 2024
5acc39d
feat: Created class of model company
simaomenezes Apr 9, 2024
ba26fc9
feat: Created class to the parse model and object form
simaomenezes Apr 9, 2024
617635b
feat: Created file jsp and js to the flow of creation and list of com…
simaomenezes Apr 9, 2024
ada746d
feat: Created class to the flow where we use to creation, list, edit …
simaomenezes Apr 9, 2024
40bbaa4
refactor: fix some things wrong and attributes to the company class
simaomenezes Apr 9, 2024
2481800
refactor: Bettered list of company
simaomenezes Apr 9, 2024
6cc5728
feat: Doing validate form
simaomenezes Apr 9, 2024
863a0ec
feat: Add file js to the flow creation of company
simaomenezes Apr 9, 2024
84c1b5d
feat: Created new company and list it
simaomenezes Apr 9, 2024
cfa9a5d
feat: Create flow to the logout, add called to the companies in menu
simaomenezes Apr 10, 2024
1f10d8e
feat: Create a public and a private (must be logged in) static page d…
simaomenezes Apr 10, 2024
6b50c26
feat: Created flow to the delete company
simaomenezes Apr 10, 2024
e0bee79
feat: Create tlow to the edit company
simaomenezes Apr 10, 2024
4988e2f
fix: resolve some errors
simaomenezes Apr 10, 2024
d8a5bb6
fix: resolve some errors
simaomenezes Apr 10, 2024
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
37 changes: 32 additions & 5 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/apache-tomcat-7.0.109">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="build/classes"/>
<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"/>
<attribute name="optional" 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>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
hs_err_pid*
replay_pid*
/build/
/target/
6 changes: 6 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
Expand Down
1 change: 1 addition & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate
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=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.ui.text.custom_code_templates=
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
11 changes: 9 additions & 2 deletions .settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="java7-struts1-jquery-bootstrap3-web-project">

<wb-module deploy-name="java7-struts1-jquery-bootstrap3-web-project-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"/>

<property name="java-output-path" value="/java7-struts1-jquery-bootstrap3-web-project/build/classes"/>
<property name="context-root" value="MyApp"/>
<property name="context-root" value="java7-struts1-jquery-bootstrap3-web-project"/>

</wb-module>

</project-modules>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
disabled=06target
eclipse.preferences.version=1
encoding/<project>=UTF-8
66 changes: 66 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>java7-struts1-jquery-bootstrap3-web-project</groupId>
<artifactId>java7-struts1-jquery-bootstrap3-web-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
<version>1.3.8</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
11 changes: 11 additions & 0 deletions src/main/java/MessageResources.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ error.password.wrong=Wrong password
user.not-found.error=User not found
user.username-taken.error=Username's already taken
user.delete.at-least-one.error=Must keep at least one user
user.email.error=Email's not valid

user.create.success=User "{0}" was created successfully
user.update.success=User "{0}" was update successfully
user.delete.success=User "{0}" was deleted successfully


company.not-found.error=Company not found
company.name-taken.error=Name's already taken
company.delete.at-least-one.error=Must keep at least one company


company.create.success=Company "{0}" was created successfully
company.update.success=Company "{0}" was update successfully
company.delete.success=Company "{0}" was deleted successfully
24 changes: 23 additions & 1 deletion src/main/java/com/my_app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
import com.my_app.db.DataSourceFactory;
import com.my_app.exception.AppGenericException;
import com.my_app.model.City;
import com.my_app.model.Company;
import com.my_app.model.Country;
import com.my_app.model.User;
import com.my_app.repo.CityRepository;
import com.my_app.repo.CompanyRepository;
import com.my_app.repo.CountryRepository;
import com.my_app.repo.UserRepository;
import com.my_app.repo.impl.CityRepositoryImpl;
import com.my_app.repo.impl.CompanyRepositoryImpl;
import com.my_app.repo.impl.CountryRepositoryImpl;
import com.my_app.repo.impl.UserRepositoryImpl;

Expand Down Expand Up @@ -81,6 +84,7 @@ private void initDb() {
try (final Connection conn = this.dataSource.getConnection()) {
initDbCountriesAndCities(conn);
initDbUsers(conn);
createDbCompanies(conn);
} catch (SQLException e) {
throw new AppGenericException("Error trying to insert initial db data", e);
}
Expand Down Expand Up @@ -115,7 +119,7 @@ private void initDbCountriesAndCities(Connection conn) throws SQLException {
private void initDbUsers(Connection conn) throws SQLException {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate(
"CREATE TABLE \"USER\" (ID IDENTITY NOT NULL PRIMARY KEY, USERNAME VARCHAR(255) UNIQUE NOT NULL, PASSWORD VARCHAR(255) NOT NULL, CITY_ID BIGINT NOT NULL, FOREIGN KEY (CITY_ID) REFERENCES CITY(ID))");
"CREATE TABLE \"USER\" (ID IDENTITY NOT NULL PRIMARY KEY, USERNAME VARCHAR(255) UNIQUE NOT NULL, PASSWORD VARCHAR(255) NOT NULL, CITY_ID BIGINT NOT NULL, EMAIL VARCHAR(255) NULL, FOREIGN KEY (CITY_ID) REFERENCES CITY(ID))");
}

final CityRepository cityRepository = new CityRepositoryImpl(conn, new CountryRepositoryImpl(conn));
Expand All @@ -130,5 +134,23 @@ private void initDbUsers(Connection conn) throws SQLException {

Logger.debug("All users created: {}", userRepository.findAll());
}

private void createDbCompanies(Connection conn) throws SQLException {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate(
"CREATE TABLE \"COMPANY\" (ID IDENTITY NOT NULL PRIMARY KEY, NAME VARCHAR(255) UNIQUE NOT NULL, ADDRESS VARCHAR(255) NOT NULL, VAT BIGINT NOT NULL, CITY_ID BIGINT NOT NULL, FOREIGN KEY (CITY_ID) REFERENCES CITY(ID))");
}

final CityRepository cityRepository = new CityRepositoryImpl(conn, new CountryRepositoryImpl(conn));
final CompanyRepository companyRepository = new CompanyRepositoryImpl(conn, cityRepository);

for (int i = 1; i < 5; i++) {
companyRepository.save(
new Company("company_name" + i, "address_company" + i, 1 + this.random.nextLong(49) + 1, cityRepository.findById((long) this.random.nextInt(49) + 1)));
}

Logger.debug("All comapny created: {}", companyRepository.findAll());

}

}
81 changes: 81 additions & 0 deletions src/main/java/com/my_app/model/Company.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.my_app.model;

public class Company {

private Long id;
private String name;
private String address;
private Long vat;
private City city;

public Company() {
super();
}

public Company(String name, String address, Long vat, City city) {
super();
this.name = name;
this.address = address;
this.vat = vat;
this.city = city;
}
public Company(Long id, String name, String address, Long vat, City city) {
super();
this.id = id;
this.name = name;
this.address = address;
this.vat = vat;
this.city = city;
}


public Long getId() {
return id;
}

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

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Long getVat() {
return vat;
}

public void setVat(Long vat) {
this.vat = vat;
}

public City getCity() {
return city;
}

public void setCity(City city) {
this.city = city;
}

public String getAddress() {
return address;
}

public String setAddress(String address) {
return address;
}

public boolean isNew() {
return this.id == null;
}

@Override
public String toString() {
return String.format("Company [id=%s, name=%s,address=%s, vat=%s, city=%s ]", id, name, address, vat, city);
}

}
15 changes: 13 additions & 2 deletions src/main/java/com/my_app/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class User {
private Long id;
private String username;
private String password;
private String email;
private City city;

public User() {
Expand All @@ -16,12 +17,13 @@ public User(String username, String password, City city) {
this.city = city;
}

public User(Long id, String username, String password, City city) {
public User(Long id, String username, String password, City city, String email) {
super();
this.id = id;
this.username = username;
this.password = password;
this.city = city;
this.email = email;
}

public Long getId() {
Expand Down Expand Up @@ -59,10 +61,19 @@ public void setCity(City city) {
public boolean isNew() {
return this.id == null;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Override
public String toString() {
return String.format("User [id=%s, username=%s, password=%s, city=%s]", id, username, password, city);
return String.format("User [id=%s, username=%s, password=%s, city=%s, email=%s]", id, username, password, city, email);
}


}
Loading