Skip to content

Commit 1c66972

Browse files
committed
Projeto do curso
1 parent edd1441 commit 1c66972

File tree

2,722 files changed

+602244
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,722 files changed

+602244
-1
lines changed

25.2-implementando-a-edicao-da-cerveja/brewer/src/main/java/com/algaworks/brewer/service/event/cerveja/CervejaListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CervejaListener {
1212
@Autowired
1313
private FotoStorage fotoStorage;
1414

15-
@EventListener(condition = "#evento.temFoto()")
15+
@EventListener(condition = "#evento.temFoto() and #evento.novaFoto")
1616
public void cervejaSalva(CervejaSalvaEvent evento) {
1717
fotoStorage.salvar(evento.getCerveja().getFoto());
1818
}

25.2-implementando-a-edicao-da-cerveja/brewer/src/main/java/com/algaworks/brewer/service/event/cerveja/CervejaSalvaEvent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ public Cerveja getCerveja() {
1919
public boolean temFoto() {
2020
return !StringUtils.isEmpty(cerveja.getFoto());
2121
}
22+
23+
public boolean isNovaFoto() {
24+
return cerveja.isNovaFoto();
25+
}
2226

2327
}
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.algaworks</groupId>
7+
<artifactId>brewer</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
10+
<packaging>war</packaging>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
15+
16+
<failOnMissingWebXml>false</failOnMissingWebXml>
17+
18+
<java.version>1.8</java.version>
19+
<maven-compiler-pluging.version>3.2</maven-compiler-pluging.version>
20+
<flyway-maven-plugin.version>4.0.2</flyway-maven-plugin.version>
21+
<mysql-connector-java.version>5.1.39</mysql-connector-java.version>
22+
23+
<!-- Spring MVC -->
24+
<spring-framework.version>4.3.0.RELEASE</spring-framework.version>
25+
26+
<!-- Servlet API -->
27+
<servlet.version>3.1.0</servlet.version>
28+
29+
<!-- Thymeleaf -->
30+
<thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
31+
32+
<!-- Bean Validation / Hibernate Validator -->
33+
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
34+
35+
<!-- Thymeleaf - Layout Dialect -->
36+
<thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version>
37+
38+
<!-- Logging -->
39+
<log4j.version>2.6</log4j.version>
40+
<jcl-over-slf4j.version>1.7.21</jcl-over-slf4j.version>
41+
42+
<!-- JPA / Hibernate -->
43+
<hibernate.version>5.1.0.Final</hibernate.version>
44+
45+
<!-- Spring Data JPA -->
46+
<spring-data-jpa.version>1.10.2.RELEASE</spring-data-jpa.version>
47+
48+
<!-- Jackson - JSON -->
49+
<jackson-core.version>2.7.5</jackson-core.version>
50+
51+
<!-- thumbnailator - Gerar Thumbnail -->
52+
<!-- https://github.com/coobird/thumbnailator -->
53+
<thumbnailator.version>0.4.8</thumbnailator.version>
54+
55+
<!-- Thymeleaf extras data attribute -->
56+
<thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-data-attribute.version>
57+
58+
<!-- Cache - Guava -->
59+
<guava.version>19.0</guava.version>
60+
61+
<!-- Apache Bean Utils -->
62+
<commons-beanutils.version>1.9.2</commons-beanutils.version>
63+
64+
<!-- Spring Security -->
65+
<spring-security.version>4.1.1.RELEASE</spring-security.version>
66+
67+
<!-- Thymeleaf - Extras Spring Security -->
68+
<thymeleaf-extras-springsecurity.version>3.0.0.RELEASE</thymeleaf-extras-springsecurity.version>
69+
70+
<!-- JUnit -->
71+
<junit.version>4.12</junit.version>
72+
73+
<!-- Java Mail -->
74+
<javax.mail.version>1.5.6</javax.mail.version>
75+
</properties>
76+
77+
<build>
78+
<plugins>
79+
<plugin>
80+
<artifactId>maven-compiler-plugin</artifactId>
81+
<version>${maven-compiler-pluging.version}</version>
82+
<configuration>
83+
<source>${java.version}</source>
84+
<target>${java.version}</target>
85+
</configuration>
86+
</plugin>
87+
88+
<plugin>
89+
<groupId>org.flywaydb</groupId>
90+
<artifactId>flyway-maven-plugin</artifactId>
91+
<version>${flyway-maven-plugin.version}</version>
92+
<configuration>
93+
<driver>com.mysql.jdbc.Driver</driver>
94+
</configuration>
95+
</plugin>
96+
</plugins>
97+
</build>
98+
99+
<dependencyManagement>
100+
<dependencies>
101+
<dependency>
102+
<groupId>org.springframework</groupId>
103+
<artifactId>spring-framework-bom</artifactId>
104+
<version>${spring-framework.version}</version>
105+
<type>pom</type>
106+
<scope>import</scope>
107+
</dependency>
108+
</dependencies>
109+
</dependencyManagement>
110+
111+
<dependencies>
112+
<!-- Spring MVC -->
113+
<dependency>
114+
<groupId>org.springframework</groupId>
115+
<artifactId>spring-webmvc</artifactId>
116+
<scope>compile</scope>
117+
<exclusions>
118+
<exclusion>
119+
<groupId>commons-logging</groupId>
120+
<artifactId>commons-logging</artifactId>
121+
</exclusion>
122+
</exclusions>
123+
</dependency>
124+
125+
<!-- Servlet API -->
126+
<dependency>
127+
<groupId>javax.servlet</groupId>
128+
<artifactId>javax.servlet-api</artifactId>
129+
<version>${servlet.version}</version>
130+
<scope>provided</scope>
131+
</dependency>
132+
133+
<!-- Thymeleaf -->
134+
<dependency>
135+
<groupId>org.thymeleaf</groupId>
136+
<artifactId>thymeleaf</artifactId>
137+
<version>${thymeleaf.version}</version>
138+
<scope>compile</scope>
139+
</dependency>
140+
141+
<dependency>
142+
<groupId>org.thymeleaf</groupId>
143+
<artifactId>thymeleaf-spring4</artifactId>
144+
<version>${thymeleaf.version}</version>
145+
<scope>compile</scope>
146+
</dependency>
147+
148+
<!-- Bean Validation / Hibernate Validator -->
149+
<dependency>
150+
<groupId>org.hibernate</groupId>
151+
<artifactId>hibernate-validator</artifactId>
152+
<version>${hibernate-validator.version}</version>
153+
<scope>compile</scope>
154+
</dependency>
155+
156+
<!-- Thymeleaf - Layout Dialect -->
157+
<dependency>
158+
<groupId>nz.net.ultraq.thymeleaf</groupId>
159+
<artifactId>thymeleaf-layout-dialect</artifactId>
160+
<version>${thymeleaf-layout-dialect.version}</version>
161+
</dependency>
162+
163+
<!-- Logging -->
164+
<dependency>
165+
<groupId>org.apache.logging.log4j</groupId>
166+
<artifactId>log4j-slf4j-impl</artifactId>
167+
<version>${log4j.version}</version>
168+
</dependency>
169+
<dependency>
170+
<groupId>org.apache.logging.log4j</groupId>
171+
<artifactId>log4j-api</artifactId>
172+
<version>${log4j.version}</version>
173+
</dependency>
174+
<dependency>
175+
<groupId>org.apache.logging.log4j</groupId>
176+
<artifactId>log4j-core</artifactId>
177+
<version>${log4j.version}</version>
178+
</dependency>
179+
<dependency>
180+
<groupId>org.slf4j</groupId>
181+
<artifactId>jcl-over-slf4j</artifactId>
182+
<version>${jcl-over-slf4j.version}</version>
183+
</dependency>
184+
185+
<!-- JPA / Hibernate -->
186+
<dependency>
187+
<groupId>org.hibernate</groupId>
188+
<artifactId>hibernate-entitymanager</artifactId>
189+
<version>${hibernate.version}</version>
190+
<scope>compile</scope>
191+
</dependency>
192+
193+
<!-- Hibernate - Java 8 support -->
194+
<dependency>
195+
<groupId>org.hibernate</groupId>
196+
<artifactId>hibernate-java8</artifactId>
197+
<version>${hibernate.version}</version>
198+
<scope>compile</scope>
199+
</dependency>
200+
201+
<!-- MySQL Driver -->
202+
<dependency>
203+
<groupId>mysql</groupId>
204+
<artifactId>mysql-connector-java</artifactId>
205+
<version>${mysql-connector-java.version}</version>
206+
<scope>provided</scope>
207+
</dependency>
208+
209+
<!-- Spring Data JPA -->
210+
<dependency>
211+
<groupId>org.springframework.data</groupId>
212+
<artifactId>spring-data-jpa</artifactId>
213+
<version>${spring-data-jpa.version}</version>
214+
<scope>compile</scope>
215+
</dependency>
216+
217+
<!-- Jackson - JSON -->
218+
<dependency>
219+
<groupId>com.fasterxml.jackson.core</groupId>
220+
<artifactId>jackson-databind</artifactId>
221+
<version>${jackson-core.version}</version>
222+
<scope>compile</scope>
223+
</dependency>
224+
225+
<!-- thumbnailator - Gerar Thumbnail -->
226+
<dependency>
227+
<groupId>net.coobird</groupId>
228+
<artifactId>thumbnailator</artifactId>
229+
<version>${thumbnailator.version}</version>
230+
<scope>compile</scope>
231+
</dependency>
232+
233+
<!-- Thymeleaf extras data attribute -->
234+
<dependency>
235+
<groupId>com.github.mxab.thymeleaf.extras</groupId>
236+
<artifactId>thymeleaf-extras-data-attribute</artifactId>
237+
<version>${thymeleaf-extras-data-attribute.version}</version>
238+
<scope>compile</scope>
239+
</dependency>
240+
241+
<!-- Cache - Guava -->
242+
<dependency>
243+
<groupId>com.google.guava</groupId>
244+
<artifactId>guava</artifactId>
245+
<version>${guava.version}</version>
246+
<scope>compile</scope>
247+
</dependency>
248+
249+
<!-- Spring Context Support -->
250+
<dependency>
251+
<groupId>org.springframework</groupId>
252+
<artifactId>spring-context-support</artifactId>
253+
<scope>compile</scope>
254+
</dependency>
255+
256+
<!-- Apache Bean Utils -->
257+
<dependency>
258+
<groupId>commons-beanutils</groupId>
259+
<artifactId>commons-beanutils</artifactId>
260+
<version>${commons-beanutils.version}</version>
261+
<scope>compile</scope>
262+
</dependency>
263+
264+
<!-- Spring Security -->
265+
<dependency>
266+
<groupId>org.springframework.security</groupId>
267+
<artifactId>spring-security-web</artifactId>
268+
<version>${spring-security.version}</version>
269+
<scope>compile</scope>
270+
</dependency>
271+
<dependency>
272+
<groupId>org.springframework.security</groupId>
273+
<artifactId>spring-security-config</artifactId>
274+
<version>${spring-security.version}</version>
275+
<scope>compile</scope>
276+
</dependency>
277+
278+
<!-- Thymeleaf - Extras Spring Security -->
279+
<dependency>
280+
<groupId>org.thymeleaf.extras</groupId>
281+
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
282+
<version>${thymeleaf-extras-springsecurity.version}</version>
283+
<scope>compile</scope>
284+
</dependency>
285+
286+
<!-- JUnit -->
287+
<dependency>
288+
<groupId>junit</groupId>
289+
<artifactId>junit</artifactId>
290+
<version>${junit.version}</version>
291+
<scope>test</scope>
292+
</dependency>
293+
294+
<!-- Java Mail -->
295+
<dependency>
296+
<groupId>com.sun.mail</groupId>
297+
<artifactId>javax.mail</artifactId>
298+
<version>${javax.mail.version}</version>
299+
<scope>compile</scope>
300+
</dependency>
301+
302+
</dependencies>
303+
304+
</project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.algaworks.brewer.config;
2+
3+
import javax.persistence.EntityManagerFactory;
4+
import javax.sql.DataSource;
5+
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
10+
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
11+
import org.springframework.orm.jpa.JpaTransactionManager;
12+
import org.springframework.orm.jpa.JpaVendorAdapter;
13+
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
14+
import org.springframework.orm.jpa.vendor.Database;
15+
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
16+
import org.springframework.transaction.PlatformTransactionManager;
17+
import org.springframework.transaction.annotation.EnableTransactionManagement;
18+
19+
import com.algaworks.brewer.model.Cerveja;
20+
import com.algaworks.brewer.repository.Cervejas;
21+
22+
@Configuration
23+
@ComponentScan(basePackageClasses = Cervejas.class)
24+
@EnableJpaRepositories(basePackageClasses = Cervejas.class, enableDefaultTransactions = false)
25+
@EnableTransactionManagement
26+
@ComponentScan(basePackageClasses = Cervejas.class)
27+
public class JPAConfig {
28+
29+
@Bean
30+
public DataSource dataSource() {
31+
JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
32+
dataSourceLookup.setResourceRef(true);
33+
return dataSourceLookup.getDataSource("jdbc/brewerDB");
34+
}
35+
36+
@Bean
37+
public JpaVendorAdapter jpaVendorAdapter() {
38+
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
39+
adapter.setDatabase(Database.MYSQL);
40+
adapter.setShowSql(false);
41+
adapter.setGenerateDdl(false);
42+
adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
43+
return adapter;
44+
}
45+
46+
@Bean
47+
public EntityManagerFactory entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
48+
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
49+
factory.setDataSource(dataSource);
50+
factory.setJpaVendorAdapter(jpaVendorAdapter);
51+
factory.setPackagesToScan(Cerveja.class.getPackage().getName());
52+
factory.afterPropertiesSet();
53+
return factory.getObject();
54+
}
55+
56+
@Bean
57+
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
58+
JpaTransactionManager transactionManager = new JpaTransactionManager();
59+
transactionManager.setEntityManagerFactory(entityManagerFactory);
60+
return transactionManager;
61+
}
62+
63+
}

0 commit comments

Comments
 (0)