Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 568259d
Showing
17 changed files
with
3,143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.iml | ||
.idea | ||
target |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
http://localhost:8080/mongo-db-app/services/personservice/get/joe@joe.com | ||
http://localhost:8080/mongo-db-app/services/personservice/new/Joe/34/joe@joe.de |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<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.comsysto.findparty</groupId> | ||
<artifactId>findparty</artifactId> | ||
<packaging>war</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>findparty</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<repositories> | ||
<repository> | ||
<id>com.springsource.repository.bundles.release</id> | ||
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name> | ||
<url>http://repository.springsource.com/maven/bundles/release</url> | ||
</repository> | ||
<repository> | ||
<id>com.springsource.repository.bundles.external</id> | ||
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name> | ||
<url>http://repository.springsource.com/maven/bundles/external</url> | ||
</repository> | ||
<repository> | ||
<id>com.springsource.repository.libraries.release</id> | ||
<name>SpringSource Enterprise Bundle Repository - SpringSource Library Releases</name> | ||
<url>http://repository.springsource.com/maven/libraries/release</url> | ||
</repository> | ||
<repository> | ||
<id>com.springsource.repository.libraries.external</id> | ||
<name>SpringSource Enterprise Bundle Repository - External Library Releases</name> | ||
<url>http://repository.springsource.com/maven/libraries/external</url> | ||
</repository> | ||
<repository> | ||
<id>spring-milestone</id> | ||
<name>Spring Maven MILESTONE Repository</name> | ||
<url>http://maven.springframework.org/milestone</url> | ||
</repository> | ||
</repositories> | ||
|
||
|
||
<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.data</groupId> | ||
<artifactId>spring-data-mongodb</artifactId> | ||
<version>1.0.0.M5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.jackson</groupId> | ||
<artifactId>jackson-jaxrs</artifactId> | ||
<version>1.9.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.1</version> | ||
</dependency> | ||
<!-- BEGIN-Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>1.5.8</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.5.8</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>1.5.8</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<version>1.2.14</version> | ||
</dependency> | ||
<!-- END-Logging --> | ||
<dependency> | ||
<groupId>commons-fileupload</groupId> | ||
<artifactId>commons-fileupload</artifactId> | ||
<version>1.2.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-web</artifactId> | ||
<version>${spring-security.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-config</artifactId> | ||
<version>${spring-security.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-taglibs</artifactId> | ||
<version>${spring-security.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-tx</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-aop</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>jstl</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.8.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<properties> | ||
<spring-security.version>3.1.0.RELEASE</spring-security.version> | ||
<spring.version>3.1.1.RELEASE</spring.version> | ||
</properties> | ||
|
||
<build> | ||
<finalName>findparty</finalName> | ||
</build> | ||
</project> |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/comsysto/findparty/util/URLEncodeDecodeUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.comsysto.labs.util; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLDecoder; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* USER: tim.hoheisel | ||
* Date: 28.03.12 | ||
* Time: 11:38 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class URLEncodeDecodeUtil { | ||
|
||
private static final Logger LOG = Logger.getLogger(URLEncodeDecodeUtil.class); | ||
|
||
public static final String UTF_8 = "UTF-8"; | ||
|
||
public static String decodeString(String value) { | ||
return decodeUTF8(value); | ||
} | ||
|
||
private static String decodeUTF8(String value) { | ||
try { | ||
return URLDecoder.decode(value, UTF_8); | ||
} catch (UnsupportedEncodingException e) { | ||
LOG.error("This type of encoding ist not supported.", e); | ||
new IllegalArgumentException("This type of encoding ist not supported.", e); | ||
} | ||
return null; | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
src/main/java/com/comsysto/findparty/web/PartyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.comsysto.labs.web; | ||
|
||
import org.comsysto.labs.track.Party; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.data.mongodb.core.MongoOperations; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.data.mongodb.core.geo.Point; | ||
|
||
|
||
import java.util.List; | ||
|
||
@Controller | ||
@RequestMapping("/party") | ||
public class PartyService { | ||
|
||
@Autowired | ||
@Qualifier("tracksMongoOperations") | ||
public MongoOperations mongoOperations; | ||
|
||
public static final Double KILOMETER = 111.0d; | ||
|
||
/** | ||
* The Attribute that is used for the search for the start position | ||
*/ | ||
public static final String START = "start"; | ||
/** | ||
* The Attribute that is used for the search for the user | ||
*/ | ||
private static final String USER = "user"; | ||
|
||
/* @RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/json") | ||
public | ||
@ResponseBody | ||
List<Party> getAll() throws Exception { | ||
return mongoOperations.findAll(Party.class); | ||
} */ | ||
|
||
/* @RequestMapping(value = "/get/{lon1}/{lat1}/{lon2}/{lat2}/", method = RequestMethod.GET, produces = "application/json") | ||
public | ||
@ResponseBody | ||
List<Party> getByBounds(@PathVariable("lon1") Double lon1, @PathVariable("lat1") Double lat1, @PathVariable("lon2") Double lon2, @PathVariable("lat2") Double lat2) throws Exception { | ||
/* | ||
> box = [[40.73083, -73.99756], [40.741404, -73.988135]] | ||
> db.places.find({"loc" : {"$within" : {"$box" : box}}}) | ||
*/ | ||
/* | ||
Criteria criteria = new Criteria(START).within(new Box(new Point(lon1, lat1), new Point(lon2, lat2))); | ||
List<Party> tracks = mongoOperations.find(new Query(criteria), | ||
Party.class); | ||
return tracks; | ||
} | ||
*/ | ||
|
||
@RequestMapping(value = "/{lon}/{lat}/{maxdistance}", method = RequestMethod.GET, produces = "application/json") | ||
public | ||
@ResponseBody | ||
List<Party> searchParties(@PathVariable("lon") Double lon, @PathVariable("lat") Double lat, @PathVariable("maxdistance") Double maxdistance) throws Exception { | ||
Criteria criteria = new Criteria(START).near(new Point(lon, lat)).maxDistance(getInKilometer(maxdistance)); | ||
List<Party> tracks = mongoOperations.find(new Query(criteria), | ||
Party.class); | ||
return tracks; | ||
} | ||
|
||
|
||
/** | ||
* The current implementation of near assumes an idealized model of a flat earth, meaning that an arcdegree | ||
* of latitude (y) and longitude (x) represent the same distance everywhere. | ||
* This is only true at the equator where they are both about equal to 69 miles or 111km. Therefore you must divide the | ||
* distance you want by 111 for kilometer and 69 for miles. | ||
* | ||
* @param maxdistance The distance around a point. | ||
* @return The calcuated distance in kilometer. | ||
*/ | ||
private Double getInKilometer(Double maxdistance) { | ||
return maxdistance / KILOMETER; | ||
} | ||
|
||
/* @RequestMapping(value = "/add", method = RequestMethod.POST, consumes = "application/json") | ||
@ResponseStatus(HttpStatus.OK) | ||
public void add(@RequestBody Party track) throws Exception { | ||
mongoOperations.insert(track); | ||
} */ | ||
|
||
/* @RequestMapping(value = "/foruser", method = RequestMethod.GET) | ||
@ResponseStatus(HttpStatus.OK) | ||
public | ||
@ResponseBody | ||
List<Party> tracksForUser() throws Exception { | ||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
Criteria criteria = Criteria.where(USER).is(principal.getUsername()); | ||
List<Party> tracks = mongoOperations.find(new Query(criteria), | ||
Party.class); | ||
return tracks; | ||
}*/ | ||
|
||
/* @RequestMapping(value = "/upload", method = RequestMethod.POST) | ||
@ResponseStatus(HttpStatus.OK) | ||
public void upload(@RequestParam("file") MultipartFile multipartFile) throws Exception { | ||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
Party track = mapper.readValue(multipartFile.getBytes(), Party.class); | ||
track.setUser(principal.getUsername()); | ||
mongoOperations.insert(track); | ||
}*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.comsysto.labs.web; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.comsysto.labs.user.User; | ||
import org.comsysto.labs.util.URLEncodeDecodeUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.data.mongodb.core.MongoOperations; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.net.URLDecoder; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.springframework.data.mongodb.core.query.Criteria.where; | ||
|
||
@Controller | ||
@RequestMapping("/user") | ||
public class UserService { | ||
|
||
public static final String USER = "user"; | ||
private final Logger LOG = Logger.getLogger(UserService.class); | ||
|
||
@Autowired | ||
@Qualifier("userMongoOperations") | ||
public MongoOperations userMongoOperations; | ||
|
||
@RequestMapping(value = "/new/{name}/{age}/{email}", method = RequestMethod.PUT) | ||
@ResponseStatus( HttpStatus.OK ) | ||
public void add(@PathVariable("name") String name, | ||
@PathVariable("age") Integer age, | ||
@PathVariable("email") String email) throws Exception { | ||
userMongoOperations.insert(new User(URLEncodeDecodeUtil.decodeString(name), age, URLEncodeDecodeUtil.decodeString(email))); | ||
LOG.info(userMongoOperations.findOne(new Query(where("email").is(URLEncodeDecodeUtil.decodeString(email))), | ||
User.class)); | ||
} | ||
|
||
@RequestMapping(value = "/drop/{email}", method = RequestMethod.DELETE) | ||
@ResponseStatus( HttpStatus.OK ) | ||
public void drop(@PathVariable("email") String email) | ||
throws Exception { | ||
User perosonToDelete = userMongoOperations.findOne( | ||
new Query(where("email").is(URLEncodeDecodeUtil.decodeString(email))), User.class); | ||
userMongoOperations.remove( | ||
new Query(where("email").is(perosonToDelete.getEmail())), | ||
User.class); | ||
LOG.info(userMongoOperations.findOne( | ||
new Query(where("id").is(perosonToDelete.getId())), | ||
User.class)); | ||
} | ||
|
||
@RequestMapping(value = "/get/{email}", method = RequestMethod.GET, produces="application/json") | ||
@ResponseBody | ||
public List<User> get(@PathVariable("email") String email) throws Exception { | ||
List<User> result = new ArrayList<User>(); | ||
if (StringUtils.isEmpty(email)) { | ||
result.addAll(userMongoOperations.findAll(User.class)); | ||
} else { | ||
result.add(userMongoOperations.findOne( | ||
new Query(where("email").is(URLDecoder.decode(email, "UTF-8"))), User.class)); | ||
} | ||
return result; | ||
} | ||
|
||
@RequestMapping(value = "/get", method = RequestMethod.GET, produces="application/json") | ||
@ResponseBody | ||
public List<User> getAll() throws Exception { | ||
return get(null); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.