Skip to content

Commit

Permalink
closes #142
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhrobbins committed Sep 7, 2014
1 parent 8d21b31 commit 30e2eeb
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.persistence.Query;

import org.joda.time.DateTime;
import org.robbins.flashcards.model.FlashCard;
import org.robbins.flashcards.model.Tag;
import org.springframework.data.domain.Page;
Expand All @@ -25,6 +26,19 @@ public Class<FlashCard> getClazz() {
return FlashCard.class;
}

@Override
public FlashCard save(final FlashCard flashCard) {
for (Tag tag : flashCard.getTags()) {
if ((tag.getId() == null) || (tag.getId() == 0)) {
tag.setCreatedBy(getAuditorAware().getCurrentAuditor());
tag.setCreatedDate(new DateTime());
tag.setLastModifiedBy(getAuditorAware().getCurrentAuditor());
tag.setLastModifiedDate(new DateTime());
}
}
return super.save(flashCard);
}

@SuppressWarnings("unchecked")
@Override
public List<FlashCard> findAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<class>org.robbins.flashcards.model.Tag</class>
<class>org.robbins.flashcards.model.User</class>
<properties>
<!-- <property name="hibernate.hbm2ddl.auto" value="update" /> -->
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="use_sql_comments" value="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?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:context="http://www.springframework.org/schema/context"
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/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<import resource="classpath:infrastructure.xml" />

<bean id="auditorAware" class="org.robbins.flashcards.auditing.AuditingAwareUser" />

<tx:annotation-driven />

<context:component-scan base-package="org.robbins.flashcards.repository" />

</beans>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?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:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
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
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
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">

<bean id="entityManagerFactory"
Expand All @@ -28,20 +28,25 @@
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<!-- <property name="generateDdl" value="false" /> -->
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/flashcardsDb"
expected-type="javax.sql.DataSource" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/flashcardapp_db" />
<property name="user" value="flashcarduser" />
<property name="password" value="flashcard" />
</bean>
</beans>

<beans profile="embedded">
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="H2" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<!-- <property name="generateDdl" value="true" /> -->
<property name="databasePlatform" value="org.hibernate.dialect.H2Dialect" />
</bean>

Expand All @@ -50,7 +55,9 @@
<property name="driverClass" value="org.h2.Driver" />
<property name="jdbcUrl" value="jdbc:h2:mem:flashcardsDb" />
</bean>
</beans>

<beans profile="test-data">
<jdbc:initialize-database>
<jdbc:script location="classpath:sql/user.sql" />
<jdbc:script location="classpath:sql/tag.sql" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="spring-jpa"
<persistence-unit name="spring-data-jpa"
transaction-type="RESOURCE_LOCAL">
<class>org.robbins.flashcards.model.FlashCard</class>
<class>org.robbins.flashcards.model.Tag</class>
<class>org.robbins.flashcards.model.User</class>
<properties>
<!-- <property name="hibernate.hbm2ddl.auto" value="update" /> -->
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="use_sql_comments" value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public abstract class AbstractCrudFacadeImpl<D, E> implements GenericCrudFacade<D>,
CrudFacade<D, E> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

@Transactional
@Component
public class DefaultFlashcardFacade extends
AbstractCrudFacadeImpl<FlashCardDto, FlashCard> implements FlashcardFacade {
Expand All @@ -45,7 +46,6 @@ public FlashCardService getService() {
}

@Override
@Transactional
public FlashCardDto save(final FlashCardDto dto) throws ServiceException {
FlashCard entity = getEntity(dto);
entity.setTags(configureTags(entity, dto.getTags()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.robbins.flashcards.service.TagService;
import org.robbins.flashcards.service.util.DtoUtil;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Component
public class DefaultTagFacade extends AbstractCrudFacadeImpl<TagDto, Tag> implements
TagFacade {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.robbins.flashcards.service.UserService;
import org.robbins.flashcards.service.util.DtoUtil;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Component
public class DefaultUserFacade extends AbstractCrudFacadeImpl<UserDto, User> implements
UserFacade {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

<tx:annotation-driven />

<bean id="mapper" class="org.dozer.DozerBeanMapper">
<property name="mappingFiles">
Expand All @@ -20,4 +24,5 @@
org.robbins.flashcards.facade,
org.robbins.flashcards.security,
org.robbins.flashcards.service" />

</beans>
13 changes: 0 additions & 13 deletions FlashCards_Struts/src/main/webapp/WEB-INF/jetty-env.xml

This file was deleted.

13 changes: 0 additions & 13 deletions FlashCards_WebServices/src/main/webapp/WEB-INF/jetty-env.xml

This file was deleted.

16 changes: 1 addition & 15 deletions FlashCards_WebServices/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" metadata-complete="true" version="3.0">
<display-name>FlashCards_WebServices</display-name>

<filter>
<filter-name>OEMIVFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
<init-param>
<param-name>entityManagerFactoryBeanName</param-name>
<param-value>entityManagerFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OEMIVFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
Expand All @@ -35,7 +21,7 @@
<!-- set the default Spring profile. this can be overridden with an environment variable (spring.profiles.active) -->
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>embedded</param-value>
<param-value>embedded,test-data</param-value>
</context-param>

<listener>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private Map<String, String> setupSearchUriVariables() {
@Test
public void testSearchByTagsIn() {
Map<String, String> uriVariables = setupSearchUriVariables();
uriVariables.put("tags", "2,3");
uriVariables.put("tags", "2,20");

// search result
FlashCardDto[] searchResult = searchEntities(searchUrl(), uriVariables,
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,11 @@
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- Maven plugin for submitting Java code coverage reports
Expand Down

0 comments on commit 30e2eeb

Please sign in to comment.