Permalink
Browse files

initial commit of mongeez example

  • Loading branch information...
Oleksii Iepishkin
Oleksii Iepishkin committed Jan 22, 2012
1 parent f22a921 commit ab5b5d40208a0cd92eec6c218effc98a46cbb3d9
View
@@ -0,0 +1,12 @@
+# maven files
+/*/target
+
+# test logs
+test-output
+messages.log
+
+# IDEA files
+.idea
+*.iml
+*.ipr
+*.iws
View
@@ -0,0 +1,83 @@
+<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>org.mongeez</groupId>
+ <artifactId>examples</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>war</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.mongeez</groupId>
+ <artifactId>mongeez</artifactId>
+ <version>0.9.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.code.morphia</groupId>
+ <artifactId>morphia</artifactId>
+ <version>1.00-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-jaxrs</artifactId>
+ <version>1.7.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aspects</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>1.6.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.6.9</version>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>morphia.googlecode.com</id>
+ <name>Morphia Repo at Google Code</name>
+ <url>http://morphia.googlecode.com/svn/mavenrepo</url>
+ </repository>
+ </repositories>
+
+ <build>
+ <finalName>examples</finalName>
+ </build>
+</project>
@@ -0,0 +1,9 @@
+package org.mongeez.examples.dao;
+
+import org.mongeez.examples.dto.Asset;
+
+import java.util.List;
+
+public interface AssetDao {
+ List<Asset> list();
+}
@@ -0,0 +1,21 @@
+package org.mongeez.examples.dao;
+
+import com.google.code.morphia.Datastore;
+import com.google.code.morphia.dao.BasicDAO;
+import org.mongeez.examples.dto.Asset;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository("assetDaoMongo")
+public class AssetDaoImpl extends BasicDAO<Asset, String> implements AssetDao {
+ @Autowired
+ public AssetDaoImpl(Datastore ds) {
+ super(Asset.class, ds);
+ }
+
+ public List<Asset> list() {
+ return find().asList();
+ }
+}
@@ -0,0 +1,69 @@
+package org.mongeez.examples.dto;
+
+import com.google.code.morphia.annotations.Entity;
+import com.google.code.morphia.annotations.Id;
+import org.codehaus.jackson.annotate.JsonPropertyOrder;
+
+import java.util.Date;
+
+@JsonPropertyOrder({"id", "assetType", "status"})
+@Entity(value = "Asset", concern = "safe")
+public class Asset {
+ @Id
+ private String id;
+
+ private String assetType;
+ private String status;
+
+ private Double dividend; // PRIVATE_PREFERRED
+ private Date expirationDate; // PRIVATE_OPTIONS
+ private String ticker; // PRIVATE_COMMONSTOCK
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getAssetType() {
+ return assetType;
+ }
+
+ public void setAssetType(String assetType) {
+ this.assetType = assetType;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public Double getDividend() {
+ return dividend;
+ }
+
+ public void setDividend(Double dividend) {
+ this.dividend = dividend;
+ }
+
+ public Date getExpirationDate() {
+ return expirationDate;
+ }
+
+ public void setExpirationDate(Date expirationDate) {
+ this.expirationDate = expirationDate;
+ }
+
+ public String getTicker() {
+ return ticker;
+ }
+
+ public void setTicker(String ticker) {
+ this.ticker = ticker;
+ }
+}
@@ -0,0 +1,21 @@
+package org.mongeez.examples.rest;
+
+import org.mongeez.examples.dao.AssetDao;
+import org.mongeez.examples.dto.Asset;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import java.util.List;
+
+@Controller
+public class AssetsConnector {
+ @Autowired
+ private AssetDao assetDao;
+
+ @RequestMapping(value = "/", method = RequestMethod.GET)
+ public List<Asset> find() {
+ return assetDao.list();
+ }
+}
@@ -0,0 +1,39 @@
+package org.mongeez.examples.utils;
+
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.springframework.web.servlet.view.json.MappingJacksonJsonView;
+
+import java.util.Map;
+
+public class MappingJacksonJsonViewEx extends MappingJacksonJsonView {
+
+ public MappingJacksonJsonViewEx() {
+ this(new ObjectMapper());
+ }
+
+ public MappingJacksonJsonViewEx(ObjectMapper objectMapper) {
+ excludeNullsFromPayload(objectMapper);
+ doNotFailOnEmptyBeans(objectMapper);
+ setObjectMapper(objectMapper);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Object filterModel(Map<String, Object> model) {
+ Map map = (Map) super.filterModel(model);
+ if (map.size() == 1) {
+ return map.values().toArray()[0];
+ }
+ return map;
+ }
+
+ public static void excludeNullsFromPayload(ObjectMapper objectMapper) {
+ objectMapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
+ }
+
+ public static void doNotFailOnEmptyBeans(ObjectMapper objectMapper) {
+ objectMapper.getSerializationConfig().disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
+ }
+}
@@ -0,0 +1,16 @@
+<?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:tx="http://www.springframework.org/schema/tx"
+ xmlns:context="http://www.springframework.org/schema/context"
+
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <context:component-scan base-package="org.mongeez.examples"/>
+ <context:annotation-config/>
+ <tx:annotation-driven/>
+
+ <import resource="dao.xml"/>
+</beans>
@@ -0,0 +1,27 @@
+<?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-3.0.xsd">
+
+ <bean id="mongoUri" class="com.mongodb.MongoURI">
+ <constructor-arg value="mongodb://localhost/assets"/>
+ </bean>
+ <bean id="mongo" class="com.mongodb.Mongo">
+ <constructor-arg ref="mongoUri"/>
+ </bean>
+
+ <bean id="mongeez" class="org.mongeez.MongeezRunner">
+ <property name="executeEnabled" value="true"/>
+ <property name="mongo" ref="mongo"/>
+ <property name="dbName" value="assets"/>
+ <property name="file" value="classpath:org/mongeez/examples/mongo/mongeez.xml"/>
+ </bean>
+
+ <!-- Morphia setup -->
+ <bean id="morphia" class="com.google.code.morphia.Morphia" depends-on="mongeez"/>
+
+ <bean id="mongoDatastore" factory-bean="morphia" factory-method="createDatastore">
+ <constructor-arg ref="mongo"/>
+ <constructor-arg value="assets"/>
+ </bean>
+</beans>
@@ -0,0 +1,40 @@
+<mongoChangeLog>
+
+ <changeSet changeId="SMS-1300" author="oleksii">
+ <script>
+
+ // clear collections
+ db.mongeez.remove({});
+ db.Asset.remove({});
+
+ // insert assets
+ common = {
+ className:"org.mongeez.examples.dto.Asset",
+ assetType: "PRIVATE_COMMONSTOCK",
+ status:"Approved",
+ ticker:"PIXR"
+ };
+ db.Asset.insert(common);
+
+
+ option = {
+ assetType: "PRIVATE_OPTIONS",
+ status:"Approved",
+ className:"org.mongeez.examples.dto.Asset",
+ expirationDate: new Date()
+ };
+ db.Asset.insert(option);
+
+
+ pref = {
+ className:"org.mongeez.examples.dto.Asset",
+ assetType: "PRIVATE_PREFFERED",
+ status:"Pending",
+ dividend: 5
+ };
+ db.Asset.insert(pref);
+
+ </script>
+ </changeSet>
+
+</mongoChangeLog>
@@ -0,0 +1,3 @@
+<changeFiles>
+ <file path="changeset-01.xml"/>
+</changeFiles>
@@ -0,0 +1,39 @@
+<?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:aop="http://www.springframework.org/schema/aop"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <aop:aspectj-autoproxy/>
+
+ <context:component-scan base-package="org.mongeez.examples.rest"/>
+ <mvc:annotation-driven/>
+
+ <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
+ <property name="mediaTypes">
+ <map>
+ <entry key="json" value="application/json"/>
+ <entry key="xml" value="application/xml"/>
+ </map>
+ </property>
+ <property name="defaultViews">
+ <list>
+ <ref bean="mappingJacksonJsonViewEx"/>
+ </list>
+ </property>
+ <property name="defaultContentType" value="application/json"/>
+ <property name="order" value="100"/>
+ </bean>
+
+ <bean id="mappingJacksonJsonViewEx" class="org.mongeez.examples.utils.MappingJacksonJsonViewEx"/>
+
+ <bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
+ <property name="order" value="0"/>
+ </bean>
+</beans>
Oops, something went wrong.

0 comments on commit ab5b5d4

Please sign in to comment.