Created Polling Station Scanner interface
Implemented Web App for the scanner Not testedPollingStation-ScannerWebApp
parent
1f8df95895
commit
b934894bc5
|
@ -0,0 +1,15 @@
|
||||||
|
package meerkat.pollingstation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Arbel Deutsch Peled on 21-Dec-15.
|
||||||
|
*/
|
||||||
|
public interface PollingStationConstants {
|
||||||
|
|
||||||
|
// Relative addresses for Scanner operations
|
||||||
|
|
||||||
|
public static final String POLLING_STATION_WEB_SCANNER_PATH = "/scanner";
|
||||||
|
public static final String POLLING_STATION_WEB_SCANNER_SCAN_PATH = "/scan";
|
||||||
|
public static final String POLLING_STATION_WEB_SCANNER_ERROR_PATH = "/error";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package meerkat.pollingstation;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
|
import meerkat.protobuf.PollingStation.*;
|
||||||
|
/**
|
||||||
|
* Created by Arbel on 05/05/2016.
|
||||||
|
* An interface for the scanner used by the Polling Station Committee
|
||||||
|
*/
|
||||||
|
public interface PollingStationScanner {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribes to new scans
|
||||||
|
* @param scanCallback is the handler for scanned data
|
||||||
|
*/
|
||||||
|
public void subscribe(FutureCallback<ScannedData> scanCallback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a scan to all subscribers
|
||||||
|
* @param scannedData contains the scanned data
|
||||||
|
*/
|
||||||
|
public void newScan(ScannedData scannedData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies subscribers about an error that occurred during scan
|
||||||
|
* @param errorMsg is the error that occurred
|
||||||
|
*/
|
||||||
|
public void reportScanError(ErrorMsg errorMsg);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package meerkat;
|
||||||
|
|
||||||
|
option java_package = "meerkat.protobuf";
|
||||||
|
|
||||||
|
// Container for scanned data
|
||||||
|
message ScannedData {
|
||||||
|
bytes data = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Container for error messages
|
||||||
|
message ErrorMsg {
|
||||||
|
string msg = 1;
|
||||||
|
}
|
|
@ -2,8 +2,10 @@
|
||||||
plugins {
|
plugins {
|
||||||
id "us.kirchmeier.capsule" version "1.0.1"
|
id "us.kirchmeier.capsule" version "1.0.1"
|
||||||
id 'com.google.protobuf' version '0.7.0'
|
id 'com.google.protobuf' version '0.7.0'
|
||||||
|
id 'org.akhikhl.gretty' version "1.2.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply plugin: 'org.akhikhl.gretty'
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
apply plugin: 'idea'
|
apply plugin: 'idea'
|
||||||
|
@ -41,6 +43,13 @@ version += "${isSnapshot ? '-SNAPSHOT' : ''}"
|
||||||
dependencies {
|
dependencies {
|
||||||
// Meerkat common
|
// Meerkat common
|
||||||
compile project(':meerkat-common')
|
compile project(':meerkat-common')
|
||||||
|
compile project(':restful-api-common')
|
||||||
|
|
||||||
|
// Jersey for RESTful API
|
||||||
|
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.+'
|
||||||
|
|
||||||
|
// Servlets
|
||||||
|
compile 'javax.servlet:javax.servlet-api:3.0.+'
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
compile 'org.slf4j:slf4j-api:1.7.7'
|
compile 'org.slf4j:slf4j-api:1.7.7'
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package meerkat.pollingstation;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
|
import meerkat.protobuf.PollingStation;
|
||||||
|
import static meerkat.rest.Constants.*;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static meerkat.pollingstation.PollingStationConstants.*;
|
||||||
|
import meerkat.protobuf.PollingStation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Arbel on 05/05/2016.
|
||||||
|
*/
|
||||||
|
@Path(POLLING_STATION_WEB_SCANNER_PATH)
|
||||||
|
public class PollingStationWebScanner implements PollingStationScanner{
|
||||||
|
|
||||||
|
private final List<FutureCallback<ScannedData>> callbacks;
|
||||||
|
|
||||||
|
public PollingStationWebScanner() {
|
||||||
|
callbacks = new LinkedList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void subscribe(FutureCallback<ScannedData> scanCallback) {
|
||||||
|
callbacks.add(scanCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path(POLLING_STATION_WEB_SCANNER_SCAN_PATH)
|
||||||
|
@POST
|
||||||
|
@Consumes(MEDIATYPE_PROTOBUF)
|
||||||
|
@Produces(MEDIATYPE_PROTOBUF)
|
||||||
|
@Override
|
||||||
|
public void newScan(ScannedData scannedData) {
|
||||||
|
|
||||||
|
if (callbacks.size() <= 0)
|
||||||
|
throw new RuntimeException("No subscribers to forward scan to!");
|
||||||
|
|
||||||
|
for (FutureCallback<ScannedData> callback : callbacks){
|
||||||
|
callback.onSuccess(scannedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path(POLLING_STATION_WEB_SCANNER_ERROR_PATH)
|
||||||
|
@POST
|
||||||
|
@Consumes(MEDIATYPE_PROTOBUF)
|
||||||
|
@Produces(MEDIATYPE_PROTOBUF)
|
||||||
|
@Override
|
||||||
|
public void reportScanError(PollingStation.ErrorMsg errorMsg) {
|
||||||
|
|
||||||
|
if (callbacks.size() <= 0)
|
||||||
|
throw new RuntimeException("No subscribers to forward error to!");
|
||||||
|
|
||||||
|
for (FutureCallback<ScannedData> callback : callbacks){
|
||||||
|
callback.onFailure(new IOException(errorMsg.getMsg()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/test")
|
||||||
|
@GET
|
||||||
|
public String test(){
|
||||||
|
return "test";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||||
|
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
|
||||||
|
<Call name="setAttribute">
|
||||||
|
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
|
||||||
|
<Arg>none</Arg>
|
||||||
|
</Call>
|
||||||
|
<Call name="setAttribute">
|
||||||
|
<Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
|
||||||
|
<Arg>none</Arg>
|
||||||
|
</Call>
|
||||||
|
</Configure>
|
|
@ -0,0 +1,20 @@
|
||||||
|
<web-app>
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>Jersey Hello World</servlet-name>
|
||||||
|
<servlet-class>
|
||||||
|
org.glassfish.jersey.servlet.ServletContainer
|
||||||
|
</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>jersey.config.server.provider.packages</param-name>
|
||||||
|
<param-value>meerkat</param-value>
|
||||||
|
</init-param>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>Jersey Hello World</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<listener>
|
||||||
|
<listener-class>meerkat.pollingstation.PollingStationWebScanner</listener-class>
|
||||||
|
</listener>
|
||||||
|
</web-app>
|
Loading…
Reference in New Issue