-
Notifications
You must be signed in to change notification settings - Fork 1
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 d8853d1
Showing
42 changed files
with
52,894 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,6 @@ | ||
build | ||
.idea | ||
.gradle | ||
*.iml | ||
*.ipr | ||
*.iws |
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 @@ | ||
ctrl-pkw | ||
======== |
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,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") | ||
} |
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 @@ | ||
rootProject.name = 'ctrl-pkw' |
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,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); | ||
} | ||
|
||
} |
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,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(); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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,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(); | ||
} | ||
} |
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,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; | ||
} | ||
|
||
} |
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,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; | ||
|
||
|
||
} |
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,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; | ||
|
||
} |
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,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; | ||
|
||
} |
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,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; | ||
|
||
|
||
} |
Oops, something went wrong.