Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 3196 discussions
r3922 - trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api
by tchemit@users.chorem.org 08 May '14
by tchemit@users.chorem.org 08 May '14
08 May '14
Author: tchemit
Date: 2014-05-08 09:34:51 +0200 (Thu, 08 May 2014)
New Revision: 3922
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3922
Log:
fix converter test
Modified:
trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java
Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java 2014-05-07 16:20:20 UTC (rev 3921)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java 2014-05-08 07:34:51 UTC (rev 3922)
@@ -1,6 +1,7 @@
package org.chorem.pollen.rest.api;
import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.ChoiceType;
import org.junit.Assert;
import org.junit.Test;
@@ -9,15 +10,24 @@
@Test
public void convertToType() throws Exception {
- String choicesStr = "[ {name: \"choice1\", choiceType: \"TEXT\"}, " +
- "{name: \"choice2\", choiceType: \"IMAGE\"} ]";
+ String choicesStr = "[ {name: \"choice1\", choiceType: \"TEXT\", choiceOrder: 1}, " +
+ "{name: \"choice2\", choiceType: \"IMAGE\", choiceOrder: 2} ]";
TopiaEntityArrayConverter converter = TopiaEntityArrayConverter.newconverter(Choice.class);
- TopiaEntityList<Choice> choices = converter.convert(TopiaEntityList.class, choicesStr);
+ Choice[] choices = converter.convert(Choice[].class, choicesStr);
Assert.assertNotNull(choices);
- Assert.assertEquals(2, choices.size());
+ Assert.assertEquals(2, choices.length);
+ Assert.assertNotNull(choices[0]);
+ Assert.assertEquals("choice1", choices[0].getName());
+ Assert.assertEquals(ChoiceType.TEXT, choices[0].getChoiceType());
+ Assert.assertEquals(1, choices[0].getChoiceOrder());
+ Assert.assertNotNull(choices[1]);
+ Assert.assertEquals("choice2", choices[1].getName());
+ Assert.assertEquals(ChoiceType.IMAGE, choices[1].getChoiceType());
+ Assert.assertEquals(2, choices[1].getChoiceOrder());
+
}
}
\ No newline at end of file
1
0
Build failed in Jenkins: pollen-nightly » Pollen :: Rest Api #21
by admin+ci-chorem.org@codelutin.com 07 May '14
by admin+ci-chorem.org@codelutin.com 07 May '14
07 May '14
See <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
Changes:
[Tony CHEMIT] improve conversions and lots of stuff... to be continued...
[Tony CHEMIT] fix json serialization
[Tony CHEMIT] - receive object as json
- change from gson to jackson since gson can only deal with field accessors :(
- clean deps
------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Pollen :: Rest Api 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti… (2 KB at 1.0 KB/sec)
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti… (613 B at 1.2 KB/sec)
[WARNING] The POM for org.antlr:stringtemplate:jar:3.2.1 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti… (2 KB at 1.3 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ pollen-rest-api ---
[INFO] Deleting <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (ensure-no-container-api) @ pollen-rest-api ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (check-project-files) @ pollen-rest-api ---
[INFO]
[INFO] --- helper-maven-plugin:2.1:share-server-secret (get-redmine-login) @ pollen-rest-api ---
[INFO] Exporting server [redmine-forge.chorem.org] privateKey in ${redmine.apiKey}
[INFO]
[INFO] --- license-maven-plugin:1.6:update-project-license (attach-licenses) @ pollen-rest-api ---
[INFO] Will create or update license file [agpl_v3] to <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO]
[INFO] --- license-maven-plugin:1.6:add-third-party (attach-licenses) @ pollen-rest-api ---
[WARNING] Unable to obtain POM for artifact : org.antlr:stringtemplate:jar:3.2.1:compile
org.apache.maven.project.InvalidProjectModelException: 1 problem was encountered while building the effective model
[FATAL] Non-readable POM /var/local/forge/data/chorem.org/maven/repository/org/antlr/stringtemplate/3.2.1/stringtemplate-3.2.1.pom: input contained no data @
for project for project
at org.apache.maven.project.DefaultMavenProjectBuilder.transformError(DefaultMavenProjectBuilder.java:193)
at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:240)
at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:251)
at org.codehaus.mojo.license.api.DefaultDependenciesTool.loadProjectDependencies(DefaultDependenciesTool.java:206)
at org.codehaus.mojo.license.api.DefaultThirdPartyHelper.loadDependencies(DefaultThirdPartyHelper.java:152)
at org.codehaus.mojo.license.AddThirdPartyMojo.loadDependencies(AddThirdPartyMojo.java:288)
at org.codehaus.mojo.license.AbstractAddThirdPartyMojo.init(AbstractAddThirdPartyMojo.java:386)
at org.codehaus.mojo.license.AbstractLicenseMojo.execute(AbstractLicenseMojo.java:174)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.jvnet.hudson.maven3.launcher.Maven31Launcher.main(Maven31Launcher.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:330)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:238)
at jenkins.maven3.agent.Maven31Main.launch(Maven31Main.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:134)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:69)
at hudson.remoting.UserRequest.perform(UserRequest.java:118)
at hudson.remoting.UserRequest.perform(UserRequest.java:48)
at hudson.remoting.Request$2.run(Request.java:328)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
[INFO] Load missing file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] Missing file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…> is up-to-date.
[INFO] Writing third-party file to <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] Will attach third party file from <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO]
[INFO] >>> i18n-maven-plugin:3.0:bundle (default) @ pollen-rest-api >>>
[INFO]
[INFO] --- i18n-maven-plugin:3.0:collect-i18n-artifacts (collect-i18n-artifacts) @ pollen-rest-api ---
[WARNING] Invalid POM for org.antlr:stringtemplate:jar:3.2.1, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/debux/webmotion…
[INFO] Downloaded: https://oss.sonatype.org/content/repositories/snapshots/org/debux/webmotion… (2 KB at 1.1 KB/sec)
[INFO] Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/debux/webmotion…
[INFO] Downloaded: https://oss.sonatype.org/content/repositories/snapshots/org/debux/webmotion… (613 B at 1.9 KB/sec)
[INFO] collected 2 i18n artifacts for locale fr_FR stored in <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] collected 2 i18n artifacts for locale en_GB stored in <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO]
[INFO] <<< i18n-maven-plugin:3.0:bundle (default) @ pollen-rest-api <<<
[INFO]
[INFO] --- i18n-maven-plugin:3.0:bundle (default) @ pollen-rest-api ---
[WARNING] bundle fr_FR contains 6/70 empty entries! (use -Di18n.showEmpty to see these entries)
[WARNING] bundle en_GB contains 6/70 empty entries! (use -Di18n.showEmpty to see these entries)
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pollen-rest-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] Copying 2 resources
[INFO] Copying 3 resources
[INFO]
[INFO] --- license-maven-plugin:1.6:update-file-header (update-file-header) @ pollen-rest-api ---
[INFO] Will search files to update from root <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] Will search files to update from root <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] - adding license header on file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] - adding license header on file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] - adding license header on file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] - adding license header on file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] - adding license header on file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] - adding license header on file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] - adding license header on file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] - adding license header on file <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] Scan 34 files header done in 181.982ms.
[INFO]
* uptodate header on 26 files.
* add header on 8 files.
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ pollen-rest-api ---
[INFO] Compiling 20 source files to <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[WARNING] <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>:[304,35] getNullValue(java.lang.Class<?>) in org.nuiton.util.ObjectUtil has been deprecated
[WARNING] <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>: Some input files use unchecked or unsafe operations.
[WARNING] <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.10:check (default) @ pollen-rest-api ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java17:1.0
[INFO]
[INFO] --- jredmine-maven-plugin:1.8.1:generate-changes (jredmine-generate-changes) @ pollen-rest-api ---
[INFO] Skipping goal (skipGenerateChanges flag is on).
[INFO]
[INFO] --- maven-antrun-plugin:1.7:run (generate-surefire-workdir) @ pollen-rest-api ---
[INFO] Executing tasks
main:
[mkdir] Created dir: <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] Executed tasks
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pollen-rest-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pollen-rest-api ---
[INFO] Compiling 5 source files to <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>:[38,9] cannot find symbol
symbol: class TopiaEntityList
location: class org.chorem.pollen.rest.api.TopiaEntityArrayConverterTest
[ERROR] <http://ci.chorem.org/jenkins/job/pollen-nightly/org.chorem.pollen$pollen-re…>:[38,61] cannot find symbol
symbol: class TopiaEntityList
location: class org.chorem.pollen.rest.api.TopiaEntityArrayConverterTest
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[JENKINS] Archiving disabled
1
0
r3921 - in trunk/pollen-ui-angular/src/main/webapp: js js/controllers partials
by garandel@users.chorem.org 07 May '14
by garandel@users.chorem.org 07 May '14
07 May '14
Author: garandel
Date: 2014-05-07 18:20:20 +0200 (Wed, 07 May 2014)
New Revision: 3921
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3921
Log:
separate element of model in $scope.data
Modified:
trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
trunk/pollen-ui-angular/src/main/webapp/js/services.js
trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html
trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html
trunk/pollen-ui-angular/src/main/webapp/partials/poll.html
Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-07 15:49:33 UTC (rev 3920)
+++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-07 16:20:20 UTC (rev 3921)
@@ -31,25 +31,26 @@
}, 5000);
});
- $scope.poll = {};
+ $scope.data = {};
+ $scope.data.poll = {};
$scope.toHTML = function (data) {
return $sce.trustAsHtml(data);
}
$scope.inlineVersion = function () {
- $scope.poll.template = 'inline';
+ $scope.data.poll.template = 'inline';
$scope.templateURL = './partials/inline-poll.html';
}
$scope.bigVersion = function () {
- $scope.poll.template = 'big';
+ $scope.data.poll.template = 'big';
$scope.templateURL = './partials/big-poll.html';
}
var initTemplateURL = function () {
- if (angular.isDefined($scope.poll.template)) {
- if ($scope.poll.template == "big") {
+ if (angular.isDefined($scope.data.poll.template)) {
+ if ($scope.data.poll.template == "big") {
$scope.bigVersion();
}
else {
@@ -78,7 +79,7 @@
$scope.globalVariables.editMode = true;
$scope.globalVariables.create = true;
- $scope.globalVariables.voted = angular.isDefined($scope.poll.votants);
+ $scope.globalVariables.voted = angular.isDefined($scope.data.votants);
$scope.globalVariables.lastType = 'TEXT';
$scope.globalVariables.lastDate = new Date();
@@ -88,8 +89,8 @@
});
$scope.addChoice = function () {
- var index = $scope.poll.choice.push(initChoice());
- var choice = $scope.poll.choice[index-1];
+ var index = $scope.data.choices.push(initChoice());
+ var choice = $scope.data.choices[index-1];
popupChoice(choice, 'Add Choice');
}
@@ -97,10 +98,10 @@
popupChoice(choice, 'Edit Choice');
}
- var deleteChoice = function (ch) {
- var index = $scope.poll.choice.indexOf(ch);
+ var deleteChoice = function (choice) {
+ var index = $scope.data.choices.indexOf(choice);
if (index > -1) {
- $scope.poll.choice.splice(index,1);
+ $scope.data.choices.splice(index,1);
}
}
@@ -110,12 +111,12 @@
controller : PollPopChoiceCtrl,
resolve : {
title : function () { return title;},
- choice : function () { return choice; }
+ choice : function () { return choice;}
}
});
- modalInstance.result.then(function (ch) {
- deleteChoice(ch);
+ modalInstance.result.then(function (choice) {
+ deleteChoice(choice);
}, function () {
$scope.globalVariables.lastType = choice.choiceType;
$scope.globalVariables.lastDate = choice.date;
@@ -128,7 +129,7 @@
controller : PollPopupSettingsCtrl,
size : 'lg',
resolve : { poll: function () {
- return $scope.poll;
+ return $scope.data.poll;
}
}
});
@@ -158,43 +159,41 @@
}
var PollPopupSettingsCtrl = function ($scope, $filter, $modalInstance, poll) {
- $scope.poll = poll;
- $scope.toDay = new Date();
+ $scope.data.poll = poll;
+ $scope.data.toDay = new Date();
- $scope.$watch('poll.beginDate', function() {
- if (poll.beginChoiceDate) {
- if (poll.beginChoiceDate < poll.beginDate) {
- poll.beginChoiceDate = poll.beginDate;
+ $scope.$watch('data.poll.beginDate', function() {
+ if (data.poll.beginChoiceDate) {
+ if (data.poll.beginChoiceDate < data.poll.beginDate) {
+ data.poll.beginChoiceDate = data.poll.beginDate;
}
}
else {
- poll.beginChoiceDate = poll.beginDate;
+ data.poll.beginChoiceDate = data.poll.beginDate;
}
});
- $scope.$watch('poll.endDate', function() {
- if (poll.endChoiceDate) {
- if (poll.endChoiceDate > poll.endDate) {
- poll.endChoiceDate = poll.endDate;
+ $scope.$watch('data.poll.endDate', function() {
+ if (data.poll.endChoiceDate) {
+ if (data.poll.endChoiceDate > data.poll.endDate) {
+ data.poll.endChoiceDate = data.poll.endDate;
}
}
- /*
else {
- poll.endChoiceDate = poll.endDate;
+ data.poll.endChoiceDate = data.poll.endDate;
}
- */
});
if (!angular.isDefined($scope.poll.continuousResults)) {
- $scope.poll.continuousResults = false;
+ $scope.data.poll.continuousResults = false;
}
if (!angular.isDefined($scope.poll.resultVisibility)) {
- $scope.poll.resultVisibility = 'EVERYBODY';
+ $scope.data.poll.resultVisibility = 'EVERYBODY';
}
if (!angular.isDefined($scope.poll.choiceAddAllowed)) {
- $scope.poll.choiceAddAllowed = false;
+ $scope.data.poll.choiceAddAllowed = false;
}
$scope.close = function () {
@@ -213,22 +212,33 @@
}])
-.controller('PollCreateCtrl', ['$scope', '$controller', 'Poll', '$http', function ($scope, $controller, Poll, $http) {
+.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', function ($scope, $controller, $location, Poll) {
$controller('PollAdminCtrl', {$scope:$scope});
var initPoll = function () {
- Poll.get({cmd:'new'}).$promise.then(function (poll) {
- $scope.poll = poll;
- $scope.poll.choice = [];
- $scope.vote = {};
- $scope.vote.choice = $scope.poll.choice;
- })
+ Poll.get({cmd:'new'}, function (poll) {
+ $scope.data.poll = poll;
+ $scope.data.choices = [];
+ $scope.data.vote = {};
+ $scope.data.vote.choices = $scope.data.choices;
+ $scope.restRequest = poll;
+ });
}
initPoll();
$scope.save = function () {
if ($scope.formValid) {
- $scope.poll.$add();
+ var poll = angular.copy($scope.data.poll);
+ poll.choice = angular.copy($scope.data.choices);
+ Poll.add(poll, function (data) {
+ $scope.globalVariables.saved = true;
+ $scope.globalVariables.restError = false;
+ $location.path('/poll/edit/'+data.topiaId);
+ }, function (error) {
+ $scope.globalVariables.restError = true;
+ $scope.restError = error;
+ }
+ );
}
else {
$scope.globalVariables.errorForm = true;
@@ -236,7 +246,7 @@
}
$scope.delete = function () {
- $scope.poll = initPoll();
+ $scope.data.poll = initPoll();
}
}])
@@ -246,19 +256,19 @@
var initPoll = function () {
Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) {
- $scope.poll = poll;
- PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) {
- $scope.poll.choice = choices;
- $scope.vote = {};
- $scope.vote.choice = $scope.poll.choice;
- });
+ $scope.data.poll = poll;
});
+ PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) {
+ $scope.data.choices = choices;
+ $scope.data.vote = {};
+ $scope.data.vote.choices = $scope.data.choices;
+ });
}
initPoll();
$scope.save = function () {
if ($scope.formValid) {
- $scope.poll.$update(function () {
+ $scope.data.poll.$update({permission:$scope.data.poll.creator.permission.token}, function () {
$scope.globalVariables.saved = true;
});
}
@@ -269,53 +279,56 @@
}
$scope.delete = function () {
- $scope.poll.$delete();
- $location.path('/');
+ $scope.data.poll.$delete({permission:$scope.data.poll.creator.permission.token}, function() {
+ $location.path('/');
+ });
}
}])
.controller('PollVoteCtrl', ['$scope', '$filter', '$controller', '$routeParams', 'Poll', 'PollChoice', function ($scope, $filter, $controller, $routeParams, Poll, PollChoice) {
$controller('PollCtrl', {$scope:$scope});
- Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) {
- $scope.poll = poll;
- PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) {
- $scope.poll.choice = choices;
- $scope.vote = {};
- $scope.vote.choice = $scope.poll.choice;
+ var initPoll = function () {
+ Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) {
+ $scope.data.poll = poll;
});
- });
+ PollChoice.query({pollId:$routeParams.pollId}, function (choices) {
+ $scope.data.choices = choices;
+ initVote();
+ });
+ }
+ initPoll();
$scope.globalVariables.editMode = false;
- $scope.$watch('vote.name', function (newVal) {
+ $scope.$watch('data.vote.name', function (newVal) {
if (newVal != '') {
$scope.globalVariables.errorForm = false;
}
});
var initVote = function () {
- $scope.vote = {};
- $scope.vote.name = "";
- $scope.vote.choice = [];
- for (var i = 0; i < $scope.poll.choice.length; ++i) {
- if ($scope.poll.choice[i].choiceType == 'TEXT') {
- $scope.vote.choice.push({name:$scope.poll.choice[i].name, value:false});
+ $scope.data.vote = {};
+ $scope.data.vote.name = "";
+ $scope.data.vote.choices = [];
+ for (var i = 0; i < $scope.data.choices.length; ++i) {
+ if ($scope.data.choices[i].choiceType == 'TEXT') {
+ $scope.data.vote.choices.push({name:$scope.data.choices[i].name, value:false});
}
- else if ($scope.poll.choice[i].choiceType == 'DATE') {
- $scope.vote.choice.push({name: $scope.poll.choice[i].date , value:false});
+ else if ($scope.poll.choices[i].choiceType == 'DATE') {
+ $scope.data.choices.push({name: $scope.data.choices[i].date , value:false});
}
}
}
$scope.voter = function () {
- if ($scope.vote.name != '') {
+ if ($scope.data.vote.name != '') {
var data = {};
- data.name = $scope.vote.name;
- data.choice = angular.copy($scope.vote.choice);
- if (!angular.isDefined($scope.poll.votants)) {
- $scope.poll.votants = [];
+ data.name = $scope.data.vote.name;
+ data.choices = angular.copy($scope.data.vote.choices);
+ if (!angular.isDefined($scope.data.votants)) {
+ $scope.data.votants = [];
}
- $scope.poll.votants.push(data);
+ $scope.data.votants.push(data);
// save vote
@@ -332,7 +345,7 @@
.controller('PollListCtrl', ['$scope', '$controller', 'Poll', function ($scope, $controller, Poll) {
$controller('PollCtrl', {$scope:$scope});
- $scope.polls = Poll.query();
+ $scope.data.polls = Poll.query();
}])
Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-07 15:49:33 UTC (rev 3920)
+++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-07 16:20:20 UTC (rev 3921)
@@ -21,6 +21,7 @@
angular.module('pollenServices', ['ngResource'])
.factory('BaseUrl', function() {
+
return 'http://localhost\\:8080/pollen-rest-api/v1';
})
@@ -41,15 +42,35 @@
transformRequest : function (data, headersGetter) {
return transformParam(data);
}
+ },
+ 'delete' : {
+ method : 'DELETE'
}
});
}])
.factory('PollChoice', ['$resource', 'BaseUrl', function ($resource, BaseUrl) {
+
+ var transformParam = function (data) {
+ var obj = angular.copy(data);
+ return 'choices='+JSON.stringify(obj);
+ };
+
return $resource(BaseUrl+'/polls/:pollId/choices/:choiceId', {choiceId : '@topiaId'},
{
- 'add' : { method:'POST'},
- 'update' : {method:'PUT'}
+ 'add' : {
+ method:'POST',
+ transformRequest : function (data, headersGetter) {
+ return transformParam(data);
+ }
+ },
+ 'update' :
+ {
+ method:'PUT',
+ transformRequest : function (data, headersGetter) {
+ return transformParam(data);
+ }
+ }
}
);
}])
\ No newline at end of file
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-07 15:49:33 UTC (rev 3920)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-07 16:20:20 UTC (rev 3921)
@@ -25,7 +25,7 @@
<!-- begin print choices -->
<tr>
<td><button ng-if="globalVariables.editMode" ng-click="bigVersion()" class="btn btn-default" >Big version</button></td>
- <td ng-repeat="choice in poll.choice" class="pollChoice pollAnim" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false">
+ <td ng-repeat="choice in data.choices" class="pollChoice pollAnim" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false">
<div ng-if="choice.choiceType == 'TEXT'" edit-me="showEdit" >
<div ng-hide="showEdit && !globalVariables.voted" class="fixe-input" title="{{choice.description}}">{{choice.name}} <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div>
<div ng-show="showEdit && !globalVariables.voted">
@@ -47,8 +47,8 @@
<!-- begin input vote -->
<tr>
- <td class="pollChoice"> <input type="text" class="form-control" placeholder="votre nom" ng-model="vote.name" /> </td>
- <td ng-repeat="choice in vote.choice" class="pollChoice">
+ <td class="pollChoice"> <input type="text" class="form-control" placeholder="votre nom" ng-model="data.vote.name" /> </td>
+ <td ng-repeat="choice in data.vote.choices" class="pollChoice">
<input type="checkbox" name="$index" ng-model="choice.value"/>
</td>
<td>
@@ -58,9 +58,9 @@
<!-- end input vote -->
<!-- begin print vote -->
- <tr ng-repeat="vote in poll.votants track by $index" class="pollAnim">
+ <tr ng-repeat="vote in data.votants track by $index" class="pollAnim">
<td class="pollChoice"> {{vote.name}}</td>
- <td ng-repeat="choice in vote.choice" class="pollChoice">
+ <td ng-repeat="choice in vote.choices" class="pollChoice">
<input type="checkbox" ng-model="choice.value" disabled/>
</td>
</tr>
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html 2014-05-07 15:49:33 UTC (rev 3920)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-list.html 2014-05-07 16:20:20 UTC (rev 3921)
@@ -1,5 +1,5 @@
-<div ng-repeat="poll in polls">
+<div ng-repeat="poll in data.polls">
<h2><a href="#/poll/vote/{{poll.topiaId}}">{{poll.title}}</a> <a href="#/poll/edit/{{poll.topiaId}}"><i class="glyphicon glyphicon-pencil"></i></a></h2>
<p ng-bind-html="toHTML(poll.description)"></p>
<hr/>
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-07 15:49:33 UTC (rev 3920)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-07 16:20:20 UTC (rev 3921)
@@ -22,6 +22,7 @@
<form class="form-inline" name="pollForm" novalidate>
<alert type="danger" ng-if="globalVariables.errorForm"> Champ non remplie </alert>
+ <alert type="danger" ng-if="globalVariables.restError"> {{restError}} </alert>
<alert type="success" ng-if="globalVariables.editMode && globalVariables.saved"> Sondage sauvegardé..</alert>
<alert type="success" ng-if="!globalVariables.editMode && globalVariables.saved"> Vote effectué..</alert>
@@ -29,16 +30,16 @@
<alert type="warning" ng-if="globalVariables.created"> <a href="#/poll/edit/{{pollId}}"> Edition du sondage </a>.. </alert>
<div class="pollTitle" edit-me="showEditTitle">
- <h1 ng-hide="showEditTitle"> {{poll.title || 'Click Me for Editing'}} </h1>
+ <h1 ng-hide="showEditTitle"> {{data.poll.title || 'Click Me for Editing'}} </h1>
- <h1 ng-show="showEditTitle"><input type="text" class="form-control" focus-me="showEditTitle" ng-model="poll.title" ng-exit="showEditTitle = false" required/></h1>
+ <h1 ng-show="showEditTitle"><input type="text" class="form-control" focus-me="showEditTitle" ng-model="data.poll.title" ng-exit="showEditTitle = false" required/></h1>
</div>
<div ng-hide="showEditDesc || !globalVariables.editMode && !poll.description " class="pollDesc" edit-me="showEditDesc">
- <div ng-bind-html="toHTML(poll.description || 'Description (Facultatif). Ce cadre disparait si aucune description n\'est mise')"></div>
+ <div ng-bind-html="toHTML(data.poll.description || 'Description (Facultatif). Ce cadre disparait si aucune description n\'est mise')"></div>
</div>
<div ng-show="showEditDesc" class="pollDesc " ng-exit="showEditDesc = false;">
- <textarea id="descEditor" data-ck-editor ng-model="poll.description"></textarea>
+ <textarea id="descEditor" data-ck-editor ng-model="data.poll.description"></textarea>
<input type="button" value="Return" class="btn btn-primary" ng-click="showEditDesc = false;"/>
</div>
1
0
Author: tchemit
Date: 2014-05-07 17:49:33 +0200 (Wed, 07 May 2014)
New Revision: 3920
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3920
Log:
improve conversions and lots of stuff... to be continued...
Added:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceTopiaDao.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverter.java
trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ErrorMap.java
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java
trunk/pollen-persistence/src/main/xmi/pollen.zargo
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java
trunk/pollen-rest-api/src/main/resources/mapping
trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java
trunk/pollen-services/src/main/resources/fixtures.yaml
trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java
Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceTopiaDao.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceTopiaDao.java (rev 0)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceTopiaDao.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -0,0 +1,17 @@
+package org.chorem.pollen.persistence.entity;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+public class ChoiceTopiaDao extends AbstractChoiceTopiaDao<Choice> {
+
+ public List<Choice> findAll(Poll poll) {
+
+ List<Choice> choices = forPollEquals(poll).
+ setOrderByArguments(Choice.PROPERTY_CHOICE_ORDER).
+ findAll();
+ return ImmutableList.copyOf(choices);
+
+ }
+}
Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -26,6 +26,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+import java.util.List;
import java.util.Set;
/**
@@ -51,7 +52,52 @@
public Set<Poll> findAllFreePolls() {
- return ImmutableSet.copyOf(forPollTypeEquals(PollType.FREE).findAll());
+ List<Poll> polls = forPollTypeEquals(PollType.FREE).findAll();
+ return ImmutableSet.copyOf(polls);
}
+
+ @Override
+ public void delete(Poll entity) {
+
+
+ { // --- remove choices --- //
+
+ ChoiceTopiaDao dao = topiaDaoSupplier
+ .getDao(Choice.class, ChoiceTopiaDao.class);
+ List<Choice> list = dao.forPollEquals(entity).findAll();
+ dao.deleteAll(list);
+
+ }
+
+ { // --- remove votes --- //
+
+ VoteTopiaDao dao = topiaDaoSupplier
+ .getDao(Vote.class, VoteTopiaDao.class);
+ List<Vote> list = dao.forPollEquals(entity).findAll();
+ dao.deleteAll(list);
+
+ }
+
+ { // --- remove comments -- //
+
+ CommentTopiaDao dao = topiaDaoSupplier
+ .getDao(Comment.class, CommentTopiaDao.class);
+ List<Comment> list = dao.forPollEquals(entity).findAll();
+ dao.deleteAll(list);
+
+ }
+
+ { // --- remove voterLists --- //
+
+ VoterListTopiaDao dao = topiaDaoSupplier
+ .getDao(VoterList.class, VoterListTopiaDao.class);
+ List<VoterList> list = dao.forPollEquals(entity).findAll();
+ dao.deleteAll(list);
+
+ }
+
+ super.delete(entity);
+
+ }
}
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -23,11 +23,8 @@
* #L%
*/
-import com.google.common.collect.Sets;
-
import java.util.Date;
import java.util.Objects;
-import java.util.Set;
/**
* TODO
@@ -85,16 +82,16 @@
(endChoiceDate != null && endChoiceDate.before(currentDate));
}
- public static Set<VoterListMember> getAllVoters(Poll poll) {
- Set<VoterListMember> result = Sets.newHashSet();
- if (poll.isVoterListNotEmpty()) {
- for (VoterList list : poll.getVoterList()) {
-
- if (!list.isMemberEmpty()) {
- result.addAll(list.getMember());
- }
- }
- }
- return result;
- }
+// public static Set<VoterListMember> getAllVoters(Poll poll) {
+// Set<VoterListMember> result = Sets.newHashSet();
+// if (poll.isVoterListNotEmpty()) {
+// for (VoterList list : poll.getVoterList()) {
+//
+// if (!list.isMemberEmpty()) {
+// result.addAll(list.getMember());
+// }
+// }
+// }
+// return result;
+// }
}
Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -1,6 +1,7 @@
package org.chorem.pollen.rest.api;
import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
@@ -45,4 +46,10 @@
}
+ public static String entitiesToString(Object o) throws JsonProcessingException {
+
+ return newEntityMapper().writeValueAsString(o);
+
+ }
+
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -48,30 +48,14 @@
// --- init converters --- //
-// serverContext.addConverter(new Converter() {
-// @Override
-// public Object convert(Class type, Object value) {
-// Object result = null;
-// if (value != null) {
-// if (value.getClass().isAssignableFrom(Date.class)) {
-// result = value;
-// } else {
-// Object o = ((Object[]) value)[0];
-// String sTime = o.toString();
-// Long time = Long.parseLong(sTime);
-// result = new Date(time);
-// }
-// }
-// return result;
-// }
-//
-// }, Date.class);
-
for (Class<? extends TopiaEntity> entityClass : PollenEntityEnum.getContractClasses()) {
TopiaEntityConverter<? extends TopiaEntity> converter = TopiaEntityConverter.newconverter(entityClass);
serverContext.addConverter(converter, entityClass);
+ TopiaEntityArrayConverter<? extends TopiaEntity> arrayConverter = TopiaEntityArrayConverter.newconverter(entityClass);
+ serverContext.addConverter(arrayConverter, arrayConverter.getDefaultType());
+
}
// --- init injectors --- //
Added: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverter.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverter.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverter.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -0,0 +1,67 @@
+package org.chorem.pollen.rest.api;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.beanutils.converters.AbstractConverter;
+import org.chorem.pollen.services.PollenTechnicalException;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.io.IOException;
+import java.lang.reflect.Array;
+
+/**
+ * Created on 5/7/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class TopiaEntityArrayConverter<E extends TopiaEntity> extends AbstractConverter {
+
+ protected final Class<E[]> type;
+
+ protected final ObjectMapper mapper;
+
+
+ public static <E extends TopiaEntity> TopiaEntityArrayConverter<E> newconverter(Class<E> entityType) {
+ return new TopiaEntityArrayConverter<>(entityType);
+ }
+
+ public TopiaEntityArrayConverter(Class<E> entityType) {
+ this.type = getArrayClass(entityType);
+ this.mapper = Jsons.newEntityMapper();
+ }
+
+ <T> Class<T[]> getArrayClass(Class<T> clazz) {
+ return (Class<T[]>) Array.newInstance(clazz, 0).getClass();
+ }
+
+ @Override
+ protected <T> T convertToType(Class<T> type, Object value) throws Throwable {
+
+ String stringValue;
+
+ if (value instanceof String) {
+
+ stringValue = (String) value;
+
+ } else {
+
+ stringValue = ((String[]) value)[0];
+
+ }
+
+ try {
+
+ E[] values = mapper.readValue(stringValue, this.type);
+ return (T) values;
+
+ } catch (IOException e) {
+ throw new PollenTechnicalException("Could not convert " + stringValue + " to " + type.getName(), e);
+ }
+
+ }
+
+ @Override
+ protected Class<?> getDefaultType() {
+ return type;
+ }
+}
Property changes on: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -1,7 +1,5 @@
package org.chorem.pollen.rest.api;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.apache.commons.beanutils.converters.AbstractConverter;
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -23,13 +23,17 @@
* #L%
*/
+import com.google.common.collect.Lists;
+import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.services.service.InvalidFormException;
import org.chorem.pollen.services.service.PollService;
import org.chorem.pollen.services.service.PollenPrincipalRef;
import org.debux.webmotion.server.WebMotionController;
import java.io.File;
+import java.util.List;
import java.util.Set;
/**
@@ -82,9 +86,21 @@
}
- public PollenPrincipalRef<Poll> createPoll(PollService pollService, Poll poll) throws InvalidFormException {
+ public PollenPrincipalRef<Poll> createPoll(PollService pollService, Poll poll, Choice[] choices, VoterList[] voterLists) throws InvalidFormException {
- Poll createdPoll = pollService.createPoll(poll);
+ List<Choice> choiceList = null;
+
+ if (choices != null && choices.length > 0) {
+ choiceList = Lists.newArrayList(choices);
+ }
+
+ List<VoterList> voterListList = null;
+
+ if (voterLists != null && voterLists.length > 0) {
+ voterListList = Lists.newArrayList(voterLists);
+ }
+
+ Poll createdPoll = pollService.createPoll(poll, choiceList, voterListList);
PollenPrincipalRef<Poll> principalRef = PollenPrincipalRef.newRef(createdPoll);
return principalRef;
Modified: trunk/pollen-rest-api/src/main/resources/mapping
===================================================================
--- trunk/pollen-rest-api/src/main/resources/mapping 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-rest-api/src/main/resources/mapping 2014-05-07 15:49:33 UTC (rev 3920)
@@ -71,6 +71,7 @@
GET /v1/polls/participated PollApi.getParticipatedPolls
POST /v1/polls PollApi.createPoll
GET /v1/polls/create PollApi.createPoll
+GET /v1/polls/edit PollApi.editPoll
PUT /v1/polls/{pollId} PollApi.editPoll
GET /v1/polls/{pollId} PollApi.getPoll
DELETE /v1/polls/{pollId} PollApi.deletePoll
Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -38,6 +38,8 @@
import java.io.IOException;
import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
import static org.junit.Assert.assertNotNull;
@@ -122,21 +124,23 @@
poll.setVoteVisibility(VoteVisibility.EVERYBODY);
poll.setVoteCountingType(1);
poll.setTitle("title");
+
+ List<Choice> choices = new ArrayList<>();
Choice choice1 = new ChoiceImpl();
choice1.setChoiceType(ChoiceType.TEXT);
choice1.setName("choiceA");
- poll.addChoice(choice1);
+ choices.add(choice1);
Choice choice2 = new ChoiceImpl();
choice2.setChoiceType(ChoiceType.TEXT);
choice2.setName("choiceB");
- poll.addChoice(choice2);
+ choices.add(choice2);
- TopiaEntityConverter<Poll> converter = TopiaEntityConverter.newconverter(Poll.class);
+ String choiceStr = Jsons.entitiesToString(choices);
+ String pollStr = Jsons.entitiesToString(poll);
- String strPoll = converter.convertToString(poll);
-
Request request = createRequest("/v1/polls")
- .addParameter("poll", strPoll)
+ .addParameter("poll", pollStr)
+ .addParameter("choices", choiceStr)
.Post();
String content = request.execute().returnContent().asString();
Added: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java (rev 0)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -0,0 +1,23 @@
+package org.chorem.pollen.rest.api;
+
+import org.chorem.pollen.persistence.entity.Choice;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TopiaEntityArrayConverterTest {
+
+ @Test
+ public void convertToType() throws Exception {
+
+ String choicesStr = "[ {name: \"choice1\", choiceType: \"TEXT\"}, " +
+ "{name: \"choice2\", choiceType: \"IMAGE\"} ]";
+
+ TopiaEntityArrayConverter converter = TopiaEntityArrayConverter.newconverter(Choice.class);
+
+ TopiaEntityList<Choice> choices = converter.convert(TopiaEntityList.class, choicesStr);
+ Assert.assertNotNull(choices);
+ Assert.assertEquals(2, choices.size());
+
+
+ }
+}
\ No newline at end of file
Property changes on: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityArrayConverterTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -1,6 +1,5 @@
package org.chorem.pollen.rest.api;
-import org.chorem.pollen.persistence.entity.ChoiceType;
import org.chorem.pollen.persistence.entity.CommentVisibility;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.PollType;
@@ -27,11 +26,11 @@
Assert.assertEquals(VoteVisibility.ANONYMOUS, poll.getVoteVisibility());
Assert.assertEquals(CommentVisibility.NOBODY, poll.getCommentVisibility());
Assert.assertEquals(PollType.FREE, poll.getPollType());
- Assert.assertEquals(2, poll.sizeChoice());
- Assert.assertEquals("choice1", poll.getChoice(0).getName());
- Assert.assertEquals(ChoiceType.TEXT, poll.getChoice(0).getChoiceType());
- Assert.assertEquals("choice2", poll.getChoice(1).getName());
- Assert.assertEquals(ChoiceType.IMAGE, poll.getChoice(1).getChoiceType());
+// Assert.assertEquals(2, poll.sizeChoice());
+// Assert.assertEquals("choice1", poll.getChoice(0).getName());
+// Assert.assertEquals(ChoiceType.TEXT, poll.getChoice(0).getChoiceType());
+// Assert.assertEquals("choice2", poll.getChoice(1).getName());
+// Assert.assertEquals(ChoiceType.IMAGE, poll.getChoice(1).getChoiceType());
String convert = converter.convert(String.class, poll);
Assert.assertNotNull(convert);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -24,8 +24,10 @@
*/
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
+import org.apache.commons.collections4.CollectionUtils;
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.ChoiceTopiaDao;
import org.chorem.pollen.persistence.entity.Poll;
@@ -49,7 +51,8 @@
Poll poll = getPollService().getPoll(pollId);
- return poll.getChoice();
+ List<Choice> choices = getChoiceDao().findAll(poll);
+ return ImmutableList.copyOf(choices);
}
@@ -74,9 +77,14 @@
checkPermission(PermissionVerb.editPoll, pollId);
Poll poll = getPollService().getPoll(pollId);
+ List<Choice> existingChoices = getChoiceDao().findAll(poll);
- checkChoiceForm(poll, choice);
+ ErrorMap errorMap = checkChoice(existingChoices, choice);
+ errorMap.failIfNotEmpty();
+ // set the choice order
+ choice.setChoiceOrder(existingChoices.size());
+
Choice result = saveChoice(poll, choice);
getPollDao().update(poll);
@@ -94,8 +102,10 @@
checkPermission(PermissionVerb.editChoice, choice.getTopiaId());
Poll poll = getPollService().getPoll(pollId);
+ List<Choice> existingChoices = getChoiceDao().findAll(poll);
- checkChoiceForm(poll, choice);
+ ErrorMap errorMap = checkChoice(existingChoices, choice);
+ errorMap.failIfNotEmpty();
Choice result = saveChoice(poll, choice);
@@ -116,9 +126,7 @@
Poll poll = getPollService().getPoll(pollId);
Choice choice = getChoice(poll, choiceId);
- poll.removeChoice(choice);
-
- getPollDao().update(poll);
+ getChoiceDao().delete(choice);
commit();
//TODO Notify Choice deleted
@@ -128,9 +136,9 @@
Choice result = getChoiceDao().findByTopiaId(choiceId);
- if (!poll.containsChoice(result)) {
+ if (!poll.equals(result.getPoll())) {
- throw new InvalidEntityLinkException(Poll.PROPERTY_CHOICE, poll, result);
+ throw new InvalidEntityLinkException(Choice.PROPERTY_POLL, result, poll);
}
@@ -150,10 +158,11 @@
// get existing choice
choiceToPersist = getChoice(poll, choice.getTopiaId());
+
} else {
// create a new choice
- choiceToPersist = choiceDao.newInstance();
+ choiceToPersist = choiceDao.create();
// create a new principal
PollenPrincipal principal = getSecurityService().generatePollenPrincipal();
@@ -166,7 +175,9 @@
choiceToPersist.setChoiceType(choice.getChoiceType());
choiceToPersist.setCreator(principal);
- poll.addChoice(choiceToPersist);
+ choiceToPersist.setPoll(poll);
+ choiceToPersist.setChoiceOrder(choice.getChoiceOrder());
+
}
switch (choiceToPersist.getChoiceType()) {
@@ -188,21 +199,80 @@
}
- protected void checkChoiceForm(Poll poll, Choice choice) throws InvalidFormException {
+// protected void checkChoiceForm(List<Choice> existingChoices, Choice choice) throws InvalidFormException {
+//
+// //TODO use nuiton validator ?
+// Multimap<String, String> errors = ArrayListMultimap.create();
+//
+// boolean choiceExists = choice.isPersisted();
+//
+// Set<String> choiceNames = Sets.newHashSet();
+//
+// checkNotNull(errors, "choiceType", choice.getChoiceType(), "choiceType can not be null");
+//
+// if (CollectionUtils.isNotEmpty(existingChoices)) {
+//
+// // get all used names
+//
+// for (Choice choice1 : existingChoices) {
+//
+// if (choiceExists &&
+// choice1.getTopiaId().equals(choice.getTopiaId())) {
+// continue;
+// }
+// choiceNames.add(choice1.getName());
+//
+// }
+// }
+//
+// switch (choice.getChoiceType()) {
+//
+// case TEXT:
+//
+// String choiceName = choice.getName();
+// boolean nameNotBlank = checkNotBlank(errors,
+// "name",
+// choiceName,
+// "choice name can not be empty");
+//
+// if (nameNotBlank) {
+// boolean nameAdded = choiceNames.add(choiceName);
+// check(errors, "name", nameAdded, "choice name already used in this list");
+// }
+//
+// break;
+// case DATE:
+//
+// throw new IllegalStateException("Not implemented");
+//
+// case IMAGE:
+//
+// throw new IllegalStateException("Not implemented");
+// }
+//
+// if (!errors.isEmpty()) {
+//
+// throw new InvalidFormException(errors);
+//
+// }
+//
+// }
- //TODO use nuiton validator ?
- Multimap<String, String> errors = ArrayListMultimap.create();
+ protected ErrorMap checkChoice(List<Choice> existingChoices, Choice choice) {
+ ErrorMap errors = new ErrorMap();
+
boolean choiceExists = choice.isPersisted();
Set<String> choiceNames = Sets.newHashSet();
- checkNotNull(errors, "choiceType", choice.getChoiceType(), "choiceType can not be null");
- if (!poll.isChoiceEmpty()) {
+ boolean withChoiceType = checkNotNull(errors, "choiceType", choice.getChoiceType(), "choiceType can not be null");
+ if (CollectionUtils.isNotEmpty(existingChoices)) {
+
// get all used names
- for (Choice choice1 : poll.getChoice()) {
+ for (Choice choice1 : existingChoices) {
if (choiceExists &&
choice1.getTopiaId().equals(choice.getTopiaId())) {
@@ -213,36 +283,37 @@
}
}
- switch (choice.getChoiceType()) {
+ if (withChoiceType) {
- case TEXT:
+ switch (choice.getChoiceType()) {
- String choiceName = choice.getName();
- boolean nameNotBlank = checkNotBlank(errors,
- "name",
- choiceName,
- "choice name can not be empty");
+ case TEXT:
- if (nameNotBlank) {
- boolean nameAdded = choiceNames.add(choiceName);
- check(errors, "name", nameAdded, "choice name already used in this list");
- }
+ String choiceName = choice.getName();
+ boolean nameNotBlank = checkNotBlank(errors,
+ "name",
+ choiceName,
+ "choice name can not be empty");
- break;
- case DATE:
+ if (nameNotBlank) {
+ boolean nameAdded = choiceNames.add(choiceName);
+ check(errors, "name", nameAdded, "choice name already used in this list");
+ }
- throw new IllegalStateException("Not implemented");
+ break;
+ case DATE:
- case IMAGE:
+ throw new IllegalStateException("Not implemented");
- throw new IllegalStateException("Not implemented");
- }
+ case IMAGE:
- if (!errors.isEmpty()) {
+ throw new IllegalStateException("Not implemented");
- throw new InvalidFormException(errors);
-
+ }
}
+ return errors;
+
}
+
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -24,6 +24,7 @@
*/
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.persistence.entity.Comment;
@@ -46,7 +47,8 @@
checkNotNull(pollId);
Poll poll = getPollService().getPoll(pollId);
- return poll.getComment();
+ List<Comment> comments = getCommentDao().forPollEquals(poll).findAll();
+ return ImmutableList.copyOf(comments);
}
@@ -113,9 +115,7 @@
Comment comment = getComment(poll, commentId);
- poll.removeComment(comment);
-
- getPollDao().update(poll);
+ getCommentDao().delete(comment);
commit();
}
@@ -124,9 +124,9 @@
Comment result = getCommentDao().findByTopiaId(commentId);
- if (!poll.containsComment(result)) {
+ if (!poll.equals(result.getPoll())) {
- throw new InvalidEntityLinkException(Poll.PROPERTY_COMMENT, poll, result);
+ throw new InvalidEntityLinkException(Comment.PROPERTY_POLL, result, poll);
}
@@ -174,9 +174,8 @@
PollenPrincipal author = getSecurityService().generatePollenPrincipal();
toSave.setAuthor(author);
+ toSave.setPoll(poll);
- poll.addComment(toSave);
-
}
toSave.setText(comment.getText());
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ErrorMap.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ErrorMap.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ErrorMap.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -0,0 +1,64 @@
+package org.chorem.pollen.services.service;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
+import java.util.Collection;
+
+/**
+ * Created on 5/7/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ErrorMap {
+
+ protected Multimap<String, String> errors;
+
+ public ErrorMap() {
+
+ errors = ArrayListMultimap.create();
+
+ }
+
+ public void addError(String key, String error) {
+
+ errors.put(key, error);
+
+ }
+
+ public void addErrors(String key, Iterable<String> error) {
+
+ errors.putAll(key, error);
+
+ }
+
+ public void copyTo(ErrorMap errorMap, String prefix) {
+
+ for (String key : errors.keySet()) {
+
+ Collection<String> errors = this.errors.get(key);
+
+ errorMap.addErrors(prefix + key, errors);
+ }
+
+ }
+
+ public boolean isEmpty() {
+
+ return errors.isEmpty();
+
+ }
+
+ public Multimap<String, String> getErrors() {
+ return errors;
+ }
+
+ public void failIfNotEmpty() throws InvalidFormException {
+
+ if (!errors.isEmpty()) {
+
+ throw new InvalidFormException(errors);
+ }
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ErrorMap.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -29,6 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.persistence.PollenPersistenceContext;
import org.chorem.pollen.persistence.PollenTopiaApplicationContext;
+import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.PollenUserTopiaDao;
@@ -37,6 +38,7 @@
import org.chorem.pollen.services.service.security.SecurityService;
import java.util.Collection;
+import java.util.List;
import java.util.Map;
public class FixturesService extends PollenServiceSupport {
@@ -102,14 +104,15 @@
PollService pollService = newService(PollService.class);
Collection<Poll> polls = fixtures.fixture("polls");
+ List<Choice> choices= fixtures.fixture("choices");
for (Poll poll : polls) {
try {
- Poll createdPoll = pollService.createPoll(poll);
+ Poll createdPoll = pollService.createPoll(poll, choices, null);
poll.setTopiaId(createdPoll.getTopiaId());
poll.setCreator(createdPoll.getCreator());
- poll.setChoice(createdPoll.getChoice());
+// poll.setChoice(createdPoll.getChoice());
} catch (InvalidFormException e) {
throw new PollenTechnicalException(e);
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -23,23 +23,18 @@
* #L%
*/
-import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.collections4.CollectionUtils;
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.Polls;
import org.chorem.pollen.persistence.entity.VoterList;
-import org.chorem.pollen.persistence.entity.VoterListMember;
import org.chorem.pollen.services.service.security.PermissionVerb;
import java.io.File;
-import java.util.HashSet;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -130,21 +125,22 @@
creator.setEmail(connectedUser.getEmail());
}
- result.setChoice(Lists.<Choice>newArrayList());
- result.setVoterList(Lists.<VoterList>newArrayList());
-
return result;
}
- public Poll createPoll(Poll poll) throws InvalidFormException {
+ public Poll createPoll(Poll poll, List<Choice> choices, List<VoterList> voterLists) throws InvalidFormException {
checkNotNull(poll);
checkIsNotPersisted(poll);
- checkPollForm(poll);
- Poll savedPoll = savePoll(poll);
+ ErrorMap errorMap = checkPoll(poll);
+ checkChoices(errorMap, choices);
+ checkvoterLists(errorMap, poll, voterLists);
+ errorMap.failIfNotEmpty();
+ Poll savedPoll = savePoll(poll, choices, voterLists);
+
getPollDao().create(savedPoll);
commit();
@@ -159,10 +155,12 @@
checkNotNull(poll);
checkIsPersisted(poll);
checkPermission(PermissionVerb.editPoll, poll.getTopiaId());
- checkPollForm(poll);
- Poll savedPoll = savePoll(poll);
+ ErrorMap errorMap = checkPoll(poll);
+ errorMap.failIfNotEmpty();
+ Poll savedPoll = savePoll(poll, null, null);
+
getPollDao().update(savedPoll);
commit();
@@ -228,19 +226,23 @@
}
- protected Poll savePoll(Poll poll) {
+ protected Poll savePoll(Poll poll, List<Choice> choices, List<VoterList> voterLists) {
boolean pollExists = poll.isPersisted();
+ List<Choice> existingChoices;
+
Poll toSave;
if (pollExists) {
toSave = getPoll(poll.getTopiaId());
+ existingChoices = getChoiceDao().findAll(poll);
} else {
toSave = getPollDao().newInstance();
+ existingChoices = new ArrayList<>();
PollenPrincipal creatorToPersist =
getSecurityService().generatePollenPrincipal();
@@ -290,20 +292,29 @@
// -- choice -- //
- for (Choice choice : poll.getChoice()) {
+ if (CollectionUtils.isNotEmpty(choices)) {
- getChoiceService().saveChoice(toSave, choice);
+ ChoiceService choiceService = getChoiceService();
+ for (Choice choice : choices) {
+
+ choice.setChoiceOrder(existingChoices.size());
+ Choice persistedChoice = choiceService.saveChoice(toSave, choice);
+ existingChoices.add(persistedChoice);
+
+ }
}
// -- voting list -- //
- if (!poll.isVoterListEmpty()) {
+ if (CollectionUtils.isNotEmpty(voterLists)) {
- for (VoterList voterList : poll.getVoterList()) {
+ VoterListService voterListService = getVoterListService();
- getVoterListService().saveVoterList(toSave, voterList);
+ for (VoterList voterList : voterLists) {
+ voterListService.saveVoterList(toSave, voterList);
+
}
}
@@ -311,10 +322,152 @@
}
- protected void checkPollForm(Poll poll) throws InvalidFormException {
+// protected void checkPollForm(Poll poll, List<Choice> choices, List<VoterList> voterLists) throws InvalidFormException {
+//
+// //TODO use nuiton validator ?
+// Multimap<String, String> errors = ArrayListMultimap.create();
+//
+// checkNotNull(errors, Poll.PROPERTY_POLL_TYPE, poll.getPollType(), "pollType can not be null");
+// checkNotNull(errors, Poll.PROPERTY_COMMENT_VISIBILITY, poll.getCommentVisibility(), "commentVisibility can not be null");
+// checkNotNull(errors, Poll.PROPERTY_VOTE_VISIBILITY, poll.getVoteVisibility(), "voteVisibility can not be null");
+// checkNotNull(errors, Poll.PROPERTY_VOTE_COUNTING_TYPE, poll.getVoteCountingType(), "voteCountingType can not be null");
+//
+// checkNotBlank(errors, Poll.PROPERTY_TITLE, poll.getTitle(), "title can not be empty");
+//
+// if (!poll.isPersisted()) {
+//
+// // check choices
+// checkNotEmpty(errors, "choice", choices, "need at least one choice");
+//
+// if (CollectionUtils.isNotEmpty(choices)) {
+//
+// // validate choices
+//
+// Set<String> choiceNames = new HashSet<>();
+// int choiceIndex = 0;
+//
+// for (Choice choice : choices) {
+//
+// String choiceField = "choice" + "[" + (choiceIndex++) + "].";
+//
+// checkNotNull(errors,
+// choiceField + Choice.PROPERTY_CHOICE_TYPE,
+// choice.getChoiceType(),
+// "choiceType can not be null");
+// if (choice.getChoiceType() != null) {
+// switch (choice.getChoiceType()) {
+//
+// case TEXT:
+//
+// boolean checkNotBlank = checkNotBlank(errors,
+// choiceField + Choice.PROPERTY_NAME,
+// choice.getName(),
+// "choice name can not be empty");
+//
+// if (checkNotBlank) {
+//
+// // check duplicated name
+//
+// check(errors,
+// choiceField + Choice.PROPERTY_NAME,
+// choiceNames.add(choice.getName()),
+// "Duplicated choice name");
+// }
+// break;
+// case DATE:
+// throw new IllegalStateException("Not implemented");
+//
+// case IMAGE:
+// throw new IllegalStateException("Not implemented");
+// }
+// }
+// }
+// }
+//
+//
+// // check voter lists
+//
+// if (Polls.isPollFree(poll)) {
+// checkEmpty(errors, "voterList", voterLists, "can't have voterList with free poll");
+// } else if (Polls.isPollRestricted(poll)) {
+// check(errors, "voterList", voterLists != null && 1 == voterLists.size(), "must have a unique voterList with a resitricted poll");
+// } else if (Polls.isPollGroup(poll)) {
+// checkNotEmpty(errors, "voterList", voterLists, "must have at least one voterList with a group poll");
+// }
+//
+//
+// if (CollectionUtils.isNotEmpty(voterLists)) {
+//
+// Set<String> voterListNames = Sets.newHashSet();
+//
+// // validate voter lists
+//
+// int voterListIndex = 0;
+//
+// for (VoterList voterList : voterLists) {
+//
+// String voterListField = "voterList" + "[" + (voterListIndex++) + "].";
+//
+// boolean notBlankName = checkNotBlank(errors, voterListField + VoterList.PROPERTY_NAME, voterList.getName(), "voterList name can not be empty");
+//
+// if (notBlankName) {
+// boolean added = voterListNames.add(voterList.getName());
+//
+// check(errors, voterListField + VoterList.PROPERTY_NAME, added, "voterList name already used");
+// }
+// check(errors, voterListField + VoterList.PROPERTY_WEIGHT, voterList.getWeight() > 0, "voterList weight must be greater than 0");
+// boolean withMember = checkNotEmpty(errors, voterListField + VoterList.PROPERTY_MEMBER, voterList.getMember(), "voterList must contains at least one member");
+//
+// if (withMember) {
+// Set<String> voterListMemberNames = Sets.newHashSet();
+// Set<String> voterListMemberEmails = Sets.newHashSet();
+//
+// int voterListMemberIndex = 0;
+//
+// for (VoterListMember voterListMember : voterList.getMember()) {
+//
+// String voterListMemberField = voterListField + VoterList.PROPERTY_MEMBER + "[" + (voterListMemberIndex++) + "].";
+//
+// String voterListMemberName = voterListMember.getName();
+// boolean nameNotNull = checkNotBlank(errors, voterListMemberField + VoterListMember.PROPERTY_NAME, voterListMemberName, "member name can not be empty");
+//
+// if (nameNotNull) {
+// boolean nameAdded = voterListMemberNames.add(voterListMemberName);
+// check(errors, voterListMemberField + VoterListMember.PROPERTY_NAME, nameAdded, "member name already used in this list");
+// }
+//
+// String voterListMemberEmail = voterListMember.getEmail();
+//
+// boolean emailNotNull = checkNotBlank(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, voterListMemberEmail, "member email can not be empty");
+//
+// if (emailNotNull) {
+//
+// voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail);
+//
+// checkValidEmail(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, voterListMemberEmail, "member email is not valid");
+// boolean emailAdded = voterListMemberEmails.add(voterListMemberEmail);
+// check(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, emailAdded, "member email already used in this list");
+// }
+//
+// check(errors, voterListMemberField + VoterListMember.PROPERTY_WEIGHT, voterListMember.getWeight() > 0, "member weight must be greater than 0");
+// }
+// }
+// }
+// }
+// }
+//
+// if (!errors.isEmpty()) {
+//
+// throw new InvalidFormException(errors);
+//
+// }
+//
+// }
+ protected ErrorMap checkPoll(Poll poll) {
+
//TODO use nuiton validator ?
- Multimap<String, String> errors = ArrayListMultimap.create();
+ ErrorMap errors = new ErrorMap();
checkNotNull(errors, Poll.PROPERTY_POLL_TYPE, poll.getPollType(), "pollType can not be null");
checkNotNull(errors, Poll.PROPERTY_COMMENT_VISIBILITY, poll.getCommentVisibility(), "commentVisibility can not be null");
@@ -322,124 +475,70 @@
checkNotNull(errors, Poll.PROPERTY_VOTE_COUNTING_TYPE, poll.getVoteCountingType(), "voteCountingType can not be null");
checkNotBlank(errors, Poll.PROPERTY_TITLE, poll.getTitle(), "title can not be empty");
- checkNotEmpty(errors, Poll.PROPERTY_CHOICE, poll.getChoice(), "need at least one choice");
- if (Polls.isPollFree(poll)) {
- checkEmpty(errors, Poll.PROPERTY_VOTER_LIST, poll.getVoterList(), "can't have voterList with free poll");
- } else if (Polls.isPollRestricted(poll)) {
- check(errors, Poll.PROPERTY_VOTER_LIST, 1 == poll.sizeVoterList(), "must have a unique voterList with a resitricted poll");
- } else if (Polls.isPollGroup(poll)) {
- checkNotEmpty(errors, Poll.PROPERTY_VOTER_LIST, poll.getVoterList(), "must have at least one voterList with a group poll");
- }
+ return errors;
- if (!poll.isChoiceEmpty()) {
+ }
- // validate choices
- Set<String> choiceNames = new HashSet<>();
- int choiceIndex = 0;
+ protected void checkChoices(ErrorMap errorMap, List<Choice> choices) {
- for (Choice choice : poll.getChoice()) {
+ boolean choicesNotEmpty = CollectionUtils.isNotEmpty(choices);
- String choiceField = Poll.PROPERTY_CHOICE + "[" + (choiceIndex++) + "].";
+ check(errorMap, "choice", choicesNotEmpty, "need at least one choice");
- checkNotNull(errors,
- choiceField + Choice.PROPERTY_CHOICE_TYPE,
- choice.getChoiceType(),
- "choiceType can not be null");
- if (choice.getChoiceType() != null) {
- switch (choice.getChoiceType()) {
+ if (choicesNotEmpty) {
- case TEXT:
+ List<Choice> existingChoices = new ArrayList<>();
- boolean checkNotBlank = checkNotBlank(errors,
- choiceField + Choice.PROPERTY_NAME,
- choice.getName(),
- "choice name can not be empty");
+ for (int i = 0; i < choices.size(); i++) {
- if (checkNotBlank) {
+ Choice choice = choices.get(i);
- // check duplicated name
+ ErrorMap choiceErrors = getChoiceService().checkChoice(existingChoices, choice);
+ choiceErrors.copyTo(errorMap, "choice[" + i + "].");
- check(errors,
- choiceField + Choice.PROPERTY_NAME,
- choiceNames.add(choice.getName()),
- "Duplicated choice name");
- }
- break;
- case DATE:
- throw new IllegalStateException("Not implemented");
+ existingChoices.add(choice);
- case IMAGE:
- throw new IllegalStateException("Not implemented");
- }
- }
}
+
}
+ }
- if (!poll.isVoterListEmpty()) {
+ protected void checkvoterLists(ErrorMap errorMap, Poll poll, List<VoterList> voterLists) {
- Set<String> voterListNames = Sets.newHashSet();
+ boolean voterListsNotEmpty = CollectionUtils.isNotEmpty(voterLists);
- // validate voter lists
+ if (Polls.isPollFree(poll)) {
- int voterListIndex = 0;
+ checkEmpty(errorMap, "voterList", voterLists, "can't have voterList with free poll");
- for (VoterList voterList : poll.getVoterList()) {
+ } else if (Polls.isPollRestricted(poll)) {
- String voterListField = Poll.PROPERTY_VOTER_LIST + "[" + (voterListIndex++) + "].";
+ check(errorMap, "voterList", voterListsNotEmpty && 1 == voterLists.size(), "must have a unique voterList with a resitricted poll");
- boolean notBlankName = checkNotBlank(errors, voterListField + VoterList.PROPERTY_NAME, voterList.getName(), "voterList name can not be empty");
+ } else if (Polls.isPollGroup(poll)) {
- if (notBlankName) {
- boolean added = voterListNames.add(voterList.getName());
+ check(errorMap, "voterList", voterListsNotEmpty, "must have at least one voterList with a group poll");
- check(errors, voterListField + VoterList.PROPERTY_NAME, added, "voterList name already used");
- }
- check(errors, voterListField + VoterList.PROPERTY_WEIGHT, voterList.getWeight() > 0, "voterList weight must be greater than 0");
- boolean withMember = checkNotEmpty(errors, voterListField + VoterList.PROPERTY_MEMBER, voterList.getMember(), "voterList must contains at least one member");
+ }
- if (withMember) {
- Set<String> voterListMemberNames = Sets.newHashSet();
- Set<String> voterListMemberEmails = Sets.newHashSet();
+ if (voterListsNotEmpty) {
- int voterListMemberIndex = 0;
+ List<VoterList> existingVoterLists = new ArrayList<>();
- for (VoterListMember voterListMember : voterList.getMember()) {
+ for (int i = 0; i < voterLists.size(); i++) {
- String voterListMemberField = voterListField + VoterList.PROPERTY_MEMBER + "[" + (voterListMemberIndex++) + "].";
+ VoterList voterList = voterLists.get(i);
- String voterListMemberName = voterListMember.getName();
- boolean nameNotNull = checkNotBlank(errors, voterListMemberField + VoterListMember.PROPERTY_NAME, voterListMemberName, "member name can not be empty");
+ ErrorMap voterListErrors = getVoterListService().checkVoterList(existingVoterLists, voterList);
- if (nameNotNull) {
- boolean nameAdded = voterListMemberNames.add(voterListMemberName);
- check(errors, voterListMemberField + VoterListMember.PROPERTY_NAME, nameAdded, "member name already used in this list");
- }
+ voterListErrors.copyTo(errorMap, "voterList[" + i + "].");
- String voterListMemberEmail = voterListMember.getEmail();
+ existingVoterLists.add(voterList);
- boolean emailNotNull = checkNotBlank(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, voterListMemberEmail, "member email can not be empty");
-
- if (emailNotNull) {
-
- voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail);
-
- checkValidEmail(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, voterListMemberEmail, "member email is not valid");
- boolean emailAdded = voterListMemberEmails.add(voterListMemberEmail);
- check(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, emailAdded, "member email already used in this list");
- }
-
- check(errors, voterListMemberField + VoterListMember.PROPERTY_WEIGHT, voterListMember.getWeight() > 0, "member weight must be greater than 0");
- }
- }
}
- }
- if (!errors.isEmpty()) {
-
- throw new InvalidFormException(errors);
-
}
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -277,4 +277,42 @@
boolean valid = check(errors, field, StringUtil.isEmail(value), error);
return valid;
}
+
+ protected boolean checkNot(ErrorMap errors, String field, boolean condition, String error) {
+ boolean valid = check(errors, field, !condition, error);
+ return valid;
+ }
+
+ protected boolean checkNotNull(ErrorMap errors, String field, Object value, String error) {
+ boolean valid = check(errors, field, value != null, error);
+ return valid;
+ }
+
+ protected boolean checkEmpty(ErrorMap errors, String field, Collection<?> value, String error) {
+ boolean valid = check(errors, field, CollectionUtils.isEmpty(value), error);
+ return valid;
+ }
+
+ protected boolean checkNotEmpty(ErrorMap errors, String field, Collection<?> value, String error) {
+ boolean valid = check(errors, field, CollectionUtils.isNotEmpty(value), error);
+ return valid;
+ }
+
+ protected boolean checkNotBlank(ErrorMap errors, String field, String value, String error) {
+ boolean valid = check(errors, field, StringUtils.isNotBlank(value), error);
+ return valid;
+ }
+
+ protected boolean checkValidEmail(ErrorMap errors, String field, String value, String error) {
+ boolean valid = check(errors, field, StringUtil.isEmail(value), error);
+ return valid;
+ }
+
+ protected boolean check(ErrorMap errors, String field, boolean condition, String error) {
+ boolean valid = condition;
+ if (!valid) {
+ errors.addError(field, error);
+ }
+ return valid;
+ }
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -24,6 +24,7 @@
*/
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.Polls;
@@ -46,10 +47,9 @@
checkNotNull(pollId);
Poll poll = getPollService().getPoll(pollId);
+ List<Vote> votes = getVoteDao().forPollEquals(poll).findAll();
+ return ImmutableList.copyOf(votes);
- List<Vote> result = poll.getVote();
- return result;
-
}
public Vote getVote(String pollId, String voteId) {
@@ -115,10 +115,8 @@
Poll poll = getPollService().getPoll(pollId);
Vote vote = getVote(poll, voteId);
-
- poll.removeVote(vote);
-
- getPollDao().update(poll);
+
+ getVoteDao().delete(vote);
commit();
//TODO Notify vote deleted
@@ -144,9 +142,9 @@
if (!errors.isEmpty()) {
throw new InvalidFormException(errors);
-
+
}
-
+
}
protected Vote saveVote(Poll poll, Vote vote) {
@@ -168,8 +166,7 @@
// PollenPrincipal author = getSecurityService().generatePollenPrincipal();
// toSave.setAuthor(author);
-
- poll.addVote(toSave);
+ toSave.setPoll(poll);
}
// toSave.setText(vote.getText());
@@ -182,16 +179,16 @@
// }
return toSave;
-
+
}
protected Vote getVote(Poll poll, String voteId) {
Vote result = getVoteDao().findByTopiaId(voteId);
- if (!poll.containsVote(result)) {
+ if (!poll.equals(result.getPoll())) {
- throw new InvalidEntityLinkException(Poll.PROPERTY_VOTE, poll, result);
+ throw new InvalidEntityLinkException(Vote.PROPERTY_POLL, result, poll);
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -24,9 +24,10 @@
*/
import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Lists;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
+import org.apache.commons.collections4.CollectionUtils;
import org.chorem.pollen.persistence.entity.FavoriteList;
import org.chorem.pollen.persistence.entity.FavoriteListMember;
import org.chorem.pollen.persistence.entity.Poll;
@@ -73,9 +74,8 @@
voterListMember.setEmail(favoriteListMember.getEmail());
result.addMember(voterListMember);
}
+ result.setPoll(poll);
- poll.addVoterList(result);
-
getPollDao().update(poll);
commit();
@@ -88,10 +88,9 @@
checkNotNull(pollId);
Poll poll = getPollService().getPoll(pollId);
+ List<VoterList> voterLists = getVoterListDao().forPollEquals(poll).findAll();
+ return ImmutableList.copyOf(voterLists);
- List<VoterList> result = Lists.newArrayList(poll.getVoterList());
- return result;
-
}
public VoterList getVoterList(String pollId, String voterListId) {
@@ -153,9 +152,7 @@
VoterList voterList = getVoterList(poll, voterListId);
- poll.removeVoterList(voterList);
-
- getPollDao().update(poll);
+ getVoterListDao().delete(voterList);
commit();
}
@@ -246,9 +243,9 @@
VoterList result = getVoterListDao().findByTopiaId(voterListId);
- if (!poll.containsVoterList(result)) {
+ if (!poll.equals(result.getPoll())) {
- throw new InvalidEntityLinkException(Poll.PROPERTY_VOTER_LIST, poll, result);
+ throw new InvalidEntityLinkException(VoterList.PROPERTY_POLL, result, poll);
}
@@ -282,10 +279,9 @@
} else {
- toSave = getVoterListDao().newInstance();
+ toSave = getVoterListDao().create();
+ toSave.setPoll(poll);
- poll.addVoterList(toSave);
-
}
toSave.setName(voterList.getName());
@@ -337,11 +333,19 @@
Set<String> voterListNames = Sets.newHashSet();
- if (!poll.isVoterListEmpty()) {
+ List<VoterList> existingVoterLists = null;
+ if (poll.isPersisted()) {
+
+ existingVoterLists = getVoterListDao().forPollEquals(poll).findAll();
+
+ }
+
+ if (CollectionUtils.isNotEmpty(existingVoterLists)) {
+
// get all used names
- for (VoterList lists : poll.getVoterList()) {
+ for (VoterList lists : existingVoterLists) {
if (voterListExists && lists.getTopiaId().equals(voterList.getTopiaId())) {
continue;
@@ -452,4 +456,77 @@
}
}
+
+ protected ErrorMap checkVoterList(List<VoterList> existingVoterLists, VoterList voterList) {
+
+ ErrorMap errors = new ErrorMap();
+
+ boolean voterListExists = voterList.isPersisted();
+
+ Set<String> voterListNames = Sets.newHashSet();
+
+ if (CollectionUtils.isNotEmpty(existingVoterLists)) {
+
+ // get all used names
+
+ for (VoterList lists : existingVoterLists) {
+
+ if (voterListExists && lists.getTopiaId().equals(voterList.getTopiaId())) {
+ continue;
+ }
+
+ voterListNames.add(voterList.getName());
+
+ }
+
+ }
+
+ checkNotBlank(errors, VoterList.PROPERTY_NAME, voterList.getName(), "voterList name can not be empty");
+ check(errors, VoterList.PROPERTY_WEIGHT, voterList.getWeight() > 0, "voterList weight must be greater than 0");
+ checkNotEmpty(errors, VoterList.PROPERTY_MEMBER, voterList.getMember(), "voterList must contains at least one member");
+
+ boolean added = voterListNames.add(voterList.getName());
+
+ check(errors, VoterList.PROPERTY_NAME, added, "voterList name already used");
+
+ Set<String> voterListMemberNames = Sets.newHashSet();
+ Set<String> voterListMemberEmails = Sets.newHashSet();
+
+ int voterListMemberIndex = 0;
+
+ if (voterList.getMember() != null) {
+ for (VoterListMember voterListMember : voterList.getMember()) {
+
+ String voterListMemberField = "member[" + (voterListMemberIndex++) + "].";
+
+ String voterListMemberName = voterListMember.getName();
+ boolean nameNotBlank = checkNotBlank(errors, voterListMemberField + VoterListMember.PROPERTY_NAME, voterListMemberName, "member name can not be empty");
+
+ if (nameNotBlank) {
+
+ boolean nameAdded = voterListMemberNames.add(voterListMemberName);
+ check(errors, voterListMemberField + VoterListMember.PROPERTY_NAME, nameAdded, "member name already used in this list");
+
+ }
+
+ String voterListMemberEmail = getCleanMail(voterListMember.getEmail());
+
+ boolean emailNotBlank = checkNotBlank(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, voterListMemberEmail, "member email can not be empty");
+
+ if (emailNotBlank) {
+
+ checkValidEmail(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, voterListMemberEmail, "member email is not valid");
+ boolean emailAdded = voterListMemberEmails.add(voterListMemberEmail);
+ check(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, emailAdded, "member email already used in this list");
+
+ }
+
+ check(errors, voterListMemberField + VoterListMember.PROPERTY_WEIGHT, voterListMember.getWeight() > 0, "member weight must be greater than 0");
+
+ }
+ }
+
+ return errors;
+
+ }
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -206,7 +206,7 @@
}
- public void checkPermission(String permission) {
+ public boolean isPermitted(String permission) {
Subject subject = getSubject();
@@ -214,8 +214,15 @@
log.info("Check permission: " + permission);
}
- boolean valid = subject.isPermitted(permission);
+ boolean permitted = subject.isPermitted(permission);
+ return permitted;
+ }
+
+ public void checkPermission(String permission) {
+
+ boolean valid = isPermitted(permission);
+
if (!valid) {
throw new PollenInvalidPermissionException(permission);
}
@@ -281,20 +288,29 @@
permissions.add(createSubjectPermission(PermissionVerb.readPoll, poll));
permissions.add(createSubjectPermission(PermissionVerb.readPoll, poll));
- if (poll.isChoiceNotEmpty()) {
- for (Choice choice : poll.getChoice()) {
+ // add choices permissions
+
+ List<Choice> choices = getChoiceDao().forPollEquals(poll).findAll();
+ if (CollectionUtils.isNotEmpty(choices)) {
+ for (Choice choice : choices) {
permissions.add(createSubjectPermission(PermissionVerb.readChoice, choice));
}
}
- if (poll.isCommentNotEmpty()) {
- for (Comment comment : poll.getComment()) {
+ // add comment permissions
+
+ List<Comment> comments = getCommentDao().forPollEquals(poll).findAll();
+ if (CollectionUtils.isNotEmpty(comments)) {
+ for (Comment comment : comments) {
permissions.add(createSubjectPermission(PermissionVerb.readComment, comment));
}
}
- if (poll.isVoteNotEmpty()) {
- for (Vote vote : poll.getVote()) {
+ // add vote permissions
+
+ List<Vote> votes = getVoteDao().forPollEquals(poll).findAll();
+ if (CollectionUtils.isNotEmpty(votes)) {
+ for (Vote vote : votes) {
permissions.add(createSubjectPermission(PermissionVerb.readVote, vote));
}
}
@@ -349,18 +365,29 @@
// creator has all rights on the poll, choices and comments, but can only read votes
permissions.add(createWildcardSubjectPermission(poll));
- if (poll.isChoiceNotEmpty()) {
- for (Choice choice : poll.getChoice()) {
+ // add choices permissions
+
+ List<Choice> choices = getChoiceDao().forPollEquals(poll).findAll();
+ if (CollectionUtils.isNotEmpty(choices)) {
+ for (Choice choice : choices) {
permissions.add(createWildcardSubjectPermission(choice));
}
}
- if (poll.isCommentNotEmpty()) {
- for (Comment comment : poll.getComment()) {
+
+ // add comment permissions
+
+ List<Comment> comments = getCommentDao().forPollEquals(poll).findAll();
+ if (CollectionUtils.isNotEmpty(comments)) {
+ for (Comment comment : comments) {
permissions.add(createWildcardSubjectPermission(comment));
}
}
- if (poll.isVoteNotEmpty()) {
- for (Vote vote : poll.getVote()) {
+
+ // add vote permissions
+
+ List<Vote> votes = getVoteDao().forPollEquals(poll).findAll();
+ if (CollectionUtils.isNotEmpty(votes)) {
+ for (Vote vote : votes) {
permissions.add(createSubjectPermission(PermissionVerb.readVote, vote));
}
}
Modified: trunk/pollen-services/src/main/resources/fixtures.yaml
===================================================================
--- trunk/pollen-services/src/main/resources/fixtures.yaml 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/main/resources/fixtures.yaml 2014-05-07 15:49:33 UTC (rev 3920)
@@ -41,41 +41,63 @@
creator: !pollen-principal
name: poll creator
email: poll_creator(a)pollen.chorem.org
- choice:
- - &normal_choixA !choice
- name: choixA
- description: choixA description
- choiceType: TEXT
- - &normal_choixB !choice
- name: choixB
- description: choixB description
- choiceType: TEXT
- - &normal_choixC !choice
- name: choixC
- description: choixC description
- choiceType: TEXT
- vote:
- - &normal_vote1 !vote
- weight: 1.0
- anonymous: false
- voteToChoice: !java.util.LinkedList
- - &normal_voteToChoice11 !vote-to-choice
- choice: *normal_choixA
- voteValue: 1
- - &normal_voteToChoice12 !vote-to-choice
- choice: *normal_choixC
- voteValue: 1
- - &normal_vote2 !vote
- weight: 1.0
- anonymous: false
- voteToChoice: !java.util.LinkedList
- - &normal_voteToChoice21 !vote-to-choice
- choice: *normal_choixA
- voteValue: 2
- - &normal_voteToChoice22 !vote-to-choice
- choice: *normal_choixB
- voteValue: 2
+# choice:
+# - &normal_choixA !choice
+# name: choixA
+# description: choixA description
+# choiceType: TEXT
+# - &normal_choixB !choice
+# name: choixB
+# description: choixB description
+# choiceType: TEXT
+# - &normal_choixC !choice
+# name: choixC
+# description: choixC description
+# choiceType: TEXT
+# vote:
+# - &normal_vote1 !vote
+# weight: 1.0
+# anonymous: false
+# voteToChoice: !java.util.LinkedList
+# - &normal_voteToChoice11 !vote-to-choice
+# choice: *normal_choixA
+# voteValue: 1
+# - &normal_voteToChoice12 !vote-to-choice
+# choice: *normal_choixC
+# voteValue: 1
+# - &normal_vote2 !vote
+# weight: 1.0
+# anonymous: false
+# voteToChoice: !java.util.LinkedList
+# - &normal_voteToChoice21 !vote-to-choice
+# choice: *normal_choixA
+# voteValue: 2
+# - &normal_voteToChoice22 !vote-to-choice
+# choice: *normal_choixB
+# voteValue: 2
+choiceA:
+ &normal_choixA !choice
+ poll: *normal
+ name: choixA
+ description: choixA description
+ choiceType: TEXT
+
+choiceB:
+ &normal_choixB !choice
+ poll: *normal
+ name: choixB
+ description: choixB description
+ choiceType: TEXT
+
+choices:
+ - *normal_choixA
+ - *normal_choixB
+
+votes:
+ - normal_vote1
+ - normal_vote2
+
users:
- *tony
- *jean
Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java
===================================================================
--- trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2014-05-07 13:14:48 UTC (rev 3919)
+++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2014-05-07 15:49:33 UTC (rev 3920)
@@ -29,8 +29,8 @@
import org.chorem.pollen.persistence.entity.PollType;
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListMember;
+import org.chorem.pollen.services.service.ChoiceService;
import org.chorem.pollen.services.service.InvalidFormException;
-import org.chorem.pollen.services.service.ChoiceService;
import org.chorem.pollen.services.service.PollService;
import org.chorem.pollen.services.service.VoterListService;
import org.chorem.pollen.services.service.security.PollenInvalidPermissionException;
@@ -40,7 +40,9 @@
import org.junit.Test;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
/**
* TODO
@@ -52,12 +54,18 @@
protected PollService service;
+ protected ChoiceService choiceService;
+
+ protected VoterListService voterListService;
+
@Before
public void setUp() throws ParseException {
loadFixtures("fixtures");
service = newService(PollService.class);
+ choiceService = newService(ChoiceService.class);
+ voterListService = newService(VoterListService.class);
getServiceContext().setDate(new Date(1363948427576l));
@@ -72,7 +80,7 @@
poll.setPollType(PollType.FREE);
try {
- service.createPoll(poll);
+ service.createPoll(poll, null, null);
Assert.fail();
} catch (InvalidFormException e) {
// missing title
@@ -82,11 +90,12 @@
poll.setTitle("poll1");
+ List<Choice> choices = new ArrayList<>();
Choice choice1 = getServiceContext().getPersistenceContext().getChoiceDao().newInstance();
- poll.addChoice(choice1);
+ choices.add(choice1);
try {
- service.createPoll(poll);
+ service.createPoll(poll, choices, null);
Assert.fail();
} catch (InvalidFormException e) {
// missing choice type
@@ -95,7 +104,7 @@
choice1.setChoiceType(ChoiceType.TEXT);
try {
- service.createPoll(poll);
+ service.createPoll(poll, choices, null);
Assert.fail();
} catch (InvalidFormException e) {
// missing choice name
@@ -110,10 +119,10 @@
choice2.setChoiceType(ChoiceType.TEXT);
choice2.setName("A");
choice2.setDescription("Choice B");
- poll.addChoice(choice2);
+ choices.add(choice2);
try {
- service.createPoll(poll);
+ service.createPoll(poll, choices, null);
Assert.fail();
} catch (InvalidFormException e) {
// duplicated choice name
@@ -123,7 +132,7 @@
choice2.setName("B");
- Poll createdPoll = service.createPoll(poll);
+ Poll createdPoll = service.createPoll(poll, choices, null);
Assert.assertNotNull(createdPoll);
Assert.assertNotNull(createdPoll.getTopiaId());
@@ -136,19 +145,20 @@
Assert.assertNotNull(createdPoll.getCreator().getTopiaId());
Assert.assertNull(createdPoll.getCreator().getName());
Assert.assertNull(createdPoll.getCreator().getEmail());
- Assert.assertNull(createdPoll.getComment());
- Assert.assertNull(createdPoll.getVote());
- Assert.assertNull(createdPoll.getVoterList());
+// Assert.assertNull(createdPoll.getComment());
+// Assert.assertNull(createdPoll.getVote());
+// Assert.assertNull(createdPoll.getVoterList());
- Assert.assertNotNull(createdPoll.getChoice());
- Assert.assertEquals(2, createdPoll.sizeChoice());
+ List<Choice> createdChoices = choiceService.getChoices(createdPoll.getTopiaId());
+ Assert.assertNotNull(createdChoices);
+ Assert.assertEquals(2, createdChoices.size());
- Choice createdChoice1 = createdPoll.getChoice(0);
+
+ Choice createdChoice1 = createdChoices.get(0);
Assert.assertNotNull(createdChoice1);
Assert.assertNotNull(createdChoice1.getTopiaId());
- ChoiceService choiceService = newService(ChoiceService.class);
Choice reloadedChoice1 = choiceService.getChoice(createdPoll.getTopiaId(), createdChoice1.getTopiaId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
@@ -156,7 +166,7 @@
Assert.assertEquals(choice1.getDescription(), createdChoice1.getDescription());
Assert.assertEquals(createdPoll.getCreator(), createdChoice1.getCreator());
- Choice createdChoice2 = createdPoll.getChoice(1);
+ Choice createdChoice2 = createdChoices.get(1);
Assert.assertNotNull(createdChoice2);
Assert.assertNotNull(createdChoice2.getTopiaId());
@@ -177,35 +187,39 @@
poll.setTitle("poll1");
+ List<Choice> choices = new ArrayList<>();
+
Choice choice1 = getServiceContext().getPersistenceContext().getChoiceDao().newInstance();
choice1.setChoiceType(ChoiceType.TEXT);
choice1.setName("A");
choice1.setDescription("Choice A");
- poll.addChoice(choice1);
+ choices.add(choice1);
Choice choice2 = getServiceContext().getPersistenceContext().getChoiceDao().newInstance();
choice2.setChoiceType(ChoiceType.TEXT);
choice2.setName("B");
choice2.setDescription("Choice B");
- poll.addChoice(choice2);
+ choices.add(choice2);
try {
- service.createPoll(poll);
+ service.createPoll(poll, choices, null);
Assert.fail();
} catch (InvalidFormException e) {
// missing voterList
assertErrorKeyFound(e, "voterList");
}
+ List<VoterList> voterLists = new ArrayList<>();
+
// add voter list
VoterList voterList = getServiceContext().getPersistenceContext().getVoterListDao().newInstance();
- poll.addVoterList(voterList);
+ voterLists.add(voterList);
try {
- service.createPoll(poll);
+ service.createPoll(poll, choices, voterLists);
Assert.fail();
} catch (InvalidFormException e) {
// missing name
@@ -221,7 +235,7 @@
voterList.addMember(voterListMember1);
try {
- service.createPoll(poll);
+ service.createPoll(poll, choices, voterLists);
Assert.fail();
} catch (InvalidFormException e) {
// missing member name
@@ -234,7 +248,7 @@
voterListMember1.setEmail("voter1_pollen.org");
try {
- service.createPoll(poll);
+ service.createPoll(poll, choices, voterLists);
Assert.fail();
} catch (InvalidFormException e) {
// invalid member email
@@ -250,7 +264,7 @@
voterList.addMember(voterListMember2);
try {
- service.createPoll(poll);
+ service.createPoll(poll, choices, voterLists);
Assert.fail();
} catch (InvalidFormException e) {
// same name
@@ -261,7 +275,7 @@
voterListMember2.setName("voter2");
voterListMember2.setEmail("voter2(a)pollen.org");
- Poll createdPoll = service.createPoll(poll);
+ Poll createdPoll = service.createPoll(poll, choices, voterLists);
Assert.assertNotNull(createdPoll);
Assert.assertNotNull(createdPoll.getTopiaId());
@@ -284,17 +298,18 @@
Assert.assertNotNull(createdPoll.getCreator().getTopiaId());
Assert.assertNull(createdPoll.getCreator().getName());
Assert.assertNull(createdPoll.getCreator().getEmail());
- Assert.assertNull(createdPoll.getComment());
- Assert.assertNull(createdPoll.getVote());
+// Assert.assertNull(createdPoll.getComment());
+// Assert.assertNull(createdPoll.getVote());
- Assert.assertNotNull(createdPoll.getChoice());
- Assert.assertEquals(2, createdPoll.sizeChoice());
+ List<Choice> createdChoices = choiceService.getChoices(createdPoll.getTopiaId());
- Choice createdChoice1 = createdPoll.getChoice(0);
+ Assert.assertNotNull(createdChoices);
+ Assert.assertEquals(2, createdChoices.size());
+
+ Choice createdChoice1 = createdChoices.get(0);
Assert.assertNotNull(createdChoice1);
Assert.assertNotNull(createdChoice1.getTopiaId());
- ChoiceService choiceService = newService(ChoiceService.class);
Choice reloadedChoice1 = choiceService.getChoice(createdPoll.getTopiaId(), createdChoice1.getTopiaId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
@@ -302,7 +317,7 @@
Assert.assertEquals(choice1.getDescription(), createdChoice1.getDescription());
Assert.assertEquals(createdPoll.getCreator(), createdChoice1.getCreator());
- Choice createdChoice2 = createdPoll.getChoice(1);
+ Choice createdChoice2 = createdChoices.get(1);
Assert.assertNotNull(createdChoice2);
Assert.assertNotNull(createdChoice2.getTopiaId());
@@ -313,13 +328,14 @@
Assert.assertEquals(choice2.getDescription(), createdChoice2.getDescription());
Assert.assertEquals(createdPoll.getCreator(), createdChoice2.getCreator());
- Assert.assertNotNull(createdPoll.getVoterList());
- Assert.assertEquals(1, createdPoll.sizeVoterList());
- VoterList createdVoterList = createdPoll.getVoterList(0);
+ List<VoterList> createdVoterLists = voterListService.getVoterLists(createdPoll.getTopiaId());
+
+ Assert.assertNotNull(createdVoterLists);
+ Assert.assertEquals(1, createdVoterLists.size());
+ VoterList createdVoterList = createdVoterLists.get(0);
Assert.assertNotNull(createdVoterList);
Assert.assertNotNull(createdVoterList.getTopiaId());
- VoterListService voterListService = newService(VoterListService.class);
VoterList reloadedVoterList = voterListService.getVoterList(createdPoll.getTopiaId(), createdVoterList.getTopiaId());
Assert.assertEquals(createdVoterList, reloadedVoterList);
1
0
r3919 - in trunk/pollen-ui-angular/src/main/webapp/js: . controllers
by garandel@users.chorem.org 07 May '14
by garandel@users.chorem.org 07 May '14
07 May '14
Author: garandel
Date: 2014-05-07 15:14:48 +0200 (Wed, 07 May 2014)
New Revision: 3919
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3919
Log:
fix create poll
Modified:
trunk/pollen-ui-angular/src/main/webapp/js/app.js
trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
trunk/pollen-ui-angular/src/main/webapp/js/services.js
Modified: trunk/pollen-ui-angular/src/main/webapp/js/app.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-07 09:21:47 UTC (rev 3918)
+++ trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-07 13:14:48 UTC (rev 3919)
@@ -18,8 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
-angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'ui.bootstrap'])
+angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'ui.bootstrap'], function($httpProvider) {
+ $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
+ $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
+})
+
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {templateUrl: './partials/home.html', controller: "HomeCtrl"})
.when('/poll/create', {templateUrl: './partials/poll.html', controller: "PollCreateCtrl"})
Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-07 09:21:47 UTC (rev 3918)
+++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-07 13:14:48 UTC (rev 3919)
@@ -213,11 +213,11 @@
}])
-.controller('PollCreateCtrl', ['$scope', '$controller', 'SkeletonPoll', 'Poll', function ($scope, $controller, SkeletonPoll, NewPoll) {
+.controller('PollCreateCtrl', ['$scope', '$controller', 'Poll', '$http', function ($scope, $controller, Poll, $http) {
$controller('PollAdminCtrl', {$scope:$scope});
var initPoll = function () {
- SkeletonPoll.get().$promise.then(function (poll) {
+ Poll.get({cmd:'new'}).$promise.then(function (poll) {
$scope.poll = poll;
$scope.poll.choice = [];
$scope.vote = {};
@@ -228,7 +228,7 @@
$scope.save = function () {
if ($scope.formValid) {
- Poll.post($scope.poll);
+ $scope.poll.$add();
}
else {
$scope.globalVariables.errorForm = true;
@@ -241,7 +241,7 @@
}])
-.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', 'Poll', 'PollChoice', function ($scope, $controller, $routeParams, Poll, PollChoice) {
+.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', '$location', 'Poll', 'PollChoice', function ($scope, $controller, $routeParams, $location, Poll, PollChoice) {
$controller('PollAdminCtrl', {$scope:$scope});
var initPoll = function () {
@@ -258,7 +258,7 @@
$scope.save = function () {
if ($scope.formValid) {
- Poll.save($scope.poll).$promise.then(function () {
+ $scope.poll.$update(function () {
$scope.globalVariables.saved = true;
});
}
@@ -269,9 +269,8 @@
}
$scope.delete = function () {
- $scope.$delete();
- $scope.poll = initPoll();
- $scope.globalVariables.voted = false;
+ $scope.poll.$delete();
+ $location.path('/');
}
}])
Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-07 09:21:47 UTC (rev 3918)
+++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-07 13:14:48 UTC (rev 3919)
@@ -20,14 +20,36 @@
*/
angular.module('pollenServices', ['ngResource'])
-.factory('SkeletonPoll', ['$resource', function ($resource) {
- return $resource('http://localhost:8080/pollen-rest-api/v1/polls/new', null, {});
-}])
+.factory('BaseUrl', function() {
+ return 'http://localhost\\:8080/pollen-rest-api/v1';
+})
-.factory('Poll', ['$resource', function ($resource) {
- return $resource('http://localhost:8080/pollen-rest-api/v1/polls/:pollId', {pollId : '@topiaId'});
+.factory('Poll', ['$resource', 'BaseUrl', function ($resource, BaseUrl) {
+ var transformParam = function (data) {
+ return 'poll='+JSON.stringify(data);
+ };
+
+ return $resource(BaseUrl+'/polls/:pollId:cmd', {pollId:'@topiaId'}, {
+ 'add' : {
+ method : 'POST',
+ transformRequest : function (data, headersGetter) {
+ return transformParam(data);
+ }
+ },
+ 'update' : {
+ method : 'PUT',
+ transformRequest : function (data, headersGetter) {
+ return transformParam(data);
+ }
+ }
+ });
}])
-.factory('PollChoice', ['$resource', function ($resource) {
- return $resource('http://localhost:8080/pollen-rest-api/v1/polls/:pollId/choices/:choiceId', {choiceId : '@topiaId'});
+.factory('PollChoice', ['$resource', 'BaseUrl', function ($resource, BaseUrl) {
+ return $resource(BaseUrl+'/polls/:pollId/choices/:choiceId', {choiceId : '@topiaId'},
+ {
+ 'add' : { method:'POST'},
+ 'update' : {method:'PUT'}
+ }
+ );
}])
\ No newline at end of file
1
0
r3918 - trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api
by tchemit@users.chorem.org 07 May '14
by tchemit@users.chorem.org 07 May '14
07 May '14
Author: tchemit
Date: 2014-05-07 11:21:47 +0200 (Wed, 07 May 2014)
New Revision: 3918
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3918
Log:
fix json serialization
Modified:
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-05-07 09:04:29 UTC (rev 3917)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-05-07 09:21:47 UTC (rev 3918)
@@ -106,24 +106,20 @@
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- map = toMap(model);
-
mapper = Jsons.newSimpleMapper();
} else if (model instanceof PollenPrincipalRef) {
- map = toMap(model);
-
mapper = Jsons.newSimpleMapper();
} else {
- map = model;
-
mapper = Jsons.newEntityMapper();
}
+ map = toMap(model);
+
// GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
// @Override
// public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext c) {
@@ -210,6 +206,7 @@
}
// single object
+ // FIXME Do this in service, not here
if (model instanceof TopiaEntity) {
@@ -243,10 +240,13 @@
}
}
+
return result;
+
}
return model;
+
}
protected static class PollenEntityBinder<E extends TopiaEntity> extends Binder<E, E> {
1
0
r3917 - in trunk: . pollen-rest-api pollen-rest-api/src/main/java/org/chorem/pollen/rest/api pollen-rest-api/src/test/java/org/chorem/pollen/rest/api
by tchemit@users.chorem.org 07 May '14
by tchemit@users.chorem.org 07 May '14
07 May '14
Author: tchemit
Date: 2014-05-07 11:04:29 +0200 (Wed, 07 May 2014)
New Revision: 3917
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3917
Log:
- receive object as json
- change from gson to jackson since gson can only deal with field accessors :(
- clean deps
Added:
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java
trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java
Modified:
trunk/pollen-rest-api/pom.xml
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
trunk/pom.xml
Modified: trunk/pollen-rest-api/pom.xml
===================================================================
--- trunk/pollen-rest-api/pom.xml 2014-05-06 15:56:39 UTC (rev 3916)
+++ trunk/pollen-rest-api/pom.xml 2014-05-07 09:04:29 UTC (rev 3917)
@@ -104,12 +104,27 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
+ </dependency-->
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.module</groupId>
+ <artifactId>jackson-module-afterburner</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
@@ -146,6 +161,12 @@
</dependency>
<dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jcl</artifactId>
<scope>test</scope>
Added: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java 2014-05-07 09:04:29 UTC (rev 3917)
@@ -0,0 +1,48 @@
+package org.chorem.pollen.rest.api;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
+import org.chorem.pollen.persistence.PollenEntityEnum;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+/**
+ * Created on 5/7/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class Jsons {
+
+ public static ObjectMapper newSimpleMapper() {
+
+ ObjectMapper mapper = new ObjectMapper()
+ .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
+ .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) //FIXME Could be better ?
+ .registerModule(new AfterburnerModule());
+
+ return mapper;
+
+ }
+
+ public static ObjectMapper newEntityMapper() {
+
+ SimpleModule module = new SimpleModule();
+
+ for (Class<? extends TopiaEntity> entityClass : PollenEntityEnum.getContractClasses()) {
+
+ Class concreteClass = PollenEntityEnum.getImplementationClass(entityClass);
+ module.addAbstractTypeMapping(entityClass, concreteClass);
+
+ }
+
+ ObjectMapper mapper = newSimpleMapper()
+ .registerModule(module);
+
+ return mapper;
+
+ }
+
+}
Property changes on: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/Jsons.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-05-06 15:56:39 UTC (rev 3916)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-05-07 09:04:29 UTC (rev 3917)
@@ -23,16 +23,11 @@
* #L%
*/
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonNull;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.persistence.PollenEntityEnum;
@@ -58,9 +53,7 @@
import java.lang.annotation.Target;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Type;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -99,64 +92,97 @@
HttpServletResponse response = context.getResponse();
response.setContentType("application/json");
- String[] includeCollection = null;
- ExposeCollection annotation = call.getCurrent().getMethod().getAnnotation(ExposeCollection.class);
- if (annotation != null) {
- includeCollection = annotation.values();
- }
+// String[] includeCollection = null;
+// ExposeCollection annotation = call.getCurrent().getMethod().getAnnotation(ExposeCollection.class);
+// if (annotation != null) {
+// includeCollection = annotation.values();
+// }
Object map;
+ ObjectMapper mapper;
+
if (model instanceof InvalidFormException) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- map = toMap(((InvalidFormException) model).getErrors());
- } else {
+ map = toMap(model);
- map = toMap(model, includeCollection);
+ mapper = Jsons.newSimpleMapper();
- }
+ } else if (model instanceof PollenPrincipalRef) {
- GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
- @Override
- public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext c) {
- JsonElement result;
+ map = toMap(model);
- if (src == null) {
- result = JsonNull.INSTANCE;
- } else {
- result = new JsonPrimitive(src.getTime());
- }
+ mapper = Jsons.newSimpleMapper();
- return result;
+ } else {
- }
- });
+ map = model;
+ mapper = Jsons.newEntityMapper();
+
+ }
+
+// GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
+// @Override
+// public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext c) {
+// JsonElement result;
+//
+// if (src == null) {
+// result = JsonNull.INSTANCE;
+// } else {
+// result = new JsonPrimitive(src.getTime());
+// }
+//
+// return result;
+//
+// }
+// });
+
PollenRestApiApplicationContext applicationContext =
PollenRestApiApplicationContext.getApplicationContext(context.getServletContext());
boolean devMode = applicationContext.getApplicationConfig().isDevMode();
+
+ String json;
+
if (devMode) {
- gsonBuilder.setPrettyPrinting();
+
+ ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter();
+ json = objectWriter.writeValueAsString(map);
+// gsonBuilder.setPrettyPrinting();
+
+ } else {
+
+ json = mapper.writeValueAsString(map);
+
}
- Gson gson = gsonBuilder.create();
- String json = gson.toJson(map);
+// Gson gson = gsonBuilder.create();
+//
+// String json = gson.toJson(map);
PrintWriter out = context.getOut();
out.print(json);
- }
- protected Object toMap(Multimap<String, String> model) {
- Map<String, Object> result = new HashMap<>();
- for (String key : model.keySet()) {
- result.put(key, model.get(key));
- }
- return result;
}
protected <M> Object toMap(M model, String... includeCollection) {
+ if (model instanceof InvalidFormException) {
+
+ InvalidFormException invalidFormException = (InvalidFormException) model;
+
+ Multimap<String, String> errors = invalidFormException.getErrors();
+
+ Map<String, Object> result = new HashMap<>();
+ for (String key : errors.keySet()) {
+ result.put(key, errors.get(key));
+ }
+
+ return result;
+
+ }
+
if (model instanceof PollenPrincipalRef<?>) {
PollenPrincipalRef<?> pollenEntityRef = (PollenPrincipalRef<?>) model;
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java 2014-05-06 15:56:39 UTC (rev 3916)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java 2014-05-07 09:04:29 UTC (rev 3917)
@@ -23,7 +23,6 @@
* #L%
*/
-import org.apache.commons.beanutils.Converter;
import org.chorem.pollen.persistence.PollenEntityEnum;
import org.chorem.pollen.services.PollenService;
import org.debux.webmotion.server.WebMotionServerListener;
@@ -35,7 +34,6 @@
import org.nuiton.topia.persistence.TopiaEntity;
import java.lang.reflect.Type;
-import java.util.Date;
/**
* TODO
@@ -50,47 +48,30 @@
// --- init converters --- //
- serverContext.addConverter(new Converter() {
- @Override
- public Object convert(Class type, Object value) {
- Object result = null;
- if (value != null) {
- if (value.getClass().isAssignableFrom(Date.class)) {
- result = value;
- } else {
- Object o = ((Object[]) value)[0];
- String sTime = o.toString();
- Long time = Long.parseLong(sTime);
- result = new Date(time);
- }
- }
- return result;
- }
+// serverContext.addConverter(new Converter() {
+// @Override
+// public Object convert(Class type, Object value) {
+// Object result = null;
+// if (value != null) {
+// if (value.getClass().isAssignableFrom(Date.class)) {
+// result = value;
+// } else {
+// Object o = ((Object[]) value)[0];
+// String sTime = o.toString();
+// Long time = Long.parseLong(sTime);
+// result = new Date(time);
+// }
+// }
+// return result;
+// }
+//
+// }, Date.class);
- }, Date.class);
+ for (Class<? extends TopiaEntity> entityClass : PollenEntityEnum.getContractClasses()) {
- Converter entityconverter = new Converter() {
- @Override
- public TopiaEntity convert(Class type, Object value) {
- TopiaEntity result;
- if (value != null && value.getClass().isAssignableFrom(TopiaEntity.class)) {
- result = (TopiaEntity) value;
- } else {
- Class<?> implementationClass = PollenEntityEnum.getImplementationClass(type);
- try {
- result = (TopiaEntity) implementationClass.newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
- return result;
- }
+ TopiaEntityConverter<? extends TopiaEntity> converter = TopiaEntityConverter.newconverter(entityClass);
+ serverContext.addConverter(converter, entityClass);
- };
- for (Class<? extends TopiaEntity> entityClass : PollenEntityEnum.getContractClasses()) {
- serverContext.addConverter(entityconverter, entityClass);
}
// --- init injectors --- //
@@ -98,19 +79,23 @@
serverContext.addInjector(new ExecutorParametersInjectorHandler.Injector() {
@Override
public PollenRestApiRequestContext getValue(Mapping m, Call call, String name, Class<?> type, Type generic) {
+
PollenRestApiRequestContext result = null;
if (PollenRestApiRequestContext.class.isAssignableFrom(type)) {
HttpContext httpContext = call.getContext();
result = PollenRestApiRequestContext.getRequestContext(httpContext);
}
+
return result;
+
}
});
serverContext.addInjector(new ExecutorParametersInjectorHandler.Injector() {
@Override
public PollenService getValue(Mapping m, Call call, String name, Class type, Type generic) {
+
PollenService result = null;
if (PollenService.class.isAssignableFrom(type)) {
HttpContext httpContext = call.getContext();
@@ -119,7 +104,9 @@
PollenRestApiRequestContext.getRequestContext(httpContext);
result = requestContext.getServiceContext().newService(type);
}
+
return result;
+
}
});
@@ -130,6 +117,7 @@
PollenRestApiApplicationContext.setApplicationContext(
serverContext.getServletContext(), applicationContext);
+
}
@Override
@@ -144,5 +132,7 @@
if (applicationContext != null) {
applicationContext.close();
}
+
}
+
}
Added: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java 2014-05-07 09:04:29 UTC (rev 3917)
@@ -0,0 +1,100 @@
+package org.chorem.pollen.rest.api;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import org.apache.commons.beanutils.converters.AbstractConverter;
+import org.chorem.pollen.persistence.PollenEntityEnum;
+import org.chorem.pollen.services.PollenTechnicalException;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.io.IOException;
+
+/**
+ * Created on 5/6/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class TopiaEntityConverter<E extends TopiaEntity> extends AbstractConverter {
+
+ protected Class<E> entityType;
+
+ protected Class<E> implementationClass;
+
+ protected ObjectMapper mapper;
+
+ public static <E extends TopiaEntity> TopiaEntityConverter<E> newconverter(Class<E> entityType) {
+ return new TopiaEntityConverter<>(entityType);
+ }
+
+ public TopiaEntityConverter(Class<E> entityType) {
+
+ this.entityType = entityType;
+
+ this.implementationClass = PollenEntityEnum.getImplementationClass(entityType);
+
+ SimpleModule module = new SimpleModule();
+
+ for (Class<? extends TopiaEntity> entityClass : PollenEntityEnum.getContractClasses()) {
+
+ Class concreteClass = PollenEntityEnum.getImplementationClass(entityClass);
+ module.addAbstractTypeMapping(entityClass, concreteClass);
+
+ }
+
+ mapper = Jsons.newEntityMapper();
+
+ }
+
+ public ObjectMapper getMapper() {
+
+ return mapper;
+
+ }
+
+ @Override
+ protected String convertToString(Object value) throws Throwable {
+
+ String result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(value);
+ return result;
+
+ }
+
+ @Override
+ protected <T> T convertToType(Class<T> type, Object value) throws Throwable {
+
+ String stringValue;
+
+ if (value instanceof String) {
+
+ stringValue = (String) value;
+
+ } else {
+
+ stringValue = ((String[]) value)[0];
+
+ }
+
+ try {
+
+ T result = (T) mapper.readValue(stringValue, implementationClass);
+
+ return result;
+
+ } catch (IOException e) {
+ throw new PollenTechnicalException("Could not convert " + stringValue + " to " + type.getName(), e);
+ }
+
+ }
+
+ @Override
+ protected Class<E> getDefaultType() {
+
+ return entityType;
+
+ }
+
+
+}
Property changes on: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/TopiaEntityConverter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java 2014-05-06 15:56:39 UTC (rev 3916)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java 2014-05-07 09:04:29 UTC (rev 3917)
@@ -22,10 +22,14 @@
*/
import org.apache.http.client.fluent.Request;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.ChoiceImpl;
import org.chorem.pollen.persistence.entity.ChoiceType;
import org.chorem.pollen.persistence.entity.CommentVisibility;
import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollImpl;
import org.chorem.pollen.persistence.entity.PollType;
+import org.chorem.pollen.persistence.entity.ResultVisibility;
import org.chorem.pollen.persistence.entity.VoteVisibility;
import org.chorem.pollen.services.PollenFixtures;
import org.junit.Before;
@@ -43,6 +47,7 @@
* @author Tony Chemit <chemit(a)codelutin.com>
* @since 2.0
*/
+@Ignore
public class PollApiTest extends AbstractPollenRestApiTest {
@Before
@@ -108,21 +113,36 @@
}
@Test
- public void postPoll() throws URISyntaxException, IOException {
- Request request = createRequest("/v1/polls").
- addParameter("poll.pollType", PollType.FREE.name()).
- addParameter("poll.commentVisibility", CommentVisibility.EVERYBODY.name()).
- addParameter("poll.voteVisibility", VoteVisibility.EVERYBODY.name()).
- addParameter("poll.voteCountingType", "1").
- addParameter("poll.title", "title").
- addParameter("poll.choice[1].choiceType", ChoiceType.TEXT.name()).
- addParameter("poll.choice[1].name", "choiceB").
- addParameter("poll.choice[0].choiceType", ChoiceType.TEXT.name()).
- addParameter("poll.choice[0].name", "choiceA").
- Post();
+ public void postPoll() throws Throwable {
+
+ Poll poll = new PollImpl();
+ poll.setPollType(PollType.FREE);
+ poll.setCommentVisibility(CommentVisibility.EVERYBODY);
+ poll.setResultVisibility(ResultVisibility.EVERYBODY);
+ poll.setVoteVisibility(VoteVisibility.EVERYBODY);
+ poll.setVoteCountingType(1);
+ poll.setTitle("title");
+ Choice choice1 = new ChoiceImpl();
+ choice1.setChoiceType(ChoiceType.TEXT);
+ choice1.setName("choiceA");
+ poll.addChoice(choice1);
+ Choice choice2 = new ChoiceImpl();
+ choice2.setChoiceType(ChoiceType.TEXT);
+ choice2.setName("choiceB");
+ poll.addChoice(choice2);
+
+ TopiaEntityConverter<Poll> converter = TopiaEntityConverter.newconverter(Poll.class);
+
+ String strPoll = converter.convertToString(poll);
+
+ Request request = createRequest("/v1/polls")
+ .addParameter("poll", strPoll)
+ .Post();
+
String content = request.execute().returnContent().asString();
showTestResult(content);
assertNotNull(content);
+
}
@Ignore
Added: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java (rev 0)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java 2014-05-07 09:04:29 UTC (rev 3917)
@@ -0,0 +1,41 @@
+package org.chorem.pollen.rest.api;
+
+import org.chorem.pollen.persistence.entity.ChoiceType;
+import org.chorem.pollen.persistence.entity.CommentVisibility;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollType;
+import org.chorem.pollen.persistence.entity.VoteVisibility;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TopiaEntityConverterTest {
+
+ @Test
+ public void convert() {
+
+ String pollStr = "{topiaCreateDate: 1399033089600, title: \"pollTitle\", " +
+ "choice: [ {name: \"choice1\", choiceType: \"TEXT\"}, " +
+ "{name: \"choice2\", choiceType: \"IMAGE\"} ], voteVisibility: \"ANONYMOUS\", " +
+ "commentVisibility:\"NOBODY\", pollType: \"FREE\" }";
+
+ TopiaEntityConverter<Poll> converter = new TopiaEntityConverter<>(Poll.class);
+
+ Poll poll = converter.convert(Poll.class, pollStr);
+
+ Assert.assertNotNull(poll);
+ Assert.assertEquals("pollTitle", poll.getTitle());
+ Assert.assertEquals(VoteVisibility.ANONYMOUS, poll.getVoteVisibility());
+ Assert.assertEquals(CommentVisibility.NOBODY, poll.getCommentVisibility());
+ Assert.assertEquals(PollType.FREE, poll.getPollType());
+ Assert.assertEquals(2, poll.sizeChoice());
+ Assert.assertEquals("choice1", poll.getChoice(0).getName());
+ Assert.assertEquals(ChoiceType.TEXT, poll.getChoice(0).getChoiceType());
+ Assert.assertEquals("choice2", poll.getChoice(1).getName());
+ Assert.assertEquals(ChoiceType.IMAGE, poll.getChoice(1).getChoiceType());
+
+ String convert = converter.convert(String.class, poll);
+ Assert.assertNotNull(convert);
+
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/TopiaEntityConverterTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-05-06 15:56:39 UTC (rev 3916)
+++ trunk/pom.xml 2014-05-07 09:04:29 UTC (rev 3917)
@@ -239,12 +239,6 @@
<!-- persistence module dependencies -->
<dependency>
- <groupId>org.hibernate.javax.persistence</groupId>
- <artifactId>hibernate-jpa-2.1-api</artifactId>
- <version>1.0.0.Draft-16</version>
- </dependency>
-
- <dependency>
<groupId>org.nuiton.topia</groupId>
<artifactId>topia-persistence</artifactId>
<version>${topiaVersion}</version>
@@ -276,13 +270,6 @@
</dependency>
<dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- <version>${hibernateVersion}</version>
- <scope>runtime</scope>
- </dependency>
-
- <dependency>
<groupId>com.esotericsoftware.yamlbeans</groupId>
<artifactId>yamlbeans</artifactId>
<version>1.06</version>
@@ -333,17 +320,17 @@
<version>${nuitonConfigVersion}</version>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-csv</artifactId>
<version>${nuitonCsvVersion}</version>
- </dependency>
+ </dependency-->
- <dependency>
+ <!--dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-validator</artifactId>
<version>${nuitonValidatorVersion}</version>
- </dependency>
+ </dependency-->
<dependency>
<groupId>org.nuiton.web</groupId>
@@ -365,15 +352,15 @@
<artifactId>shiro-core</artifactId>
<version>${shiroVersion}</version>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>${shiroVersion}</version>
- </dependency>
+ </dependency-->
<!-- JFreeChart -->
- <dependency>
+ <!--dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.14</version>
@@ -383,21 +370,15 @@
<groupId>org.jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.17</version>
- </dependency>
+ </dependency-->
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.12.1.GA</version>
- </dependency>
-
<!-- Rome (rss) -->
- <dependency>
+ <!--dependency>
<groupId>rome</groupId>
<artifactId>rome</artifactId>
<version>1.0</version>
- </dependency>
+ </dependency-->
<!-- Logging -->
@@ -416,12 +397,12 @@
<version>0.8.13</version>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
- </dependency>
+ </dependency-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@@ -429,31 +410,49 @@
<version>${httpCommonsHttpclientVersion}</version>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${httpCommonsHttpclientVersion}</version>
- </dependency>
+ </dependency-->
- <dependency>
+ <!--dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
+ </dependency-->
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.3.3</version>
</dependency>
<dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.3.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.module</groupId>
+ <artifactId>jackson-module-afterburner</artifactId>
+ <version>2.3.3</version>
+ </dependency>
+
+ <dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-runner</artifactId>
<version>${jettyVersion}</version>
<scope>provided</scope>
- </dependency>
+ </dependency-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
@@ -483,11 +482,11 @@
<scope>provided</scope>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
- </dependency>
+ </dependency-->
<dependency>
<groupId>org.mockito</groupId>
@@ -497,7 +496,7 @@
</dependency>
<!-- Selenium -->
- <dependency>
+ <!--dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>${seleniumVersion}</version>
@@ -550,7 +549,7 @@
<artifactId>selenium-remote-driver</artifactId>
<version>${seleniumVersion}</version>
<scope>test</scope>
- </dependency>
+ </dependency-->
</dependencies>
</dependencyManagement>
1
0
r3916 - in trunk/pollen-ui-angular/src/main/webapp: . js js/controllers partials
by garandel@users.chorem.org 06 May '14
by garandel@users.chorem.org 06 May '14
06 May '14
Author: garandel
Date: 2014-05-06 17:56:39 +0200 (Tue, 06 May 2014)
New Revision: 3916
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3916
Log:
migrate restangular to resource / send a single json data
Modified:
trunk/pollen-ui-angular/src/main/webapp/index.html
trunk/pollen-ui-angular/src/main/webapp/js/app.js
trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
trunk/pollen-ui-angular/src/main/webapp/js/services.js
trunk/pollen-ui-angular/src/main/webapp/partials/poll.html
Modified: trunk/pollen-ui-angular/src/main/webapp/index.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-06 08:56:15 UTC (rev 3915)
+++ trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-06 15:56:39 UTC (rev 3916)
@@ -30,10 +30,10 @@
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-resource.min…"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.0/ui-bootst…"></script>
- <script src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.4.0/restangular.min.js"></script>
<script src="js/libs/ckeditor/ckeditor.js"></script>
<script src="js/app.js"></script>
+ <script src="js/services.js"></script>
<script src="js/controllers/pollCtrl.js"></script>
</head>
<body>
Modified: trunk/pollen-ui-angular/src/main/webapp/js/app.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-06 08:56:15 UTC (rev 3915)
+++ trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-06 15:56:39 UTC (rev 3916)
@@ -18,52 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
-angular.module('pollen', ["restangular", 'ngRoute', 'pollControllers', 'ui.bootstrap'], function($httpProvider) {
- // Use x-www-form-urlencoded Content-Type
- $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
+angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'ui.bootstrap'])
- /**
- * The workhorse; converts an object to x-www-form-urlencoded serialization.
- * @param {Object} obj
- * @return {String}
- */
- var param = function(obj) {
- var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
-
- for(name in obj) {
- value = obj[name];
-
- if(value instanceof Array) {
- for(i=0; i<value.length; ++i) {
- subValue = value[i];
- fullSubName = name + '[' + i + ']';
- innerObj = {};
- innerObj[fullSubName] = subValue;
- query += param(innerObj) + '&';
- }
- }
- else if(value instanceof Object) {
- for(subName in value) {
- subValue = value[subName];
- fullSubName = name + '.' + subName ;
- innerObj = {};
- innerObj[fullSubName] = subValue;
- query += param(innerObj) + '&';
- }
- }
- else if(value !== undefined && value !== null)
- query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
- }
-
- return query.length ? query.substr(0, query.length - 1) : query;
- };
-
- // Override $http service's default transformRequest
- $httpProvider.defaults.transformRequest = [function(data) {
- return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
- }];
-})
-
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {templateUrl: './partials/home.html', controller: "HomeCtrl"})
.when('/poll/create', {templateUrl: './partials/poll.html', controller: "PollCreateCtrl"})
@@ -74,15 +30,7 @@
}])
-.config(['RestangularProvider', function (RestangularProvider) {
- //RestangularProvider.setBaseUrl('http://demo.codelutin.com/pollen-rest-api-latest/v1');
- RestangularProvider.setBaseUrl('http://localhost:8080/pollen-rest-api/v1');
-}])
-.factory('PollsRest', ['Restangular', function(Restangular) {
- return Restangular.service('polls');
-}])
-
.directive('focusMe', function($timeout) {
return {
link: function($scope, element, attrs) {
Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-06 08:56:15 UTC (rev 3915)
+++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-06 15:56:39 UTC (rev 3916)
@@ -65,7 +65,7 @@
}])
-.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', 'Restangular', '$http', function ($scope, $controller, $modal, $filter, $timeout, Restangular, $http) {
+.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', function ($scope, $controller, $modal, $filter, $timeout) {
$controller('PollCtrl', {$scope:$scope});
var initChoice = function () {
@@ -134,19 +134,6 @@
});
}
- $scope.reset = function () {
- $scope.poll = initPoll();
- $scope.voteChoice = $scope.poll.choice;
- pollStorage.put({});
- }
-
- $scope.delete = function () {
- $scope.poll = initPoll();
- $scope.voteChoice= $scope.poll.choice;
- $scope.globalVariables.voted = false;
- pollStorage.put({});
- }
-
var PollPopChoiceCtrl = function ($scope, $filter, $modalInstance, title, choice) {
$scope.title = title;
$scope.choice = choice;
@@ -191,9 +178,11 @@
poll.endChoiceDate = poll.endDate;
}
}
+ /*
else {
poll.endChoiceDate = poll.endDate;
}
+ */
});
if (!angular.isDefined($scope.poll.continuousResults)) {
@@ -224,47 +213,41 @@
}])
-.controller('PollCreateCtrl', ['$scope', '$controller', 'Restangular', '$http', function ($scope, $controller, Restangular, $http) {
+.controller('PollCreateCtrl', ['$scope', '$controller', 'SkeletonPoll', 'Poll', function ($scope, $controller, SkeletonPoll, NewPoll) {
$controller('PollAdminCtrl', {$scope:$scope});
var initPoll = function () {
- Restangular.service('polls').one('new').get().then(function (skeletonPoll) {
- $scope.poll = skeletonPoll;
+ SkeletonPoll.get().$promise.then(function (poll) {
+ $scope.poll = poll;
$scope.poll.choice = [];
$scope.vote = {};
$scope.vote.choice = $scope.poll.choice;
- });
+ })
}
initPoll();
$scope.save = function () {
if ($scope.formValid) {
- var data = {};
- data.poll = $scope.poll;
-
-// Restangular.all('polls').post('polls', data).then(function (data) {;
- $http.post('http://localhost:8080/pollen-rest-api/v1/polls', data).success(function (data) {
- $scope.test = data;
- $scope.globalVariables.saved = true;
- });
-
+ Poll.post($scope.poll);
}
else {
$scope.globalVariables.errorForm = true;
}
+ }
+ $scope.delete = function () {
+ $scope.poll = initPoll();
}
}])
-.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', 'Restangular', '$http', function ($scope, $controller, $routeParams, Restangular, $http) {
+.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', 'Poll', 'PollChoice', function ($scope, $controller, $routeParams, Poll, PollChoice) {
$controller('PollAdminCtrl', {$scope:$scope});
var initPoll = function () {
-
- Restangular.one('polls', $routeParams.pollId).get().then(function (poll) {
+ Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) {
$scope.poll = poll;
- Restangular.one('polls', $routeParams.pollId).all('choices').getList().then(function (choices) {
+ PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) {
$scope.poll.choice = choices;
$scope.vote = {};
$scope.vote.choice = $scope.poll.choice;
@@ -275,36 +258,37 @@
$scope.save = function () {
if ($scope.formValid) {
- var data = {};
- data.poll = $scope.poll;
-
-// Restangular.all('polls').post('polls', data).then(function (data) {;
- $http.put('http://localhost:8080/pollen-rest-api/v1/polls/'+$routeParams.pollId, data).success(function (data) {
- $scope.test = data;
+ Poll.save($scope.poll).$promise.then(function () {
$scope.globalVariables.saved = true;
});
-
}
else {
$scope.globalVariables.errorForm = true;
}
}
+
+ $scope.delete = function () {
+ $scope.$delete();
+ $scope.poll = initPoll();
+ $scope.globalVariables.voted = false;
+ }
}])
-.controller('PollVoteCtrl', ['$scope', '$filter', '$controller', '$routeParams', 'Restangular', function ($scope, $filter, $controller, $routeParams, Restangular) {
+.controller('PollVoteCtrl', ['$scope', '$filter', '$controller', '$routeParams', 'Poll', 'PollChoice', function ($scope, $filter, $controller, $routeParams, Poll, PollChoice) {
$controller('PollCtrl', {$scope:$scope});
- Restangular.one('polls', $routeParams.pollId).get().then(function (poll) {
+ Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) {
$scope.poll = poll;
- Restangular.one('polls', $routeParams.pollId).all('choices').getList().then(function (choices) {
+ PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) {
$scope.poll.choice = choices;
- initVote();
- })
+ $scope.vote = {};
+ $scope.vote.choice = $scope.poll.choice;
+ });
});
$scope.globalVariables.editMode = false;
- $scope.$watch('vote.ame', function (newVal) {
+ $scope.$watch('vote.name', function (newVal) {
if (newVal != '') {
$scope.globalVariables.errorForm = false;
}
@@ -346,12 +330,11 @@
}
}])
-.controller('PollListCtrl', ['$scope', '$controller', 'Restangular', function ($scope, $controller, Restangular) {
+.controller('PollListCtrl', ['$scope', '$controller', 'Poll', function ($scope, $controller, Poll) {
$controller('PollCtrl', {$scope:$scope});
- Restangular.all('polls').getList().then(function (polls) {
- $scope.polls = polls;
- });
+ $scope.polls = Poll.query();
+
}])
;
\ No newline at end of file
Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-06 08:56:15 UTC (rev 3915)
+++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-06 15:56:39 UTC (rev 3916)
@@ -18,7 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
-angular.module('pollenServices', ['ngResource']).factory('Poll', function($resource) {
- return $resource('http://localhost:8080/pollen/v1/polls/:pollId', {}, {
- });
-});
\ No newline at end of file
+angular.module('pollenServices', ['ngResource'])
+
+.factory('SkeletonPoll', ['$resource', function ($resource) {
+ return $resource('http://localhost:8080/pollen-rest-api/v1/polls/new', null, {});
+}])
+
+.factory('Poll', ['$resource', function ($resource) {
+ return $resource('http://localhost:8080/pollen-rest-api/v1/polls/:pollId', {pollId : '@topiaId'});
+}])
+
+.factory('PollChoice', ['$resource', function ($resource) {
+ return $resource('http://localhost:8080/pollen-rest-api/v1/polls/:pollId/choices/:choiceId', {choiceId : '@topiaId'});
+}])
\ No newline at end of file
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-06 08:56:15 UTC (rev 3915)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-06 15:56:39 UTC (rev 3916)
@@ -21,11 +21,12 @@
<form class="form-inline" name="pollForm" novalidate>
- <alert type="'danger'" ng-if="globalVariables.errorForm"> Champ non remplie </alert>
- <alert type="'success'" ng-if="globalVariables.editMode && globalVariables.saved"> Sondage sauvegardé..</alert>
- <alert type="'success'" ng-if="!globalVariables.editMode && globalVariables.saved"> Vote effectué..</alert>
+ <alert type="danger" ng-if="globalVariables.errorForm"> Champ non remplie </alert>
+ <alert type="success" ng-if="globalVariables.editMode && globalVariables.saved"> Sondage sauvegardé..</alert>
+ <alert type="success" ng-if="!globalVariables.editMode && globalVariables.saved"> Vote effectué..</alert>
- <alert type="'warning'" ng-if="globalVariables.voted"> Les votes ont commencé, certaine modification sont inaccessible.. </alert>
+ <alert type="warning" ng-if="globalVariables.voted"> Les votes ont commencé, certaine modification sont inaccessible.. </alert>
+ <alert type="warning" ng-if="globalVariables.created"> <a href="#/poll/edit/{{pollId}}"> Edition du sondage </a>.. </alert>
<div class="pollTitle" edit-me="showEditTitle">
<h1 ng-hide="showEditTitle"> {{poll.title || 'Click Me for Editing'}} </h1>
@@ -52,7 +53,6 @@
<hr/>
<button type="button" class="btn btn-default" ng-model="globalVariables.editMode" btn-checkbox>Mode Edition</button>
<button class="btn btn-primary" ng-click="save()">Save</button>
- <button class="btn btn-warning" ng-click="reset();" ng-if="!globalVariables.voted">Reset</button>
<button class="btn btn-danger" ng-click="delete();">Delete</button>
<button class="btn btn-default" ng-click="popupSettings()">Settings</button>
</div>
1
0
r3915 - in trunk/pollen-ui-angular/src/main/webapp: js/controllers partials
by garandel@users.chorem.org 06 May '14
by garandel@users.chorem.org 06 May '14
06 May '14
Author: garandel
Date: 2014-05-06 10:56:15 +0200 (Tue, 06 May 2014)
New Revision: 3915
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3915
Log:
update settings popup, and date popup
Modified:
trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html
trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html
trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html
trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html
Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-05 15:39:10 UTC (rev 3914)
+++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-06 08:56:15 UTC (rev 3915)
@@ -172,7 +172,30 @@
var PollPopupSettingsCtrl = function ($scope, $filter, $modalInstance, poll) {
$scope.poll = poll;
+ $scope.toDay = new Date();
+ $scope.$watch('poll.beginDate', function() {
+ if (poll.beginChoiceDate) {
+ if (poll.beginChoiceDate < poll.beginDate) {
+ poll.beginChoiceDate = poll.beginDate;
+ }
+ }
+ else {
+ poll.beginChoiceDate = poll.beginDate;
+ }
+ });
+
+ $scope.$watch('poll.endDate', function() {
+ if (poll.endChoiceDate) {
+ if (poll.endChoiceDate > poll.endDate) {
+ poll.endChoiceDate = poll.endDate;
+ }
+ }
+ else {
+ poll.endChoiceDate = poll.endDate;
+ }
+ });
+
if (!angular.isDefined($scope.poll.continuousResults)) {
$scope.poll.continuousResults = false;
}
@@ -196,7 +219,6 @@
return 'Non';
}
}
-
}
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html 2014-05-05 15:39:10 UTC (rev 3914)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html 2014-05-06 08:56:15 UTC (rev 3915)
@@ -41,7 +41,12 @@
{{choice.date | date:'dd/MM/yyyy'}}
</h3>
<h3 ng-show="showEdit || isOpen">
- <input type="text" ng-model="choice.date" datepicker-popup="dd/MM/yyyy" is-open="isOpen" focus-me="showEdit" ng-exit="showEdit = false" required/>
+ <input type="text" ng-model="choice.date"
+ datepicker-popup="dd/MM/yyyy"
+ is-open="isOpen"
+ focus-me="showEdit"
+ ng-exit="showEdit = false"
+ ng-click="isOpen = true" required/>
</h3>
</div>
</div>
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-05 15:39:10 UTC (rev 3914)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-06 08:56:15 UTC (rev 3915)
@@ -36,7 +36,7 @@
<div ng-if="choice.choiceType == 'DATE'" edit-me="showEdit" >
<div ng-hide="!globalVariables.voted && showEdit || isOpen" class="fixe-input" title="{{choice.description}}">{{choice.date | date:'dd/MM/yyyy'}} <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div>
<div ng-show="!globalVariables.voted && showEdit || isOpen" >
- <input type="text" class="form-control" ng-model="choice.date" focus-me="showEdit" datepicker-popup="dd/MM/yyyy" is-open="isOpen" ng-exit="showEdit = false" required/>
+ <input type="text" class="form-control" ng-model="choice.date" focus-me="showEdit" datepicker-popup="dd/MM/yyyy" is-open="isOpen" ng-exit="showEdit = false" ng-click="isOpen = true" required/>
<input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/>
</div>
</div>
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html 2014-05-05 15:39:10 UTC (rev 3914)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html 2014-05-06 08:56:15 UTC (rev 3915)
@@ -49,7 +49,7 @@
<div class="col-sm-6">
<div class="right-inner-addon ">
<i class="glyphicon glyphicon-calendar glyphicon-input"></i>
- <input id="popNameChoiceDate" class="form-control" datepicker-popup="dd/MM/yyyy" type="text" ng-model="choice.date" is-open="opened"/>
+ <input id="popNameChoiceDate" class="form-control" datepicker-popup="dd/MM/yyyy" type="text" ng-model="choice.date" is-open="opened" ng-click="opened = true"/>
</div>
</div>
</div>
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html 2014-05-05 15:39:10 UTC (rev 3914)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html 2014-05-06 08:56:15 UTC (rev 3915)
@@ -35,8 +35,11 @@
<div class="col-lg-8">
<input id="popBeginDate" class="form-control" type="text"
datepicker-popup="dd/MM/yyyy"
+ min-date="toDay"
+ max-date="poll.endDate"
ng-model="poll.beginDate"
- is-open="beginDateOpened"/>
+ is-open="beginDateOpened"
+ ng-click="beginDateOpened = true" />
</div>
</div>
@@ -45,8 +48,10 @@
<div class="col-lg-8">
<input id="popEndDate" class="form-control" type="text"
datepicker-popup="dd/MM/yyyy"
+ min-date="poll.beginDate"
ng-model="poll.endDate"
- is-open="endDateOpened"/>
+ is-open="endDateOpened"
+ ng-click="endDateOpened = true" />
</div>
</div>
@@ -80,20 +85,23 @@
<input class="form-control" type="text" id="popBeginChoiceDate"
datepicker-popup="dd/MM/yyyy"
min-date="poll.beginDate"
- max-date="poll.endDate"
+ max-date="poll.endChoiceDate"
ng-model="poll.beginChoiceDate"
- is-open="beginChoiceDateOpened"/>
+ is-open="beginChoiceDateOpened"
+ ng-click="beginChoiceDateOpened = true" />
</div>
</div>
- <div class="form-group" ng-show="poll.choiceAddAllowed" for="popEndChoiceDate">
+ <div class="form-group" ng-if="poll.choiceAddAllowed" for="popEndChoiceDate">
<label class="col-lg-4 control-label">Date de fin : </label>
<div class="col-lg-8">
<input class="form-control" type="text" id="popEndChoiceDate"
datepicker-popup="dd/MM/yyyy"
- min-date="poll.beginDate"
+ min-date="poll.beginChoiceDate"
max-date="poll.endDate"
+
ng-model="poll.endChoiceDate"
- is-open="endChoiceDateOpened"/>
+ is-open="endChoiceDateOpened"
+ ng-click="endChoiceDateOpened = true" />
</div>
</div>
@@ -126,7 +134,7 @@
<button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="6">Vote alternatif</button>
<button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="7">Coombs</button>
</div>
- <p>description type...</p>
+ <p>Description du types de vote</p>
</div>
</div>
</div>
@@ -140,7 +148,6 @@
<button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'ANONYMOUS'">Anonyme</button>
</div>
</div>
- </div>
<div class="form-group">
<label class="col-lg-4 control-label">Autoriser les votes anonymes :</label>
1
0
r3914 - in trunk/pollen-ui-angular/src/main/webapp: . js/controllers partials
by garandel@users.chorem.org 05 May '14
by garandel@users.chorem.org 05 May '14
05 May '14
Author: garandel
Date: 2014-05-05 17:39:10 +0200 (Mon, 05 May 2014)
New Revision: 3914
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3914
Log:
Add popup setting
Added:
trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html
Modified:
trunk/pollen-ui-angular/src/main/webapp/index.html
trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
trunk/pollen-ui-angular/src/main/webapp/partials/poll.html
Modified: trunk/pollen-ui-angular/src/main/webapp/index.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-05 12:36:59 UTC (rev 3913)
+++ trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-05 15:39:10 UTC (rev 3914)
@@ -29,7 +29,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-resource.min…"></script>
- <script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.10.0/ui-bootst…"></script>
+ <script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.0/ui-bootst…"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.4.0/restangular.min.js"></script>
<script src="js/libs/ckeditor/ckeditor.js"></script>
Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-05 12:36:59 UTC (rev 3913)
+++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-05 15:39:10 UTC (rev 3914)
@@ -122,6 +122,18 @@
});
}
+ $scope.popupSettings = function () {
+ var modalInstance = $modal.open({
+ templateUrl : 'partials/poll-popupSettings.html',
+ controller : PollPopupSettingsCtrl,
+ size : 'lg',
+ resolve : { poll: function () {
+ return $scope.poll;
+ }
+ }
+ });
+ }
+
$scope.reset = function () {
$scope.poll = initPoll();
$scope.voteChoice = $scope.poll.choice;
@@ -158,8 +170,36 @@
}
+ var PollPopupSettingsCtrl = function ($scope, $filter, $modalInstance, poll) {
+ $scope.poll = poll;
+ if (!angular.isDefined($scope.poll.continuousResults)) {
+ $scope.poll.continuousResults = false;
+ }
+ if (!angular.isDefined($scope.poll.resultVisibility)) {
+ $scope.poll.resultVisibility = 'EVERYBODY';
+ }
+
+ if (!angular.isDefined($scope.poll.choiceAddAllowed)) {
+ $scope.poll.choiceAddAllowed = false;
+ }
+
+ $scope.close = function () {
+ $modalInstance.dismiss();
+ }
+
+ $scope.printCheckbox= function (value) {
+ if (value) {
+ return 'Oui';
+ } else {
+ return 'Non';
+ }
+ }
+
+ }
+
+
}])
.controller('PollCreateCtrl', ['$scope', '$controller', 'Restangular', '$http', function ($scope, $controller, Restangular, $http) {
Added: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html (rev 0)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupSettings.html 2014-05-05 15:39:10 UTC (rev 3914)
@@ -0,0 +1,156 @@
+<!--
+ #%L
+ Pollen :: UI (Angular)
+ %%
+ Copyright (C) 2009 - 2014 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ -->
+
+
+
+<form class="form-horizontal">
+ <div class="modal-header">
+ <h3 class="modal-title">Configuration</h3>
+ </div>
+
+ <div class="modal-body">
+
+ <h4>Confiuration global</h4>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label" for="popBeginDate">Date de début : </label>
+ <div class="col-lg-8">
+ <input id="popBeginDate" class="form-control" type="text"
+ datepicker-popup="dd/MM/yyyy"
+ ng-model="poll.beginDate"
+ is-open="beginDateOpened"/>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label" for="popEndDate">Date de fin : </label>
+ <div class="col-lg-8">
+ <input id="popEndDate" class="form-control" type="text"
+ datepicker-popup="dd/MM/yyyy"
+ ng-model="poll.endDate"
+ is-open="endDateOpened"/>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label">Résultat : </label>
+ <div class="col-lg-8 btn-group">
+ <button type="button" class="btn btn-success" ng-model="poll.resultVisibility" btn-radio="'EVERYBODY'">Public</button>
+ <button type="button" class="btn btn-success" ng-model="poll.resultVisibility" btn-radio="'VOTER'">Participants</button>
+ <button type="button" class="btn btn-success" ng-model="poll.resultVisibility" btn-radio="'CREATOR'">Créateur</button>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label" for="popContinuousResults">Résultat continue : </label>
+ <div class="col-lg-8">
+ <button class="btn btn-default" id="popContinuousResults" ng-model="poll.continuousResults" btn-checkbox>{{printCheckbox(poll.continuousResults)}}</button>
+ </div>
+ </div>
+
+ <h4>Configuration des Choix</h4>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label" for="popChoiceAddAllowed">Ajout de choix par les votants :</label>
+ <div class="col-lg-8">
+ <button class="btn btn-default" id="popChoiceAddAllowed" ng-model="poll.choiceAddAllowed" btn-checkbox >{{printCheckbox(poll.choiceAddAllowed)}}</button>
+ </div>
+ </div>
+ <div class="form-group" ng-show="poll.choiceAddAllowed">
+ <label class="col-lg-4 control-label" for="popBeginChoiceDate">Date de début : </label>
+ <div class="col-lg-8">
+ <input class="form-control" type="text" id="popBeginChoiceDate"
+ datepicker-popup="dd/MM/yyyy"
+ min-date="poll.beginDate"
+ max-date="poll.endDate"
+ ng-model="poll.beginChoiceDate"
+ is-open="beginChoiceDateOpened"/>
+ </div>
+ </div>
+ <div class="form-group" ng-show="poll.choiceAddAllowed" for="popEndChoiceDate">
+ <label class="col-lg-4 control-label">Date de fin : </label>
+ <div class="col-lg-8">
+ <input class="form-control" type="text" id="popEndChoiceDate"
+ datepicker-popup="dd/MM/yyyy"
+ min-date="poll.beginDate"
+ max-date="poll.endDate"
+ ng-model="poll.endChoiceDate"
+ is-open="endChoiceDateOpened"/>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label" for="popLimitedVote">Limiter les votes :</label>
+ <div class="col-lg-8">
+ <button class="btn btn-default" id="popLimitedVote" ng-model="poll.limitedVote" btn-checkbox >{{printCheckbox(poll.limitedVote)}}</button>
+ </div>
+ </div>
+ <div class="form-group" ng-show="poll.limitedVote">
+ <label class="col-lg-4 control-label" for="popMaxChoiceNumber">Nombre de vote :</label>
+ <div class="col-lg-6">
+ <input type="text" class="form-control" id="popMaxChoiceNumber" ng-model="poll.maxChoiceNumber"/>
+ </div>
+ </div>
+
+ <h4> Configuration des Réponses </h4>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label">Type : </label>
+ <div class="col-lg-8">
+ <div class="btn-group">
+ <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="1">Normal</button>
+ <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="2">Pourcentage</button>
+ <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="3">Condorcet</button>
+ <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="4">Nombre</button>
+ </div>
+ <div class="btn-group">
+ <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="5">Borda</button>
+ <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="6">Vote alternatif</button>
+ <button type="button" class="btn btn-success" ng-model="poll.voteCountingType" btn-radio="7">Coombs</button>
+ </div>
+ <p>description type...</p>
+ </div>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label">Visibilité : </label>
+ <div class="col-lg-8 btn-group">
+ <button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'EVERYBODY'">Public</button>
+ <button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'VOTER'">Participants</button>
+ <button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'CREATOR'">Créateur</button>
+ <button type="button" class="btn btn-success" ng-model="poll.voteVisibility" btn-radio="'ANONYMOUS'">Anonyme</button>
+ </div>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-lg-4 control-label">Autoriser les votes anonymes :</label>
+ <div class="col-lg-8">
+ <button class="btn btn-default" ng-model="poll.anonymousVoteAllowed" btn-checkbox >{{printCheckbox(poll.anonymousVoteAllowed)}}</button>
+ </div>
+ </div>
+
+
+ <div class="modal-footer">
+ <button type="button" class="btn btn-primary" ng-click="close()">close</button>
+ </div>
+</form>
\ No newline at end of file
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-05 12:36:59 UTC (rev 3913)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-05 15:39:10 UTC (rev 3914)
@@ -54,6 +54,7 @@
<button class="btn btn-primary" ng-click="save()">Save</button>
<button class="btn btn-warning" ng-click="reset();" ng-if="!globalVariables.voted">Reset</button>
<button class="btn btn-danger" ng-click="delete();">Delete</button>
+ <button class="btn btn-default" ng-click="popupSettings()">Settings</button>
</div>
</form>
\ No newline at end of file
1
0