--- a/.classpath Mon Oct 21 13:58:20 2013 +0200
+++ b/.classpath Mon Oct 21 15:00:17 2013 +0200
@@ -22,13 +22,13 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/mongodb/mongo-java-driver/2.11.0/mongo-java-driver-2.11.0.jar" sourcepath="M2_REPO/org/mongodb/mongo-java-driver/2.10.1/mongo-java-driver-2.10.1-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/mongodb/mongo-java-driver/2.11.3/mongo-java-driver-2.11.3.jar" sourcepath="M2_REPO/org/mongodb/mongo-java-driver/2.10.1/mongo-java-driver-2.10.1-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/mongodb/mongo-java-driver/2.10.1/mongo-java-driver-2.10.1-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.2.1.RELEASE/spring-context-3.2.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-context/3.2.1.RELEASE/spring-context-3.2.1.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.2.4.RELEASE/spring-context-3.2.4.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-context/3.2.1.RELEASE/spring-context-3.2.1.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/spring-context/3.2.1.RELEASE/spring-context-3.2.1.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
@@ -39,7 +39,7 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.2.1.RELEASE/spring-beans-3.2.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-beans/3.2.1.RELEASE/spring-beans-3.2.1.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.2.3.RELEASE/spring-beans-3.2.3.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-beans/3.2.1.RELEASE/spring-beans-3.2.1.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/spring-beans/3.2.1.RELEASE/spring-beans-3.2.1.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
@@ -50,19 +50,19 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/data/spring-data-mongodb/1.2.0.RELEASE/spring-data-mongodb-1.2.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/data/spring-data-mongodb/1.2.0.RELEASE/spring-data-mongodb-1.2.0.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/data/spring-data-mongodb/1.3.1.RELEASE/spring-data-mongodb-1.3.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/data/spring-data-mongodb/1.2.0.RELEASE/spring-data-mongodb-1.2.0.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/data/spring-data-mongodb/1.2.0.RELEASE/spring-data-mongodb-1.2.0.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/data/spring-data-commons/1.5.0.RELEASE/spring-data-commons-1.5.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/data/spring-data-commons/1.5.0.RELEASE/spring-data-commons-1.5.0.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/data/spring-data-commons/1.6.1.RELEASE/spring-data-commons-1.6.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/data/spring-data-commons/1.5.0.RELEASE/spring-data-commons-1.5.0.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/data/spring-data-commons/1.5.0.RELEASE/spring-data-commons-1.5.0.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/data/spring-data-jpa/1.3.0.RELEASE/spring-data-jpa-1.3.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/data/spring-data-jpa/1.3.0.RELEASE/spring-data-jpa-1.3.0.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/data/spring-data-jpa/1.4.1.RELEASE/spring-data-jpa-1.4.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/data/spring-data-jpa/1.3.0.RELEASE/spring-data-jpa-1.3.0.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/data/spring-data-jpa/1.3.0.RELEASE/spring-data-jpa-1.3.0.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
@@ -86,36 +86,36 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar" sourcepath="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.jar" sourcepath="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5-sources.jar">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.2.1.RELEASE/spring-core-3.2.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-core/3.2.1.RELEASE/spring-core-3.2.1.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.2.4.RELEASE/spring-core-3.2.4.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-core/3.2.1.RELEASE/spring-core-3.2.1.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/spring-core/3.2.1.RELEASE/spring-core-3.2.1.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/spring-web/3.2.1.RELEASE/spring-web-3.2.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-web/3.2.1.RELEASE/spring-web-3.2.1.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-web/3.2.4.RELEASE/spring-web-3.2.4.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-web/3.2.1.RELEASE/spring-web-3.2.1.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/spring-web/3.2.1.RELEASE/spring-web-3.2.1.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/spring-webmvc/3.2.1.RELEASE/spring-webmvc-3.2.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-webmvc/3.2.1.RELEASE/spring-webmvc-3.2.1.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-webmvc/3.2.4.RELEASE/spring-webmvc-3.2.4.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-webmvc/3.2.1.RELEASE/spring-webmvc-3.2.1.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/spring-webmvc/3.2.1.RELEASE/spring-webmvc-3.2.1.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/junit/junit/4.10/junit-4.10.jar" sourcepath="M2_REPO/junit/junit/4.10/junit-4.10-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.11/junit-4.11.jar" sourcepath="M2_REPO/junit/junit/4.10/junit-4.10-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/junit/junit/4.10/junit-4.10-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/spring-test/3.2.1.RELEASE/spring-test-3.2.1.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-test/3.2.1.RELEASE/spring-test-3.2.1.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-test/3.2.4.RELEASE/spring-test-3.2.4.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-test/3.2.1.RELEASE/spring-test-3.2.1.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/spring-test/3.2.1.RELEASE/spring-test-3.2.1.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
@@ -126,25 +126,25 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.7/commons-codec-1.7.jar" sourcepath="M2_REPO/commons-codec/commons-codec/1.7/commons-codec-1.7-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.8/commons-codec-1.8.jar" sourcepath="M2_REPO/commons-codec/commons-codec/1.7/commons-codec-1.7-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/commons-codec/commons-codec/1.7/commons-codec-1.7-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/security/spring-security-core/3.1.3.RELEASE/spring-security-core-3.1.3.RELEASE.jar" sourcepath="M2_REPO/org/springframework/security/spring-security-core/3.1.3.RELEASE/spring-security-core-3.1.3.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/security/spring-security-core/3.1.4.RELEASE/spring-security-core-3.1.4.RELEASE.jar" sourcepath="M2_REPO/org/springframework/security/spring-security-core/3.1.3.RELEASE/spring-security-core-3.1.3.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/security/spring-security-core/3.1.3.RELEASE/spring-security-core-3.1.3.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/security/spring-security-config/3.1.3.RELEASE/spring-security-config-3.1.3.RELEASE.jar" sourcepath="M2_REPO/org/springframework/security/spring-security-config/3.1.3.RELEASE/spring-security-config-3.1.3.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/security/spring-security-config/3.1.4.RELEASE/spring-security-config-3.1.4.RELEASE.jar" sourcepath="M2_REPO/org/springframework/security/spring-security-config/3.1.3.RELEASE/spring-security-config-3.1.3.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/security/spring-security-config/3.1.3.RELEASE/spring-security-config-3.1.3.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/org/springframework/security/spring-security-web/3.1.3.RELEASE/spring-security-web-3.1.3.RELEASE.jar" sourcepath="M2_REPO/org/springframework/security/spring-security-web/3.1.3.RELEASE/spring-security-web-3.1.3.RELEASE-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/org/springframework/security/spring-security-web/3.1.4.RELEASE/spring-security-web-3.1.4.RELEASE.jar" sourcepath="M2_REPO/org/springframework/security/spring-security-web/3.1.3.RELEASE/spring-security-web-3.1.3.RELEASE-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/org/springframework/security/spring-security-web/3.1.3.RELEASE/spring-security-web-3.1.3.RELEASE-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
@@ -172,13 +172,13 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/joda-time/joda-time/2.1/joda-time-2.1.jar" sourcepath="M2_REPO/joda-time/joda-time/2.1/joda-time-2.1-sources.jar">
+ <classpathentry kind="var" path="M2_REPO/joda-time/joda-time/2.3/joda-time-2.3.jar" sourcepath="M2_REPO/joda-time/joda-time/2.1/joda-time-2.1-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:file:/Users/ymh/.m2/repository/joda-time/joda-time/2.1/joda-time-2.1-javadoc.jar!/"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
- <classpathentry kind="var" path="M2_REPO/javax/validation/validation-api/1.1.0.CR2/validation-api-1.1.0.CR2.jar">
+ <classpathentry kind="var" path="M2_REPO/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
@@ -200,5 +200,6 @@
<classpathentry kind="var" path="M2_REPO/org/glassfish/jersey/ext/jersey-spring3/2.3.1/jersey-spring3-2.3.1.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/ws/rs/javax.ws.rs-api/2.0/javax.ws.rs-api-2.0.jar"/>
<classpathentry kind="var" path="M2_REPO/org/glassfish/jersey/media/jersey-media-json-jackson/2.3.1/jersey-media-json-jackson-2.3.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
<classpathentry kind="output" path="server/target/classes"/>
</classpath>
--- a/server/pom.xml Mon Oct 21 13:58:20 2013 +0200
+++ b/server/pom.xml Mon Oct 21 15:00:17 2013 +0200
@@ -12,32 +12,32 @@
<coweb-version>1.0.1-SNAPSHOT</coweb-version>
<cowebx-version>1.0</cowebx-version>
<jersey-version>2.3.1</jersey-version>
- <spring-version>3.2.1.RELEASE</spring-version>
- <spring-data-mongodb-version>1.2.0.RELEASE</spring-data-mongodb-version>
- <spring-security-version>3.1.3.RELEASE</spring-security-version>
- <spring-data-commons-version>1.5.0.RELEASE</spring-data-commons-version>
- <spring-data-jpa-version>1.3.0.RELEASE</spring-data-jpa-version>
+ <spring-version>3.2.4.RELEASE</spring-version>
+ <spring-data-mongodb-version>1.3.1.RELEASE</spring-data-mongodb-version>
+ <spring-security-version>3.1.4.RELEASE</spring-security-version>
+ <spring-data-commons-version>1.6.1.RELEASE</spring-data-commons-version>
+ <spring-data-jpa-version>1.4.1.RELEASE</spring-data-jpa-version>
<jetty-plugin-version>8.1.13.v20130916</jetty-plugin-version>
<jetty-version>8.1.13.v20130916</jetty-version>
- <junit-version>4.10</junit-version>
- <thymeleaf-version>2.0.16</thymeleaf-version>
- <thymeleaf-springsecurity-version>2.0.0</thymeleaf-springsecurity-version>
+ <junit-version>4.11</junit-version>
+ <thymeleaf-version>2.1.0-beta2</thymeleaf-version>
+ <thymeleaf-springsecurity-version>2.1.0-beta2</thymeleaf-springsecurity-version>
<cometd-version>2.7.0</cometd-version>
<jackson-version>2.2.3</jackson-version>
- <joda-version>2.1</joda-version>
- <mongo-driver-version>2.11.0</mongo-driver-version>
+ <joda-version>2.3</joda-version>
+ <mongo-driver-version>2.11.3</mongo-driver-version>
<jaxrs-api-version>2.0</jaxrs-api-version>
<javax-annotation-version>1.2</javax-annotation-version>
<javax-inject-version>1</javax-inject-version>
<javax-servlet-api-version>3.0.1</javax-servlet-api-version>
<javax-servlet-jstl-version>1.2</javax-servlet-jstl-version>
<javax-persistence-api-version>1.0.2</javax-persistence-api-version>
- <javax-validation-api-version>1.1.0.CR2</javax-validation-api-version>
- <hibernate-validator-version>4.2.0.Final</hibernate-validator-version>
+ <javax-validation-api-version>1.1.0.Final</javax-validation-api-version>
+ <hibernate-validator-version>5.0.1.Final</hibernate-validator-version>
<slf4j-log4j12-version>1.7.5</slf4j-log4j12-version>
- <nekohtml-version>1.9.16</nekohtml-version>
- <commons-codec-version>1.7</commons-codec-version>
- <bson4jackson-version>2.1.1</bson4jackson-version>
+ <nekohtml-version>1.9.19</nekohtml-version>
+ <commons-codec-version>1.8</commons-codec-version>
+ <bson4jackson-version>2.2.3</bson4jackson-version>
<fasterxml-java-uuid-generator-version>3.1.3</fasterxml-java-uuid-generator-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
--- a/server/src/main/java/org/iri_research/renkan/Constants.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/Constants.java Mon Oct 21 15:00:17 2013 +0200
@@ -10,71 +10,73 @@
public class Constants {
-
- static {
-
- }
-
- public final static List<String> VERSION = Collections.unmodifiableList(new ArrayList<String>() {
- private static final long serialVersionUID = -6935554100028328149L;
- {
- add("0");
- add("6");
- add("4");
- add("final");
- add("0");
- }
- });
-
- public static String getVersion() {
-
- String[] version_array = VERSION.toArray(new String[VERSION.size()]);
-
- String version = String.format("%s.%s",version_array[0], version_array[1]);
- if(version_array[2] != null && !version_array[2].isEmpty() && Integer.parseInt(version_array[2]) > 0 ) {
- version = String.format("%s.%s", version, version_array[2]);
- }
- if (version_array[3] == "alpha" && version_array[4] == "0") {
- version = String.format("%s pre-alpha",version);
- }
- else if(version_array[3] != "final") {
- version = String.format("%s %s %s", version, version_array[3], version_array[4]);
- }
- return version;
+ static {
+
+ }
+
+ public final static List<String> VERSION = Collections
+ .unmodifiableList(new ArrayList<String>() {
+ private static final long serialVersionUID = -6935554100028328149L;
+ {
+ add("0");
+ add("6");
+ add("4");
+ add("final");
+ add("0");
+ }
+ });
+
+ public static String getVersion() {
+
+ String[] version_array = VERSION.toArray(new String[VERSION.size()]);
+
+ String version = String.format("%s.%s", version_array[0],
+ version_array[1]);
+ if (version_array[2] != null && !version_array[2].isEmpty()
+ && Integer.parseInt(version_array[2]) > 0) {
+ version = String.format("%s.%s", version, version_array[2]);
+ }
+ if (version_array[3] == "alpha" && version_array[4] == "0") {
+ version = String.format("%s pre-alpha", version);
+ } else if (version_array[3] != "final") {
+ version = String.format("%s %s %s", version, version_array[3],
+ version_array[4]);
+ }
+ return version;
- }
-
- public final static String KEYHEX = "f2338d2299ac28ef64f82956fde37337b87a2b9e8fc03e28fa0768cac37d838113c7d0fc78c60fce1e23b1b3e03ac7db4676b3189c267f26baaab10f72544441";
- public final static int SALT_LENGTH = 24;
- public final static int PAGINATION_SIZE = 10;
- public final static String PROPERTIES_SERVLET_CONTEXT_NAME = "renkan.properties";
- public final static String PROPERTIES_CLASSPATH_NAME = "renkan_run.properties";
- public final static String ANONYMOUS_USER_BASE_NAME = "Anonymous";
-
- private final static EthernetAddress ETHERNET_ADRESS = EthernetAddress.fromInterface();
- public final static NoArgGenerator UUID_GENERATOR = Generators.timeBasedGenerator(ETHERNET_ADRESS);
+ }
+
+ public final static String KEYHEX = "f2338d2299ac28ef64f82956fde37337b87a2b9e8fc03e28fa0768cac37d838113c7d0fc78c60fce1e23b1b3e03ac7db4676b3189c267f26baaab10f72544441";
+ public final static int SALT_LENGTH = 24;
+ public final static int PAGINATION_SIZE = 10;
+ public final static String PROPERTIES_SERVLET_CONTEXT_NAME = "renkan.properties";
+ public final static String PROPERTIES_CLASSPATH_NAME = "renkan_run.properties";
+ public final static String ANONYMOUS_USER_BASE_NAME = "Anonymous";
+
+ private final static EthernetAddress ETHERNET_ADRESS = EthernetAddress
+ .fromInterface();
+ public final static NoArgGenerator UUID_GENERATOR = Generators
+ .timeBasedGenerator(ETHERNET_ADRESS);
+
+ public enum EditMode {
+ READ_ONLY(1), EDITION(2);
- public enum EditMode {
- READ_ONLY(1),
- EDITION(2);
-
- private int value;
-
- private final static EditMode[] editModeValues = EditMode.values();
-
- private EditMode(int i) {
- this.value = i;
- }
-
- public static EditMode fromInt(int val) {
- for(int i=0; i < editModeValues.length; i++) {
- if(editModeValues[i].value == val)
- {
- return editModeValues[i];
- }
- }
- return null;
- }
- }
+ private int value;
+
+ private final static EditMode[] editModeValues = EditMode.values();
+
+ private EditMode(int i) {
+ this.value = i;
+ }
+
+ public static EditMode fromInt(int val) {
+ for (int i = 0; i < editModeValues.length; i++) {
+ if (editModeValues[i].value == val) {
+ return editModeValues[i];
+ }
+ }
+ return null;
+ }
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/RenkanException.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/RenkanException.java Mon Oct 21 15:00:17 2013 +0200
@@ -2,24 +2,24 @@
public class RenkanException extends Exception {
- /**
+ /**
*
*/
- private static final long serialVersionUID = -6952770322990047437L;
+ private static final long serialVersionUID = -6952770322990047437L;
- public RenkanException() {
- }
+ public RenkanException() {
+ }
- public RenkanException(String message) {
- super(message);
- }
+ public RenkanException(String message) {
+ super(message);
+ }
- public RenkanException(Throwable exc) {
- super(exc);
- }
+ public RenkanException(Throwable exc) {
+ super(exc);
+ }
- public RenkanException(String message, Throwable exc) {
- super(message, exc);
- }
+ public RenkanException(String message, Throwable exc) {
+ super(message, exc);
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/RenkanProperties.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/RenkanProperties.java Mon Oct 21 15:00:17 2013 +0200
@@ -11,35 +11,37 @@
@Named
public class RenkanProperties {
- @Resource(name="renkanProperties")
- private Properties properties;
-
- private final Logger logger = LoggerFactory.getLogger(RenkanProperties.class);
-
+ @Resource(name = "renkanProperties")
+ private Properties properties;
+
+ private final Logger logger = LoggerFactory
+ .getLogger(RenkanProperties.class);
+
private static volatile RenkanProperties instance = null;
-
- private RenkanProperties()
- {
- this.logger.debug("Building RenkanProperties");
+
+ private RenkanProperties() {
+ this.logger.debug("Building RenkanProperties");
}
-
+
public static RenkanProperties getInstance() {
- if (instance == null) {
- synchronized (RenkanProperties.class) {
- if(instance == null) {
- instance = new RenkanProperties();
- }
- }
- }
- return instance;
+ if (instance == null) {
+ synchronized (RenkanProperties.class) {
+ if (instance == null) {
+ instance = new RenkanProperties();
+ }
+ }
+ }
+ return instance;
}
-
- public int getPaginationSize() {
- return Integer.parseInt(properties.getProperty("renkan.pagination.size", Integer.toString(Constants.PAGINATION_SIZE)));
- }
- public String getProperty(String name, String defaultVal) {
- return properties.getProperty(name, defaultVal);
- }
-
+ public int getPaginationSize() {
+ return Integer.parseInt(properties.getProperty(
+ "renkan.pagination.size",
+ Integer.toString(Constants.PAGINATION_SIZE)));
+ }
+
+ public String getProperty(String name, String defaultVal) {
+ return properties.getProperty(name, defaultVal);
+ }
+
}
--- a/server/src/main/java/org/iri_research/renkan/RenkanRuntimeException.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/RenkanRuntimeException.java Mon Oct 21 15:00:17 2013 +0200
@@ -2,25 +2,24 @@
public class RenkanRuntimeException extends RuntimeException {
-
- /**
+ /**
*
*/
- private static final long serialVersionUID = 736470650035855769L;
+ private static final long serialVersionUID = 736470650035855769L;
- public RenkanRuntimeException() {
- }
+ public RenkanRuntimeException() {
+ }
- public RenkanRuntimeException(String message) {
- super(message);
- }
+ public RenkanRuntimeException(String message) {
+ super(message);
+ }
- public RenkanRuntimeException(Throwable exc) {
- super(exc);
- }
+ public RenkanRuntimeException(Throwable exc) {
+ super(exc);
+ }
- public RenkanRuntimeException(String message, Throwable exc) {
- super(message, exc);
- }
+ public RenkanRuntimeException(String message, Throwable exc) {
+ super(message, exc);
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/controller/AuthController.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/controller/AuthController.java Mon Oct 21 15:00:17 2013 +0200
@@ -10,21 +10,20 @@
@Controller
@RequestMapping("/auth")
public class AuthController {
-
- @SuppressWarnings("unused")
- private final Logger logger = LoggerFactory.getLogger(AuthController.class);
-
- @RequestMapping(value="/login", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"})
- public String login() {
- return "auth/login";
- }
+
+ @SuppressWarnings("unused")
+ private final Logger logger = LoggerFactory.getLogger(AuthController.class);
+
+ @RequestMapping(value = "/login", method = RequestMethod.GET, produces = { "text/html;charset=UTF-8" })
+ public String login() {
+ return "auth/login";
+ }
- @RequestMapping(value="/loginfailed", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"})
- public String loginFailed(Model model) {
-
- model.addAttribute("login_error", true);
- return "auth/login";
- }
+ @RequestMapping(value = "/loginfailed", method = RequestMethod.GET, produces = { "text/html;charset=UTF-8" })
+ public String loginFailed(Model model) {
-
+ model.addAttribute("login_error", true);
+ return "auth/login";
+ }
+
}
--- a/server/src/main/java/org/iri_research/renkan/controller/RenkanRootController.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/controller/RenkanRootController.java Mon Oct 21 15:00:17 2013 +0200
@@ -27,62 +27,70 @@
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.servlet.ModelAndView;
-
@Controller
@RequestMapping("/")
public class RenkanRootController {
- private final Logger logger = LoggerFactory.getLogger(RenkanRootController.class);
-
- @Autowired
- private ProjectsRepository projectsRepository;
-
- @Autowired
- private SpacesRepository spacesRepository;
-
- @RequestMapping(value="", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"})
- public String renkanIndex(Model model, @PageableDefaults(sort={"created"}, sortDir=Direction.DESC, pageNumber=0, value=Constants.PAGINATION_SIZE) Pageable p, HttpServletRequest request) {
+ private final Logger logger = LoggerFactory
+ .getLogger(RenkanRootController.class);
+
+ @Autowired
+ private ProjectsRepository projectsRepository;
+
+ @Autowired
+ private SpacesRepository spacesRepository;
+
+ @RequestMapping(value = "", method = RequestMethod.GET, produces = { "text/html;charset=UTF-8" })
+ public String renkanIndex(
+ Model model,
+ @PageableDefaults(sort = { "created" }, sortDir = Direction.DESC, pageNumber = 0, value = Constants.PAGINATION_SIZE) Pageable p,
+ HttpServletRequest request) {
- Page<Space> page = this.spacesRepository.findAll(p);
-
- model.addAttribute("page", page);
- model.addAttribute("baseUrl", Utils.buildBaseUrl(request));
- model.addAttribute("projectsCount", this.projectsRepository.getCountBySpace());
-
- return "renkanIndex";
- }
+ Page<Space> page = this.spacesRepository.findAll(p);
+
+ model.addAttribute("page", page);
+ model.addAttribute("baseUrl", Utils.buildBaseUrl(request));
+ model.addAttribute("projectsCount",
+ this.projectsRepository.getCountBySpace());
- @RequestMapping(value="/s/{space_id}", method = RequestMethod.GET, produces={"text/html;charset=UTF-8"})
- public ModelAndView spaceIndex(@PathVariable("space_id") String spaceId, @RequestParam(required=false) String filter, @PageableDefaults(sort={"updated","created"}, sortDir=Direction.DESC, pageNumber=0, value=Constants.PAGINATION_SIZE) Pageable p, HttpServletRequest request) {
-
- logger.debug("SpaceId : " + (spaceId== null ? "null" : spaceId));
-
- Map<String, Object> model = new HashMap<String, Object>();
+ return "renkanIndex";
+ }
+
+ @RequestMapping(value = "/s/{space_id}", method = RequestMethod.GET, produces = { "text/html;charset=UTF-8" })
+ public ModelAndView spaceIndex(
+ @PathVariable("space_id") String spaceId,
+ @RequestParam(required = false) String filter,
+ @PageableDefaults(sort = { "updated", "created" }, sortDir = Direction.DESC, pageNumber = 0, value = Constants.PAGINATION_SIZE) Pageable p,
+ HttpServletRequest request) {
- if("_".equals(spaceId)) {
- spaceId = null;
- }
-
- Space space = this.spacesRepository.findOne(spaceId);
-
- if(null == space) {
- throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Space " + spaceId + " not found.");
- }
-
- model.put("space", space);
- Page<Project> page;
- if(filter != null && !filter.isEmpty()) {
- page = this.projectsRepository.findBySpaceIdAndTitleRegex(spaceId, filter, p);
- }
- else {
- page = this.projectsRepository.findBySpaceId(spaceId, p);
- }
-
- model.put("page", page);
- model.put("baseUrl", Utils.buildBaseUrl(request));
-
- return new ModelAndView("projectIndex", model);
- }
-
-
+ logger.debug("SpaceId : " + (spaceId == null ? "null" : spaceId));
+
+ Map<String, Object> model = new HashMap<String, Object>();
+
+ if ("_".equals(spaceId)) {
+ spaceId = null;
+ }
+
+ Space space = this.spacesRepository.findOne(spaceId);
+
+ if (null == space) {
+ throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Space "
+ + spaceId + " not found.");
+ }
+
+ model.put("space", space);
+ Page<Project> page;
+ if (filter != null && !filter.isEmpty()) {
+ page = this.projectsRepository.findBySpaceIdAndTitleRegex(spaceId,
+ filter, p);
+ } else {
+ page = this.projectsRepository.findBySpaceId(spaceId, p);
+ }
+
+ model.put("page", page);
+ model.put("baseUrl", Utils.buildBaseUrl(request));
+
+ return new ModelAndView("projectIndex", model);
+ }
+
}
--- a/server/src/main/java/org/iri_research/renkan/controller/Utils.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/controller/Utils.java Mon Oct 21 15:00:17 2013 +0200
@@ -5,29 +5,27 @@
import javax.servlet.http.HttpServletRequest;
public class Utils {
-
- public static String buildBaseUrl(HttpServletRequest request) {
- StringBuffer baseUrl = request.getRequestURL();
- boolean firstParam = true;
- Enumeration<?> namesEnum = request.getParameterNames();
- while(namesEnum.hasMoreElements()) {
- String paramName =
- (String)namesEnum.nextElement();
-
- if("p.page".equals(paramName)) {
- continue;
- }
- for(String val:request.getParameterValues(paramName)) {
- if(firstParam) {
- baseUrl.append('?');
- firstParam = false;
- }
- else {
- baseUrl.append('&');
- }
- baseUrl.append(paramName).append('=').append(val);
- }
- }
- return baseUrl.toString();
- }
+
+ public static String buildBaseUrl(HttpServletRequest request) {
+ StringBuffer baseUrl = request.getRequestURL();
+ boolean firstParam = true;
+ Enumeration<?> namesEnum = request.getParameterNames();
+ while (namesEnum.hasMoreElements()) {
+ String paramName = (String) namesEnum.nextElement();
+
+ if ("p.page".equals(paramName)) {
+ continue;
+ }
+ for (String val : request.getParameterValues(paramName)) {
+ if (firstParam) {
+ baseUrl.append('?');
+ firstParam = false;
+ } else {
+ baseUrl.append('&');
+ }
+ baseUrl.append(paramName).append('=').append(val);
+ }
+ }
+ return baseUrl.toString();
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/controller/admin/UsersAdminController.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/controller/admin/UsersAdminController.java Mon Oct 21 15:00:17 2013 +0200
@@ -154,7 +154,7 @@
model.addAttribute("key", user.getKey(newSalt));
return "admin/userDeleteConfirm";
-
+
} else if (RequestMethod.POST.equals(method) && key != null
&& !key.isEmpty() && salt != null && !salt.isEmpty()) {
--- a/server/src/main/java/org/iri_research/renkan/coweb/RenkanSessionModerator.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/RenkanSessionModerator.java Mon Oct 21 15:00:17 2013 +0200
@@ -18,208 +18,252 @@
import com.fasterxml.jackson.databind.ObjectMapper;
public class RenkanSessionModerator extends DefaultSessionModerator {
-
- private final Logger logger = LoggerFactory.getLogger(RenkanSessionModerator.class);
-
- private ProjectsRepository projectsRepository;
-
-
- public RenkanSessionModerator() {
- super();
- }
-
- public ProjectsRepository getProjectsRepository() {
- if(this.projectsRepository == null) {
- ApplicationContext context = SpringConfigurer.getInstance().getApplicationContext();
- this.projectsRepository = (ProjectsRepository)context.getBean("projectsRepository");
- }
- return projectsRepository;
- }
+
+ private final Logger logger = LoggerFactory
+ .getLogger(RenkanSessionModerator.class);
+
+ private ProjectsRepository projectsRepository;
+
+ public RenkanSessionModerator() {
+ super();
+ }
+
+ public ProjectsRepository getProjectsRepository() {
+ if (this.projectsRepository == null) {
+ ApplicationContext context = SpringConfigurer.getInstance()
+ .getApplicationContext();
+ this.projectsRepository = (ProjectsRepository) context
+ .getBean("projectsRepository");
+ }
+ return projectsRepository;
+ }
+
+ @Override
+ public synchronized boolean canClientJoinSession(String clientId,
+ Map<String, Object> userDefined) {
+
+ this.logger.debug("canClientJoinSession: " + clientId + " , "
+ + (userDefined == null ? "null" : userDefined.toString()));
+
+ if (RenkanSessionModeratorState.INSTANCE.getUsersActivationMap()
+ .containsKey(clientId)) {
+ this.logger
+ .warn("Client id already declared in user activation map: "
+ + clientId);
+ }
+
+ String projectId = (String) userDefined.get("project_id");
+
+ if (projectId == null) {
+ return false;
+ }
+
+ RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().put(
+ clientId, projectId);
+ return true;
+ }
+
+ private synchronized void activateProject(String clientId) {
- @Override
- public synchronized boolean canClientJoinSession(String clientId, Map<String,Object> userDefined) {
-
- this.logger.debug("canClientJoinSession: " + clientId + " , " + (userDefined==null?"null":userDefined.toString()));
-
- if(RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().containsKey(clientId)) {
- this.logger.warn("Client id already declared in user activation map: " + clientId);
- }
-
- String projectId = (String)userDefined.get("project_id");
-
- if(projectId == null) {
- return false;
- }
-
- RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().put(clientId, projectId);
- return true;
- }
-
- private synchronized void activateProject(String clientId) {
-
- if(!RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().containsKey(clientId)) {
- this.logger.warn("Client id not declared in user activation map: " + clientId);
- return;
- }
- String project_id = RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().get(clientId);
- if(project_id == null) {
- this.logger.warn("Null project id for client id in user activation map: " + clientId);
- return;
- }
-
- List<String> user_list = RenkanSessionModeratorState.INSTANCE.getProjectsActivationMap().get(project_id);
- if(user_list == null) {
- user_list = new ArrayList<String>();
- RenkanSessionModeratorState.INSTANCE.getProjectsActivationMap().put(project_id, user_list);
- }
+ if (!RenkanSessionModeratorState.INSTANCE.getUsersActivationMap()
+ .containsKey(clientId)) {
+ this.logger.warn("Client id not declared in user activation map: "
+ + clientId);
+ return;
+ }
+ String project_id = RenkanSessionModeratorState.INSTANCE
+ .getUsersActivationMap().get(clientId);
+ if (project_id == null) {
+ this.logger
+ .warn("Null project id for client id in user activation map: "
+ + clientId);
+ return;
+ }
+
+ List<String> user_list = RenkanSessionModeratorState.INSTANCE
+ .getProjectsActivationMap().get(project_id);
+ if (user_list == null) {
+ user_list = new ArrayList<String>();
+ RenkanSessionModeratorState.INSTANCE.getProjectsActivationMap()
+ .put(project_id, user_list);
+ }
+
+ if (!user_list.contains(clientId)) {
+ user_list.add(clientId);
+ }
+
+ }
+
+ @Override
+ public synchronized void onClientJoinSession(String clientId) {
+
+ this.logger.debug("onClientJoinSession: " + clientId);
- if(!user_list.contains(clientId)) {
- user_list.add(clientId);
- }
+ this.activateProject(clientId);
+
+ }
+
+ @Override
+ public synchronized void onClientLeaveSession(String clientId) {
+
+ this.logger.debug("onClientLeaveSession: " + clientId);
+
+ String project_id = RenkanSessionModeratorState.INSTANCE
+ .getUsersActivationMap().get(clientId);
+
+ RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().remove(
+ clientId);
+ if (project_id == null) {
+ this.logger.warn("Leaving client have no associated project: "
+ + clientId);
+ return;
+ }
+
+ List<String> user_list = RenkanSessionModeratorState.INSTANCE
+ .getProjectsActivationMap().get(project_id);
+ if (user_list == null) {
+ this.logger
+ .warn("Leaving client have associated project but no project list : "
+ + clientId + ", " + project_id);
+ return;
+ }
+
+ if (!user_list.remove(clientId)) {
+ this.logger
+ .warn("Leaving client have associated project but not in project list : "
+ + clientId + ", " + project_id);
+ return;
+ }
- }
-
- @Override
- public synchronized void onClientJoinSession(String clientId) {
-
- this.logger.debug("onClientJoinSession: " + clientId);
-
- this.activateProject(clientId);
-
- }
-
- @Override
- public synchronized void onClientLeaveSession(String clientId) {
-
- this.logger.debug("onClientLeaveSession: " + clientId);
-
- String project_id = RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().get(clientId);
-
- RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().remove(clientId);
- if(project_id == null) {
- this.logger.warn("Leaving client have no associated project: " + clientId);
- return;
- }
-
- List<String> user_list = RenkanSessionModeratorState.INSTANCE.getProjectsActivationMap().get(project_id);
- if(user_list == null) {
- this.logger.warn("Leaving client have associated project but no project list : " + clientId + ", " + project_id);
- return;
- }
-
- if(!user_list.remove(clientId)) {
- this.logger.warn("Leaving client have associated project but not in project list : " + clientId + ", " + project_id);
- return;
- }
-
- if(user_list.isEmpty()) {
- this.logger.debug("Leaving client, project list empty, removing from active projects: " + clientId + ", " + project_id);
- RenkanSessionModeratorState.INSTANCE.getProjectsActivationMap().remove(project_id);
- }
-
- List<RosterUser> r_user_list = RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().get(project_id);
- if(r_user_list == null) {
- this.logger.warn("Leaving client have associated project but no user list : " + clientId + ", " + project_id);
- return;
- }
- for (RosterUser rosterUser : r_user_list) {
- if( rosterUser.getClientId().equals(clientId)) {
- r_user_list.remove(rosterUser);
- }
- }
- if(r_user_list.isEmpty()) {
- this.logger.debug("Leaving client, user list empty, removing from active projects: " + clientId + ", " + project_id);
- RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().remove(project_id);
- }
-
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public synchronized void onSync(String clientId, Map<String, Object> data) {
-
- this.logger.debug("Debugging onSync client id: " + clientId);
- this.logger.debug("Debugging onSync: " + data.toString());
- this.logger.debug("Debugging onSync channel: " + data.get("channel"));
- this.logger.debug("Debugging onSync type: " + data.get("type"));
- this.logger.debug("Debugging onSync site: " + data.get("site"));
- this.logger.debug("Debugging onSync value: " + data.get("value"));
- this.logger.debug("Debugging onSync position: " + data.get("position"));
-
- Map<String, Object> values = null;
- if(data.containsKey("value") && data.get("value") != null) {
- values = ((Map<String, Object>) data.get("value"));
- }
-
- if(values == null) {
- this.logger.warn("onSync : no values in message.");
- return;
- }
-
- String sync_type = (String) values.get("_type");
- if(sync_type == null || sync_type.length() == 0) {
- this.logger.warn("onSync : no type in value of message.");
- return;
- }
-
- if(sync_type.startsWith("_")) {
- this.logger.debug("onSync : type sync begin with _, ignore. " + sync_type);
- return;
- }
-
- ApplicationContext context = SpringConfigurer.getInstance().getApplicationContext();
-
- String beanName = String.format("%sSyncEventManager", sync_type.toLowerCase());
-
- try {
- ISyncEventManager<?, ?> eventManager = (ISyncEventManager<?, ?>)context.getBean(beanName);
- logger.debug("Debugging on Sync : dispatch to " + beanName);
- eventManager.dispatchEvent(clientId, data);
- }
- catch(Throwable e) {
- this.logger.error(String.format("onSync EventManagerClass %s not found : error %s : %s", sync_type, e.toString(), e.getMessage()));
- }
-
- }
+ if (user_list.isEmpty()) {
+ this.logger
+ .debug("Leaving client, project list empty, removing from active projects: "
+ + clientId + ", " + project_id);
+ RenkanSessionModeratorState.INSTANCE.getProjectsActivationMap()
+ .remove(project_id);
+ }
+
+ List<RosterUser> r_user_list = RenkanSessionModeratorState.INSTANCE
+ .getProjectsUsersList().get(project_id);
+ if (r_user_list == null) {
+ this.logger
+ .warn("Leaving client have associated project but no user list : "
+ + clientId + ", " + project_id);
+ return;
+ }
+ for (RosterUser rosterUser : r_user_list) {
+ if (rosterUser.getClientId().equals(clientId)) {
+ r_user_list.remove(rosterUser);
+ }
+ }
+ if (r_user_list.isEmpty()) {
+ this.logger
+ .debug("Leaving client, user list empty, removing from active projects: "
+ + clientId + ", " + project_id);
+ RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().remove(
+ project_id);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public synchronized void onSync(String clientId, Map<String, Object> data) {
+
+ this.logger.debug("Debugging onSync client id: " + clientId);
+ this.logger.debug("Debugging onSync: " + data.toString());
+ this.logger.debug("Debugging onSync channel: " + data.get("channel"));
+ this.logger.debug("Debugging onSync type: " + data.get("type"));
+ this.logger.debug("Debugging onSync site: " + data.get("site"));
+ this.logger.debug("Debugging onSync value: " + data.get("value"));
+ this.logger.debug("Debugging onSync position: " + data.get("position"));
+
+ Map<String, Object> values = null;
+ if (data.containsKey("value") && data.get("value") != null) {
+ values = ((Map<String, Object>) data.get("value"));
+ }
+
+ if (values == null) {
+ this.logger.warn("onSync : no values in message.");
+ return;
+ }
+
+ String sync_type = (String) values.get("_type");
+ if (sync_type == null || sync_type.length() == 0) {
+ this.logger.warn("onSync : no type in value of message.");
+ return;
+ }
+
+ if (sync_type.startsWith("_")) {
+ this.logger.debug("onSync : type sync begin with _, ignore. "
+ + sync_type);
+ return;
+ }
- @Override
- public Map<String, Object> getLateJoinState() {
- this.logger.debug("getLateJoinState");
-
- Map<String, Object> res = super.getLateJoinState();
- ObjectMapper mapper = new ObjectMapper();
-
- for (String clientId : RenkanSessionModeratorState.INSTANCE.getUsersActivationMap().keySet()) {
- this.activateProject(clientId);
- }
-
- this.logger.debug("getLateJoinState : Project activated");
-
- for (String project_id : RenkanSessionModeratorState.INSTANCE.getProjectsActivationMap().keySet()) {
+ ApplicationContext context = SpringConfigurer.getInstance()
+ .getApplicationContext();
+
+ String beanName = String.format("%sSyncEventManager",
+ sync_type.toLowerCase());
+
+ try {
+ ISyncEventManager<?, ?> eventManager = (ISyncEventManager<?, ?>) context
+ .getBean(beanName);
+ logger.debug("Debugging on Sync : dispatch to " + beanName);
+ eventManager.dispatchEvent(clientId, data);
+ } catch (Throwable e) {
+ this.logger.error(String.format(
+ "onSync EventManagerClass %s not found : error %s : %s",
+ sync_type, e.toString(), e.getMessage()));
+ }
+
+ }
+
+ @Override
+ public Map<String, Object> getLateJoinState() {
+ this.logger.debug("getLateJoinState");
+
+ Map<String, Object> res = super.getLateJoinState();
+ ObjectMapper mapper = new ObjectMapper();
+
+ for (String clientId : RenkanSessionModeratorState.INSTANCE
+ .getUsersActivationMap().keySet()) {
+ this.activateProject(clientId);
+ }
+
+ this.logger.debug("getLateJoinState : Project activated");
- Project p = this.getProjectsRepository().findOne(project_id);
- if (p != null) {
- try {
- res.put("renkan_"+project_id, mapper.writeValueAsString(p));
- } catch (JsonProcessingException e) {
- this.logger.error("Error when deserializing project " + project_id, e);
- }
- }
-
- String user_res = "[]";
- if(RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().containsKey(project_id)) {
- try {
- user_res = mapper.writeValueAsString(RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().get(project_id));
- } catch (JsonProcessingException e) {
- this.logger.error("Error when deserializing user list " + project_id, e);
- }
- }
- res.put("users_"+project_id, user_res);
- }
-
-
- this.logger.debug("getLateJoinState res : " + res.toString());
- return res;
- }
+ for (String project_id : RenkanSessionModeratorState.INSTANCE
+ .getProjectsActivationMap().keySet()) {
+
+ Project p = this.getProjectsRepository().findOne(project_id);
+ if (p != null) {
+ try {
+ res.put("renkan_" + project_id,
+ mapper.writeValueAsString(p));
+ } catch (JsonProcessingException e) {
+ this.logger.error("Error when deserializing project "
+ + project_id, e);
+ }
+ }
+
+ String user_res = "[]";
+ if (RenkanSessionModeratorState.INSTANCE.getProjectsUsersList()
+ .containsKey(project_id)) {
+ try {
+ user_res = mapper
+ .writeValueAsString(RenkanSessionModeratorState.INSTANCE
+ .getProjectsUsersList().get(project_id));
+ } catch (JsonProcessingException e) {
+ this.logger.error("Error when deserializing user list "
+ + project_id, e);
+ }
+ }
+ res.put("users_" + project_id, user_res);
+ }
+
+ this.logger.debug("getLateJoinState res : " + res.toString());
+ return res;
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/coweb/SpringConfigurer.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/SpringConfigurer.java Mon Oct 21 15:00:17 2013 +0200
@@ -10,43 +10,40 @@
import org.springframework.stereotype.Component;
@Component
-//@Scope("prototype")
-public class SpringConfigurer implements ApplicationContextAware
-{
-
- //private BayeuxServer bayeuxServer;
- //private ServerAnnotationProcessor processor;
- private final Logger logger = LoggerFactory.getLogger(SpringConfigurer.class);
+// @Scope("prototype")
+public class SpringConfigurer implements ApplicationContextAware {
+
+ // private BayeuxServer bayeuxServer;
+ // private ServerAnnotationProcessor processor;
+ private final Logger logger = LoggerFactory
+ .getLogger(SpringConfigurer.class);
private ApplicationContext context;
-
+
private static volatile SpringConfigurer instance = null;
-
- private SpringConfigurer()
- {
- this.logger.debug("Building SpringConfigurer");
- }
-
- public static SpringConfigurer getInstance() {
- if (instance == null) {
- synchronized (SpringConfigurer.class) {
- if(instance == null) {
- instance = new SpringConfigurer();
- }
- }
- }
- return instance;
+
+ private SpringConfigurer() {
+ this.logger.debug("Building SpringConfigurer");
}
+ public static SpringConfigurer getInstance() {
+ if (instance == null) {
+ synchronized (SpringConfigurer.class) {
+ if (instance == null) {
+ instance = new SpringConfigurer();
+ }
+ }
+ }
+ return instance;
+ }
-
- @Override
- @Inject
- public void setApplicationContext(ApplicationContext context)
- throws BeansException {
- this.context = context;
- }
-
- public ApplicationContext getApplicationContext() {
- return this.context;
- }
+ @Override
+ @Inject
+ public void setApplicationContext(ApplicationContext context)
+ throws BeansException {
+ this.context = context;
+ }
+
+ public ApplicationContext getApplicationContext() {
+ return this.context;
+ }
}
\ No newline at end of file
--- a/server/src/main/java/org/iri_research/renkan/coweb/event/AbstractSyncEventManager.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/event/AbstractSyncEventManager.java Mon Oct 21 15:00:17 2013 +0200
@@ -23,194 +23,211 @@
import com.mongodb.DBObject;
import com.mongodb.WriteResult;
+public abstract class AbstractSyncEventManager<T extends IRenkanModel<ID>, ID extends Serializable>
+ implements IPersistedSyncEventManager<T, ID> {
-public abstract class AbstractSyncEventManager<T extends IRenkanModel<ID>, ID extends Serializable> implements IPersistedSyncEventManager<T,ID> {
+ private final Logger logger = LoggerFactory
+ .getLogger(AbstractSyncEventManager.class);
+
+ @Inject
+ private ProjectsRepository projectsRepository;
+
+ @Inject
+ private ProjectSyncsRepository projectSyncsRepository;
+
+ @Override
+ public ProjectsRepository getProjectsRepository() {
+ return this.projectsRepository;
+ }
+
+ @Override
+ public abstract IRenkanRepository<T, ID> getObjectRepository();
+
+ @Override
+ public void dispatchEvent(String clientId, Map<String, Object> data) {
- private final Logger logger = LoggerFactory.getLogger(AbstractSyncEventManager.class);
-
- @Inject
- private ProjectsRepository projectsRepository;
-
- @Inject
- private ProjectSyncsRepository projectSyncsRepository;
-
- @Override
- public ProjectsRepository getProjectsRepository() {
- return this.projectsRepository;
- }
-
- @Override
- public abstract IRenkanRepository<T, ID> getObjectRepository();
-
- @Override
- public void dispatchEvent(String clientId, Map<String, Object> data) {
-
- this.saveSyncEvent(data);
+ this.saveSyncEvent(data);
+
+ String eventType = (String) data.get("type");
- String eventType = (String) data.get("type");
-
- if("null".equalsIgnoreCase(eventType)) {
- this.nullOperation(null, data);
- }
- else if ("update".equalsIgnoreCase(eventType)) {
- this.update(clientId, data);
- }
- else if ("insert".equalsIgnoreCase(eventType)) {
- this.insert(clientId, data);
- }
- else if("delete".equalsIgnoreCase(eventType)) {
- this.delete(clientId, data);
- }
- else {
- logger.warn(String.format("dispatchEvent : eventType unknown %s", eventType));
- }
- }
+ if ("null".equalsIgnoreCase(eventType)) {
+ this.nullOperation(null, data);
+ } else if ("update".equalsIgnoreCase(eventType)) {
+ this.update(clientId, data);
+ } else if ("insert".equalsIgnoreCase(eventType)) {
+ this.insert(clientId, data);
+ } else if ("delete".equalsIgnoreCase(eventType)) {
+ this.delete(clientId, data);
+ } else {
+ logger.warn(String.format("dispatchEvent : eventType unknown %s",
+ eventType));
+ }
+ }
+
+ private void saveSyncEvent(Map<String, Object> data) {
+
+ String project_id = null;
+ String user_id = null;
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
- private void saveSyncEvent(Map<String, Object> data) {
-
- String project_id = null;
- String user_id = null;
-
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
-
- if(values != null) {
- project_id = (String) values.get("_project_id");
- }
-
- if (project_id == null || "".equals(project_id)) {
- logger.warn("saveSyncEvent : project id is null. Can not save sync event");
- return;
- }
-
- Project p = this.projectsRepository.findOne(project_id);
-
- if (p == null) {
- logger.warn("saveSyncEvent : project not found. Can not save sync event");
- return;
- }
-
- p.setUpdated(new Date());
- this.projectsRepository.save(p);
-
- user_id = (String) values.get("_user_id");
-
- if (user_id == null) {
- logger.warn("saveSyncEvent : No user id");
- }
+ if (values != null) {
+ project_id = (String) values.get("_project_id");
+ }
+
+ if (project_id == null || "".equals(project_id)) {
+ logger.warn("saveSyncEvent : project id is null. Can not save sync event");
+ return;
+ }
+
+ Project p = this.projectsRepository.findOne(project_id);
+
+ if (p == null) {
+ logger.warn("saveSyncEvent : project not found. Can not save sync event");
+ return;
+ }
+
+ p.setUpdated(new Date());
+ this.projectsRepository.save(p);
+
+ user_id = (String) values.get("_user_id");
+
+ if (user_id == null) {
+ logger.warn("saveSyncEvent : No user id");
+ }
- try {
- ProjectSync ps = this.projectSyncsRepository.getProjectSync(data.toString(), p, user_id);
- this.projectSyncsRepository.save(ps);
- } catch (RenkanException e) {
- logger.warn("saveSyncEvent : Error when getting Projectr syn object",e);
- }
-
- }
+ try {
+ ProjectSync ps = this.projectSyncsRepository.getProjectSync(
+ data.toString(), p, user_id);
+ this.projectSyncsRepository.save(ps);
+ } catch (RenkanException e) {
+ logger.warn(
+ "saveSyncEvent : Error when getting Projectr syn object", e);
+ }
+
+ }
+
+ protected abstract List<T> getObjectList(Project project);
- protected abstract List<T> getObjectList(Project project);
+ @Override
+ public void update(String clientId, Map<String, Object> data) {
+
+ this.logger.debug("AbstractSyncEventManager: update "
+ + this.getClass().getName());
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
+ String obj_id = (String) values.get("id");
+
+ this.logger.debug(String.format("update %s %s", this.getClass()
+ .getName(), obj_id));
+
+ DBCollection objCollection = this.getObjectRepository().getCollection();
+ DBObject obj = objCollection.findOne(obj_id);
- @Override
- public void update(String clientId, Map<String, Object> data) {
-
- this.logger.debug("AbstractSyncEventManager: update " + this.getClass().getName());
-
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
- String obj_id = (String) values.get("id");
-
- this.logger.debug(String.format("update %s %s", this.getClass().getName(), obj_id));
-
- DBCollection objCollection = this.getObjectRepository().getCollection();
- DBObject obj = objCollection.findOne(obj_id);
-
- if (null == obj) {
- throw new CowebException("Object update: object not found", String.format("Object %s not found in %s", obj_id, objCollection.getName()));
- }
-
- boolean obj_changed = false;
- // update object
- for (String fieldname : values.keySet()) {
- if(!"id".equalsIgnoreCase(fieldname) && !fieldname.startsWith("_"))
- {
- Object new_value = values.get(fieldname);
- Object old_value = obj.get(fieldname);
- if((new_value == null && old_value != null) || (new_value != null && !new_value.equals(old_value))) {
- obj.put(fieldname, new_value);
- obj_changed = true;
- }
- }
- }
-
- if(obj_changed) {
- obj.put("_id", obj_id);
- WriteResult res = this.getObjectRepository().getCollection().update(new BasicDBObject("_id", obj_id), obj, true, false);
-
- if(!res.getLastError().ok()) {
- throw new CowebException(String.format("Error when writing object %s in %s", obj_id, objCollection.getName()), res.getLastError().getErrorMessage());
- }
- }
- }
+ if (null == obj) {
+ throw new CowebException("Object update: object not found",
+ String.format("Object %s not found in %s", obj_id,
+ objCollection.getName()));
+ }
+
+ boolean obj_changed = false;
+ // update object
+ for (String fieldname : values.keySet()) {
+ if (!"id".equalsIgnoreCase(fieldname) && !fieldname.startsWith("_")) {
+ Object new_value = values.get(fieldname);
+ Object old_value = obj.get(fieldname);
+ if ((new_value == null && old_value != null)
+ || (new_value != null && !new_value.equals(old_value))) {
+ obj.put(fieldname, new_value);
+ obj_changed = true;
+ }
+ }
+ }
+
+ if (obj_changed) {
+ obj.put("_id", obj_id);
+ WriteResult res = this.getObjectRepository().getCollection()
+ .update(new BasicDBObject("_id", obj_id), obj, true, false);
- @Override
- public abstract void insert(String clientId, Map<String, Object> data);
+ if (!res.getLastError().ok()) {
+ throw new CowebException(String.format(
+ "Error when writing object %s in %s", obj_id,
+ objCollection.getName()), res.getLastError()
+ .getErrorMessage());
+ }
+ }
+ }
+
+ @Override
+ public abstract void insert(String clientId, Map<String, Object> data);
+
+ @Override
+ public void delete(String clientId, Map<String, Object> data) {
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
+ String project_id = (String) values.get("_project_id");
+ Project project = this.getProjectsRepository().findOne(project_id);
+
+ if (null == project) {
+ throw new CowebException(this.getClass().getName()
+ + " delete: project not found", String.format(
+ "Project %s not found", project_id));
+ }
+
+ Integer position = (Integer) data.get("position");
- @Override
- public void delete(String clientId, Map<String, Object> data) {
-
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
- String project_id = (String) values.get("_project_id");
- Project project = this.getProjectsRepository().findOne(project_id);
-
- if (null == project) {
- throw new CowebException(this.getClass().getName() + " delete: project not found", String.format("Project %s not found", project_id));
- }
+ if (position == null || position < 0) {
+ throw new CowebException("object delete: bad delete position",
+ String.format("Bad position %s not found",
+ position == null ? "null" : position.toString()));
+ }
+ int index = position.intValue();
+
+ @SuppressWarnings("unchecked")
+ ID object_id = (ID) values.get("id");
+
+ this.logger.debug(String.format(
+ "delete object %s in pos %d for project %s", object_id, index,
+ project_id));
+
+ IRenkanModel<ID> currentObject = null;
+
+ List<T> objList = this.getObjectList(project);
+
+ if (index < objList.size()) {
+ currentObject = objList.get(index);
+ }
- Integer position = (Integer)data.get("position");
-
- if(position == null || position < 0) {
- throw new CowebException("object delete: bad delete position", String.format("Bad position %s not found", position==null?"null":position.toString()));
- }
- int index = position.intValue();
-
- @SuppressWarnings("unchecked")
- ID object_id = (ID) values.get("id");
-
- this.logger.debug(String.format("delete object %s in pos %d for project %s", object_id, index, project_id));
-
- IRenkanModel<ID> currentObject = null;
-
- List<T> objList = this.getObjectList(project);
-
- if(index < objList.size()) {
- currentObject = objList.get(index);
- }
-
- if(currentObject == null || !object_id.equals(currentObject.getId())) {
- index = -1;
- this.logger.warn(String.format("delete object %s in pos %d for project %s not current object", object_id, index, project_id));
- for(int i=0;i<project.getNodes().size();i++) {
- if(object_id.equals(objList.get(i).getId())) {
- index = i;
- break;
- }
- }
- }
-
- if(index<0) {
- this.logger.warn(String.format("delete object %s in pos %d for project %s not found", object_id, index, project_id));
- }
- else {
- objList.remove(index);
- this.getObjectRepository().delete(object_id);
- this.getProjectsRepository().save(project);
- }
+ if (currentObject == null || !object_id.equals(currentObject.getId())) {
+ index = -1;
+ this.logger
+ .warn(String
+ .format("delete object %s in pos %d for project %s not current object",
+ object_id, index, project_id));
+ for (int i = 0; i < project.getNodes().size(); i++) {
+ if (object_id.equals(objList.get(i).getId())) {
+ index = i;
+ break;
+ }
+ }
+ }
- }
+ if (index < 0) {
+ this.logger.warn(String.format(
+ "delete object %s in pos %d for project %s not found",
+ object_id, index, project_id));
+ } else {
+ objList.remove(index);
+ this.getObjectRepository().delete(object_id);
+ this.getProjectsRepository().save(project);
+ }
- @Override
- public abstract void nullOperation(String clientId, Map<String, Object> data);
-
-
+ }
+
+ @Override
+ public abstract void nullOperation(String clientId, Map<String, Object> data);
+
}
--- a/server/src/main/java/org/iri_research/renkan/coweb/event/EdgeSyncEventManager.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/event/EdgeSyncEventManager.java Mon Oct 21 15:00:17 2013 +0200
@@ -18,101 +18,107 @@
import org.slf4j.LoggerFactory;
@Named
-public class EdgeSyncEventManager extends AbstractSyncEventManager<Edge, String> {
+public class EdgeSyncEventManager extends
+ AbstractSyncEventManager<Edge, String> {
- private final Logger logger = LoggerFactory.getLogger(EdgeSyncEventManager.class);
+ private final Logger logger = LoggerFactory
+ .getLogger(EdgeSyncEventManager.class);
- @Inject
- private NodesRepository nodesRepository;
+ @Inject
+ private NodesRepository nodesRepository;
- @Inject
- private UsersRepository usersRepository;
-
- @Inject
- private EdgesRepository edgesRepository;
+ @Inject
+ private UsersRepository usersRepository;
+
+ @Inject
+ private EdgesRepository edgesRepository;
-
- public NodesRepository getNodesRepository() {
- return nodesRepository;
- }
+ public NodesRepository getNodesRepository() {
+ return nodesRepository;
+ }
+
+ public UsersRepository getUsersRepository() {
+ return usersRepository;
+ }
- public UsersRepository getUsersRepository() {
- return usersRepository;
- }
+ public EdgesRepository getEdgesRepository() {
+ return edgesRepository;
+ }
+
+ @Override
+ public IRenkanRepository<Edge, String> getObjectRepository() {
+ return this.getEdgesRepository();
+ }
+
+ @Override
+ public void insert(String clientId, Map<String, Object> data) {
- public EdgesRepository getEdgesRepository() {
- return edgesRepository;
- }
-
-
- @Override
- public IRenkanRepository<Edge, String> getObjectRepository() {
- return this.getEdgesRepository();
- }
-
-
- @Override
- public void insert(String clientId, Map<String, Object> data) {
-
- // get project
- this.logger.debug("EdgeSyncEventManager: insert Edge");
-
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
- String project_id = (String) values.get("_project_id");
+ // get project
+ this.logger.debug("EdgeSyncEventManager: insert Edge");
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
+ String project_id = (String) values.get("_project_id");
+
+ Project project = this.getProjectsRepository().findOne(project_id);
+
+ if (null == project) {
+ throw new CowebException("Edge insert: project not found",
+ String.format("Project %s not found", project_id));
+ }
+
+ String creator_id = (String) values.get("created_by");
- Project project = this.getProjectsRepository().findOne(project_id);
-
- if (null == project) {
- throw new CowebException("Edge insert: project not found", String.format("Project %s not found", project_id));
- }
+ String from_node_id = (String) values.get("from");
+ Node from_node = this.getNodesRepository().findOne(from_node_id);
+
+ if (null == from_node) {
+ throw new CowebException("Edge insert: from not found",
+ String.format("from %s not found", from_node_id));
+ }
+
+ String to_node_id = (String) values.get("to");
+ Node to_node = this.getNodesRepository().findOne(to_node_id);
+
+ if (null == to_node) {
+ throw new CowebException("Edge insert: to not found",
+ String.format("to %s not found", to_node_id));
+ }
+
+ String edge_id = (String) values.get("id");
+
+ Edge edge = new Edge(edge_id, (String) values.get("title"),
+ (String) values.get("description"), (String) values.get("uri"),
+ (String) values.get("color"), from_node, to_node, creator_id,
+ project_id);
+
+ Integer position = (Integer) data.get("position");
- String creator_id = (String) values.get("created_by");
-
- String from_node_id = (String)values.get("from");
- Node from_node = this.getNodesRepository().findOne(from_node_id);
-
- if(null == from_node) {
- throw new CowebException("Edge insert: from not found", String.format("from %s not found", from_node_id));
- }
-
- String to_node_id = (String)values.get("to");
- Node to_node = this.getNodesRepository().findOne(to_node_id);
-
- if(null == to_node) {
- throw new CowebException("Edge insert: to not found", String.format("to %s not found", to_node_id));
- }
-
- String edge_id = (String)values.get("id");
-
- Edge edge = new Edge(edge_id, (String)values.get("title"), (String)values.get("description"), (String)values.get("uri"), (String)values.get("color"), from_node, to_node, creator_id, project_id);
-
-
- Integer position = (Integer)data.get("position");
-
- if(position == null || position < 0) {
- throw new CowebException("Edge insert: bad insert position", String.format("Bad position %s not found", position==null?"null":position.toString()));
- }
- int index = position.intValue();
- List<Edge> edges = project.getEdges();
- if(index > edges.size()) {
- index = edges.size();
- }
- edges.add(index,edge);
+ if (position == null || position < 0) {
+ throw new CowebException("Edge insert: bad insert position",
+ String.format("Bad position %s not found",
+ position == null ? "null" : position.toString()));
+ }
+ int index = position.intValue();
+ List<Edge> edges = project.getEdges();
+ if (index > edges.size()) {
+ index = edges.size();
+ }
+ edges.add(index, edge);
- this.getEdgesRepository().save(edge);
- this.getProjectsRepository().save(project);
-
- }
-
- @Override
- public void nullOperation(String clientId, Map<String, Object> data) {
- this.logger.debug("nullOperation: NOP");
- }
+ this.getEdgesRepository().save(edge);
+ this.getProjectsRepository().save(project);
+
+ }
- @Override
- protected List<Edge> getObjectList(Project project) {
- return project.getEdges();
- }
+ @Override
+ public void nullOperation(String clientId, Map<String, Object> data) {
+ this.logger.debug("nullOperation: NOP");
+ }
+
+ @Override
+ protected List<Edge> getObjectList(Project project) {
+ return project.getEdges();
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/coweb/event/IPersistedSyncEventManager.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/event/IPersistedSyncEventManager.java Mon Oct 21 15:00:17 2013 +0200
@@ -5,9 +5,11 @@
import org.iri_research.renkan.repositories.IRenkanRepository;
import org.iri_research.renkan.repositories.ProjectsRepository;
-public interface IPersistedSyncEventManager<T, ID extends Serializable> extends ISyncEventManager<T, ID> {
-
- public ProjectsRepository getProjectsRepository();
- public IRenkanRepository<T,ID> getObjectRepository();
+public interface IPersistedSyncEventManager<T, ID extends Serializable> extends
+ ISyncEventManager<T, ID> {
+
+ public ProjectsRepository getProjectsRepository();
+
+ public IRenkanRepository<T, ID> getObjectRepository();
}
--- a/server/src/main/java/org/iri_research/renkan/coweb/event/ISyncEventManager.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/event/ISyncEventManager.java Mon Oct 21 15:00:17 2013 +0200
@@ -4,13 +4,15 @@
import java.util.Map;
public interface ISyncEventManager<T, ID extends Serializable> {
-
- public void dispatchEvent(String clientId, Map<String, Object> data);
+
+ public void dispatchEvent(String clientId, Map<String, Object> data);
+
+ public void update(String clientId, Map<String, Object> data);
- public void update(String clientId, Map<String, Object> data);
- public void insert(String clientId, Map<String, Object> data);
- public void delete(String clientId, Map<String, Object> data);
- public void nullOperation(String clientId, Map<String, Object> data);
-
+ public void insert(String clientId, Map<String, Object> data);
+
+ public void delete(String clientId, Map<String, Object> data);
+
+ public void nullOperation(String clientId, Map<String, Object> data);
}
--- a/server/src/main/java/org/iri_research/renkan/coweb/event/NodeSyncEventManager.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/event/NodeSyncEventManager.java Mon Oct 21 15:00:17 2013 +0200
@@ -17,87 +17,96 @@
import org.springframework.data.mongodb.core.geo.Point;
@Named
-public class NodeSyncEventManager extends AbstractSyncEventManager<Node, String> {
+public class NodeSyncEventManager extends
+ AbstractSyncEventManager<Node, String> {
- private final Logger logger = LoggerFactory.getLogger(NodeSyncEventManager.class);
+ private final Logger logger = LoggerFactory
+ .getLogger(NodeSyncEventManager.class);
+
+ @Inject
+ private NodesRepository nodesRepository;
- @Inject
- private NodesRepository nodesRepository;
+ @Inject
+ private UsersRepository usersRepository;
- @Inject
- private UsersRepository usersRepository;
+ public NodesRepository getNodesRepository() {
+ return nodesRepository;
+ }
+
+ @Override
+ public IRenkanRepository<Node, String> getObjectRepository() {
+ return this.getNodesRepository();
+ }
-
- public NodesRepository getNodesRepository() {
- return nodesRepository;
- }
-
- @Override
- public IRenkanRepository<Node, String> getObjectRepository() {
- return this.getNodesRepository();
- }
-
- public UsersRepository getUsersRepository() {
- return this.usersRepository;
- }
+ public UsersRepository getUsersRepository() {
+ return this.usersRepository;
+ }
+
+ @Override
+ public void insert(String clientId, Map<String, Object> data) {
+
+ // get project
+ this.logger.debug("NodeSyncEventManager: insert Node");
-
- @Override
- public void insert(String clientId, Map<String, Object> data) {
-
- // get project
- this.logger.debug("NodeSyncEventManager: insert Node");
-
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
- String project_id = (String) values.get("_project_id");
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
+ String project_id = (String) values.get("_project_id");
+
+ Project project = this.getProjectsRepository().findOne(project_id);
- Project project = this.getProjectsRepository().findOne(project_id);
-
- if (null == project) {
- throw new CowebException("node insert: project not found", String.format("Project %s not found", project_id));
- }
+ if (null == project) {
+ throw new CowebException("node insert: project not found",
+ String.format("Project %s not found", project_id));
+ }
+
+ String creator_id = (String) values.get("created_by");
- String creator_id = (String) values.get("created_by");
-
- @SuppressWarnings("unchecked")
- Map<String, Object> positionValues = (Map<String, Object>) values.get("position");
-
- Point nodePosition = new Point(((Number)positionValues.get("x")).doubleValue(), ((Number)positionValues.get("y")).doubleValue());
-
- String image = (String)values.get("image");
-
- String node_id = (String)values.get("id");
-
- Integer size = (Integer)values.get("size");
-
- Node node = new Node(node_id, (String)values.get("title"), (String)values.get("description"), (String)values.get("uri"), (String)values.get("color"), creator_id, nodePosition, image, size, project_id);
-
- Integer position = (Integer)data.get("position");
-
- if(position == null || position < 0) {
- throw new CowebException("node insert: bad insert position", String.format("Bad position %s not found", position==null?"null":position.toString()));
- }
- int index = position.intValue();
- List<Node> nodes = project.getNodes();
- if(index > nodes.size()) {
- index = nodes.size();
- }
- nodes.add(index,node);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> positionValues = (Map<String, Object>) values
+ .get("position");
+
+ Point nodePosition = new Point(
+ ((Number) positionValues.get("x")).doubleValue(),
+ ((Number) positionValues.get("y")).doubleValue());
+
+ String image = (String) values.get("image");
+
+ String node_id = (String) values.get("id");
+
+ Integer size = (Integer) values.get("size");
+
+ Node node = new Node(node_id, (String) values.get("title"),
+ (String) values.get("description"), (String) values.get("uri"),
+ (String) values.get("color"), creator_id, nodePosition, image,
+ size, project_id);
+
+ Integer position = (Integer) data.get("position");
- this.getNodesRepository().save(node);
- this.getProjectsRepository().save(project);
-
- }
-
- @Override
- public void nullOperation(String clientId, Map<String, Object> data) {
- this.logger.debug("nullOperation: NOP");
- }
+ if (position == null || position < 0) {
+ throw new CowebException("node insert: bad insert position",
+ String.format("Bad position %s not found",
+ position == null ? "null" : position.toString()));
+ }
+ int index = position.intValue();
+ List<Node> nodes = project.getNodes();
+ if (index > nodes.size()) {
+ index = nodes.size();
+ }
+ nodes.add(index, node);
- @Override
- protected List<Node> getObjectList(Project project) {
- return project.getNodes();
- }
+ this.getNodesRepository().save(node);
+ this.getProjectsRepository().save(project);
+
+ }
+
+ @Override
+ public void nullOperation(String clientId, Map<String, Object> data) {
+ this.logger.debug("nullOperation: NOP");
+ }
+
+ @Override
+ protected List<Node> getObjectList(Project project) {
+ return project.getNodes();
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/coweb/event/ProjectSyncEventManager.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/event/ProjectSyncEventManager.java Mon Oct 21 15:00:17 2013 +0200
@@ -15,50 +15,63 @@
/**
* @author ymh
- *
+ *
*/
@Named
-public class ProjectSyncEventManager extends AbstractSyncEventManager<Project, String> {
+public class ProjectSyncEventManager extends
+ AbstractSyncEventManager<Project, String> {
+
+ private final Logger logger = LoggerFactory
+ .getLogger(ProjectSyncEventManager.class);
+
+ @Override
+ public IRenkanRepository<Project, String> getObjectRepository() {
+ return this.getProjectsRepository();
+ }
- private final Logger logger = LoggerFactory.getLogger(ProjectSyncEventManager.class);
-
- @Override
- public IRenkanRepository<Project, String> getObjectRepository() {
- return this.getProjectsRepository();
- }
-
- /* (non-Javadoc)
- * @see org.iri_research.renkan.coweb.event.AbstractSyncEventManager#insert(java.util.Map)
- */
- @Override
- public void insert(String clientId, Map<String, Object> data) {
- this.logger.debug("Insert called, do nothing");
- // do nothing
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.iri_research.renkan.coweb.event.AbstractSyncEventManager#insert(java
+ * .util.Map)
+ */
+ @Override
+ public void insert(String clientId, Map<String, Object> data) {
+ this.logger.debug("Insert called, do nothing");
+ // do nothing
+ }
- /* (non-Javadoc)
- * @see org.iri_research.renkan.coweb.event.AbstractSyncEventManager#delete(java.util.Map)
- */
- @Override
- public void delete(String clientId, Map<String, Object> data) {
- this.logger.debug("Delete called, do nothing");
- // do nothing
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.iri_research.renkan.coweb.event.AbstractSyncEventManager#delete(java
+ * .util.Map)
+ */
+ @Override
+ public void delete(String clientId, Map<String, Object> data) {
+ this.logger.debug("Delete called, do nothing");
+ // do nothing
+ }
- /* (non-Javadoc)
- * @see org.iri_research.renkan.coweb.event.AbstractSyncEventManager#nullOperation(java.util.Map)
- */
- @Override
- public void nullOperation(String clientId, Map<String, Object> data) {
- this.logger.debug("Null called, do nothing");
- // do nothing
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.iri_research.renkan.coweb.event.AbstractSyncEventManager#nullOperation
+ * (java.util.Map)
+ */
+ @Override
+ public void nullOperation(String clientId, Map<String, Object> data) {
+ this.logger.debug("Null called, do nothing");
+ // do nothing
+ }
- @Override
- protected List<Project> getObjectList(Project project) {
- this.logger.error("Get object list called error");
- throw new UnsupportedOperationException("Get object list called error");
- }
-
+ @Override
+ protected List<Project> getObjectList(Project project) {
+ this.logger.error("Get object list called error");
+ throw new UnsupportedOperationException("Get object list called error");
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/coweb/event/RosterSyncEventManager.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/event/RosterSyncEventManager.java Mon Oct 21 15:00:17 2013 +0200
@@ -12,185 +12,196 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Named
+public class RosterSyncEventManager implements
+ ISyncEventManager<RosterUser, String> {
-@Named
-public class RosterSyncEventManager implements ISyncEventManager<RosterUser, String> {
+ private final Logger logger = LoggerFactory
+ .getLogger(RosterSyncEventManager.class);
- private final Logger logger = LoggerFactory.getLogger(RosterSyncEventManager.class);
-
+ @Override
+ public void insert(String clientId, Map<String, Object> data) {
+ logger.debug("RosterUserSyncEventManager.insert " + data.toString());
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
+ String projectId = (String) values.get("_project_id");
+
+ List<RosterUser> usersList = null;
- @Override
- public void insert(String clientId, Map<String, Object> data) {
- logger.debug("RosterUserSyncEventManager.insert " + data.toString());
-
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
- String projectId = (String) values.get("_project_id");
+ if (RenkanSessionModeratorState.INSTANCE.getProjectsUsersList()
+ .containsKey(projectId)) {
+ usersList = RenkanSessionModeratorState.INSTANCE
+ .getProjectsUsersList().get(projectId);
+ }
+ if (usersList == null) {
+ usersList = new ArrayList<RosterUser>();
+ RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().put(
+ projectId, usersList);
+ }
+
+ String id = (String) values.get("id");
- List<RosterUser> usersList = null;
-
- if(RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().containsKey(projectId)) {
- usersList = RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().get(projectId);
- }
- if(usersList == null) {
- usersList = new ArrayList<RosterUser>();
- RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().put(projectId, usersList);
- }
-
- String id = (String)values.get("id");
+ RosterUser user = null;
+
+ for (RosterUser rosterUser : usersList) {
+ if (rosterUser.getId().equals(id)) {
+ user = rosterUser;
+ break;
+ }
+ }
+ if (user != null) {
+ this.update(clientId, data);
+ return;
+ }
- RosterUser user = null;
-
- for (RosterUser rosterUser : usersList) {
- if(rosterUser.getId().equals(id)) {
- user = rosterUser;
- break;
- }
- }
- if(user != null) {
- this.update(clientId, data);
- return;
- }
-
- String title = (String)values.get("title");
- String description = (String)values.get("description");
- String uri = (String)values.get("uri");
- String color = (String)values.get("color");
- Long site_id = (Long)values.get("site_id");
-
- user = new RosterUser(id, title, description, uri, color, projectId, site_id, clientId);
-
- Integer position = (Integer)data.get("position");
- if(position == null) {
- position = new Integer(0);
- }
-
- usersList.add(position.intValue(), user);
-
- logger.debug("RosterUserSyncEventManager.insert in " + projectId + " : " + RenkanSessionModeratorState.INSTANCE.getProjectsActivationMap().toString());
-
- }
+ String title = (String) values.get("title");
+ String description = (String) values.get("description");
+ String uri = (String) values.get("uri");
+ String color = (String) values.get("color");
+ Long site_id = (Long) values.get("site_id");
+
+ user = new RosterUser(id, title, description, uri, color, projectId,
+ site_id, clientId);
+
+ Integer position = (Integer) data.get("position");
+ if (position == null) {
+ position = new Integer(0);
+ }
+
+ usersList.add(position.intValue(), user);
+
+ logger.debug("RosterUserSyncEventManager.insert in "
+ + projectId
+ + " : "
+ + RenkanSessionModeratorState.INSTANCE
+ .getProjectsActivationMap().toString());
+
+ }
- @Override
- public void nullOperation(String clientId, Map<String, Object> data) {
- // do nothing
- return;
- }
+ @Override
+ public void nullOperation(String clientId, Map<String, Object> data) {
+ // do nothing
+ return;
+ }
- @Override
- public void update(String clientId, Map<String, Object> data) {
- logger.debug("RosterUserSyncEventManager.update " + data.toString());
+ @Override
+ public void update(String clientId, Map<String, Object> data) {
+ logger.debug("RosterUserSyncEventManager.update " + data.toString());
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
+ String projectId = (String) values.get("_project_id");
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
- String projectId = (String) values.get("_project_id");
+ List<RosterUser> usersList = null;
- List<RosterUser> usersList = null;
-
- if(RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().containsKey(projectId)) {
- usersList = RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().get(projectId);
- }
-
- if(usersList == null) {
- logger.debug("RosterUserSyncEventManager.update : null user list");
- return;
- }
-
- String id = (String)values.get("id");
+ if (RenkanSessionModeratorState.INSTANCE.getProjectsUsersList()
+ .containsKey(projectId)) {
+ usersList = RenkanSessionModeratorState.INSTANCE
+ .getProjectsUsersList().get(projectId);
+ }
+
+ if (usersList == null) {
+ logger.debug("RosterUserSyncEventManager.update : null user list");
+ return;
+ }
+
+ String id = (String) values.get("id");
- RosterUser user = null;
-
- for (RosterUser rosterUser : usersList) {
- if(rosterUser.getId().equals(id)) {
- user = rosterUser;
- break;
- }
- }
-
- if(user == null) {
- logger.debug("RosterUserSyncEventManager.update : user not found in list");
- return;
- }
-
- String title = (String)values.get("title");
- String description = (String)values.get("description");
- String uri = (String)values.get("uri");
- String color = (String)values.get("color");
-
- if(title != null) {
- user.setTitle(title);
- }
- if(description != null) {
- user.setDescription(description);
- }
- if(uri != null) {
- user.setUri(uri);
- }
- if(color != null) {
- user.setColor(color);
- }
-
- return;
-
- }
+ RosterUser user = null;
+
+ for (RosterUser rosterUser : usersList) {
+ if (rosterUser.getId().equals(id)) {
+ user = rosterUser;
+ break;
+ }
+ }
+
+ if (user == null) {
+ logger.debug("RosterUserSyncEventManager.update : user not found in list");
+ return;
+ }
+
+ String title = (String) values.get("title");
+ String description = (String) values.get("description");
+ String uri = (String) values.get("uri");
+ String color = (String) values.get("color");
- @Override
- public void delete(String clientId, Map<String, Object> data) {
- logger.debug("RosterUserSyncEventManager.delete " + data.toString());
-
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
- String projectId = (String) values.get("_project_id");
+ if (title != null) {
+ user.setTitle(title);
+ }
+ if (description != null) {
+ user.setDescription(description);
+ }
+ if (uri != null) {
+ user.setUri(uri);
+ }
+ if (color != null) {
+ user.setColor(color);
+ }
+
+ return;
+
+ }
+
+ @Override
+ public void delete(String clientId, Map<String, Object> data) {
+ logger.debug("RosterUserSyncEventManager.delete " + data.toString());
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
+ String projectId = (String) values.get("_project_id");
+
+ List<RosterUser> usersList = null;
- List<RosterUser> usersList = null;
-
- if(RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().containsKey(projectId)) {
- usersList = RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().get(projectId);
- }
-
- if(usersList == null) {
- logger.debug("RosterUserSyncEventManager.delete : null user list");
- return;
- }
-
- Integer position = (Integer)data.get("position");
-
- if(position == null || position < 0) {
- throw new CowebException("object delete: bad delete position", String.format("Bad position %s not found", position==null?"null":position.toString()));
- }
- int index = position.intValue();
-
- usersList.remove(index);
-
- if(usersList.isEmpty()) {
- RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().remove(projectId);
- }
-
- return;
-
- }
-
- @Override
- public void dispatchEvent(String clientId, Map<String, Object> data) {
-
- String eventType = (String) data.get("type");
-
- if("null".equalsIgnoreCase(eventType)) {
- this.nullOperation(clientId, data);
- }
- else if ("update".equalsIgnoreCase(eventType)) {
- this.update(clientId, data);
- }
- else if ("insert".equalsIgnoreCase(eventType)) {
- this.insert(clientId, data);
- }
- else if("delete".equalsIgnoreCase(eventType)) {
- this.delete(clientId, data);
- }
- else {
- logger.warn(String.format("dispatchEvent : eventType unknown %s", eventType));
- }
- }
+ if (RenkanSessionModeratorState.INSTANCE.getProjectsUsersList()
+ .containsKey(projectId)) {
+ usersList = RenkanSessionModeratorState.INSTANCE
+ .getProjectsUsersList().get(projectId);
+ }
+
+ if (usersList == null) {
+ logger.debug("RosterUserSyncEventManager.delete : null user list");
+ return;
+ }
+
+ Integer position = (Integer) data.get("position");
+
+ if (position == null || position < 0) {
+ throw new CowebException("object delete: bad delete position",
+ String.format("Bad position %s not found",
+ position == null ? "null" : position.toString()));
+ }
+ int index = position.intValue();
+
+ usersList.remove(index);
+ if (usersList.isEmpty()) {
+ RenkanSessionModeratorState.INSTANCE.getProjectsUsersList().remove(
+ projectId);
+ }
+
+ return;
+
+ }
+
+ @Override
+ public void dispatchEvent(String clientId, Map<String, Object> data) {
+
+ String eventType = (String) data.get("type");
+
+ if ("null".equalsIgnoreCase(eventType)) {
+ this.nullOperation(clientId, data);
+ } else if ("update".equalsIgnoreCase(eventType)) {
+ this.update(clientId, data);
+ } else if ("insert".equalsIgnoreCase(eventType)) {
+ this.insert(clientId, data);
+ } else if ("delete".equalsIgnoreCase(eventType)) {
+ this.delete(clientId, data);
+ } else {
+ logger.warn(String.format("dispatchEvent : eventType unknown %s",
+ eventType));
+ }
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/coweb/event/UserSyncEventManager.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/coweb/event/UserSyncEventManager.java Mon Oct 21 15:00:17 2013 +0200
@@ -17,77 +17,83 @@
import org.slf4j.LoggerFactory;
@Named
-public class UserSyncEventManager extends AbstractSyncEventManager<User, String> {
+public class UserSyncEventManager extends
+ AbstractSyncEventManager<User, String> {
+
+ private final Logger logger = LoggerFactory
+ .getLogger(UserSyncEventManager.class);
- private final Logger logger = LoggerFactory.getLogger(UserSyncEventManager.class);
-
- private final static String DEFAULT_COLOR = "#000080";
+ private final static String DEFAULT_COLOR = "#000080";
+
+ @Inject
+ private UsersRepository usersRepository;
+
+ public UsersRepository getUsersRepository() {
+ return this.usersRepository;
+ }
- @Inject
- private UsersRepository usersRepository;
-
- public UsersRepository getUsersRepository() {
- return this.usersRepository;
- }
-
- @Override
- public IRenkanRepository<User, String> getObjectRepository() {
- return this.getUsersRepository();
- }
+ @Override
+ public IRenkanRepository<User, String> getObjectRepository() {
+ return this.getUsersRepository();
+ }
+
+ @Override
+ public void insert(String clientId, Map<String, Object> data) {
+
+ // get project
+ this.logger.debug("UserSyncEventManager: insert User");
+ @SuppressWarnings("unchecked")
+ Map<String, Object> values = (Map<String, Object>) data.get("value");
+ String project_id = (String) values.get("_project_id");
- @Override
- public void insert(String clientId, Map<String, Object> data) {
-
- // get project
- this.logger.debug("UserSyncEventManager: insert User");
-
- @SuppressWarnings("unchecked")
- Map<String, Object> values = (Map<String, Object>) data.get("value");
- String project_id = (String) values.get("_project_id");
+ Project project = this.getProjectsRepository().findOne(project_id);
+
+ if (null == project) {
+ throw new CowebException("user insert: project not found",
+ String.format("Project %s not found", project_id));
+ }
- Project project = this.getProjectsRepository().findOne(project_id);
-
- if (null == project) {
- throw new CowebException("user insert: project not found", String.format("Project %s not found", project_id));
- }
-
- String user_id = (String)values.get("id");
- String color = (String)values.get("color");
- if(color == null || color.length() == 0) {
- color = UserSyncEventManager.DEFAULT_COLOR;
- }
-
- User user = new User(user_id, (String)values.get("title"), (String)values.get("description"), (String)values.get("uri"), color);
-
- Integer position = (Integer)data.get("position");
-
- if(position == null || position < 0) {
- throw new CowebException("node insert: bad insert position", String.format("Bad position %s not found", position==null?"null":position.toString()));
- }
- int index = position.intValue();
- //TODO: correct this. done that to compile
- List<User> users = new ArrayList<User>();//project.getUsers();
- if(index > users.size()) {
- index = users.size();
- }
- users.add(index,user);
+ String user_id = (String) values.get("id");
+ String color = (String) values.get("color");
+ if (color == null || color.length() == 0) {
+ color = UserSyncEventManager.DEFAULT_COLOR;
+ }
+
+ User user = new User(user_id, (String) values.get("title"),
+ (String) values.get("description"), (String) values.get("uri"),
+ color);
+
+ Integer position = (Integer) data.get("position");
- this.getUsersRepository().save(user);
- this.getProjectsRepository().save(project);
-
- }
+ if (position == null || position < 0) {
+ throw new CowebException("node insert: bad insert position",
+ String.format("Bad position %s not found",
+ position == null ? "null" : position.toString()));
+ }
+ int index = position.intValue();
+ // TODO: correct this. done that to compile
+ List<User> users = new ArrayList<User>();// project.getUsers();
+ if (index > users.size()) {
+ index = users.size();
+ }
+ users.add(index, user);
- @Override
- public void nullOperation(String clientId, Map<String, Object> data) {
- this.logger.debug("nullOperation: NOP");
- }
+ this.getUsersRepository().save(user);
+ this.getProjectsRepository().save(project);
+
+ }
- @Override
- protected List<User> getObjectList(Project project) {
- //TODO: correct this, this is wrong, just put here to cpmpile
- return null;
- //return project.getUsers();
- }
+ @Override
+ public void nullOperation(String clientId, Map<String, Object> data) {
+ this.logger.debug("nullOperation: NOP");
+ }
+
+ @Override
+ protected List<User> getObjectList(Project project) {
+ // TODO: correct this, this is wrong, just put here to cpmpile
+ return null;
+ // return project.getUsers();
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/forms/RenkanForm.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/forms/RenkanForm.java Mon Oct 21 15:00:17 2013 +0200
@@ -26,7 +26,7 @@
}
public RenkanForm(RM model) {
- if(model == null) {
+ if (model == null) {
return;
}
this.model = model;
--- a/server/src/main/java/org/iri_research/renkan/forms/UserForm.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/forms/UserForm.java Mon Oct 21 15:00:17 2013 +0200
@@ -21,7 +21,7 @@
public UserForm(User model) {
super(model);
- if(model != null) {
+ if (model != null) {
this.avatar = model.getAvatar();
this.credentialExpirationDate = model.getCredentialExpirationDate();
this.email = model.getEmail();
@@ -38,8 +38,6 @@
private boolean enabled;
private boolean locked;
-
-
public String getAvatar() {
return avatar;
}
@@ -120,7 +118,5 @@
public void setUsersRepository(UsersRepository usersRepository) {
this.usersRepository = usersRepository;
}
-
-
}
--- a/server/src/main/java/org/iri_research/renkan/management/MigrateRenkanUser.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/management/MigrateRenkanUser.java Mon Oct 21 15:00:17 2013 +0200
@@ -16,57 +16,62 @@
@Component
public class MigrateRenkanUser {
-
- public static void main(String[] args) {
-
- @SuppressWarnings("resource")
- ApplicationContext context = new ClassPathXmlApplicationContext("classpath:WEB-INF/applicationContext.xml");
-
- MigrateRenkanUser p = context.getBean(MigrateRenkanUser.class);
- p.start(args);
-
- }
-
- @Autowired
- private MongoTemplate template;
-
- private void start(String[] args) {
-
- DBCollection userColl = template.getCollection(template.getCollectionName(User.class));
- DBCollection renkanUserColl = template.getCollection(template.getCollectionName(RenkanUser.class));
- DBCollection projectColl = template.getCollection(template.getCollectionName(Project.class));
-
- for (DBObject user: userColl.find()) {
- if(!user.containsField("project_id")) {
- continue;
- }
- String projectId = (String) user.get("project_id");
- if(projectId == null || projectId.isEmpty()) {
- user.removeField("project_id");
- userColl.save(user);
- continue;
- }
- DBObject proj = new BasicDBObject();
- proj.put("_id", projectId);
- if(projectColl.findOne(proj) != null) {
- DBObject renkanUser = new BasicDBObject();
- renkanUser.put("project_id", projectId);
- renkanUser.put("user_id", user.get("_id"));
- if(renkanUserColl.findOne(renkanUser) == null) {
- System.out.println(String.format("%s : %s : %s", user.get("_id"),user.get("title"),user.get("project_id")));
- renkanUser = new BasicDBObject();
- renkanUser.put("project_id", user.get("project_id"));
- renkanUser.put("user_id", user.get("_id"));
- renkanUser.put("color", user.get("color"));
- renkanUserColl.insert(renkanUser);
- }
- user.removeField("project_id");
- userColl.save(user);
- }
- else {
- userColl.remove(user, WriteConcern.ACKNOWLEDGED);
- }
- }
-
- }
+
+ public static void main(String[] args) {
+
+ @SuppressWarnings("resource")
+ ApplicationContext context = new ClassPathXmlApplicationContext(
+ "classpath:WEB-INF/applicationContext.xml");
+
+ MigrateRenkanUser p = context.getBean(MigrateRenkanUser.class);
+ p.start(args);
+
+ }
+
+ @Autowired
+ private MongoTemplate template;
+
+ private void start(String[] args) {
+
+ DBCollection userColl = template.getCollection(template
+ .getCollectionName(User.class));
+ DBCollection renkanUserColl = template.getCollection(template
+ .getCollectionName(RenkanUser.class));
+ DBCollection projectColl = template.getCollection(template
+ .getCollectionName(Project.class));
+
+ for (DBObject user : userColl.find()) {
+ if (!user.containsField("project_id")) {
+ continue;
+ }
+ String projectId = (String) user.get("project_id");
+ if (projectId == null || projectId.isEmpty()) {
+ user.removeField("project_id");
+ userColl.save(user);
+ continue;
+ }
+ DBObject proj = new BasicDBObject();
+ proj.put("_id", projectId);
+ if (projectColl.findOne(proj) != null) {
+ DBObject renkanUser = new BasicDBObject();
+ renkanUser.put("project_id", projectId);
+ renkanUser.put("user_id", user.get("_id"));
+ if (renkanUserColl.findOne(renkanUser) == null) {
+ System.out.println(String.format("%s : %s : %s",
+ user.get("_id"), user.get("title"),
+ user.get("project_id")));
+ renkanUser = new BasicDBObject();
+ renkanUser.put("project_id", user.get("project_id"));
+ renkanUser.put("user_id", user.get("_id"));
+ renkanUser.put("color", user.get("color"));
+ renkanUserColl.insert(renkanUser);
+ }
+ user.removeField("project_id");
+ userColl.save(user);
+ } else {
+ userColl.remove(user, WriteConcern.ACKNOWLEDGED);
+ }
+ }
+
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/models/AbstractRenkanModel.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/models/AbstractRenkanModel.java Mon Oct 21 15:00:17 2013 +0200
@@ -87,8 +87,8 @@
public void setColor(String color) {
this.color = color;
}
-
- abstract protected String getRawKeyPart();
+
+ abstract protected String getRawKeyPart();
private String getRawKey(String salt) {
StringBuffer key = new StringBuffer(salt != null ? salt + "|" : "");
--- a/server/src/main/java/org/iri_research/renkan/models/IRenkanModel.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/models/IRenkanModel.java Mon Oct 21 15:00:17 2013 +0200
@@ -5,28 +5,38 @@
import org.iri_research.renkan.RenkanException;
import org.iri_research.renkan.RenkanRuntimeException;
+public interface IRenkanModel<ID extends Serializable> {
-public interface IRenkanModel<ID extends Serializable> {
-
- public ID getId();
- /**
- * Set the object id.
- * This method must throw a RenkanException if the current object id is not null
- * @param id
- * @throws RenkanRuntimeException if the current id is not null
- */
- public void setId(ID id) throws RenkanRuntimeException;
- public String getTitle();
- public String getDescription();
- public String getUri();
- public String getColor();
+ public ID getId();
+
+ /**
+ * Set the object id. This method must throw a RenkanException if the
+ * current object id is not null
+ *
+ * @param id
+ * @throws RenkanRuntimeException
+ * if the current id is not null
+ */
+ public void setId(ID id) throws RenkanRuntimeException;
+
+ public String getTitle();
+
+ public String getDescription();
- public void setTitle(String title);
- public void setDescription(String description);
- public void setUri(String uri);
- public void setColor(String color);
- public String getKey(String salt) throws RenkanException;
- public boolean checkKey(String key, String salt) throws RenkanException;
+ public String getUri();
+
+ public String getColor();
+
+ public void setTitle(String title);
+
+ public void setDescription(String description);
-
+ public void setUri(String uri);
+
+ public void setColor(String color);
+
+ public String getKey(String salt) throws RenkanException;
+
+ public boolean checkKey(String key, String salt) throws RenkanException;
+
}
--- a/server/src/main/java/org/iri_research/renkan/models/ProjectSync.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/models/ProjectSync.java Mon Oct 21 15:00:17 2013 +0200
@@ -8,56 +8,54 @@
import com.fasterxml.jackson.annotation.JsonFormat;
-
-@Document(collection="projectSyncs")
+@Document(collection = "projectSyncs")
public class ProjectSync {
- private ObjectId id;
-
- private String data;
-
- @DBRef
- private Project project;
-
- private int revision;
-
- @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ", timezone="GMT")
- private Date created;
-
- private String user;
+ private ObjectId id;
+
+ private String data;
+
+ @DBRef
+ private Project project;
+
+ private int revision;
+
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ", timezone = "GMT")
+ private Date created;
+
+ private String user;
- public ProjectSync(ObjectId id, String data, Project project, int revision,
- Date created, String user) {
- this.id = id;
- this.data = data;
- this.project = project;
- this.revision = revision;
- this.created = created;
- this.user = user;
- if(this.created == null) {
- this.created = new Date(System.currentTimeMillis());
- }
- }
+ public ProjectSync(ObjectId id, String data, Project project, int revision,
+ Date created, String user) {
+ this.id = id;
+ this.data = data;
+ this.project = project;
+ this.revision = revision;
+ this.created = created;
+ this.user = user;
+ if (this.created == null) {
+ this.created = new Date(System.currentTimeMillis());
+ }
+ }
- public ObjectId getId() {
- return id;
- }
+ public ObjectId getId() {
+ return id;
+ }
- public String getData() {
- return data;
- }
+ public String getData() {
+ return data;
+ }
- public Project getProject() {
- return project;
- }
+ public Project getProject() {
+ return project;
+ }
- public int getRevision() {
- return revision;
- }
+ public int getRevision() {
+ return revision;
+ }
- public String getUser() {
- return user;
- }
-
-
+ public String getUser() {
+ return user;
+ }
+
}
--- a/server/src/main/java/org/iri_research/renkan/models/RenkanSessionModeratorState.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/models/RenkanSessionModeratorState.java Mon Oct 21 15:00:17 2013 +0200
@@ -5,23 +5,22 @@
import java.util.Map;
public enum RenkanSessionModeratorState {
- INSTANCE;
-
- private Map<String, String> usersActivationMap = new HashMap<String, String>();
- private Map<String, List<String>> projectsActivationMap = new HashMap<String, List<String>>();
- private Map<String, List<RosterUser>> projectsUsersList = new HashMap<String, List<RosterUser>>();
-
- public Map<String, String> getUsersActivationMap() {
- return usersActivationMap;
- }
+ INSTANCE;
+
+ private Map<String, String> usersActivationMap = new HashMap<String, String>();
+ private Map<String, List<String>> projectsActivationMap = new HashMap<String, List<String>>();
+ private Map<String, List<RosterUser>> projectsUsersList = new HashMap<String, List<RosterUser>>();
+
+ public Map<String, String> getUsersActivationMap() {
+ return usersActivationMap;
+ }
- public Map<String, List<String>> getProjectsActivationMap() {
- return projectsActivationMap;
- }
+ public Map<String, List<String>> getProjectsActivationMap() {
+ return projectsActivationMap;
+ }
- public Map<String, List<RosterUser>> getProjectsUsersList() {
- return projectsUsersList;
- }
-
-
+ public Map<String, List<RosterUser>> getProjectsUsersList() {
+ return projectsUsersList;
+ }
+
}
--- a/server/src/main/java/org/iri_research/renkan/models/RenkanUser.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/models/RenkanUser.java Mon Oct 21 15:00:17 2013 +0200
@@ -2,62 +2,60 @@
import org.springframework.data.mongodb.core.mapping.Field;
+public class RenkanUser {
-public class RenkanUser {
-
- @Field(value="user_id")
- private String userId;
- private String color;
- private String username;
-
-
- @SuppressWarnings("unused")
- private RenkanUser() {
- }
-
- public RenkanUser(String projectId, String userId, String color,
- String username) {
- this.userId = userId;
- this.color = color;
- this.username = username;
- }
+ @Field(value = "user_id")
+ private String userId;
+ private String color;
+ private String username;
+
+ @SuppressWarnings("unused")
+ private RenkanUser() {
+ }
+
+ public RenkanUser(String projectId, String userId, String color,
+ String username) {
+ this.userId = userId;
+ this.color = color;
+ this.username = username;
+ }
+
+ public RenkanUser(RenkanUser user) {
+ if (user != null) {
+ this.setUserId(user.getUserId());
+ this.setColor(user.getColor());
+ this.setUsername(user.getUsername());
+ }
+ }
- public RenkanUser(RenkanUser user) {
- if(user != null) {
- this.setUserId(user.getUserId());
- this.setColor(user.getColor());
- this.setUsername(user.getUsername());
- }
- }
-
- @Field(value="user_id")
- public String getUserId() {
- return userId;
- }
-
- @Field(value="user_id")
- public void setUserId(String userId) {
- this.userId = userId;
- }
-
- public String getColor() {
- return color;
- }
-
- public void setColor(String color) {
- this.color = color;
- }
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public boolean isAnonymous() {
- return this.getUserId() == null;
- }
+ @Field(value = "user_id")
+ public String getUserId() {
+ return userId;
+ }
+
+ @Field(value = "user_id")
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getColor() {
+ return color;
+ }
+
+ public void setColor(String color) {
+ this.color = color;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public boolean isAnonymous() {
+ return this.getUserId() == null;
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/models/User.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/models/User.java Mon Oct 21 15:00:17 2013 +0200
@@ -34,10 +34,12 @@
public User() {
}
+
public User(String id, String title, String description, String uri,
String color) {
super(id, title, description, uri, color);
}
+
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
// TODO Auto-generated method stub
@@ -47,6 +49,7 @@
public String getAvatar() {
return avatar;
}
+
public String getColor() {
return this.color;
}
@@ -68,7 +71,7 @@
public String getPassword() {
return this.password;
}
-
+
@Override
@JsonIgnore
public String getUsername() {
@@ -124,6 +127,7 @@
public void setLocked(boolean locked) {
this.locked = locked;
}
+
@Override
protected String getRawKeyPart() {
return "";
--- a/server/src/main/java/org/iri_research/renkan/repositories/IRenkanRepository.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/IRenkanRepository.java Mon Oct 21 15:00:17 2013 +0200
@@ -7,7 +7,7 @@
import com.mongodb.DBCollection;
public interface IRenkanRepository<T, ID extends Serializable> extends
- PagingAndSortingRepository<T, ID> {
+ PagingAndSortingRepository<T, ID> {
- public DBCollection getCollection();
+ public DBCollection getCollection();
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectRevisionsRepository.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectRevisionsRepository.java Mon Oct 21 15:00:17 2013 +0200
@@ -3,8 +3,8 @@
import org.bson.types.ObjectId;
import org.iri_research.renkan.models.ProjectRevision;
-public interface ProjectRevisionsRepository extends
- IRenkanRepository<ProjectRevision, ObjectId>,
- ProjectRevisionsRepositoryCustom {
+public interface ProjectRevisionsRepository extends
+ IRenkanRepository<ProjectRevision, ObjectId>,
+ ProjectRevisionsRepositoryCustom {
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectRevisionsRepositoryCustom.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectRevisionsRepositoryCustom.java Mon Oct 21 15:00:17 2013 +0200
@@ -4,7 +4,7 @@
import org.iri_research.renkan.models.ProjectRevision;
public interface ProjectRevisionsRepositoryCustom {
-
- public ProjectRevision getProjectRevision(Project project, int revision);
-
+
+ public ProjectRevision getProjectRevision(Project project, int revision);
+
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectRevisionsRepositoryImpl.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectRevisionsRepositoryImpl.java Mon Oct 21 15:00:17 2013 +0200
@@ -8,20 +8,15 @@
@Component
public class ProjectRevisionsRepositoryImpl implements
- ProjectRevisionsRepositoryCustom {
-
- @Override
- public ProjectRevision getProjectRevision(Project project, int revision) {
- ProjectRevision pr = new ProjectRevision(
- project.getTitle(),
- project.getDescription(),
- project.getUri(),
- project,
- revision,
- new Date(System.currentTimeMillis())
- );
-
- return pr;
- }
+ ProjectRevisionsRepositoryCustom {
+
+ @Override
+ public ProjectRevision getProjectRevision(Project project, int revision) {
+ ProjectRevision pr = new ProjectRevision(project.getTitle(),
+ project.getDescription(), project.getUri(), project, revision,
+ new Date(System.currentTimeMillis()));
+
+ return pr;
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectSyncsRepository.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectSyncsRepository.java Mon Oct 21 15:00:17 2013 +0200
@@ -3,8 +3,7 @@
import org.bson.types.ObjectId;
import org.iri_research.renkan.models.ProjectSync;
-public interface ProjectSyncsRepository extends
- IRenkanRepository<ProjectSync, ObjectId>,
- ProjectSyncsRepositoryCustom {
+public interface ProjectSyncsRepository extends
+ IRenkanRepository<ProjectSync, ObjectId>, ProjectSyncsRepositoryCustom {
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectSyncsRepositoryCustom.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectSyncsRepositoryCustom.java Mon Oct 21 15:00:17 2013 +0200
@@ -5,9 +5,11 @@
import org.iri_research.renkan.models.ProjectSync;
public interface ProjectSyncsRepositoryCustom {
-
- public ProjectSync getProjectSync(String data, Project project, String user) throws RenkanException;
-
- public ProjectSync getProjectSync(String data, String project_id, String user) throws RenkanException;
-
+
+ public ProjectSync getProjectSync(String data, Project project, String user)
+ throws RenkanException;
+
+ public ProjectSync getProjectSync(String data, String project_id,
+ String user) throws RenkanException;
+
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectSyncsRepositoryImpl.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectSyncsRepositoryImpl.java Mon Oct 21 15:00:17 2013 +0200
@@ -9,47 +9,45 @@
import org.springframework.stereotype.Component;
@Component
-public class ProjectSyncsRepositoryImpl implements
- ProjectSyncsRepositoryCustom {
+public class ProjectSyncsRepositoryImpl implements ProjectSyncsRepositoryCustom {
+
+ @Autowired
+ private ProjectsRepository projectRepository;
+
+ @Override
+ public ProjectSync getProjectSync(String data, Project project, String user)
+ throws RenkanException {
+
+ if (project == null) {
+ throw new RenkanException("ProjectSyncsRepository : Null Project.");
+ }
+
+ ProjectSync ps = new ProjectSync(null, data, project,
+ this.projectRepository.getRevCounter(project.getId()),
+ new Date(System.currentTimeMillis()), user);
+
+ return ps;
+ }
- @Autowired
- private ProjectsRepository projectRepository;
-
- @Override
- public ProjectSync getProjectSync(String data, Project project, String user) throws RenkanException {
-
- if(project == null) {
- throw new RenkanException("ProjectSyncsRepository : Null Project.");
- }
-
- ProjectSync ps = new ProjectSync(
- null,
- data,
- project,
- this.projectRepository.getRevCounter(project.getId()),
- new Date(System.currentTimeMillis()),
- user
- );
-
- return ps;
- }
+ @Override
+ public ProjectSync getProjectSync(String data, String project_id,
+ String user) throws RenkanException {
+
+ if (project_id == null || "".equals(project_id)) {
+ throw new RenkanException(
+ "ProjectSyncsRepository : Null or empty project id.");
+ }
- @Override
- public ProjectSync getProjectSync(String data, String project_id, String user)
- throws RenkanException {
-
- if(project_id == null || "".equals(project_id) ) {
- throw new RenkanException("ProjectSyncsRepository : Null or empty project id.");
- }
-
- Project p = this.projectRepository.findOne(project_id);
-
- if(p == null) {
- throw new RenkanException("ProjectSyncsRepository : project not found for id " + project_id);
- }
-
- return this.getProjectSync(data, p, user);
-
- }
+ Project p = this.projectRepository.findOne(project_id);
+
+ if (p == null) {
+ throw new RenkanException(
+ "ProjectSyncsRepository : project not found for id "
+ + project_id);
+ }
+
+ return this.getProjectSync(data, p, user);
+
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepository.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepository.java Mon Oct 21 15:00:17 2013 +0200
@@ -7,13 +7,17 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.Query;
-public interface ProjectsRepository extends IRenkanRepository<Project, String>, ProjectsRepositoryCustom {
-
- List<Project> findBySpaceId(String spaceId);
- Page<Project> findBySpaceId(String spaceId, Pageable p);
+public interface ProjectsRepository extends IRenkanRepository<Project, String>,
+ ProjectsRepositoryCustom {
+
+ List<Project> findBySpaceId(String spaceId);
+
+ Page<Project> findBySpaceId(String spaceId, Pageable p);
- @Query("{ 'space_id' : ?0, 'title' : { '$regex':?1, '$options': 'i'} }")
- List<Project> findBySpaceIdAndTitleRegex(String spaceId, String title);
- @Query("{ 'space_id' : ?0, 'title' : { '$regex':?1, '$options': 'i'} }")
- Page<Project> findBySpaceIdAndTitleRegex(String spaceId, String title, Pageable p);
+ @Query("{ 'space_id' : ?0, 'title' : { '$regex':?1, '$options': 'i'} }")
+ List<Project> findBySpaceIdAndTitleRegex(String spaceId, String title);
+
+ @Query("{ 'space_id' : ?0, 'title' : { '$regex':?1, '$options': 'i'} }")
+ Page<Project> findBySpaceIdAndTitleRegex(String spaceId, String title,
+ Pageable p);
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryCustom.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryCustom.java Mon Oct 21 15:00:17 2013 +0200
@@ -6,20 +6,27 @@
import org.iri_research.renkan.models.Project;
public interface ProjectsRepositoryCustom {
-
- public int getRevCounter(String projectId);
- public Map<String, Integer> getCountBySpace();
- public Map<String, Integer> getCountBySpace(Collection<String> spaceIds);
+
+ public int getRevCounter(String projectId);
+
+ public Map<String, Integer> getCountBySpace();
+
+ public Map<String, Integer> getCountBySpace(Collection<String> spaceIds);
+
+ public Map<String, Integer> getCountByUser();
+
+ public Map<String, Integer> getCountByUser(Collection<String> userIds);
- public Map<String, Integer> getCountByUser();
- public Map<String, Integer> getCountByUser(Collection<String> userIds);
- public Map<String, Integer> getCountByUsername();
- public Map<String, Integer> getCountByUsername(Collection<String> usernames);
-
- public void deleteRecursive(String projectId);
- public void deleteRecursive(Project project);
- public void deleteRecursive(Iterable<? extends Project> projects);
-
- public Project copy(Project p, String newTitle);
-
+ public Map<String, Integer> getCountByUsername();
+
+ public Map<String, Integer> getCountByUsername(Collection<String> usernames);
+
+ public void deleteRecursive(String projectId);
+
+ public void deleteRecursive(Project project);
+
+ public void deleteRecursive(Iterable<? extends Project> projects);
+
+ public Project copy(Project p, String newTitle);
+
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryImpl.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryImpl.java Mon Oct 21 15:00:17 2013 +0200
@@ -26,197 +26,204 @@
@Component
public class ProjectsRepositoryImpl implements ProjectsRepositoryCustom {
-
- @SuppressWarnings("unused")
- private final Logger logger = LoggerFactory.getLogger(ProjectsRepositoryImpl.class);
-
- @Autowired
- private ProjectsRepository projectsRepository;
+
+ @SuppressWarnings("unused")
+ private final Logger logger = LoggerFactory
+ .getLogger(ProjectsRepositoryImpl.class);
+
+ @Autowired
+ private ProjectsRepository projectsRepository;
+
+ @Autowired
+ private NodesRepository nodesRepository;
- @Autowired
- private NodesRepository nodesRepository;
+ @Autowired
+ private EdgesRepository edgesRepository;
- @Autowired
- private EdgesRepository edgesRepository;
-
- @Autowired
- private ProjectRevisionsRepository projectRevisionsRepository;
+ @Autowired
+ private ProjectRevisionsRepository projectRevisionsRepository;
+
+ private class GroupSpaceResult {
+ public String space_id;
+ public int count;
+ }
-
- private class GroupSpaceResult {
- public String space_id;
- public int count;
- }
-
- @Autowired
- private MongoTemplate mongoTemplate;
-
- @Override
- public int getRevCounter(String projectId) {
- Project p = this.mongoTemplate.findAndModify(query(where("id").is(projectId)), new Update().inc("rev_counter", 1), Project.class);
-
- if(p == null) {
- return -1;
- }
- return p.getRevCounter();
- }
-
+ @Autowired
+ private MongoTemplate mongoTemplate;
+
+ @Override
+ public int getRevCounter(String projectId) {
+ Project p = this.mongoTemplate.findAndModify(
+ query(where("id").is(projectId)),
+ new Update().inc("rev_counter", 1), Project.class);
- @Override
- public Map<String, Integer> getCountBySpace(Collection<String> spaceIds) {
+ if (p == null) {
+ return -1;
+ }
+ return p.getRevCounter();
+ }
+
+ @Override
+ public Map<String, Integer> getCountBySpace(Collection<String> spaceIds) {
+
+ Criteria filter = null;
+
+ if (spaceIds != null) {
+ filter = Criteria.where("space_id").in(spaceIds);
+ }
- Criteria filter = null;
-
- if(spaceIds != null) {
- filter = Criteria.where("space_id").in(spaceIds);
- }
-
- GroupByResults<GroupSpaceResult> groupResult = this.mongoTemplate.group(
- filter,
- this.mongoTemplate.getCollectionName(Project.class),
- GroupBy.key("space_id").initialDocument("{ count: 0 }").reduceFunction("function(doc, prev) { prev.count += 1; }"),
- GroupSpaceResult.class);
-
- HashMap<String, Integer> res = new HashMap<>();
- for (GroupSpaceResult gr : groupResult) {
- res.put(gr.space_id, new Integer(gr.count));
- }
-
- return res;
-
- }
-
- @Override
- public Map<String, Integer> getCountBySpace() {
- return this.getCountBySpace(null);
- }
+ GroupByResults<GroupSpaceResult> groupResult = this.mongoTemplate
+ .group(filter,
+ this.mongoTemplate.getCollectionName(Project.class),
+ GroupBy.key("space_id")
+ .initialDocument("{ count: 0 }")
+ .reduceFunction(
+ "function(doc, prev) { prev.count += 1; }"),
+ GroupSpaceResult.class);
+
+ HashMap<String, Integer> res = new HashMap<>();
+ for (GroupSpaceResult gr : groupResult) {
+ res.put(gr.space_id, new Integer(gr.count));
+ }
+
+ return res;
+
+ }
+
+ @Override
+ public Map<String, Integer> getCountBySpace() {
+ return this.getCountBySpace(null);
+ }
+
+ @Override
+ public Project copy(Project p, String newTitle) {
+ Project res = new Project(p);
+ res.setTitle(newTitle);
+ this.nodesRepository.save(res.getNodes());
+ this.edgesRepository.save(res.getEdges());
- @Override
- public Project copy(Project p, String newTitle) {
-
- Project res = new Project(p);
- res.setTitle(newTitle);
- this.nodesRepository.save(res.getNodes());
- this.edgesRepository.save(res.getEdges());
-
- return this.projectsRepository.save(res);
- }
+ return this.projectsRepository.save(res);
+ }
+
+ @Override
+ public void deleteRecursive(String projectId) {
+ this.deleteRecursive(this.projectsRepository.findOne(projectId));
+ }
- @Override
- public void deleteRecursive(String projectId) {
- this.deleteRecursive(this.projectsRepository.findOne(projectId));
- }
+ @Override
+ public void deleteRecursive(Project project) {
+ this.deleteRecursive(Arrays.asList(new Project[] { project }));
+ }
- @Override
- public void deleteRecursive(Project project) {
- this.deleteRecursive(Arrays.asList(new Project[] {project}));
- }
+ @Override
+ public void deleteRecursive(Iterable<? extends Project> projects) {
+
+ for (Project p : projects) {
+ if (p == null) {
+ continue;
+ }
- @Override
- public void deleteRecursive(Iterable<? extends Project> projects) {
-
- for(Project p: projects) {
- if( p == null) {
- continue;
- }
-
- ProjectRevision pr = this.projectRevisionsRepository.getProjectRevision(p, this.projectsRepository.getRevCounter(p.getId()));
- this.projectRevisionsRepository.save(pr);
-
- //delete edges
- this.edgesRepository.delete(p.getEdges());
- //delete nodes
- this.nodesRepository.delete(p.getNodes());
- //delete project
- this.projectsRepository.delete(p);
- }
- }
+ ProjectRevision pr = this.projectRevisionsRepository
+ .getProjectRevision(p,
+ this.projectsRepository.getRevCounter(p.getId()));
+ this.projectRevisionsRepository.save(pr);
+
+ // delete edges
+ this.edgesRepository.delete(p.getEdges());
+ // delete nodes
+ this.nodesRepository.delete(p.getNodes());
+ // delete project
+ this.projectsRepository.delete(p);
+ }
+ }
+
+ @Override
+ public Map<String, Integer> getCountByUser() {
+ return getCountByUser(null);
+ }
+
+ @Override
+ public Map<String, Integer> getCountByUser(Collection<String> userIds) {
+
+ Criteria filter = null;
+ if (userIds != null) {
+ filter = Criteria.where("users.user_id").in(userIds);
+ }
- @Override
- public Map<String, Integer> getCountByUser() {
- return getCountByUser(null);
- }
+ DBObject projectOp = new BasicDBObject("$project", new BasicDBObject(
+ "users", 1));
+ DBObject unwindOp = new BasicDBObject("$unwind", "$users");
+ DBObject groupOpFields = new BasicDBObject("_id", "$users.user_id");
+ groupOpFields.put("count", new BasicDBObject("$sum", 1));
+ DBObject groupOp = new BasicDBObject("$group", groupOpFields);
+ DBObject matchOp = null;
+ if (filter != null) {
+ matchOp = new BasicDBObject("$match", filter.getCriteriaObject());
+ }
+ AggregationOutput output = null;
+ if (filter != null) {
+ output = this.projectsRepository.getCollection().aggregate(matchOp,
+ projectOp, unwindOp, matchOp, groupOp);
+ } else {
+ output = this.projectsRepository.getCollection().aggregate(
+ projectOp, unwindOp, groupOp);
+ }
+
+ HashMap<String, Integer> res = new HashMap<>();
- @Override
- public Map<String, Integer> getCountByUser(Collection<String> userIds) {
-
- Criteria filter = null;
-
- if(userIds != null) {
- filter = Criteria.where("users.user_id").in(userIds);
- }
-
- DBObject projectOp = new BasicDBObject("$project", new BasicDBObject("users", 1));
- DBObject unwindOp = new BasicDBObject("$unwind","$users");
- DBObject groupOpFields = new BasicDBObject("_id", "$users.user_id");
- groupOpFields.put("count", new BasicDBObject("$sum", 1));
- DBObject groupOp = new BasicDBObject("$group",groupOpFields);
- DBObject matchOp = null;
- if(filter != null) {
- matchOp = new BasicDBObject("$match", filter.getCriteriaObject());
- }
-
- AggregationOutput output = null;
- if(filter!=null) {
- output = this.projectsRepository.getCollection().aggregate(matchOp, projectOp, unwindOp, matchOp, groupOp);
- }
- else {
- output = this.projectsRepository.getCollection().aggregate(projectOp, unwindOp, groupOp);
- }
-
- HashMap<String, Integer> res = new HashMap<>();
-
- for (DBObject groupRes : output.results()) {
- res.put((String)groupRes.get("_id"), (Integer)groupRes.get("count"));
- }
-
- return res;
- }
+ for (DBObject groupRes : output.results()) {
+ res.put((String) groupRes.get("_id"),
+ (Integer) groupRes.get("count"));
+ }
+
+ return res;
+ }
+ @Override
+ public Map<String, Integer> getCountByUsername() {
+ return this.getCountByUsername(null);
+ }
+
+ @Override
+ public Map<String, Integer> getCountByUsername(Collection<String> usernames) {
+
+ Criteria filter = null;
+
+ if (usernames != null) {
+ filter = Criteria.where("users.username").in(usernames);
+ }
- @Override
- public Map<String, Integer> getCountByUsername() {
- return this.getCountByUsername(null);
- }
-
+ DBObject projectOp = new BasicDBObject("$project", new BasicDBObject(
+ "users", 1));
+ DBObject unwindOp = new BasicDBObject("$unwind", "$users");
+ DBObject groupOpFields = new BasicDBObject("_id", "$users.username");
+ groupOpFields.put("count", new BasicDBObject("$sum", 1));
+ DBObject groupOp = new BasicDBObject("$group", groupOpFields);
+ DBObject matchOp = null;
+ if (filter != null) {
+ matchOp = new BasicDBObject("$match", filter.getCriteriaObject());
+ }
- @Override
- public Map<String, Integer> getCountByUsername(Collection<String> usernames) {
-
- Criteria filter = null;
-
- if(usernames != null) {
- filter = Criteria.where("users.username").in(usernames);
- }
-
- DBObject projectOp = new BasicDBObject("$project", new BasicDBObject("users", 1));
- DBObject unwindOp = new BasicDBObject("$unwind","$users");
- DBObject groupOpFields = new BasicDBObject("_id", "$users.username");
- groupOpFields.put("count", new BasicDBObject("$sum", 1));
- DBObject groupOp = new BasicDBObject("$group",groupOpFields);
- DBObject matchOp = null;
- if(filter != null) {
- matchOp = new BasicDBObject("$match", filter.getCriteriaObject());
- }
-
- AggregationOutput output = null;
- if(filter!=null) {
- output = this.projectsRepository.getCollection().aggregate(matchOp, projectOp, unwindOp, matchOp, groupOp);
- }
- else {
- output = this.projectsRepository.getCollection().aggregate(projectOp, unwindOp, groupOp);
- }
-
- HashMap<String, Integer> res = new HashMap<>();
-
- for (DBObject groupRes : output.results()) {
- res.put((String)groupRes.get("_id"), (Integer)groupRes.get("count"));
- }
-
- return res;
+ AggregationOutput output = null;
+ if (filter != null) {
+ output = this.projectsRepository.getCollection().aggregate(matchOp,
+ projectOp, unwindOp, matchOp, groupOp);
+ } else {
+ output = this.projectsRepository.getCollection().aggregate(
+ projectOp, unwindOp, groupOp);
+ }
- }
+ HashMap<String, Integer> res = new HashMap<>();
+
+ for (DBObject groupRes : output.results()) {
+ res.put((String) groupRes.get("_id"),
+ (Integer) groupRes.get("count"));
+ }
+
+ return res;
+
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/RenkanRepository.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/RenkanRepository.java Mon Oct 21 15:00:17 2013 +0200
@@ -8,16 +8,17 @@
import com.mongodb.DBCollection;
-public class RenkanRepository<T, ID extends Serializable> extends SimpleMongoRepository<T, ID> implements
- IRenkanRepository<T, ID> {
+public class RenkanRepository<T, ID extends Serializable> extends
+ SimpleMongoRepository<T, ID> implements IRenkanRepository<T, ID> {
- public RenkanRepository(MongoEntityInformation<T,ID> metadata,
- MongoOperations mongoOperations) {
- super(metadata, mongoOperations);
- }
+ public RenkanRepository(MongoEntityInformation<T, ID> metadata,
+ MongoOperations mongoOperations) {
+ super(metadata, mongoOperations);
+ }
- @Override
- public DBCollection getCollection() {
- return this.getMongoOperations().getCollection(this.getEntityInformation().getCollectionName());
- }
+ @Override
+ public DBCollection getCollection() {
+ return this.getMongoOperations().getCollection(
+ this.getEntityInformation().getCollectionName());
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/RenkanRepositoryException.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/RenkanRepositoryException.java Mon Oct 21 15:00:17 2013 +0200
@@ -2,10 +2,10 @@
public class RenkanRepositoryException extends Exception {
- private static final long serialVersionUID = -7433823426870169568L;
-
- public RenkanRepositoryException(String message) {
- super(message);
- }
+ private static final long serialVersionUID = -7433823426870169568L;
+
+ public RenkanRepositoryException(String message) {
+ super(message);
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/RenkanRepositoryFactory.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/RenkanRepositoryFactory.java Mon Oct 21 15:00:17 2013 +0200
@@ -10,41 +10,45 @@
public class RenkanRepositoryFactory extends MongoRepositoryFactory {
- private MongoOperations mongoOperations;
- public RenkanRepositoryFactory(MongoOperations mongoOperations) {
- super(mongoOperations);
- this.mongoOperations = mongoOperations;
- }
+ private MongoOperations mongoOperations;
+
+ public RenkanRepositoryFactory(MongoOperations mongoOperations) {
+ super(mongoOperations);
+ this.mongoOperations = mongoOperations;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.repository.core.support.RepositoryFactorySupport
+ * #getTargetRepository(org.springframework.data.repository.core.
+ * RepositoryMetadata)
+ */
+ @Override
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected Object getTargetRepository(RepositoryMetadata metadata) {
+
+ Object res = super.getTargetRepository(metadata);
- /*
- * (non-Javadoc)
- * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getTargetRepository(org.springframework.data.repository.core.RepositoryMetadata)
- */
- @Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected Object getTargetRepository(RepositoryMetadata metadata) {
-
- Object res = super.getTargetRepository(metadata);
-
- if(SimpleMongoRepository.class.equals(res.getClass())) {
- MongoEntityInformation<?, Serializable> entityInformation = this.getEntityInformation(metadata.getDomainType());
- return new RenkanRepository(entityInformation, this.mongoOperations);
- }
- else {
- return res;
- }
+ if (SimpleMongoRepository.class.equals(res.getClass())) {
+ MongoEntityInformation<?, Serializable> entityInformation = this
+ .getEntityInformation(metadata.getDomainType());
+ return new RenkanRepository(entityInformation, this.mongoOperations);
+ } else {
+ return res;
+ }
+
+ }
- }
-
- @Override
- protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
- Class<?> res = super.getRepositoryBaseClass(metadata);
- if(SimpleMongoRepository.class.equals(res)) {
- return RenkanRepository.class;
- }
- else {
- return res;
- }
- }
-
+ @Override
+ protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
+ Class<?> res = super.getRepositoryBaseClass(metadata);
+ if (SimpleMongoRepository.class.equals(res)) {
+ return RenkanRepository.class;
+ } else {
+ return res;
+ }
+ }
+
}
--- a/server/src/main/java/org/iri_research/renkan/repositories/RenkanRepositoryFactoryBean.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/RenkanRepositoryFactoryBean.java Mon Oct 21 15:00:17 2013 +0200
@@ -7,11 +7,13 @@
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
-public class RenkanRepositoryFactoryBean<T extends Repository<S,ID>,S,ID extends Serializable> extends MongoRepositoryFactoryBean<T,S,ID> {
-
- @Override
- protected RepositoryFactorySupport getFactoryInstance(MongoOperations operations) {
- return new RenkanRepositoryFactory(operations);
- }
-
+public class RenkanRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
+ extends MongoRepositoryFactoryBean<T, S, ID> {
+
+ @Override
+ protected RepositoryFactorySupport getFactoryInstance(
+ MongoOperations operations) {
+ return new RenkanRepositoryFactory(operations);
+ }
+
}
\ No newline at end of file
--- a/server/src/main/java/org/iri_research/renkan/repositories/UsersRepository.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/repositories/UsersRepository.java Mon Oct 21 15:00:17 2013 +0200
@@ -7,8 +7,9 @@
import org.springframework.data.domain.Pageable;
public interface UsersRepository extends IRenkanRepository<User, String> {
-
- public List<User> findByTitle(String title);
- public Page<User> findByTitle(String title, Pageable p);
+
+ public List<User> findByTitle(String title);
+
+ public Page<User> findByTitle(String title, Pageable p);
}
--- a/server/src/main/java/org/iri_research/renkan/rest/ObjectMapperProvider.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/rest/ObjectMapperProvider.java Mon Oct 21 15:00:17 2013 +0200
@@ -15,7 +15,8 @@
@Override
public ObjectMapper getContext(Class<?> type) {
ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS , false);
+ objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
+ false);
return objectMapper;
}
--- a/server/src/main/java/org/iri_research/renkan/rest/ProjectsResource.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/rest/ProjectsResource.java Mon Oct 21 15:00:17 2013 +0200
@@ -16,44 +16,43 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-
@Singleton
@Path("projects")
@Component
public class ProjectsResource extends RenkanResource<Project, String> {
-
- @SuppressWarnings("unused")
- private Logger logger = LoggerFactory.getLogger(ProjectsResource.class);
-
- @Autowired
- private ProjectsRepository projectsRepository;
+
+ @SuppressWarnings("unused")
+ private Logger logger = LoggerFactory.getLogger(ProjectsResource.class);
+
+ @Autowired
+ private ProjectsRepository projectsRepository;
- @Override
- protected IRenkanRepository<Project, String> getRepository() {
- return this.projectsRepository;
- }
+ @Override
+ protected IRenkanRepository<Project, String> getRepository() {
+ return this.projectsRepository;
+ }
- @Override
- protected String getNewId() {
- return Constants.UUID_GENERATOR.generate().toString();
- }
+ @Override
+ protected String getNewId() {
+ return Constants.UUID_GENERATOR.generate().toString();
+ }
- @Override
- protected void prepareObject(Project obj) {
- if(obj.getCreated() == null) {
- obj.setCreated(new Date());
- }
- obj.setUpdated(new Date());
- }
+ @Override
+ protected void prepareObject(Project obj) {
+ if (obj.getCreated() == null) {
+ obj.setCreated(new Date());
+ }
+ obj.setUpdated(new Date());
+ }
- @Override
- protected List<String> getObjectListFieldList() {
- return Arrays.asList(this.baseObjectListFieldList);
- }
-
- @Override
- protected void doDeleteObject(String objectId) {
- this.projectsRepository.deleteRecursive(objectId);
- }
+ @Override
+ protected List<String> getObjectListFieldList() {
+ return Arrays.asList(this.baseObjectListFieldList);
+ }
+
+ @Override
+ protected void doDeleteObject(String objectId) {
+ this.projectsRepository.deleteRecursive(objectId);
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/rest/RenkanResource.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/rest/RenkanResource.java Mon Oct 21 15:00:17 2013 +0200
@@ -64,9 +64,10 @@
// the callbacl query param is used
@GET
@Path("{id : [a-zA-Z\\-0-9]+}")
- @JSONP(callback="callback", queryParam="callback")
- @Produces({"application/javascript", "application/x-javascript",
- "text/ecmascript", "application/ecmascript", "text/jscript", MediaType.APPLICATION_JSON + ";charset=utf-8"})
+ @JSONP(callback = "callback", queryParam = "callback")
+ @Produces({ "application/javascript", "application/x-javascript",
+ "text/ecmascript", "application/ecmascript", "text/jscript",
+ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public T getObject(@PathParam("id") ID objectId) {
this.logger.debug("GetObject: " + objectId);
@@ -96,8 +97,9 @@
/**
* test: curl -i -X PUT -H 'Content-Type: application/json' -d
+ *
* @test-data.json http://localhost:8080/renkan/rest/spaces/
- * 12eff140-e65c-11e1-aff1-0800200c9a66
+ * 12eff140-e65c-11e1-aff1-0800200c9a66
*
* @param objId
* @param objectContent
--- a/server/src/main/java/org/iri_research/renkan/rest/RestApplication.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/rest/RestApplication.java Mon Oct 21 15:00:17 2013 +0200
@@ -4,7 +4,6 @@
import org.glassfish.jersey.server.spring.SpringLifecycleListener;
import org.glassfish.jersey.server.spring.scope.RequestContextFilter;
-
public class RestApplication extends ResourceConfig {
public RestApplication() {
this.packages("org.iri_research.renkan.rest");
--- a/server/src/main/java/org/iri_research/renkan/services/RenkanUserDetailsService.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/services/RenkanUserDetailsService.java Mon Oct 21 15:00:17 2013 +0200
@@ -13,17 +13,18 @@
@Service
public class RenkanUserDetailsService implements UserDetailsService {
- @Autowired
- private UsersRepository usersRepository;
-
- @Override
- public UserDetails loadUserByUsername(String username)
- throws UsernameNotFoundException {
- List<User> res = this.usersRepository.findByTitle(username);
- if(res == null || res.size() == 0) {
- throw new UsernameNotFoundException(String.format("User {0} not found.", username));
- }
- return res.get(0);
- }
+ @Autowired
+ private UsersRepository usersRepository;
+
+ @Override
+ public UserDetails loadUserByUsername(String username)
+ throws UsernameNotFoundException {
+ List<User> res = this.usersRepository.findByTitle(username);
+ if (res == null || res.size() == 0) {
+ throw new UsernameNotFoundException(String.format(
+ "User {0} not found.", username));
+ }
+ return res.get(0);
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/utils/ColorGenerator.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/utils/ColorGenerator.java Mon Oct 21 15:00:17 2013 +0200
@@ -4,21 +4,21 @@
import java.util.Random;
public class ColorGenerator {
-
- public static Color randomColor() {
-
- Random rand = new Random();
-
- float r = rand.nextFloat()*0.5f + 0.5f;
- float g = rand.nextFloat()*0.5f + 0.5f;
- float b = rand.nextFloat()*0.5f + 0.5f;
-
- return new Color(r, g, b);
- }
-
- public static String randomColorHex() {
- Color resColor = ColorGenerator.randomColor();
- return Integer.toHexString(resColor.getRGB());
- }
+
+ public static Color randomColor() {
+
+ Random rand = new Random();
+
+ float r = rand.nextFloat() * 0.5f + 0.5f;
+ float g = rand.nextFloat() * 0.5f + 0.5f;
+ float b = rand.nextFloat() * 0.5f + 0.5f;
+
+ return new Color(r, g, b);
+ }
+
+ public static String randomColorHex() {
+ Color resColor = ColorGenerator.randomColor();
+ return Integer.toHexString(resColor.getRGB());
+ }
}
--- a/server/src/main/java/org/iri_research/renkan/utils/RenkanLogger.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/utils/RenkanLogger.java Mon Oct 21 15:00:17 2013 +0200
@@ -7,9 +7,9 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
-@Retention(RUNTIME)
-@Target(FIELD)
-@Documented
+@Retention(RUNTIME)
+@Target(FIELD)
+@Documented
public @interface RenkanLogger {
}
--- a/server/src/main/java/org/iri_research/renkan/utils/RenkanLoggerInjector.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/main/java/org/iri_research/renkan/utils/RenkanLoggerInjector.java Mon Oct 21 15:00:17 2013 +0200
@@ -13,27 +13,27 @@
@Component
public class RenkanLoggerInjector implements BeanPostProcessor {
- @Override
- public Object postProcessBeforeInitialization(final Object bean,
- String beanName) throws BeansException {
- ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
- public void doWith(Field field) throws IllegalArgumentException,
- IllegalAccessException {
- // make the field accessible if defined private
- ReflectionUtils.makeAccessible(field);
- if (field.getAnnotation(RenkanLogger.class) != null) {
- org.slf4j.Logger logger = LoggerFactory.getLogger(bean
- .getClass());
- field.set(bean, logger);
- }
- }
- });
- return bean;
- }
+ @Override
+ public Object postProcessBeforeInitialization(final Object bean,
+ String beanName) throws BeansException {
+ ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
+ public void doWith(Field field) throws IllegalArgumentException,
+ IllegalAccessException {
+ // make the field accessible if defined private
+ ReflectionUtils.makeAccessible(field);
+ if (field.getAnnotation(RenkanLogger.class) != null) {
+ org.slf4j.Logger logger = LoggerFactory.getLogger(bean
+ .getClass());
+ field.set(bean, logger);
+ }
+ }
+ });
+ return bean;
+ }
- @Override
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
- return bean;
- }
+ @Override
+ public Object postProcessAfterInitialization(Object bean, String beanName)
+ throws BeansException {
+ return bean;
+ }
}
\ No newline at end of file
--- a/server/src/test/java/org/iri_research/renkan/test/controller/AdminControllerTest.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/test/java/org/iri_research/renkan/test/controller/AdminControllerTest.java Mon Oct 21 15:00:17 2013 +0200
@@ -37,443 +37,530 @@
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@ContextConfiguration(locations={"controller-context.xml", "file:src/main/webapp/WEB-INF/spring-servlet.xml"})
+@ContextConfiguration(locations = { "controller-context.xml",
+ "file:src/main/webapp/WEB-INF/spring-servlet.xml" })
public class AdminControllerTest {
-
- private final static int SPACE_NB = 3;
-
- private Logger logger = LoggerFactory.getLogger(AdminControllerTest.class);
-
- @Autowired
- private SpacesRepository spacesRepository;
- @Autowired
- private ProjectsRepository projectsRepository;
-
- private Map<String, Space> spacesList = new HashMap<String, Space>(SPACE_NB);
- private List<String> spacesUuids = new ArrayList<>(SPACE_NB);
-
- private ArrayList<Project> testProjects = new ArrayList<Project>();
-
- @Autowired
- private WebApplicationContext context;
- private MockMvc mvc;
-
-
- @Before
- public void setup() {
-
- logger.debug("Setup");
- spacesRepository.deleteAll();
- projectsRepository.deleteAll();
-
- ArrayList<Project> pl = new ArrayList<Project>();
- for(int i=0;i<SPACE_NB;i++) {
- Date creationDate = new Date();
- String uuid = UUID.randomUUID().toString();
- spacesUuids.add(uuid);
- Space testSpace = new Space(uuid, "test " + i, "Test space " + 1, "{}", "http://ldt.iri.centrepompidou.fr", "#ababab", "test_user", "http://ldt.iri.centrepompidou.fr", creationDate);
- testSpace = spacesRepository.save(testSpace);
- this.spacesList.put(uuid, testSpace);
- for(int j=0; j<SPACE_NB-1-i; j++) {
- pl.add(new Project(testSpace.getId(), UUID.randomUUID().toString(), "test"+((SPACE_NB-1)*i+j+1), "desc"+((SPACE_NB-1)*i+j+1), "http://localhost:8080/rest/projects/id"+((SPACE_NB-1)*i+j+1), creationDate));
- }
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- for(Project p: projectsRepository.save(pl)) {
- this.testProjects.add(p);
- }
-
- this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
- }
-
- @After
- public void teardown() {
- spacesRepository.deleteAll();
- projectsRepository.deleteAll();
- }
+
+ private final static int SPACE_NB = 3;
+
+ private Logger logger = LoggerFactory.getLogger(AdminControllerTest.class);
+
+ @Autowired
+ private SpacesRepository spacesRepository;
+ @Autowired
+ private ProjectsRepository projectsRepository;
+
+ private Map<String, Space> spacesList = new HashMap<String, Space>(SPACE_NB);
+ private List<String> spacesUuids = new ArrayList<>(SPACE_NB);
+
+ private ArrayList<Project> testProjects = new ArrayList<Project>();
+
+ @Autowired
+ private WebApplicationContext context;
+ private MockMvc mvc;
+
+ @Before
+ public void setup() {
+
+ logger.debug("Setup");
+ spacesRepository.deleteAll();
+ projectsRepository.deleteAll();
+
+ ArrayList<Project> pl = new ArrayList<Project>();
+ for (int i = 0; i < SPACE_NB; i++) {
+ Date creationDate = new Date();
+ String uuid = UUID.randomUUID().toString();
+ spacesUuids.add(uuid);
+ Space testSpace = new Space(uuid, "test " + i, "Test space " + 1,
+ "{}", "http://ldt.iri.centrepompidou.fr", "#ababab",
+ "test_user", "http://ldt.iri.centrepompidou.fr",
+ creationDate);
+ testSpace = spacesRepository.save(testSpace);
+ this.spacesList.put(uuid, testSpace);
+ for (int j = 0; j < SPACE_NB - 1 - i; j++) {
+ pl.add(new Project(testSpace.getId(), UUID.randomUUID()
+ .toString(), "test" + ((SPACE_NB - 1) * i + j + 1),
+ "desc" + ((SPACE_NB - 1) * i + j + 1),
+ "http://localhost:8080/rest/projects/id"
+ + ((SPACE_NB - 1) * i + j + 1), creationDate));
+ }
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ for (Project p : projectsRepository.save(pl)) {
+ this.testProjects.add(p);
+ }
+
+ this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
+ }
+
+ @After
+ public void teardown() {
+ spacesRepository.deleteAll();
+ projectsRepository.deleteAll();
+ }
+
+ @Test
+ public void testContext() throws Exception {
+ MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/");
+ MvcResult res = this.mvc.perform(get)
+ .andExpect(MockMvcResultMatchers.status().isOk()).andReturn();
+
+ logger.debug("testContext resp : "
+ + res.getResponse().getContentAsString());
+
+ }
+
+ @Test
+ public void testSpacePostUpdate() throws Exception {
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/save");
+ post = post.param("id", this.spacesUuids.get(0));
+ post = post.param("title", "New title");
+ post = post.param("description", "New description");
+ post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
+ post = post.param("color", "#ffffff");
+ post = post.param("binConfig", "{}");
+
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isSeeOther())
+ .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
+
+ Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
+
+ Assert.assertNotNull("Should find space", sp);
+ Assert.assertEquals("Title equals", "New title", sp.getTitle());
+ Assert.assertEquals("Description equals", "New description",
+ sp.getDescription());
+ Assert.assertEquals("Uri equals",
+ "http://ldt.iri.centrepompidou.fr/new/uri", sp.getUri());
+ Assert.assertEquals("Color equals", "#ffffff", sp.getColor());
+ Assert.assertEquals("BinConfig equals", "{}", sp.getBinConfig());
+
+ }
+
+ @Test
+ public void testSpacePostCreate() throws Exception {
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/save");
+ post = post.param("title", "New title");
+ post = post.param("description", "New description");
+ post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
+ post = post.param("color", "#ffffff");
+ post = post.param("binConfig", "{}");
+
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isSeeOther())
+ .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
+
+ Assert.assertEquals("Must have one more space", SPACE_NB + 1,
+ this.spacesRepository.count());
-
- @Test
- public void testContext() throws Exception {
- MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/");
- MvcResult res = this.mvc.perform(get)
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andReturn();
-
- logger.debug("testContext resp : " + res.getResponse().getContentAsString());
-
- }
-
- @Test
- public void testSpacePostUpdate() throws Exception {
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/save");
- post = post.param("id", this.spacesUuids.get(0));
- post = post.param("title", "New title");
- post = post.param("description", "New description");
- post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
- post = post.param("color", "#ffffff");
- post = post.param("binConfig", "{}");
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isSeeOther())
- .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
-
- Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
-
- Assert.assertNotNull("Should find space", sp);
- Assert.assertEquals("Title equals", "New title", sp.getTitle());
- Assert.assertEquals("Description equals", "New description", sp.getDescription());
- Assert.assertEquals("Uri equals", "http://ldt.iri.centrepompidou.fr/new/uri", sp.getUri());
- Assert.assertEquals("Color equals", "#ffffff", sp.getColor());
- Assert.assertEquals("BinConfig equals", "{}", sp.getBinConfig());
-
- }
+ for (Space sp : this.spacesRepository.findAll()) {
+ if (this.spacesList.containsKey(sp.getId())) {
+ continue;
+ } else {
+ Assert.assertNotNull("Should find space", sp);
+ Assert.assertEquals("Title equals", "New title", sp.getTitle());
+ Assert.assertEquals("Description equals", "New description",
+ sp.getDescription());
+ Assert.assertEquals("Uri equals",
+ "http://ldt.iri.centrepompidou.fr/new/uri", sp.getUri());
+ Assert.assertEquals("Color equals", "#ffffff", sp.getColor());
+ Assert.assertEquals("BinConfig equals", "{}", sp.getBinConfig());
+ Assert.assertTrue(
+ "id sould match uuid regex",
+ sp.getId()
+ .matches(
+ "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"));
+ Assert.assertNotNull("Date created should be not null",
+ sp.getCreated());
+ }
+ }
+ }
+
+ @Test
+ public void testSpacePostUpdateEmptyTitle() throws Exception {
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/save");
+ post = post.param("id", this.spacesUuids.get(0));
+ post = post.param("title", "");
+ post = post.param("description", "New description");
+ post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
+ post = post.param("color", "#ffffff");
+ post = post.param("binConfig", "{}");
+
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
+ .andExpect(MockMvcResultMatchers.model().hasErrors())
+ .andExpect(MockMvcResultMatchers.model().errorCount(1))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasErrors(
+ "space"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasFieldErrors(
+ "space", "title"));
+
+ Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
+
+ Assert.assertNotNull("Should find space", sp);
+ Assert.assertEquals("Title equals", "test 0", sp.getTitle());
+
+ }
+
+ @Test
+ public void testSpacePostCreateEmptyTitle() throws Exception {
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/save");
+ post = post.param("title", "");
+ post = post.param("description", "New description");
+ post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
+ post = post.param("color", "#ffffff");
+ post = post.param("binConfig", "{}");
- @Test
- public void testSpacePostCreate() throws Exception {
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/save");
- post = post.param("title", "New title");
- post = post.param("description", "New description");
- post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
- post = post.param("color", "#ffffff");
- post = post.param("binConfig", "{}");
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isSeeOther())
- .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
-
-
- Assert.assertEquals("Must have one more space", SPACE_NB + 1, this.spacesRepository.count());
-
- for (Space sp : this.spacesRepository.findAll()) {
- if(this.spacesList.containsKey(sp.getId())) {
- continue;
- }
- else {
- Assert.assertNotNull("Should find space", sp);
- Assert.assertEquals("Title equals", "New title", sp.getTitle());
- Assert.assertEquals("Description equals", "New description", sp.getDescription());
- Assert.assertEquals("Uri equals", "http://ldt.iri.centrepompidou.fr/new/uri", sp.getUri());
- Assert.assertEquals("Color equals", "#ffffff", sp.getColor());
- Assert.assertEquals("BinConfig equals", "{}", sp.getBinConfig());
- Assert.assertTrue("id sould match uuid regex", sp.getId().matches("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"));
- Assert.assertNotNull("Date created should be not null", sp.getCreated());
- }
- }
- }
-
- @Test
- public void testSpacePostUpdateEmptyTitle() throws Exception {
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/save");
- post = post.param("id", this.spacesUuids.get(0));
- post = post.param("title", "");
- post = post.param("description", "New description");
- post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
- post = post.param("color", "#ffffff");
- post = post.param("binConfig", "{}");
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
- .andExpect(MockMvcResultMatchers.model().hasErrors())
- .andExpect(MockMvcResultMatchers.model().errorCount(1))
- .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space"))
- .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("space", "title"));
-
- Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
-
- Assert.assertNotNull("Should find space", sp);
- Assert.assertEquals("Title equals", "test 0", sp.getTitle());
-
- }
-
- @Test
- public void testSpacePostCreateEmptyTitle() throws Exception {
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/save");
- post = post.param("title", "");
- post = post.param("description", "New description");
- post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
- post = post.param("color", "#ffffff");
- post = post.param("binConfig", "{}");
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
- .andExpect(MockMvcResultMatchers.model().hasErrors())
- .andExpect(MockMvcResultMatchers.model().errorCount(1))
- .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space"))
- .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("space", "title"));
-
- Assert.assertEquals("Must not have one more space", SPACE_NB, this.spacesRepository.count());
-
- }
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
+ .andExpect(MockMvcResultMatchers.model().hasErrors())
+ .andExpect(MockMvcResultMatchers.model().errorCount(1))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasErrors(
+ "space"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasFieldErrors(
+ "space", "title"));
+
+ Assert.assertEquals("Must not have one more space", SPACE_NB,
+ this.spacesRepository.count());
+
+ }
+
+ @Test
+ public void testSpacePostUpdateBadJson() throws Exception {
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/save");
+ post = post.param("id", this.spacesUuids.get(0));
+ post = post.param("title", "New Title");
+ post = post.param("description", "New description");
+ post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
+ post = post.param("color", "#ffffff");
+ post = post.param("binConfig", "{");
+
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
+ .andExpect(MockMvcResultMatchers.model().hasErrors())
+ .andExpect(MockMvcResultMatchers.model().errorCount(1))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasErrors(
+ "space"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasFieldErrors(
+ "space", "binConfig"));
+
+ Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
+
+ Assert.assertNotNull("Should find space", sp);
+ Assert.assertEquals("Bin config equals", "{}", sp.getBinConfig());
+
+ }
+
+ @Test
+ public void testSpacePostCreateBadJson() throws Exception {
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/save");
+ post = post.param("title", "New Title");
+ post = post.param("description", "New description");
+ post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
+ post = post.param("color", "#ffffff");
+ post = post.param("binConfig", "}");
+
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
+ .andExpect(MockMvcResultMatchers.model().hasErrors())
+ .andExpect(MockMvcResultMatchers.model().errorCount(1))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasErrors(
+ "space"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasFieldErrors(
+ "space", "binConfig"));
- @Test
- public void testSpacePostUpdateBadJson() throws Exception {
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/save");
- post = post.param("id", this.spacesUuids.get(0));
- post = post.param("title", "New Title");
- post = post.param("description", "New description");
- post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
- post = post.param("color", "#ffffff");
- post = post.param("binConfig", "{");
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
- .andExpect(MockMvcResultMatchers.model().hasErrors())
- .andExpect(MockMvcResultMatchers.model().errorCount(1))
- .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space"))
- .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("space", "binConfig"));
-
- Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
-
- Assert.assertNotNull("Should find space", sp);
- Assert.assertEquals("Bin config equals", "{}", sp.getBinConfig());
-
- }
-
- @Test
- public void testSpacePostCreateBadJson() throws Exception {
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/save");
- post = post.param("title", "New Title");
- post = post.param("description", "New description");
- post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
- post = post.param("color", "#ffffff");
- post = post.param("binConfig", "}");
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
- .andExpect(MockMvcResultMatchers.model().hasErrors())
- .andExpect(MockMvcResultMatchers.model().errorCount(1))
- .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space"))
- .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("space", "binConfig"));
-
- Assert.assertEquals("Must not have one more space", SPACE_NB, this.spacesRepository.count());
-
- }
+ Assert.assertEquals("Must not have one more space", SPACE_NB,
+ this.spacesRepository.count());
+
+ }
+
+ @Test
+ public void testSpacePostUpdateAllErrors() throws Exception {
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/save");
+ post = post.param("id", this.spacesUuids.get(0));
+ post = post.param("title", "");
+ post = post.param("description", "New description");
+ post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
+ post = post.param("color", "#ffffff");
+ post = post.param("binConfig", "{");
+
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
+ .andExpect(MockMvcResultMatchers.model().hasErrors())
+ .andExpect(MockMvcResultMatchers.model().errorCount(2))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasErrors(
+ "space"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasFieldErrors(
+ "space", "title"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasFieldErrors(
+ "space", "binConfig"));
+
+ Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
+
+ Assert.assertNotNull("Should find space", sp);
+ Assert.assertEquals("Bin config equals", "{}", sp.getBinConfig());
+ Assert.assertEquals("title equals", "test 0", sp.getTitle());
+
+ }
+
+ @Test
+ public void testSpacePostCreateAllErrors() throws Exception {
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/save");
+ post = post.param("title", "");
+ post = post.param("description", "New description");
+ post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
+ post = post.param("color", "#ffffff");
+ post = post.param("binConfig", "}");
- @Test
- public void testSpacePostUpdateAllErrors() throws Exception {
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/save");
- post = post.param("id", this.spacesUuids.get(0));
- post = post.param("title", "");
- post = post.param("description", "New description");
- post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
- post = post.param("color", "#ffffff");
- post = post.param("binConfig", "{");
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
- .andExpect(MockMvcResultMatchers.model().hasErrors())
- .andExpect(MockMvcResultMatchers.model().errorCount(2))
- .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space"))
- .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("space", "title"))
- .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("space", "binConfig"));
-
- Space sp = this.spacesRepository.findOne(this.spacesUuids.get(0));
-
- Assert.assertNotNull("Should find space", sp);
- Assert.assertEquals("Bin config equals", "{}", sp.getBinConfig());
- Assert.assertEquals("title equals", "test 0", sp.getTitle());
-
- }
-
- @Test
- public void testSpacePostCreateAllErrors() throws Exception {
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/save");
- post = post.param("title", "");
- post = post.param("description", "New description");
- post = post.param("uri", "http://ldt.iri.centrepompidou.fr/new/uri");
- post = post.param("color", "#ffffff");
- post = post.param("binConfig", "}");
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
- .andExpect(MockMvcResultMatchers.model().hasErrors())
- .andExpect(MockMvcResultMatchers.model().errorCount(2))
- .andExpect(MockMvcResultMatchers.model().attributeHasErrors("space"))
- .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("space", "title"))
- .andExpect(MockMvcResultMatchers.model().attributeHasFieldErrors("space", "binConfig"));
-
- Assert.assertEquals("Must not have one more space", SPACE_NB, this.spacesRepository.count());
-
- }
-
- @Test
- public void testDeleteSpace() throws Exception {
-
- MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/admin/spaces/delete/"+this.spacesUuids.get(SPACE_NB-1));
-
- MvcResult res = this.mvc.perform(get)
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.view().name("admin/spaceDeleteConfirm"))
- .andExpect(MockMvcResultMatchers.model().attributeExists("spaceObj", "key", "salt"))
- .andReturn();
-
- Map<String, Object> model = res.getModelAndView().getModel();
-
- Space space = (Space)model.get("spaceObj");
- Assert.assertNotNull("Space is not null", space);
- Assert.assertEquals("Must be first space id", this.spacesUuids.get(SPACE_NB-1), space.getId());
-
- String key = (String)model.get("key");
- Assert.assertNotNull("key is not null", key);
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.view().name("admin/spaceEdit"))
+ .andExpect(MockMvcResultMatchers.model().hasErrors())
+ .andExpect(MockMvcResultMatchers.model().errorCount(2))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasErrors(
+ "space"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasFieldErrors(
+ "space", "title"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeHasFieldErrors(
+ "space", "binConfig"));
+
+ Assert.assertEquals("Must not have one more space", SPACE_NB,
+ this.spacesRepository.count());
+
+ }
+
+ @Test
+ public void testDeleteSpace() throws Exception {
+
+ MockHttpServletRequestBuilder get = MockMvcRequestBuilders
+ .get("/admin/spaces/delete/"
+ + this.spacesUuids.get(SPACE_NB - 1));
+
+ MvcResult res = this.mvc
+ .perform(get)
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(
+ MockMvcResultMatchers.view().name(
+ "admin/spaceDeleteConfirm"))
+ .andExpect(
+ MockMvcResultMatchers.model().attributeExists(
+ "spaceObj", "key", "salt")).andReturn();
+
+ Map<String, Object> model = res.getModelAndView().getModel();
- String salt = (String)model.get("salt");
- Assert.assertNotNull("salt is not null", salt);
-
- Assert.assertTrue("Key must be checked", space.checkKey(key, salt));
-
- }
+ Space space = (Space) model.get("spaceObj");
+ Assert.assertNotNull("Space is not null", space);
+ Assert.assertEquals("Must be first space id",
+ this.spacesUuids.get(SPACE_NB - 1), space.getId());
+
+ String key = (String) model.get("key");
+ Assert.assertNotNull("key is not null", key);
+
+ String salt = (String) model.get("salt");
+ Assert.assertNotNull("salt is not null", salt);
+
+ Assert.assertTrue("Key must be checked", space.checkKey(key, salt));
+
+ }
+
+ @Test
+ public void testDeleteFakeSpace() throws Exception {
+
+ MockHttpServletRequestBuilder get = MockMvcRequestBuilders
+ .get("/admin/spaces/delete/" + UUID.randomUUID().toString());
+
+ try {
+ this.mvc.perform(get).andExpect(
+ MockMvcResultMatchers.status().isNotFound());
+ } catch (NestedServletException e) {
+ Assert.assertNotNull("Nested exception must not be null",
+ e.getCause());
+ Assert.assertEquals(
+ "Inner exception must be a HttpClientErrorException",
+ HttpClientErrorException.class, e.getCause().getClass());
+ Assert.assertEquals("Exception error status must be not found",
+ HttpStatus.NOT_FOUND,
+ ((HttpClientErrorException) e.getCause()).getStatusCode());
+ }
+
+ }
+
+ @Test
+ public void testDeleteSpaceProject() throws Exception {
- @Test
- public void testDeleteFakeSpace() throws Exception {
-
- MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/admin/spaces/delete/" + UUID.randomUUID().toString());
-
- try {
- this.mvc.perform(get)
- .andExpect(MockMvcResultMatchers.status().isNotFound());
- }
- catch(NestedServletException e) {
- Assert.assertNotNull("Nested exception must not be null", e.getCause());
- Assert.assertEquals("Inner exception must be a HttpClientErrorException", HttpClientErrorException.class, e.getCause().getClass());
- Assert.assertEquals("Exception error status must be not found", HttpStatus.NOT_FOUND, ((HttpClientErrorException)e.getCause()).getStatusCode());
- }
-
- }
-
- @Test
- public void testDeleteSpaceProject() throws Exception {
-
- MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/admin/spaces/delete/" + this.spacesUuids.get(0));
-
- try {
- this.mvc.perform(get)
- .andExpect(MockMvcResultMatchers.status().isBadRequest());
- }
- catch(NestedServletException e) {
- Assert.assertNotNull("Nested exception must not be null", e.getCause());
- Assert.assertEquals("Inner exception must be a HttpClientErrorException", HttpClientErrorException.class, e.getCause().getClass());
- Assert.assertEquals("Exception error status must be not found", HttpStatus.BAD_REQUEST, ((HttpClientErrorException)e.getCause()).getStatusCode());
- }
-
- }
-
- @Test
- public void testDoDeleteSpaceNoKey() throws Exception {
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post("/admin/spaces/delete/"+this.spacesUuids.get(SPACE_NB-1));
-
- try {
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isBadRequest());
- }
- catch(NestedServletException e) {
- Assert.assertNotNull("Nested exception must not be null", e.getCause());
- Assert.assertEquals("Inner exception must be a HttpClientErrorException", HttpClientErrorException.class, e.getCause().getClass());
- Assert.assertEquals("Exception error status must be not found", HttpStatus.BAD_REQUEST, ((HttpClientErrorException)e.getCause()).getStatusCode());
- }
+ MockHttpServletRequestBuilder get = MockMvcRequestBuilders
+ .get("/admin/spaces/delete/" + this.spacesUuids.get(0));
+
+ try {
+ this.mvc.perform(get).andExpect(
+ MockMvcResultMatchers.status().isBadRequest());
+ } catch (NestedServletException e) {
+ Assert.assertNotNull("Nested exception must not be null",
+ e.getCause());
+ Assert.assertEquals(
+ "Inner exception must be a HttpClientErrorException",
+ HttpClientErrorException.class, e.getCause().getClass());
+ Assert.assertEquals("Exception error status must be not found",
+ HttpStatus.BAD_REQUEST,
+ ((HttpClientErrorException) e.getCause()).getStatusCode());
+ }
+
+ }
+
+ @Test
+ public void testDoDeleteSpaceNoKey() throws Exception {
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders
+ .post("/admin/spaces/delete/"
+ + this.spacesUuids.get(SPACE_NB - 1));
+
+ try {
+ this.mvc.perform(post).andExpect(
+ MockMvcResultMatchers.status().isBadRequest());
+ } catch (NestedServletException e) {
+ Assert.assertNotNull("Nested exception must not be null",
+ e.getCause());
+ Assert.assertEquals(
+ "Inner exception must be a HttpClientErrorException",
+ HttpClientErrorException.class, e.getCause().getClass());
+ Assert.assertEquals("Exception error status must be not found",
+ HttpStatus.BAD_REQUEST,
+ ((HttpClientErrorException) e.getCause()).getStatusCode());
+ }
+
+ Assert.assertEquals("Must have same nb of space", SPACE_NB,
+ this.spacesRepository.count());
+
+ }
+
+ @Test
+ public void testDoDeleteSpace() throws Exception {
+
+ Space space = this.spacesList.get(this.spacesUuids.get(SPACE_NB - 1));
+
+ SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
+ rand.setSeed(System.currentTimeMillis());
+ byte[] rawSalt = new byte[50];
+ rand.nextBytes(rawSalt);
+ String salt = Hex.encodeHexString(rawSalt);
+ String key = space.getKey(salt);
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post(String
+ .format("/admin/spaces/delete/%s?key=%s&salt=%s",
+ this.spacesUuids.get(SPACE_NB - 1), key, salt));
+
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isSeeOther())
+ .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
+
+ Assert.assertEquals("Must have one less space", SPACE_NB - 1,
+ this.spacesRepository.count());
-
- Assert.assertEquals("Must have same nb of space", SPACE_NB, this.spacesRepository.count());
-
- }
-
- @Test
- public void testDoDeleteSpace() throws Exception {
-
- Space space = this.spacesList.get(this.spacesUuids.get(SPACE_NB-1));
-
- SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
- rand.setSeed(System.currentTimeMillis());
- byte[] rawSalt = new byte[50];
- rand.nextBytes(rawSalt);
- String salt = Hex.encodeHexString(rawSalt);
- String key = space.getKey(salt);
-
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post(String.format("/admin/spaces/delete/%s?key=%s&salt=%s",this.spacesUuids.get(SPACE_NB-1), key, salt));
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isSeeOther())
- .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
-
- Assert.assertEquals("Must have one less space", SPACE_NB-1, this.spacesRepository.count());
-
- space = this.spacesRepository.findOne(this.spacesUuids.get(SPACE_NB-1));
-
- Assert.assertNull("Space " + this.spacesUuids.get(SPACE_NB-1) + " deleted", space);
-
- }
+ space = this.spacesRepository.findOne(this.spacesUuids
+ .get(SPACE_NB - 1));
+
+ Assert.assertNull("Space " + this.spacesUuids.get(SPACE_NB - 1)
+ + " deleted", space);
+
+ }
+
+ @Test
+ public void testDoDeleteSpaceFake() throws Exception {
+
+ Space space = this.spacesList.get(this.spacesUuids.get(SPACE_NB - 1));
+
+ SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
+ rand.setSeed(System.currentTimeMillis());
+ byte[] rawSalt = new byte[50];
+ rand.nextBytes(rawSalt);
+ String salt = Hex.encodeHexString(rawSalt);
+ String key = space.getKey(salt);
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post(String
+ .format("/admin/spaces/delete/%s?key=%s&salt=%s",
+ UUID.randomUUID(), key, salt));
+
+ this.mvc.perform(post)
+ .andExpect(MockMvcResultMatchers.status().isSeeOther())
+ .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
+
+ Assert.assertEquals("Must have the same nb of space", SPACE_NB,
+ this.spacesRepository.count());
+
+ }
-
- @Test
- public void testDoDeleteSpaceFake() throws Exception {
-
- Space space = this.spacesList.get(this.spacesUuids.get(SPACE_NB-1));
-
- SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
- rand.setSeed(System.currentTimeMillis());
- byte[] rawSalt = new byte[50];
- rand.nextBytes(rawSalt);
- String salt = Hex.encodeHexString(rawSalt);
- String key = space.getKey(salt);
-
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post(String.format("/admin/spaces/delete/%s?key=%s&salt=%s",UUID.randomUUID(), key, salt));
-
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isSeeOther())
- .andExpect(MockMvcResultMatchers.redirectedUrl("/admin/spaces"));
-
- Assert.assertEquals("Must have the same nb of space", SPACE_NB, this.spacesRepository.count());
-
- }
+ @Test
+ public void testDoDeleteSpaceProject() throws Exception {
+
+ Space space = this.spacesList.get(this.spacesUuids.get(0));
+
+ SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
+ rand.setSeed(System.currentTimeMillis());
+ byte[] rawSalt = new byte[50];
+ rand.nextBytes(rawSalt);
+ String salt = Hex.encodeHexString(rawSalt);
+ String key = space.getKey(salt);
+
+ MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post(String
+ .format("/admin/spaces/delete/%s?key=%s&salt=%s",
+ this.spacesUuids.get(0), key, salt));
- @Test
- public void testDoDeleteSpaceProject() throws Exception {
-
- Space space = this.spacesList.get(this.spacesUuids.get(0));
-
- SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
- rand.setSeed(System.currentTimeMillis());
- byte[] rawSalt = new byte[50];
- rand.nextBytes(rawSalt);
- String salt = Hex.encodeHexString(rawSalt);
- String key = space.getKey(salt);
-
-
- MockHttpServletRequestBuilder post = MockMvcRequestBuilders.post(String.format("/admin/spaces/delete/%s?key=%s&salt=%s",this.spacesUuids.get(0), key, salt));
-
- try {
- this.mvc.perform(post)
- .andExpect(MockMvcResultMatchers.status().isBadRequest());
- }
- catch(NestedServletException e) {
- Assert.assertNotNull("Nested exception must not be null", e.getCause());
- Assert.assertEquals("Inner exception must be a HttpClientErrorException", HttpClientErrorException.class, e.getCause().getClass());
- Assert.assertEquals("Exception error status must be not found", HttpStatus.BAD_REQUEST, ((HttpClientErrorException)e.getCause()).getStatusCode());
- }
-
- Assert.assertEquals("Must have the same nb of space", SPACE_NB, this.spacesRepository.count());
-
- }
+ try {
+ this.mvc.perform(post).andExpect(
+ MockMvcResultMatchers.status().isBadRequest());
+ } catch (NestedServletException e) {
+ Assert.assertNotNull("Nested exception must not be null",
+ e.getCause());
+ Assert.assertEquals(
+ "Inner exception must be a HttpClientErrorException",
+ HttpClientErrorException.class, e.getCause().getClass());
+ Assert.assertEquals("Exception error status must be not found",
+ HttpStatus.BAD_REQUEST,
+ ((HttpClientErrorException) e.getCause()).getStatusCode());
+ }
+
+ Assert.assertEquals("Must have the same nb of space", SPACE_NB,
+ this.spacesRepository.count());
+
+ }
}
--- a/server/src/test/java/org/iri_research/renkan/test/repositories/ProjectSyncsRepositoryTest.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/test/java/org/iri_research/renkan/test/repositories/ProjectSyncsRepositoryTest.java Mon Oct 21 15:00:17 2013 +0200
@@ -1,6 +1,5 @@
package org.iri_research.renkan.test.repositories;
-
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;
@@ -23,143 +22,154 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("repositories-context.xml")
public class ProjectSyncsRepositoryTest {
- private Logger logger = LoggerFactory.getLogger(ProjectSyncsRepositoryTest.class);
-
- @Autowired
- private ProjectsRepository projectRepository;
+ private Logger logger = LoggerFactory
+ .getLogger(ProjectSyncsRepositoryTest.class);
+
+ @Autowired
+ private ProjectsRepository projectRepository;
+
+ @Autowired
+ private ProjectSyncsRepository projectSyncsRepository;
+
+ @Autowired
+ private SpacesRepository spacesRepository;
+
+ private ArrayList<Project> testProjects = new ArrayList<Project>();
+
+ public ProjectSyncsRepositoryTest() {
+ }
+
+ @Before
+ public void setup() {
+
+ logger.debug("Setup");
+ Space testSpace = new Space(UUID.randomUUID().toString(), "test",
+ "Test space", null, null, null, "test_user", null, null);
+ testSpace = spacesRepository.save(testSpace);
+ ArrayList<Project> pl = new ArrayList<Project>();
+ pl.add(new Project(testSpace.getId(), null, "test1", "desc1",
+ "http://localhost:8080/rest/projects/id1", new Date()));
+ pl.add(new Project(testSpace.getId(), null, "test2", "desc2",
+ "http://localhost:8080/rest/projects/id2", new Date()));
+ logger.debug("Setup : new Project ");
+ for (Project p : projectRepository.save(pl)) {
+ this.testProjects.add(p);
+ }
+ }
- @Autowired
- private ProjectSyncsRepository projectSyncsRepository;
-
- @Autowired
- private SpacesRepository spacesRepository;
-
-
- private ArrayList<Project> testProjects = new ArrayList<Project>();
-
- public ProjectSyncsRepositoryTest() {
- }
-
- @Before
- public void setup() {
-
- logger.debug("Setup");
- Space testSpace = new Space(UUID.randomUUID().toString(), "test", "Test space", null, null, null, "test_user", null, null);
- testSpace = spacesRepository.save(testSpace);
- ArrayList<Project> pl = new ArrayList<Project>();
- pl.add(new Project(testSpace.getId(), null, "test1", "desc1", "http://localhost:8080/rest/projects/id1", new Date()));
- pl.add(new Project(testSpace.getId(), null, "test2", "desc2", "http://localhost:8080/rest/projects/id2", new Date()));
- logger.debug("Setup : new Project ");
- for(Project p: projectRepository.save(pl)) {
- this.testProjects.add(p);
- }
- }
-
- @After
- public void teardown() {
- logger.debug("Teardown");
- projectRepository.deleteAll();
- projectSyncsRepository.deleteAll();
- }
-
+ @After
+ public void teardown() {
+ logger.debug("Teardown");
+ projectRepository.deleteAll();
+ projectSyncsRepository.deleteAll();
+ }
+
+ @Test
+ public void testGetCollection() {
+ String collectionName = this.projectSyncsRepository.getCollection()
+ .getName();
+
+ Assert.assertEquals("The collection name should be projectSyncs",
+ "projectSyncs", collectionName);
+
+ }
+
+ @Test
+ public void testGetProjectSync() throws RenkanException {
+
+ Project p = projectRepository.findOne(this.testProjects.get(0).getId());
+
+ String data = "{\"example\":\"this is an example\"}";
+
+ ProjectSync ps = projectSyncsRepository
+ .getProjectSync(data, p, "user1");
+
+ ps = this.projectSyncsRepository.save(ps);
+
+ ps = this.projectSyncsRepository.findOne(ps.getId());
+
+ Assert.assertNotNull(ps);
+ Assert.assertEquals(data, ps.getData());
+
+ }
+
+ @Test
+ public void testGetProjectSyncRevision() throws RenkanException {
- @Test
- public void testGetCollection() {
- String collectionName = this.projectSyncsRepository.getCollection().getName();
-
- Assert.assertEquals("The collection name should be projectSyncs", "projectSyncs", collectionName);
-
- }
-
- @Test
- public void testGetProjectSync() throws RenkanException {
-
- Project p = projectRepository.findOne(this.testProjects.get(0).getId());
-
- String data = "{\"example\":\"this is an example\"}";
-
- ProjectSync ps = projectSyncsRepository.getProjectSync(data, p, "user1");
-
- ps = this.projectSyncsRepository.save(ps);
-
-
- ps = this.projectSyncsRepository.findOne(ps.getId());
-
- Assert.assertNotNull(ps);
- Assert.assertEquals(data, ps.getData());
-
- }
-
-
- @Test
- public void testGetProjectSyncRevision() throws RenkanException {
-
- Project p = projectRepository.findOne(this.testProjects.get(0).getId());
-
- String data = "{\"example\":\"this is an example\"}";
-
- ProjectSync ps = projectSyncsRepository.getProjectSync(data, p, "user1");
-
- ps = this.projectSyncsRepository.save(ps);
- ps = this.projectSyncsRepository.findOne(ps.getId());
-
- p = projectRepository.findOne(this.testProjects.get(0).getId());
-
- Assert.assertNotNull(ps.getProject());
- Assert.assertEquals(p.getId(), ps.getProject().getId());
- Assert.assertEquals("Revision of the project sync mustbe one less tha the rev counter pf the project", p.getRevCounter()-1, ps.getRevision());
-
- Assert.assertEquals("Revision of the project sync mustbe one less tha the rev counter of its project", ps.getProject().getRevCounter()-1, ps.getRevision());
-
- }
-
- @Test(expected=RenkanException.class)
- public void testGetProjectSyncExceptionNullProject() throws RenkanException {
-
- String data = "{\"example\":\"this is an example\"}";
- Project p = null;
- ProjectSync ps = projectSyncsRepository.getProjectSync(data, p, "user1");
-
- // should never be executed.
- Assert.assertNull(ps);
- }
-
- @Test(expected=RenkanException.class)
- public void testGetProjectSyncExceptionNullId() throws RenkanException {
-
- String data = "{\"example\":\"this is an example\"}";
- String project_id = null;
- ProjectSync ps = projectSyncsRepository.getProjectSync(data, project_id, "user1");
-
- // should never be executed.
- Assert.assertNull(ps);
- }
-
- @Test(expected=RenkanException.class)
- public void testGetProjectSyncExceptionEmptyId() throws RenkanException {
-
- String data = "{\"example\":\"this is an example\"}";
- String project_id = "";
- ProjectSync ps = projectSyncsRepository.getProjectSync(data, project_id, "user1");
-
- // should never be executed.
- Assert.assertNull(ps);
- }
-
- @Test(expected=RenkanException.class)
- public void testGetProjectSyncExceptionBadId() throws RenkanException {
-
- String data = "{\"example\":\"this is an example\"}";
- String project_id = "BAD_ID";
- ProjectSync ps = projectSyncsRepository.getProjectSync(data, project_id, "user1");
-
- // should never be executed.
- Assert.assertNull(ps);
- }
-
+ Project p = projectRepository.findOne(this.testProjects.get(0).getId());
+
+ String data = "{\"example\":\"this is an example\"}";
+
+ ProjectSync ps = projectSyncsRepository
+ .getProjectSync(data, p, "user1");
+
+ ps = this.projectSyncsRepository.save(ps);
+ ps = this.projectSyncsRepository.findOne(ps.getId());
+
+ p = projectRepository.findOne(this.testProjects.get(0).getId());
+
+ Assert.assertNotNull(ps.getProject());
+ Assert.assertEquals(p.getId(), ps.getProject().getId());
+ Assert.assertEquals(
+ "Revision of the project sync mustbe one less tha the rev counter pf the project",
+ p.getRevCounter() - 1, ps.getRevision());
+
+ Assert.assertEquals(
+ "Revision of the project sync mustbe one less tha the rev counter of its project",
+ ps.getProject().getRevCounter() - 1, ps.getRevision());
+
+ }
+
+ @Test(expected = RenkanException.class)
+ public void testGetProjectSyncExceptionNullProject() throws RenkanException {
+
+ String data = "{\"example\":\"this is an example\"}";
+ Project p = null;
+ ProjectSync ps = projectSyncsRepository
+ .getProjectSync(data, p, "user1");
+
+ // should never be executed.
+ Assert.assertNull(ps);
+ }
+
+ @Test(expected = RenkanException.class)
+ public void testGetProjectSyncExceptionNullId() throws RenkanException {
+
+ String data = "{\"example\":\"this is an example\"}";
+ String project_id = null;
+ ProjectSync ps = projectSyncsRepository.getProjectSync(data,
+ project_id, "user1");
+
+ // should never be executed.
+ Assert.assertNull(ps);
+ }
+
+ @Test(expected = RenkanException.class)
+ public void testGetProjectSyncExceptionEmptyId() throws RenkanException {
+
+ String data = "{\"example\":\"this is an example\"}";
+ String project_id = "";
+ ProjectSync ps = projectSyncsRepository.getProjectSync(data,
+ project_id, "user1");
+
+ // should never be executed.
+ Assert.assertNull(ps);
+ }
+
+ @Test(expected = RenkanException.class)
+ public void testGetProjectSyncExceptionBadId() throws RenkanException {
+
+ String data = "{\"example\":\"this is an example\"}";
+ String project_id = "BAD_ID";
+ ProjectSync ps = projectSyncsRepository.getProjectSync(data,
+ project_id, "user1");
+
+ // should never be executed.
+ Assert.assertNull(ps);
+ }
+
}
--- a/server/src/test/java/org/iri_research/renkan/test/repositories/ProjectsRepositoryTest.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/test/java/org/iri_research/renkan/test/repositories/ProjectsRepositoryTest.java Mon Oct 21 15:00:17 2013 +0200
@@ -1,6 +1,5 @@
package org.iri_research.renkan.test.repositories;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -42,563 +41,654 @@
import com.mongodb.DBObject;
import com.mongodb.DBRef;
-
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("repositories-context.xml")
public class ProjectsRepositoryTest {
- private final static int SPACE_NB = 3;
-
- private Logger logger = LoggerFactory.getLogger(ProjectsRepositoryTest.class);
-
- @Autowired
- private ProjectsRepository projectsRepository;
-
- @Autowired
- private SpacesRepository spacesRepository;
-
- @Autowired
- private NodesRepository nodesRepository;
-
- @Autowired
- private EdgesRepository edgesRepository;
-
- @Autowired
- private UsersRepository usersRepository;
-
- @Autowired
- private ProjectRevisionsRepository projectRevisionsRepository;
-
- @Autowired
- private MongoTemplate mongoTemplate;
-
- private ArrayList<Project> testProjects = new ArrayList<Project>();
- private List<Node> testNodes = new ArrayList<>();
- private List<Edge> testEdges = new ArrayList<>();
- private List<User> testUsers = new ArrayList<>();
-
- private Date creationDate = new Date();
-
- private List<String> spaceIds = new ArrayList<>();
-
- private Project copyProject;
-
- public ProjectsRepositoryTest() {
- }
-
- @Before
- public void setup() {
+ private final static int SPACE_NB = 3;
+
+ private Logger logger = LoggerFactory
+ .getLogger(ProjectsRepositoryTest.class);
+
+ @Autowired
+ private ProjectsRepository projectsRepository;
+
+ @Autowired
+ private SpacesRepository spacesRepository;
+
+ @Autowired
+ private NodesRepository nodesRepository;
+
+ @Autowired
+ private EdgesRepository edgesRepository;
+
+ @Autowired
+ private UsersRepository usersRepository;
+
+ @Autowired
+ private ProjectRevisionsRepository projectRevisionsRepository;
+
+ @Autowired
+ private MongoTemplate mongoTemplate;
+
+ private ArrayList<Project> testProjects = new ArrayList<Project>();
+ private List<Node> testNodes = new ArrayList<>();
+ private List<Edge> testEdges = new ArrayList<>();
+ private List<User> testUsers = new ArrayList<>();
+
+ private Date creationDate = new Date();
+
+ private List<String> spaceIds = new ArrayList<>();
+
+ private Project copyProject;
+
+ public ProjectsRepositoryTest() {
+ }
+
+ @Before
+ public void setup() {
+
+ logger.debug("Setup");
+
+ // CREATE USERS
+ for (int i = 0; i < SPACE_NB + 1; i++) {
+ this.testUsers.add(new User(UUID.randomUUID().toString(),
+ "test_user" + (i + 1), "Test user " + (i + 1),
+ "http://www.iri.centrepompidou.fr/users/test_user"
+ + (i + 1), "#" + ColorGenerator.randomColorHex()));
+ }
+ usersRepository.save(this.testUsers);
+
+ ArrayList<Project> pl = new ArrayList<Project>();
+ Space testSpace = null;
+ for (int i = 0; i < SPACE_NB; i++) {
+ spaceIds.add(UUID.randomUUID().toString());
+ testSpace = new Space(this.spaceIds.get(i), "test space " + i,
+ "Test space " + i, null, null, null, "test_user", null,
+ this.creationDate);
+ testSpace = spacesRepository.save(testSpace);
+ for (int j = 0; j < SPACE_NB - 1 - i; j++) {
+ final Project project = new Project(testSpace.getId(), UUID
+ .randomUUID().toString(), "test project "
+ + ((SPACE_NB - 1) * i + j + 1), "desc"
+ + ((SPACE_NB - 1) * i + j + 1),
+ "http://localhost:8080/rest/projects/id"
+ + ((SPACE_NB - 1) * i + j + 1),
+ this.creationDate);
+ pl.add(project);
+ }
+ }
- logger.debug("Setup");
-
- // CREATE USERS
- for(int i=0; i<SPACE_NB+1; i++) {
- this.testUsers.add(new User(UUID.randomUUID().toString(), "test_user"+(i+1), "Test user " + (i+1), "http://www.iri.centrepompidou.fr/users/test_user"+(i+1), "#"+ColorGenerator.randomColorHex()));
- }
- usersRepository.save(this.testUsers);
-
-
- ArrayList<Project> pl = new ArrayList<Project>();
- Space testSpace = null;
- for(int i=0; i<SPACE_NB; i++) {
- spaceIds.add(UUID.randomUUID().toString());
- testSpace = new Space(this.spaceIds.get(i), "test space " + i, "Test space " + i, null, null, null, "test_user", null, this.creationDate);
- testSpace = spacesRepository.save(testSpace);
- for(int j=0; j<SPACE_NB-1-i; j++) {
- final Project project = new Project(testSpace.getId(), UUID.randomUUID().toString(), "test project "+((SPACE_NB-1)*i+j+1), "desc"+((SPACE_NB-1)*i+j+1), "http://localhost:8080/rest/projects/id"+((SPACE_NB-1)*i+j+1), this.creationDate);
- pl.add(project);
- }
- }
-
- for(int i=0; i<testUsers.size()-1;i++) {
- User u = this.testUsers.get(i);
- for(int j=0;j<pl.size();j++) {
- Project p = pl.get(j);
- if(j<pl.size()-i) {
- p.addUser(u);
- }
- else {
- p.addUser(null, null);
- }
-
- }
- }
-
- for(Project p: projectsRepository.save(pl)) {
- this.testProjects.add(p);
- }
-
- copyProject = this.testProjects.get(0);
-
- for(int i=0;i<3;i++) {
- Node node = new Node("Node"+i, "Node"+i, "Node "+i, "http://renkan.org/nodes/node"+i, "#ffff0"+i, "test_user", new Point(0, i), "http://renkan.org/images/node"+i, i, copyProject.getId());
- node = this.nodesRepository.save(node);
- copyProject.getNodes().add(node);
- this.testNodes.add(node);
- }
- for(int i=0;i<3;i++) {
- Edge edge = new Edge("Node"+i, "Node"+i, "Node "+i, "http://renkan.org/edges/edge"+i, "#ffff0"+i, this.testNodes.get((i+2)%3), this.testNodes.get(i), "test_user", copyProject.getId());
- edge = this.edgesRepository.save(edge);
- copyProject.getEdges().add(edge);
- this.testEdges.add(edge);
- }
-
- this.projectsRepository.save(copyProject);
+ for (int i = 0; i < testUsers.size() - 1; i++) {
+ User u = this.testUsers.get(i);
+ for (int j = 0; j < pl.size(); j++) {
+ Project p = pl.get(j);
+ if (j < pl.size() - i) {
+ p.addUser(u);
+ } else {
+ p.addUser(null, null);
+ }
+
+ }
+ }
+
+ for (Project p : projectsRepository.save(pl)) {
+ this.testProjects.add(p);
+ }
+
+ copyProject = this.testProjects.get(0);
+
+ for (int i = 0; i < 3; i++) {
+ Node node = new Node("Node" + i, "Node" + i, "Node " + i,
+ "http://renkan.org/nodes/node" + i, "#ffff0" + i,
+ "test_user", new Point(0, i),
+ "http://renkan.org/images/node" + i, i, copyProject.getId());
+ node = this.nodesRepository.save(node);
+ copyProject.getNodes().add(node);
+ this.testNodes.add(node);
+ }
+ for (int i = 0; i < 3; i++) {
+ Edge edge = new Edge("Node" + i, "Node" + i, "Node " + i,
+ "http://renkan.org/edges/edge" + i, "#ffff0" + i,
+ this.testNodes.get((i + 2) % 3), this.testNodes.get(i),
+ "test_user", copyProject.getId());
+ edge = this.edgesRepository.save(edge);
+ copyProject.getEdges().add(edge);
+ this.testEdges.add(edge);
+ }
+
+ this.projectsRepository.save(copyProject);
+
+ }
- }
-
- @After
- public void teardown() {
- logger.debug("Teardown");
- edgesRepository.deleteAll();
- nodesRepository.deleteAll();
- projectRevisionsRepository.deleteAll();
- projectsRepository.deleteAll();
- spacesRepository.deleteAll();
- usersRepository.deleteAll();
- }
-
- @Test
- public void testInitialRevCounter() {
-
- Project p = projectsRepository.findOne(this.testProjects.get(0).getId());
-
- Assert.assertEquals("Initial rev counter should be 1", 1, p.getRevCounter());
- }
-
- @Test
- public void testIncrementRevCounter() {
-
- int revCounter = projectsRepository.getRevCounter(this.testProjects.get(0).getId());
- Assert.assertEquals("After 1 call rev counter should be 1", 1, revCounter);
- revCounter = projectsRepository.getRevCounter(this.testProjects.get(0).getId());
- Assert.assertEquals("After 2 calls rev counter should be 2", 2, revCounter);
+ @After
+ public void teardown() {
+ logger.debug("Teardown");
+ edgesRepository.deleteAll();
+ nodesRepository.deleteAll();
+ projectRevisionsRepository.deleteAll();
+ projectsRepository.deleteAll();
+ spacesRepository.deleteAll();
+ usersRepository.deleteAll();
+ }
+
+ @Test
+ public void testInitialRevCounter() {
+
+ Project p = projectsRepository
+ .findOne(this.testProjects.get(0).getId());
+
+ Assert.assertEquals("Initial rev counter should be 1", 1,
+ p.getRevCounter());
+ }
+
+ @Test
+ public void testIncrementRevCounter() {
+
+ int revCounter = projectsRepository.getRevCounter(this.testProjects
+ .get(0).getId());
+ Assert.assertEquals("After 1 call rev counter should be 1", 1,
+ revCounter);
+ revCounter = projectsRepository.getRevCounter(this.testProjects.get(0)
+ .getId());
+ Assert.assertEquals("After 2 calls rev counter should be 2", 2,
+ revCounter);
+
+ for (int i = 0; i < 10; i++) {
+ revCounter = projectsRepository.getRevCounter(this.testProjects
+ .get(0).getId());
+ }
+
+ Assert.assertEquals("After 10 more calls rev counter should be 12", 12,
+ revCounter);
+
+ Project p = projectsRepository
+ .findOne(this.testProjects.get(0).getId());
- for(int i=0; i<10; i++) {
- revCounter = projectsRepository.getRevCounter(this.testProjects.get(0).getId());
- }
-
- Assert.assertEquals("After 10 more calls rev counter should be 12", 12, revCounter);
-
- Project p = projectsRepository.findOne(this.testProjects.get(0).getId());
-
- Assert.assertEquals("next rev counter should be 13", 13, p.getRevCounter());
-
- p = projectsRepository.findOne(this.testProjects.get(1).getId());
-
- Assert.assertEquals("other project next rev counter should be 1", 1, p.getRevCounter());
-
- }
-
-
- @Test
- public void testIncrementNonExisting() {
-
- int revCounter = projectsRepository.getRevCounter("aaaa");
- Assert.assertEquals("Rev counter non existing == -1", -1, revCounter);
-
- }
-
- @Test
- public void testIncrementNull() {
-
- int revCounter = projectsRepository.getRevCounter(null);
- Assert.assertEquals("Rev counter null == -1", -1, revCounter);
-
- }
+ Assert.assertEquals("next rev counter should be 13", 13,
+ p.getRevCounter());
+
+ p = projectsRepository.findOne(this.testProjects.get(1).getId());
+
+ Assert.assertEquals("other project next rev counter should be 1", 1,
+ p.getRevCounter());
+
+ }
+
+ @Test
+ public void testIncrementNonExisting() {
+
+ int revCounter = projectsRepository.getRevCounter("aaaa");
+ Assert.assertEquals("Rev counter non existing == -1", -1, revCounter);
+
+ }
+
+ @Test
+ public void testIncrementNull() {
+
+ int revCounter = projectsRepository.getRevCounter(null);
+ Assert.assertEquals("Rev counter null == -1", -1, revCounter);
+
+ }
+
+ @Test
+ public void testIncrementEmpty() {
+
+ int revCounter = projectsRepository.getRevCounter("");
+ Assert.assertEquals("Rev counter empty == -1", -1, revCounter);
+
+ }
+
+ @Test
+ public void testDateCreation() {
+
+ for (Project p : projectsRepository.findAll()) {
+ Assert.assertEquals(this.creationDate, p.getCreated());
+ }
+ }
+
+ @Test
+ public void testGetCountBySpace() {
+
+ Map<String, Integer> groupRes = projectsRepository.getCountBySpace();
+
+ Assert.assertNotNull("GroupRes not null", groupRes);
+ Assert.assertEquals("Group res size", SPACE_NB - 1, groupRes.size());
+
+ for (int i = 0; i < (SPACE_NB - 1); i++) {
+ Integer count = groupRes.get(this.spaceIds.get(i));
+ Assert.assertNotNull("count not null", count);
+ Assert.assertEquals("Nb of project/space", 2 - i, count.intValue());
+ }
+
+ Assert.assertNull("Last space id has no project i.e count is null",
+ groupRes.get(this.spaceIds.get(SPACE_NB - 1)));
+ }
+
+ @Test
+ public void testGetCountBySpaceFilter() {
+
+ List<String> spacesIdsFilter = Arrays.asList(this.spaceIds.get(0));
+
+ Map<String, Integer> groupRes = projectsRepository
+ .getCountBySpace(spacesIdsFilter);
+
+ Assert.assertNotNull("GroupRes not null", groupRes);
+ Assert.assertEquals("Group res size", 1, groupRes.size());
+
+ Integer count = groupRes.get(this.spaceIds.get(0));
+ Assert.assertNotNull("count not null", count);
+ Assert.assertEquals("Nb of project/space", 2, count.intValue());
- @Test
- public void testIncrementEmpty() {
-
- int revCounter = projectsRepository.getRevCounter("");
- Assert.assertEquals("Rev counter empty == -1", -1, revCounter);
-
- }
-
- @Test
- public void testDateCreation() {
-
- for (Project p : projectsRepository.findAll()) {
- Assert.assertEquals(this.creationDate, p.getCreated());
- }
- }
-
- @Test
- public void testGetCountBySpace() {
-
- Map<String, Integer> groupRes = projectsRepository.getCountBySpace();
-
- Assert.assertNotNull("GroupRes not null", groupRes);
- Assert.assertEquals("Group res size", SPACE_NB-1, groupRes.size());
-
- for(int i=0;i<(SPACE_NB-1);i++) {
- Integer count = groupRes.get(this.spaceIds.get(i));
- Assert.assertNotNull("count not null", count);
- Assert.assertEquals("Nb of project/space", 2-i, count.intValue());
- }
-
- Assert.assertNull("Last space id has no project i.e count is null", groupRes.get(this.spaceIds.get(SPACE_NB-1)));
- }
-
- @Test
- public void testGetCountBySpaceFilter() {
-
- List<String> spacesIdsFilter = Arrays.asList(this.spaceIds.get(0));
-
- Map<String, Integer> groupRes = projectsRepository.getCountBySpace(spacesIdsFilter);
-
- Assert.assertNotNull("GroupRes not null", groupRes);
- Assert.assertEquals("Group res size", 1, groupRes.size());
-
- Integer count = groupRes.get(this.spaceIds.get(0));
- Assert.assertNotNull("count not null", count);
- Assert.assertEquals("Nb of project/space", 2, count.intValue());
-
- for(int i=1; i<SPACE_NB; i++) {
- Assert.assertNull("other space id has no project i.e count is null", groupRes.get(this.spaceIds.get(i)));
- }
- }
+ for (int i = 1; i < SPACE_NB; i++) {
+ Assert.assertNull(
+ "other space id has no project i.e count is null",
+ groupRes.get(this.spaceIds.get(i)));
+ }
+ }
+
+ @Test
+ public void testGetCountByUser() {
+
+ Map<String, Integer> groupRes = projectsRepository.getCountByUser();
+ int nu = this.testUsers.size();
+
+ Assert.assertNotNull("GroupRes not null", groupRes);
+ Assert.assertEquals("Group res size", nu, groupRes.size());
+
+ for (int i = 0; i < nu - 1; i++) {
+ Integer count = groupRes.get(this.testUsers.get(i).getId());
+ Assert.assertNotNull("count not null", count);
+ Assert.assertEquals("Nb of user/project", testProjects.size() - i,
+ count.intValue());
+ }
+ Assert.assertNull("Last user id has no project i.e count is null",
+ groupRes.get(this.testUsers.get(nu - 1).getId()));
+
+ Integer count = groupRes.get(null);
+ Assert.assertNotNull("count not null", count);
+ Assert.assertEquals("Nb of anonymous user/project", (nu - 1) * (nu - 2)
+ / 2, count.intValue());
+ }
+
+ @Test
+ public void testGetCountByUserFilter() {
+
+ List<String> userIdsFilter = Arrays.asList(this.testUsers.get(0)
+ .getId());
+
+ Map<String, Integer> groupRes = projectsRepository
+ .getCountByUser(userIdsFilter);
+
+ Assert.assertNotNull("GroupRes not null", groupRes);
+ Assert.assertEquals("Group res size", 1, groupRes.size());
- @Test
- public void testGetCountByUser() {
-
- Map<String, Integer> groupRes = projectsRepository.getCountByUser();
- int nu = this.testUsers.size();
-
- Assert.assertNotNull("GroupRes not null", groupRes);
- Assert.assertEquals("Group res size", nu, groupRes.size());
-
- for(int i=0;i<nu-1;i++) {
- Integer count = groupRes.get(this.testUsers.get(i).getId());
- Assert.assertNotNull("count not null", count);
- Assert.assertEquals("Nb of user/project", testProjects.size()-i, count.intValue());
- }
- Assert.assertNull("Last user id has no project i.e count is null", groupRes.get(this.testUsers.get(nu-1).getId()));
-
- Integer count = groupRes.get(null);
- Assert.assertNotNull("count not null", count);
- Assert.assertEquals("Nb of anonymous user/project", (nu-1)*(nu-2)/2, count.intValue());
- }
-
- @Test
- public void testGetCountByUserFilter() {
-
- List<String> userIdsFilter = Arrays.asList(this.testUsers.get(0).getId());
-
- Map<String, Integer> groupRes = projectsRepository.getCountByUser(userIdsFilter);
-
- Assert.assertNotNull("GroupRes not null", groupRes);
- Assert.assertEquals("Group res size", 1, groupRes.size());
-
- Integer count = groupRes.get(this.testUsers.get(0).getId());
- Assert.assertNotNull("count not null", count);
- Assert.assertEquals("Nb of user/project", testProjects.size(), count.intValue());
+ Integer count = groupRes.get(this.testUsers.get(0).getId());
+ Assert.assertNotNull("count not null", count);
+ Assert.assertEquals("Nb of user/project", testProjects.size(),
+ count.intValue());
+
+ }
+
+ @Test
+ public void testGetCountByUsername() {
+
+ Map<String, Integer> groupRes = projectsRepository.getCountByUsername();
+ int nu = this.testUsers.size() - 1;
+ int nb_username = this.testUsers.size() + (SPACE_NB - 1) * SPACE_NB / 2
+ - 2;
+
+ Assert.assertNotNull("GroupRes not null", groupRes);
+ Assert.assertEquals("Group res size", nb_username, groupRes.size());
- }
-
- @Test
- public void testGetCountByUsername() {
-
- Map<String, Integer> groupRes = projectsRepository.getCountByUsername();
- int nu = this.testUsers.size() - 1;
- int nb_username = this.testUsers.size() + (SPACE_NB-1)*SPACE_NB/2 -2;
-
- Assert.assertNotNull("GroupRes not null", groupRes);
- Assert.assertEquals("Group res size", nb_username, groupRes.size());
-
- for(int i=0;i<nu-1;i++) {
- Integer count = groupRes.get(this.testUsers.get(i).getUsername());
- Assert.assertNotNull("count not null", count);
- Assert.assertEquals("Nb of user/project", testProjects.size()-i, count.intValue());
- }
- Assert.assertNull("Last user id has no project i.e count is null", groupRes.get(this.testUsers.get(nu).getUsername()));
-
- for(int i=1;i<nu;i++) {
- String anonymous_username = String.format("Anonymous-%d", i);
- Integer count = groupRes.get(anonymous_username);
- Assert.assertEquals("Nb of anonymous user/project", nu-i, count.intValue());
- }
-
-
- }
+ for (int i = 0; i < nu - 1; i++) {
+ Integer count = groupRes.get(this.testUsers.get(i).getUsername());
+ Assert.assertNotNull("count not null", count);
+ Assert.assertEquals("Nb of user/project", testProjects.size() - i,
+ count.intValue());
+ }
+ Assert.assertNull("Last user id has no project i.e count is null",
+ groupRes.get(this.testUsers.get(nu).getUsername()));
+ for (int i = 1; i < nu; i++) {
+ String anonymous_username = String.format("Anonymous-%d", i);
+ Integer count = groupRes.get(anonymous_username);
+ Assert.assertEquals("Nb of anonymous user/project", nu - i,
+ count.intValue());
+ }
+
+ }
+
+ @Test
+ public void testGetCountByUsernameFilter() {
+
+ List<String> usernamesFilter = Arrays.asList(this.testUsers.get(0)
+ .getUsername());
+
+ Map<String, Integer> groupRes = projectsRepository
+ .getCountByUsername(usernamesFilter);
- @Test
- public void testGetCountByUsernameFilter() {
-
- List<String> usernamesFilter = Arrays.asList(this.testUsers.get(0).getUsername());
-
- Map<String, Integer> groupRes = projectsRepository.getCountByUsername(usernamesFilter);
-
- Assert.assertNotNull("GroupRes not null", groupRes);
- Assert.assertEquals("Group res size", 1, groupRes.size());
-
- Integer count = groupRes.get(this.testUsers.get(0).getUsername());
- Assert.assertNotNull("count not null", count);
- Assert.assertEquals("Nb of user/project", testProjects.size(), count.intValue());
+ Assert.assertNotNull("GroupRes not null", groupRes);
+ Assert.assertEquals("Group res size", 1, groupRes.size());
+
+ Integer count = groupRes.get(this.testUsers.get(0).getUsername());
+ Assert.assertNotNull("count not null", count);
+ Assert.assertEquals("Nb of user/project", testProjects.size(),
+ count.intValue());
+
+ }
+
+ @Test
+ public void testCopyProjectCreation() {
+ DBCollection coll = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(Project.class));
+
+ DBObject filter = new BasicDBObject();
+ filter.put("_id", copyProject.getId());
+
+ DBCursor resFind = coll.find(filter);
+
+ Assert.assertEquals("The project must be found", 1, resFind.count());
+
+ for (DBObject obj : coll.find(filter)) {
+ Assert.assertEquals("id must be equal", copyProject.getId(),
+ obj.get("_id"));
+ }
+ }
+
+ @Test
+ public void testCopyProjectCopy() {
+
+ Project newProject = this.projectsRepository.copy(this.copyProject,
+ "copy_project");
+
+ DBCollection coll = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(Project.class));
- }
+ DBObject filter = new BasicDBObject();
+ filter.put("_id", newProject.getId());
+
+ DBCursor resFind = coll.find(filter);
+
+ Assert.assertEquals("The project must be found", 1, resFind.count());
+
+ for (DBObject obj : resFind) {
+ Assert.assertEquals("id must be equal", newProject.getId(),
+ obj.get("_id"));
+ Assert.assertEquals("title must be must be copy_project",
+ "copy_project", obj.get("title"));
+ Assert.assertEquals(
+ "space_id must be must be same than copyProject",
+ this.copyProject.getSpaceId(), obj.get("space_id"));
+ }
+
+ filter = new BasicDBObject();
+ filter.put("project_id", newProject.getId());
+
+ DBCollection nodesColl = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(Node.class));
+ resFind = nodesColl.find(filter);
+
+ Assert.assertEquals("Must have 3 nodes", this.copyProject.getNodes()
+ .size(), resFind.count());
+
+ for (DBObject obj : resFind) {
+ // find node with same title in copy project
+ Node originalNode = null;
+ for (Node n : this.copyProject.getNodes()) {
+ if (n.getTitle().equals(obj.get("title"))) {
+ originalNode = n;
+ break;
+ }
+ }
+
+ Assert.assertNotNull("Must fincd original Node", originalNode);
-
-
- @Test
- public void testCopyProjectCreation() {
- DBCollection coll = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Project.class));
-
- DBObject filter = new BasicDBObject();
- filter.put("_id", copyProject.getId());
-
- DBCursor resFind = coll.find(filter);
-
- Assert.assertEquals("The project must be found", 1, resFind.count());
-
- for(DBObject obj: coll.find(filter)) {
- Assert.assertEquals("id must be equal", copyProject.getId(), obj.get("_id"));
- }
- }
-
- @Test
- public void testCopyProjectCopy() {
-
- Project newProject = this.projectsRepository.copy(this.copyProject, "copy_project");
-
- DBCollection coll = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Project.class));
-
- DBObject filter = new BasicDBObject();
- filter.put("_id", newProject.getId());
-
- DBCursor resFind = coll.find(filter);
-
- Assert.assertEquals("The project must be found", 1, resFind.count());
-
- for(DBObject obj: resFind) {
- Assert.assertEquals("id must be equal", newProject.getId(), obj.get("_id"));
- Assert.assertEquals("title must be must be copy_project", "copy_project", obj.get("title"));
- Assert.assertEquals("space_id must be must be same than copyProject", this.copyProject.getSpaceId(), obj.get("space_id"));
- }
-
-
- filter = new BasicDBObject();
- filter.put("project_id", newProject.getId());
-
- DBCollection nodesColl = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Node.class));
- resFind = nodesColl.find(filter);
-
- Assert.assertEquals("Must have 3 nodes", this.copyProject.getNodes().size(), resFind.count());
-
- for(DBObject obj: resFind) {
- // find node with same title in copy project
- Node originalNode = null;
- for(Node n: this.copyProject.getNodes()) {
- if(n.getTitle().equals(obj.get("title"))) {
- originalNode = n;
- break;
- }
- }
-
- Assert.assertNotNull("Must fincd original Node", originalNode);
-
- //color, desc, id diff, uri, created_by, image, position, diff projectif, size
- Assert.assertNotSame("id must be differents", originalNode.getId(), obj.get("_id"));
- Assert.assertNotSame("project id must be differents", originalNode.getProjectId(), obj.get("project_id"));
+ // color, desc, id diff, uri, created_by, image, position, diff
+ // projectif, size
+ Assert.assertNotSame("id must be differents", originalNode.getId(),
+ obj.get("_id"));
+ Assert.assertNotSame("project id must be differents",
+ originalNode.getProjectId(), obj.get("project_id"));
+
+ Assert.assertEquals("same color", originalNode.getColor(),
+ obj.get("color"));
+ Assert.assertEquals("same desc", originalNode.getDescription(),
+ obj.get("description"));
+ Assert.assertEquals("same uri", originalNode.getUri(),
+ obj.get("uri"));
+ Assert.assertEquals("same image", originalNode.getImage(),
+ obj.get("image"));
+ Assert.assertEquals("same position", originalNode.getPosition()
+ .getX(), ((DBObject) obj.get("position")).get("x"));
+ Assert.assertEquals("same position", originalNode.getPosition()
+ .getY(), ((DBObject) obj.get("position")).get("y"));
+ Assert.assertEquals("same size", originalNode.getSize(),
+ obj.get("size"));
+
+ }
+
+ DBCollection edgesColl = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(Edge.class));
+ resFind = edgesColl.find(filter);
+
+ Assert.assertEquals("Must have 3 edges", this.copyProject.getEdges()
+ .size(), resFind.count());
+
+ for (DBObject obj : resFind) {
+ // find node with same title in copy project
+ Edge originalEdge = null;
+ for (Edge e : this.copyProject.getEdges()) {
+ if (e.getTitle().equals(obj.get("title"))) {
+ originalEdge = e;
+ break;
+ }
+ }
- Assert.assertEquals("same color", originalNode.getColor(), obj.get("color"));
- Assert.assertEquals("same desc", originalNode.getDescription(), obj.get("description"));
- Assert.assertEquals("same uri", originalNode.getUri(), obj.get("uri"));
- Assert.assertEquals("same image", originalNode.getImage(), obj.get("image"));
- Assert.assertEquals("same position", originalNode.getPosition().getX(), ((DBObject)obj.get("position")).get("x"));
- Assert.assertEquals("same position", originalNode.getPosition().getY(), ((DBObject)obj.get("position")).get("y"));
- Assert.assertEquals("same size", originalNode.getSize(), obj.get("size"));
-
- }
-
- DBCollection edgesColl = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Edge.class));
- resFind = edgesColl.find(filter);
-
- Assert.assertEquals("Must have 3 edges", this.copyProject.getEdges().size(), resFind.count());
-
- for(DBObject obj: resFind) {
- // find node with same title in copy project
- Edge originalEdge = null;
- for(Edge e: this.copyProject.getEdges()) {
- if(e.getTitle().equals(obj.get("title"))) {
- originalEdge = e;
- break;
- }
- }
-
- Assert.assertNotNull("Must find original Node", originalEdge);
-
- //color, desc, id diff, uri, created_by, image, position, diff projectif, size
- Assert.assertFalse("id must be differents", originalEdge.getId().equals(obj.get("_id")));
- Assert.assertFalse("project id must be differents", originalEdge.getProjectId().equals(obj.get("project_id")));
+ Assert.assertNotNull("Must find original Node", originalEdge);
+
+ // color, desc, id diff, uri, created_by, image, position, diff
+ // projectif, size
+ Assert.assertFalse("id must be differents", originalEdge.getId()
+ .equals(obj.get("_id")));
+ Assert.assertFalse("project id must be differents", originalEdge
+ .getProjectId().equals(obj.get("project_id")));
+
+ Assert.assertEquals("same color", originalEdge.getColor(),
+ obj.get("color"));
+ Assert.assertEquals("same desc", originalEdge.getDescription(),
+ obj.get("description"));
+ Assert.assertEquals("same uri", originalEdge.getUri(),
+ obj.get("uri"));
+
+ // get FromNode
+ DBObject fromNode = nodesColl.findOne(((DBRef) obj.get("from"))
+ .getId());
+ Assert.assertNotNull("fromNode must exits ", fromNode);
+ Assert.assertFalse("must be different from node", originalEdge
+ .getFrom().equals(fromNode.get("_id")));
+ Assert.assertEquals("same from title", originalEdge.getFromNode()
+ .getTitle(), fromNode.get("title"));
+
+ DBObject toNode = nodesColl
+ .findOne(((DBRef) obj.get("to")).getId());
+ Assert.assertNotNull("toNode must exits", toNode);
+ Assert.assertFalse("must be different to node", originalEdge
+ .getTo().equals(toNode.get("_id")));
+ Assert.assertEquals("same to title", originalEdge.getToNode()
+ .getTitle(), toNode.get("title"));
+
+ }
+ }
+
+ @Test
+ public void testDeleteRecursive() {
+
+ List<Node> nodes = copyProject.getNodes();
+ List<Edge> edges = copyProject.getEdges();
+
+ this.projectsRepository.deleteRecursive(copyProject);
- Assert.assertEquals("same color", originalEdge.getColor(), obj.get("color"));
- Assert.assertEquals("same desc", originalEdge.getDescription(), obj.get("description"));
- Assert.assertEquals("same uri", originalEdge.getUri(), obj.get("uri"));
-
-
- // get FromNode
- DBObject fromNode = nodesColl.findOne(((DBRef)obj.get("from")).getId());
- Assert.assertNotNull("fromNode must exits ", fromNode);
- Assert.assertFalse("must be different from node", originalEdge.getFrom().equals(fromNode.get("_id")));
- Assert.assertEquals("same from title", originalEdge.getFromNode().getTitle(), fromNode.get("title"));
-
- DBObject toNode = nodesColl.findOne(((DBRef)obj.get("to")).getId());
- Assert.assertNotNull("toNode must exits", toNode);
- Assert.assertFalse("must be different to node", originalEdge.getTo().equals(toNode.get("_id")));
- Assert.assertEquals("same to title", originalEdge.getToNode().getTitle(), toNode.get("title"));
-
- }
- }
-
- @Test
- public void testDeleteRecursive() {
-
- List<Node> nodes= copyProject.getNodes();
- List<Edge> edges= copyProject.getEdges();
-
- this.projectsRepository.deleteRecursive(copyProject);
-
- DBObject filter = new BasicDBObject();
- filter.put("_id", copyProject.getId());
-
- DBCollection coll = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Project.class));
- DBCursor resFind = coll.find(filter);
-
- Assert.assertEquals("The project must not be found", 0, resFind.count());
-
- filter = new BasicDBObject();
- filter.put("project_id", copyProject.getId());
-
- DBCollection nodesColl = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Node.class));
- resFind = nodesColl.find(filter);
-
- Assert.assertEquals("no nodes left", 0, resFind.count());
-
- for(Node n: nodes) {
- DBObject nobj = nodesColl.findOne(n.getId());
- Assert.assertNull("node should be deleted", nobj);
- }
+ DBObject filter = new BasicDBObject();
+ filter.put("_id", copyProject.getId());
+
+ DBCollection coll = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(Project.class));
+ DBCursor resFind = coll.find(filter);
+
+ Assert.assertEquals("The project must not be found", 0, resFind.count());
+
+ filter = new BasicDBObject();
+ filter.put("project_id", copyProject.getId());
+
+ DBCollection nodesColl = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(Node.class));
+ resFind = nodesColl.find(filter);
+
+ Assert.assertEquals("no nodes left", 0, resFind.count());
+
+ for (Node n : nodes) {
+ DBObject nobj = nodesColl.findOne(n.getId());
+ Assert.assertNull("node should be deleted", nobj);
+ }
+
+ DBCollection edgesColl = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(Edge.class));
+ resFind = edgesColl.find(filter);
+
+ Assert.assertEquals("no edges left", 0, resFind.count());
+
+ for (Edge e : edges) {
+ DBObject eobj = edgesColl.findOne(e.getId());
+ Assert.assertNull("edge should be deleted", eobj);
+ }
+
+ }
-
- DBCollection edgesColl = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Edge.class));
- resFind = edgesColl.find(filter);
-
- Assert.assertEquals("no edges left", 0, resFind.count());
-
- for(Edge e: edges) {
- DBObject eobj = edgesColl.findOne(e.getId());
- Assert.assertNull("edge should be deleted", eobj);
- }
-
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testDeleteRecursiveProjectRevision() {
-
- List<Node> nodes= copyProject.getNodes();
- List<Edge> edges= copyProject.getEdges();
-
- int revCounter = copyProject.getRevCounter();
-
- this.projectsRepository.deleteRecursive(copyProject);
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testDeleteRecursiveProjectRevision() {
+
+ List<Node> nodes = copyProject.getNodes();
+ List<Edge> edges = copyProject.getEdges();
+
+ int revCounter = copyProject.getRevCounter();
+
+ this.projectsRepository.deleteRecursive(copyProject);
+
+ DBCollection coll = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(ProjectRevision.class));
+
+ DBObject filter = new BasicDBObject();
+ filter.put("project", new DBRef(mongoTemplate.getDb(), "projects",
+ copyProject.getId()));
+ filter.put("revision", new Integer(revCounter));
+
+ DBObject revision = coll.findOne(filter);
+
+ Assert.assertNotNull("Must find revision", revision);
+
+ for (DBObject nobj : ((Iterable<DBObject>) revision.get("nodes"))) {
+ Node node = null;
+ for (Node n : nodes) {
+ if (n.getId().equals(nobj.get("_id"))) {
+ node = n;
+ break;
+ }
+ }
+ Assert.assertNotNull("Node must be in the original list", node);
+ Assert.assertEquals("Nodes must have same title", node.getTitle(),
+ nobj.get("title"));
+ }
- DBCollection coll = mongoTemplate.getCollection(mongoTemplate.getCollectionName(ProjectRevision.class));
-
- DBObject filter = new BasicDBObject();
- filter.put("project", new DBRef(mongoTemplate.getDb(), "projects", copyProject.getId()));
- filter.put("revision", new Integer(revCounter));
-
- DBObject revision = coll.findOne(filter);
-
- Assert.assertNotNull("Must find revision", revision);
-
- for(DBObject nobj: ((Iterable<DBObject>)revision.get("nodes"))) {
- Node node = null;
- for(Node n: nodes) {
- if(n.getId().equals(nobj.get("_id"))) {
- node = n;
- break;
- }
- }
- Assert.assertNotNull("Node must be in the original list", node);
- Assert.assertEquals("Nodes must have same title", node.getTitle(), nobj.get("title"));
- }
-
- for(DBObject eobj: ((Iterable<DBObject>)revision.get("edges"))) {
- Edge edge = null;
- for(Edge e: edges) {
- if(e.getId().equals(eobj.get("_id"))) {
- edge = e;
- break;
- }
- }
- Assert.assertNotNull("Edge must be in the original list", edge);
- Assert.assertEquals("Edges must have same title", edge.getTitle(), eobj.get("title"));
- }
-
- }
-
- @Test
- public void testFindBySpaceIdAndTitleRegex() {
-
- List<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(this.spaceIds.get(0), ".*Project.*");
-
- Assert.assertEquals("res must have length " + (SPACE_NB -1) , SPACE_NB-1, res.size());
- for(Project p: res) {
- Assert.assertEquals("project must belong to the same space", this.spaceIds.get(0), p.getSpaceId());
- Assert.assertNotNull("project title must not be null", p.getTitle());
- Assert.assertTrue("project tilte must contains title", p.getTitle().matches(".*project.*"));
- }
- }
-
- @Test
- public void testFindBySpaceIdAndTitleRegexBad() {
-
- List<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(this.spaceIds.get(0), ".*foo.*");
-
- Assert.assertEquals("res must have zero length", 0, res.size());
- }
-
- @Test
- public void testFindBySpaceIdAndTitleRegexPageable() {
-
- PageRequest pr = new PageRequest(0, 1);
-
- Page<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(this.spaceIds.get(0), ".*Project.*", pr);
-
- Assert.assertEquals("res must have length 1", 1, res.getNumberOfElements());
- for(Project p: res) {
- Assert.assertEquals("project must belong to the same space", this.spaceIds.get(0), p.getSpaceId());
- Assert.assertNotNull("project title must not be null", p.getTitle());
- Assert.assertTrue("project tilte must contains title", p.getTitle().matches(".*project.*"));
- }
- }
-
- @Test
- public void testFindBySpaceIdAndTitleRegexPageableBadSize() {
-
- PageRequest pr = new PageRequest(0, 3);
-
- Page<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(this.spaceIds.get(0), ".*Project.*", pr);
-
- Assert.assertEquals("res must have length 2", 2, res.getNumberOfElements());
- for(Project p: res) {
- Assert.assertEquals("project must belong to the same space", this.spaceIds.get(0), p.getSpaceId());
- Assert.assertNotNull("project title must not be null", p.getTitle());
- Assert.assertTrue("project tilte must contains title", p.getTitle().matches(".*project.*"));
- }
- }
-
- @Test
- public void testFindBySpaceIdAndTitleRegexPageableBadPage() {
-
- PageRequest pr = new PageRequest(1, 3);
-
- Page<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(this.spaceIds.get(0), ".*Project.*", pr);
-
- Assert.assertEquals("res must have length 0", 0, res.getNumberOfElements());
- }
+ for (DBObject eobj : ((Iterable<DBObject>) revision.get("edges"))) {
+ Edge edge = null;
+ for (Edge e : edges) {
+ if (e.getId().equals(eobj.get("_id"))) {
+ edge = e;
+ break;
+ }
+ }
+ Assert.assertNotNull("Edge must be in the original list", edge);
+ Assert.assertEquals("Edges must have same title", edge.getTitle(),
+ eobj.get("title"));
+ }
+
+ }
+
+ @Test
+ public void testFindBySpaceIdAndTitleRegex() {
+
+ List<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(
+ this.spaceIds.get(0), ".*Project.*");
+
+ Assert.assertEquals("res must have length " + (SPACE_NB - 1),
+ SPACE_NB - 1, res.size());
+ for (Project p : res) {
+ Assert.assertEquals("project must belong to the same space",
+ this.spaceIds.get(0), p.getSpaceId());
+ Assert.assertNotNull("project title must not be null", p.getTitle());
+ Assert.assertTrue("project tilte must contains title", p.getTitle()
+ .matches(".*project.*"));
+ }
+ }
+
+ @Test
+ public void testFindBySpaceIdAndTitleRegexBad() {
+
+ List<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(
+ this.spaceIds.get(0), ".*foo.*");
+
+ Assert.assertEquals("res must have zero length", 0, res.size());
+ }
+
+ @Test
+ public void testFindBySpaceIdAndTitleRegexPageable() {
+
+ PageRequest pr = new PageRequest(0, 1);
+
+ Page<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(
+ this.spaceIds.get(0), ".*Project.*", pr);
+
+ Assert.assertEquals("res must have length 1", 1,
+ res.getNumberOfElements());
+ for (Project p : res) {
+ Assert.assertEquals("project must belong to the same space",
+ this.spaceIds.get(0), p.getSpaceId());
+ Assert.assertNotNull("project title must not be null", p.getTitle());
+ Assert.assertTrue("project tilte must contains title", p.getTitle()
+ .matches(".*project.*"));
+ }
+ }
+
+ @Test
+ public void testFindBySpaceIdAndTitleRegexPageableBadSize() {
+
+ PageRequest pr = new PageRequest(0, 3);
+
+ Page<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(
+ this.spaceIds.get(0), ".*Project.*", pr);
+
+ Assert.assertEquals("res must have length 2", 2,
+ res.getNumberOfElements());
+ for (Project p : res) {
+ Assert.assertEquals("project must belong to the same space",
+ this.spaceIds.get(0), p.getSpaceId());
+ Assert.assertNotNull("project title must not be null", p.getTitle());
+ Assert.assertTrue("project tilte must contains title", p.getTitle()
+ .matches(".*project.*"));
+ }
+ }
+
+ @Test
+ public void testFindBySpaceIdAndTitleRegexPageableBadPage() {
+
+ PageRequest pr = new PageRequest(1, 3);
+
+ Page<Project> res = this.projectsRepository.findBySpaceIdAndTitleRegex(
+ this.spaceIds.get(0), ".*Project.*", pr);
+
+ Assert.assertEquals("res must have length 0", 0,
+ res.getNumberOfElements());
+ }
}
--- a/server/src/test/java/org/iri_research/renkan/test/repositories/SpacesRepositoryTest.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/test/java/org/iri_research/renkan/test/repositories/SpacesRepositoryTest.java Mon Oct 21 15:00:17 2013 +0200
@@ -32,103 +32,130 @@
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("repositories-context.xml")
public class SpacesRepositoryTest {
-
- private final static int SPACE_NB = 3;
-
- private Logger logger = LoggerFactory.getLogger(SpacesRepositoryTest.class);
-
- @Autowired
- private SpacesRepository spacesRepository;
+
+ private final static int SPACE_NB = 3;
+
+ private Logger logger = LoggerFactory.getLogger(SpacesRepositoryTest.class);
+
+ @Autowired
+ private SpacesRepository spacesRepository;
+
+ @Autowired
+ private MongoTemplate mongoTemplate;
+
+ private Map<String, Space> spacesList = new HashMap<String, Space>(SPACE_NB);
+ private List<String> spacesUuids = new ArrayList<>(SPACE_NB);
+
+ @Before
+ public void setup() {
- @Autowired
- private MongoTemplate mongoTemplate;
-
- private Map<String, Space> spacesList = new HashMap<String, Space>(SPACE_NB);
- private List<String> spacesUuids = new ArrayList<>(SPACE_NB);
-
- @Before
- public void setup() {
-
- logger.debug("Setup");
- spacesRepository.deleteAll();
- for(int i=0;i<SPACE_NB;i++) {
- Date creationDate = new Date();
- String uuid = UUID.randomUUID().toString();
- spacesUuids.add(uuid);
- Space testSpace = new Space(uuid, "test " + i, "Test space " + 1, "{}", "http://ldt.iri.centrepompidou.fr", "#ababab", "test_user", "http://ldt.iri.centrepompidou.fr", creationDate);
- testSpace = spacesRepository.save(testSpace);
- this.spacesList.put(uuid, testSpace);
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
-
- @Test
- public void testFieldMapping() {
- // query json directly with mongodb driver
- // check field values
- DBCollection coll = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Space.class));
-
- for(DBObject obj: coll.find()) {
- Assert.assertTrue("mongo object must have _id field", obj.containsField("_id"));
+ logger.debug("Setup");
+ spacesRepository.deleteAll();
+ for (int i = 0; i < SPACE_NB; i++) {
+ Date creationDate = new Date();
+ String uuid = UUID.randomUUID().toString();
+ spacesUuids.add(uuid);
+ Space testSpace = new Space(uuid, "test " + i, "Test space " + 1,
+ "{}", "http://ldt.iri.centrepompidou.fr", "#ababab",
+ "test_user", "http://ldt.iri.centrepompidou.fr",
+ creationDate);
+ testSpace = spacesRepository.save(testSpace);
+ this.spacesList.put(uuid, testSpace);
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
- String id = obj.get("_id").toString();
-
- Space sp = this.spacesList.get(id);
-
- Assert.assertTrue("mongo object must have title field", obj.containsField("title"));
- Assert.assertEquals("Titles must be the same", obj.get("title"), sp.getTitle());
+ @Test
+ public void testFieldMapping() {
+ // query json directly with mongodb driver
+ // check field values
+ DBCollection coll = mongoTemplate.getCollection(mongoTemplate
+ .getCollectionName(Space.class));
+
+ for (DBObject obj : coll.find()) {
+ Assert.assertTrue("mongo object must have _id field",
+ obj.containsField("_id"));
+
+ String id = obj.get("_id").toString();
+
+ Space sp = this.spacesList.get(id);
+
+ Assert.assertTrue("mongo object must have title field",
+ obj.containsField("title"));
+ Assert.assertEquals("Titles must be the same", obj.get("title"),
+ sp.getTitle());
+
+ Assert.assertTrue("mongo object must have description field",
+ obj.containsField("description"));
+ Assert.assertEquals("description must be the same",
+ obj.get("description"), sp.getDescription());
- Assert.assertTrue("mongo object must have description field", obj.containsField("description"));
- Assert.assertEquals("description must be the same", obj.get("description"), sp.getDescription());
+ Assert.assertTrue("mongo object must have color field",
+ obj.containsField("color"));
+ Assert.assertEquals("Color must be the same", obj.get("color"),
+ sp.getColor());
- Assert.assertTrue("mongo object must have color field", obj.containsField("color"));
- Assert.assertEquals("Color must be the same", obj.get("color"), sp.getColor());
+ Assert.assertTrue("mongo object must have uri field",
+ obj.containsField("uri"));
+ Assert.assertEquals("Uri must be the same", obj.get("uri"),
+ sp.getUri());
- Assert.assertTrue("mongo object must have uri field", obj.containsField("uri"));
- Assert.assertEquals("Uri must be the same", obj.get("uri"), sp.getUri());
+ Assert.assertTrue("mongo object must have image field",
+ obj.containsField("image"));
+ Assert.assertEquals("Image must be the same", obj.get("image"),
+ sp.getImage());
- Assert.assertTrue("mongo object must have image field", obj.containsField("image"));
- Assert.assertEquals("Image must be the same", obj.get("image"), sp.getImage());
-
- Assert.assertTrue("mongo object must have created field", obj.containsField("created"));
- Assert.assertEquals("Created must be the same", obj.get("created"), sp.getCreated());
+ Assert.assertTrue("mongo object must have created field",
+ obj.containsField("created"));
+ Assert.assertEquals("Created must be the same", obj.get("created"),
+ sp.getCreated());
- Assert.assertTrue("mongo object must have bin_config field", obj.containsField("bin_config"));
- Assert.assertEquals("Uri must be the same", obj.get("bin_config"), sp.getBinConfig());
+ Assert.assertTrue("mongo object must have bin_config field",
+ obj.containsField("bin_config"));
+ Assert.assertEquals("Uri must be the same", obj.get("bin_config"),
+ sp.getBinConfig());
+
+ Assert.assertTrue("mongo object must have created_by field",
+ obj.containsField("created_by"));
+ Assert.assertEquals("created by must be the same",
+ obj.get("created_by"), sp.getCreatedBy());
+
+ }
+ }
- Assert.assertTrue("mongo object must have created_by field", obj.containsField("created_by"));
- Assert.assertEquals("created by must be the same", obj.get("created_by"), sp.getCreatedBy());
-
- }
- }
-
- @Test
- public void testPagination() {
-
- Sort s = new Sort(Direction.DESC, "created");
- Pageable p = new PageRequest(0, 2, s);
-
- Page<Space> page = this.spacesRepository.findAll(p);
-
- Assert.assertEquals("page content length must be two", 2, page.getNumberOfElements());
- Assert.assertEquals("id must be id of last created space", this.spacesUuids.get(SPACE_NB-1), page.getContent().get(0).getId());
- Assert.assertEquals("id must be id of last created space", this.spacesUuids.get(SPACE_NB-2), page.getContent().get(1).getId());
-
- p = new PageRequest(1, 2, s);
- page = this.spacesRepository.findAll(p);
- Assert.assertEquals("page content length must be one", 1, page.getNumberOfElements());
- Assert.assertEquals("id must be id of first created space", this.spacesUuids.get(0), page.getContent().get(0).getId());
-
- }
-
- @After
- public void teardown() {
- spacesRepository.deleteAll();
- }
+ @Test
+ public void testPagination() {
+
+ Sort s = new Sort(Direction.DESC, "created");
+ Pageable p = new PageRequest(0, 2, s);
+
+ Page<Space> page = this.spacesRepository.findAll(p);
-
+ Assert.assertEquals("page content length must be two", 2,
+ page.getNumberOfElements());
+ Assert.assertEquals("id must be id of last created space",
+ this.spacesUuids.get(SPACE_NB - 1), page.getContent().get(0)
+ .getId());
+ Assert.assertEquals("id must be id of last created space",
+ this.spacesUuids.get(SPACE_NB - 2), page.getContent().get(1)
+ .getId());
+
+ p = new PageRequest(1, 2, s);
+ page = this.spacesRepository.findAll(p);
+ Assert.assertEquals("page content length must be one", 1,
+ page.getNumberOfElements());
+ Assert.assertEquals("id must be id of first created space",
+ this.spacesUuids.get(0), page.getContent().get(0).getId());
+
+ }
+
+ @After
+ public void teardown() {
+ spacesRepository.deleteAll();
+ }
+
}
--- a/server/src/test/java/org/iri_research/renkan/test/rest/ProjectRestTest.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/test/java/org/iri_research/renkan/test/rest/ProjectRestTest.java Mon Oct 21 15:00:17 2013 +0200
@@ -38,6 +38,7 @@
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
+
//import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -75,7 +76,7 @@
public ProjectRestTest() {
}
- //@Override
+ // @Override
// protected AppDescriptor configure() {
// return new WebAppDescriptor.Builder("org.iri_research.renkan.rest")
// .contextPath("rest")
@@ -87,20 +88,19 @@
// .contextListenerClass(ContextLoaderListener.class)
// .build();
// };
-
+
@Override
protected Application configure() {
ResourceConfig rc = new ResourceConfig()
- .packages("org.iri_research.renkan.rest")
- .register(SpringLifecycleListener.class)
- .register(RequestContextFilter.class)
- .property("contextConfigLocation",
- "classpath:/org/iri_research/renkan/test/rest/rest-context.xml");
+ .packages("org.iri_research.renkan.rest")
+ .register(SpringLifecycleListener.class)
+ .register(RequestContextFilter.class)
+ .property("contextConfigLocation",
+ "classpath:/org/iri_research/renkan/test/rest/rest-context.xml");
rc.setApplicationName("rest");
return rc;
};
-
-
+
@Before
public void setup() {
--- a/server/src/test/java/org/iri_research/renkan/test/rest/SpaceRestTest.java Mon Oct 21 13:58:20 2013 +0200
+++ b/server/src/test/java/org/iri_research/renkan/test/rest/SpaceRestTest.java Mon Oct 21 15:00:17 2013 +0200
@@ -41,8 +41,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-
-
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("rest-context.xml")
public class SpaceRestTest extends JerseyTest {
@@ -95,14 +93,15 @@
"http://ldt.iri.centrepompidou.fr", creationDate);
testSpace = spacesRepository.save(testSpace);
this.spacesList.put(firstSpaceUUID, testSpace);
-
+
Resource resource = Resource.builder(SpacesResource.class).build();
String baseUri = resource.getPath();
- logger.debug("Path is " + baseUri);
+ logger.debug("Path is " + baseUri);
for (Resource cres : resource.getChildResources()) {
- logger.debug(cres.getAllMethods().toString() + " at " + baseUri + "/" + cres.getPath());
+ logger.debug(cres.getAllMethods().toString() + " at " + baseUri
+ + "/" + cres.getPath());
}
-
+
}
@After
@@ -153,7 +152,8 @@
public void testTitle() throws JsonProcessingException, IOException {
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces").request().get(String.class);
+ String respString = WebTarget.path("spaces").request()
+ .get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode spacesList = mapper.readTree(respString);
@@ -176,7 +176,8 @@
public void testDescription() throws JsonProcessingException, IOException {
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces").request().get(String.class);
+ String respString = WebTarget.path("spaces").request()
+ .get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode spacesList = mapper.readTree(respString);
@@ -200,7 +201,8 @@
public void testUri() throws JsonProcessingException, IOException {
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces").request().get(String.class);
+ String respString = WebTarget.path("spaces").request()
+ .get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode spacesList = mapper.readTree(respString);
@@ -223,7 +225,8 @@
public void testColor() throws JsonProcessingException, IOException {
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces").request().get(String.class);
+ String respString = WebTarget.path("spaces").request()
+ .get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode spacesList = mapper.readTree(respString);
@@ -246,7 +249,8 @@
public void testBinConfig() throws JsonProcessingException, IOException {
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces").request().get(String.class);
+ String respString = WebTarget.path("spaces").request()
+ .get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode spacesList = mapper.readTree(respString);
@@ -270,7 +274,8 @@
public void testCreatedBy() throws JsonProcessingException, IOException {
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces").request().get(String.class);
+ String respString = WebTarget.path("spaces").request()
+ .get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode spacesList = mapper.readTree(respString);
@@ -294,7 +299,8 @@
public void testCreated() throws JsonProcessingException, IOException {
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces").request().get(String.class);
+ String respString = WebTarget.path("spaces").request()
+ .get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode spacesList = mapper.readTree(respString);
@@ -322,7 +328,8 @@
public void testImage() throws JsonProcessingException, IOException {
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces").request().get(String.class);
+ String respString = WebTarget.path("spaces").request()
+ .get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode spacesList = mapper.readTree(respString);
@@ -346,9 +353,8 @@
Space space = this.spacesList.get(this.firstSpaceUUID);
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.APPLICATION_JSON)
- .get(String.class);
+ String respString = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON).get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(respString);
@@ -374,9 +380,8 @@
Space space = this.spacesList.get(this.firstSpaceUUID);
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.APPLICATION_JSON)
- .get(String.class);
+ String respString = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON).get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(respString);
@@ -395,9 +400,8 @@
Space space = this.spacesList.get(this.firstSpaceUUID);
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.APPLICATION_JSON)
- .get(String.class);
+ String respString = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON).get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(respString);
@@ -415,9 +419,8 @@
Space space = this.spacesList.get(this.firstSpaceUUID);
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.APPLICATION_JSON)
- .get(String.class);
+ String respString = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON).get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(respString);
@@ -434,9 +437,8 @@
Space space = this.spacesList.get(this.firstSpaceUUID);
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.APPLICATION_JSON)
- .get(String.class);
+ String respString = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON).get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(respString);
@@ -455,9 +457,8 @@
Space space = this.spacesList.get(this.firstSpaceUUID);
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.APPLICATION_JSON)
- .get(String.class);
+ String respString = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON).get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(respString);
@@ -476,9 +477,8 @@
Space space = this.spacesList.get(this.firstSpaceUUID);
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.APPLICATION_JSON)
- .get(String.class);
+ String respString = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON).get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(respString);
@@ -496,9 +496,8 @@
Space space = this.spacesList.get(this.firstSpaceUUID);
WebTarget WebTarget = this.target();
- String respString = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.APPLICATION_JSON)
- .get(String.class);
+ String respString = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON).get(String.class);
logger.debug("RESPONSE : " + respString);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(respString);
@@ -668,9 +667,9 @@
color, image, created, bin_config, created_by);
WebTarget WebTarget = this.target();
- Response resp = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request()//type(MediaType.APPLICATION_JSON)
- .accept(MediaType.APPLICATION_JSON)//.entity(spaceJson)
+ Response resp = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request()// type(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON)// .entity(spaceJson)
.put(Entity.entity(spaceJson, MediaType.APPLICATION_JSON));
String respStr = "";
@@ -727,9 +726,8 @@
color, image, created, bin_config, created_by);
WebTarget WebTarget = this.target();
- Response resp = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request()
- .accept(MediaType.APPLICATION_JSON)
+ Response resp = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.APPLICATION_JSON)
.put(Entity.entity(spaceJson, MediaType.APPLICATION_JSON));
String respStr = resp.readEntity(String.class);
@@ -777,9 +775,8 @@
public void testDelete() {
WebTarget WebTarget = this.target();
- Response resp = WebTarget.path("spaces")
- .path(this.firstSpaceUUID).request().accept(MediaType.TEXT_PLAIN)
- .delete();
+ Response resp = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .request().accept(MediaType.TEXT_PLAIN).delete();
String respStr = resp.readEntity(String.class);
URI reqUri = WebTarget.getUriBuilder().path("spaces")
@@ -802,8 +799,7 @@
public void testSingleGetJsonp() throws JsonProcessingException,
IOException {
WebTarget WebTarget = this.target();
- Response resp = WebTarget.path("spaces")
- .path(this.firstSpaceUUID)
+ Response resp = WebTarget.path("spaces").path(this.firstSpaceUUID)
.queryParam("callback", "callback_func").request()
.accept("application/javascript").get();
Assert.assertEquals("return type must be application/javascript",
@@ -846,10 +842,9 @@
public void testSingleGetJsonpAcceptAll() throws JsonProcessingException,
IOException {
WebTarget WebTarget = this.target();
- Response resp = WebTarget.path("spaces")
- .path(this.firstSpaceUUID)
- .queryParam("callback", "callback_func").request().accept("*/*")
- .get();
+ Response resp = WebTarget.path("spaces").path(this.firstSpaceUUID)
+ .queryParam("callback", "callback_func").request()
+ .accept("*/*").get();
Assert.assertEquals("return type must be application/javascript",
"application/javascript", resp.getMediaType().toString());