Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
trombka committed Feb 4, 2015
0 parents commit d8853d1
Show file tree
Hide file tree
Showing 42 changed files with 52,894 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build
.idea
.gradle
*.iml
*.ipr
*.iws
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ctrl-pkw
========
67 changes: 67 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
buildscript {
ext {
springBootVersion = '1.2.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
}

apply plugin: 'java'
apply plugin: 'spring-boot'

jar {
baseName = 'ctrl-pkw'
version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
mavenLocal()
maven { url "http://download.osgeo.org/webdav/geotools" }
maven { url "http://www.hibernatespatial.org/repository" }
//maven { url "http://repo.opengeo.org" }
maven { url "http://dev.mapfish.org/maven/repository/" }
}

dependencies {
compile("org.projectlombok:lombok:1.14.8")

compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-undertow")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-jersey")
compile("org.springframework.boot:spring-boot-starter-batch")
compile("org.springframework:spring-context-support")
compile("org.springframework.shell:spring-shell:1.1.0.RELEASE")
compile("org.springframework.plugin:spring-plugin-core:1.1.0.RELEASE")
compile("org.apache.commons:commons-lang3:3.3.2")

//compile('org.glassfish.jersey.ext:jersey-declarative-linking:2.16-SNAPSHOT')
compile('org.glassfish.jersey.ext:jersey-declarative-linking:2.15')
compile('org.glassfish.jersey.ext:jersey-bean-validation:2.15')
compile("com.fasterxml.jackson.datatype:jackson-datatype-joda:2.3.2")

compile("org.opengeo:geodb:0.7")
compile("com.h2database:h2:1.4.185")
compile("org.hibernate:hibernate-spatial:4.3")
compile("org.jadira.usertype:usertype.core:3.2.0.GA")

compile("com.datastax.cassandra:cassandra-driver-core:2.1.3")
compile("com.datastax.cassandra:cassandra-driver-mapping:2.1.3")

testCompile("junit:junit:4.10")
//testCompile("org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-bundle:2.13")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.assertj:assertj-core:1.7.0")
testCompile("org.springframework.batch:spring-batch-test")
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'ctrl-pkw'
37 changes: 37 additions & 0 deletions src/main/java/pl/ctrlpkw/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package pl.ctrlpkw;

import com.google.common.cache.CacheBuilder;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCacheManager;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
@EnableCaching
@EnableBatchProcessing
public class Application {

@Bean
public GeometryFactory geometryFactory() {
return new GeometryFactory();
}

@Bean
public CacheManager cacheManager() {
GuavaCacheManager cacheManager = new GuavaCacheManager();
cacheManager.setCacheBuilder(CacheBuilder.newBuilder()
.expireAfterWrite(60, TimeUnit.SECONDS).maximumSize(100));
return cacheManager;
}

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}
39 changes: 39 additions & 0 deletions src/main/java/pl/ctrlpkw/CassandraContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package pl.ctrlpkw;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import com.datastax.driver.mapping.MappingManager;
import lombok.Getter;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class CassandraContext implements InitializingBean, DisposableBean {

@Getter
private Cluster cluster;

@Getter
private Session session;

@Getter
private MappingManager mappingManager;

@Value("${cassandra.contactPoint}")
private String contactPoint;

@Override
public void afterPropertiesSet() throws Exception {
cluster = Cluster.builder().addContactPoint(contactPoint).build();
session = cluster.connect();
mappingManager = new MappingManager(session);
}

@Override
public void destroy() throws Exception {
session.close();
cluster.close();
}
}
23 changes: 23 additions & 0 deletions src/main/java/pl/ctrlpkw/JerseyConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pl.ctrlpkw;

import pl.ctrlpkw.api.ObjectMapperProvider;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
import org.springframework.stereotype.Component;

import javax.ws.rs.ApplicationPath;

@Component
@ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {

public JerseyConfig() {
packages("pl.ctrlpkw.api.resource");
register(ObjectMapperProvider.class);

//Declarative linking need the patched version of Jersey
//register(DeclarativeLinkingFeature.class);

property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
}
}
21 changes: 21 additions & 0 deletions src/main/java/pl/ctrlpkw/api/LinkSerializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pl.ctrlpkw.api;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import javax.ws.rs.core.Link;
import java.io.IOException;

public class LinkSerializer extends JsonSerializer<Link> {

@Override
public void serialize(Link link, JsonGenerator jg, SerializerProvider sp)
throws IOException, JsonProcessingException {
jg.writeStartObject();
jg.writeStringField("rel", link.getRel());
jg.writeStringField("href", link.getUri().toString());
jg.writeEndObject();
}
}
38 changes: 38 additions & 0 deletions src/main/java/pl/ctrlpkw/api/ObjectMapperProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pl.ctrlpkw.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.joda.JodaModule;

import javax.ws.rs.core.Link;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

@Provider
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {

final ObjectMapper defaultObjectMapper;

public ObjectMapperProvider() {
defaultObjectMapper = createDefaultMapper();
}

@Override
public ObjectMapper getContext(Class<?> type) {
return defaultObjectMapper;
}

private static ObjectMapper createDefaultMapper() {
final ObjectMapper mapper = new ObjectMapper();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Link.class, new LinkSerializer());

mapper
.registerModule(simpleModule)
.registerModule(new JodaModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return mapper;
}

}
38 changes: 38 additions & 0 deletions src/main/java/pl/ctrlpkw/api/dto/Ballot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pl.ctrlpkw.api.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Builder;
import pl.ctrlpkw.api.resource.BallotsResource;
import org.glassfish.jersey.linking.Binding;
import org.glassfish.jersey.linking.InjectLink;
import org.glassfish.jersey.linking.InjectLinks;
import org.joda.time.LocalDate;

import javax.ws.rs.core.Link;
import java.util.*;

@Getter
@Setter
@Builder
public class Ballot {

@JsonIgnore
private LocalDate votingDate;

private Integer no;

private String question;

private List<String> options;

@InjectLinks({
@InjectLink(resource = BallotsResource.class, rel = "self", method = "readOne", style = InjectLink.Style.ABSOLUTE,
bindings = { @Binding(name = "date", value = "${instance.votingDate}") }
)
})
private List<Link> links;


}
43 changes: 43 additions & 0 deletions src/main/java/pl/ctrlpkw/api/dto/BallotResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pl.ctrlpkw.api.dto;

import com.google.common.collect.Sets;
//import com.wordnik.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Builder;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

//@ApiModel
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BallotResult {

@NotNull
private Integer ballotNo;

@NotNull
private Long votersEntitledCount;

@NotNull
private Long ballotsGivenCount;

@NotNull
private Long votesCastCount;

@NotNull
private Long votesValidCount;

private List<Long> votesCountPerOption;

}
20 changes: 20 additions & 0 deletions src/main/java/pl/ctrlpkw/api/dto/Location.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package pl.ctrlpkw.api.dto;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Builder;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Location {

private Double latitude;
private Double longitude;

}
33 changes: 33 additions & 0 deletions src/main/java/pl/ctrlpkw/api/dto/Protocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pl.ctrlpkw.api.dto;

//import com.wordnik.swagger.annotations.ApiModel;
//import com.wordnik.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Builder;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Collection;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
//@ApiModel
public class Protocol {

@NotNull
private String communityCode;

@NotNull
private Integer wardNo;

@Valid
private Collection<BallotResult> ballotResults;


}
Loading

0 comments on commit d8853d1

Please sign in to comment.