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
May 2014
- 5 participants
- 203 discussions
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository Pollen.
See http://git.None/Pollen.git
commit d85e3bc3e6ab6b2377d1e6d99e6002b7616a4d1f
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue May 27 08:39:57 2014 +0200
use bean for vote counting result (to encore ids)
---
.../chorem/pollen/rest/api/v1/VoteCountingApi.java | 12 +--
.../pollen/services/bean/ChoiceScoreBean.java | 95 ++++++++++++++++++++++
.../services/bean/GroupVoteCountingResultBean.java | 46 +++++++++++
.../services/bean/VoteCountingResultBean.java | 71 ++++++++++++++++
.../services/service/VoteCountingService.java | 31 ++++---
5 files changed, 239 insertions(+), 16 deletions(-)
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java
index a4b83ac..ec19159 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java
@@ -24,10 +24,10 @@ package org.chorem.pollen.rest.api.v1;
*/
import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.services.bean.GroupVoteCountingResultBean;
import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.VoteCountingResultBean;
import org.chorem.pollen.services.service.VoteCountingService;
-import org.chorem.pollen.votecounting.model.GroupVoteCountingResult;
-import org.chorem.pollen.votecounting.model.VoteCountingResult;
import org.debux.webmotion.server.WebMotionController;
/**
@@ -38,16 +38,16 @@ import org.debux.webmotion.server.WebMotionController;
*/
public class VoteCountingApi extends WebMotionController {
- public VoteCountingResult getMainResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) {
+ public VoteCountingResultBean getMainResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) {
- VoteCountingResult result = voteCountingService.getMainResult(pollId.getEntityId());
+ VoteCountingResultBean result = voteCountingService.getMainResult(pollId.getEntityId());
return result;
}
- public GroupVoteCountingResult getGroupResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) {
+ public GroupVoteCountingResultBean getGroupResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) {
- GroupVoteCountingResult result = voteCountingService.getGroupResult(pollId.getEntityId());
+ GroupVoteCountingResultBean result = voteCountingService.getGroupResult(pollId.getEntityId());
return result;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceScoreBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceScoreBean.java
new file mode 100644
index 0000000..0f07a0d
--- /dev/null
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceScoreBean.java
@@ -0,0 +1,95 @@
+package org.chorem.pollen.services.bean;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+
+import java.math.BigDecimal;
+
+/**
+ * Created on 5/27/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ChoiceScoreBean {
+
+ /** Id of the choice. */
+ protected PollenEntityId<Choice> choiceId;
+
+ /**
+ * Global score for this choice (in some vote count it does not mean a
+ * lot (and it should be improved to take account of the notion of round)).
+ */
+ protected BigDecimal scoreValue;
+
+ /** Order of this score (0 is winner, 1 is second,...). */
+ protected int scoreOrder;
+
+ public ChoiceScoreBean() {
+ this.choiceId = PollenEntityId.newId(Choice.class);
+ }
+
+ public void fromResult(ChoiceScore result) {
+
+ setChoiceId(result.getChoiceId());
+ setScoreOrder(result.getScoreOrder());
+ setScoreValue(result.getScoreValue());
+
+ }
+
+ public PollenEntityId<Choice> getChoiceId() {
+ return choiceId;
+ }
+
+ public void setChoiceId(String choiceId) {
+
+ Preconditions.checkNotNull("choiceId can not be null", choiceId);
+ this.choiceId.setEntityId(choiceId);
+ }
+
+
+ public void setChoiceId(PollenEntityId<Choice> choiceId) {
+ Preconditions.checkNotNull("choiceId can not be null", choiceId);
+ this.choiceId = choiceId;
+ }
+
+
+ public BigDecimal getScoreValue() {
+ return scoreValue;
+ }
+
+ public void setScoreValue(BigDecimal scoreValue) {
+ this.scoreValue = scoreValue;
+ }
+
+ public int getScoreOrder() {
+ return scoreOrder;
+ }
+
+ public void setScoreOrder(int scoreOrder) {
+ this.scoreOrder = scoreOrder;
+ }
+}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/GroupVoteCountingResultBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/GroupVoteCountingResultBean.java
new file mode 100644
index 0000000..0a91df6
--- /dev/null
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/GroupVoteCountingResultBean.java
@@ -0,0 +1,46 @@
+package org.chorem.pollen.services.bean;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
+import org.chorem.pollen.votecounting.model.GroupVoteCountingResult;
+
+/**
+ * //FIXME
+ * Created on 5/27/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class GroupVoteCountingResultBean {
+
+
+ public void fromResult(GroupVoteCountingResult result) {
+
+ //FIXME
+
+ }
+
+ public VoteCountingResultBean getMainResult() {
+ return null;
+ }
+
+}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingResultBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingResultBean.java
new file mode 100644
index 0000000..d76b13b
--- /dev/null
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingResultBean.java
@@ -0,0 +1,71 @@
+package org.chorem.pollen.services.bean;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Created on 5/27/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoteCountingResultBean {
+
+ /**
+ * Results for each choice.
+ * <p/>
+ * <strong>Note:</strong> Natural order is used to describe choice scores
+ * (first is winner,...).
+ */
+ protected List<ChoiceScoreBean> scores;
+
+ public VoteCountingResultBean() {
+ scores = new LinkedList<>();
+ }
+
+ public void fromResult(VoteCountingResult result) {
+
+ scores.clear();
+
+ for (ChoiceScore choiceScore : result.getScores()) {
+
+ ChoiceScoreBean choiceScoreBean = new ChoiceScoreBean();
+ choiceScoreBean.fromResult(choiceScore);
+ scores.add(choiceScoreBean);
+
+ }
+
+ }
+
+ public List<ChoiceScoreBean> getScores() {
+ return scores;
+ }
+
+ public void setScores(List<ChoiceScoreBean> scores) {
+ this.scores = scores;
+ }
+}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java
index cd3a08d..90fb857 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java
@@ -32,6 +32,8 @@ import org.chorem.pollen.persistence.entity.Vote;
import org.chorem.pollen.persistence.entity.VoteToChoice;
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListMember;
+import org.chorem.pollen.services.bean.GroupVoteCountingResultBean;
+import org.chorem.pollen.services.bean.VoteCountingResultBean;
import org.chorem.pollen.votecounting.VoteCounting;
import org.chorem.pollen.votecounting.VoteCountingFactory;
import org.chorem.pollen.votecounting.VoteCountingStrategy;
@@ -55,18 +57,18 @@ import java.util.Set;
*/
public class VoteCountingService extends PollenServiceSupport {
- public VoteCountingResult getMainResult(String pollId) {
+ public VoteCountingResultBean getMainResult(String pollId) {
Preconditions.checkNotNull(pollId);
Poll poll = getPollService().getPoll0(pollId);
- VoteCountingResult mainResult;
+ VoteCountingResultBean mainResult;
if (Polls.isPollGroup(poll)) {
- GroupVoteCountingResult groupResult = getGroupResult(pollId);
+ GroupVoteCountingResultBean groupResult = getGroupResult(pollId);
mainResult = groupResult.getMainResult();
} else {
@@ -78,7 +80,7 @@ public class VoteCountingService extends PollenServiceSupport {
}
- public VoteCountingResult getSimpleResult(String pollId) {
+ public VoteCountingResultBean getSimpleResult(String pollId) {
Preconditions.checkNotNull(pollId);
@@ -90,14 +92,18 @@ public class VoteCountingService extends PollenServiceSupport {
GroupOfVoter groupOfVoter = toSimpleVotersGroup(votes);
- GroupVoteCountingResult result = strategy.votecount(groupOfVoter);
+ GroupVoteCountingResult groupVoteCountingResult = strategy.votecount(groupOfVoter);
- VoteCountingResult mainResult = result.getMainResult();
- return mainResult;
+ VoteCountingResult mainResult = groupVoteCountingResult.getMainResult();
+
+ VoteCountingResultBean result = new VoteCountingResultBean();
+ result.fromResult(mainResult);
+
+ return result;
}
- public GroupVoteCountingResult getGroupResult(String pollId) {
+ public GroupVoteCountingResultBean getGroupResult(String pollId) {
Preconditions.checkNotNull(pollId);
@@ -111,14 +117,19 @@ public class VoteCountingService extends PollenServiceSupport {
// Create a groupVoter including of the root voters
GroupOfVoter group = toGroupOfVoters(poll, voterLists, votes);
- GroupVoteCountingResult result = strategy.votecount(group);
+ GroupVoteCountingResult groupVoteCountingResult = strategy.votecount(group);
+
+
+ GroupVoteCountingResultBean result = new GroupVoteCountingResultBean();
+ result.fromResult(groupVoteCountingResult);
+
return result;
}
/**
- * Collect all vote for all voters of the givne poll.
+ * Collect all vote for all voters of the given poll.
* <p/>
* The result (a set of simple voters) are stored in a fictiv group of voter.
* <p/>
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository Pollen.
See http://git.None/Pollen.git
commit 106624546e9212dc20fc354dddc1881a3eb522ee
Author: Adrien Garandel <a.garandel(a)dralagen.fr>
Date: Mon May 26 16:00:00 2014 +0200
update home interface of poll
---
pollen-ui-angular/src/main/webapp/js/app.js | 11 +++++++++++
pollen-ui-angular/src/main/webapp/partials/poll-link.html | 6 ++++--
.../src/main/webapp/partials/poll-popupChoice.html | 4 ++--
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js
index 0cc6144..a7b5d62 100644
--- a/pollen-ui-angular/src/main/webapp/js/app.js
+++ b/pollen-ui-angular/src/main/webapp/js/app.js
@@ -162,6 +162,17 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC
};
})
+.directive('selectOnClick', function () {
+ return {
+ restrict: 'A',
+ link: function (scope, element, attrs) {
+ element.on('click', function () {
+ this.select();
+ });
+ }
+ };
+})
+
.directive('autoSave', function ($timeout) {
return {
restrict : 'A',
diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-link.html b/pollen-ui-angular/src/main/webapp/partials/poll-link.html
index 0e00f8b..fefdde1 100644
--- a/pollen-ui-angular/src/main/webapp/partials/poll-link.html
+++ b/pollen-ui-angular/src/main/webapp/partials/poll-link.html
@@ -19,6 +19,8 @@
#L%
-->
<div>
- <alert type="warning" ng-if="globalVariables.linkEdit && data.poll.permission"> Lien d'édition : <a href="{{globalVariables.linkEdit}}">{{globalVariables.linkEdit}}</a> </alert>
- <alert type="success" ng-if="globalVariables.linkVote"> Lien de vote : <a href="{{globalVariables.linkVote}}"> {{globalVariables.linkVote}}</a> </alert>
+ <h2>Sondage:</h2>
+
+ <alert type="warning" ng-if="globalVariables.linkEdit && data.poll.permission"> Lien d'édition : <input type="text" select-on-click value="{{globalVariables.linkEdit}}" readonly class="form-control"/> </alert>
+ <alert type="success" ng-if="globalVariables.linkVote"> Lien de partage pour le vote : <input type="text" select-on-click value="{{globalVariables.linkVote}}" readonly class="form-control"/> </alert>
</div>
diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html b/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html
index d17db00..a2d05ce 100644
--- a/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html
+++ b/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html
@@ -39,7 +39,7 @@
<label for="popNameChoiceCheck" class="col-sm-4 control-label">Nom du Choix : </label>
<div class="col-sm-6">
- <input id="popNameChoiceCheck" type="text" ng-model="choice.name" class="form-control" />
+ <input id="popNameChoiceCheck" type="text" ng-model="choice.name" class="form-control" focus-me="choice.choiceType == 'TEXT'"/>
</div>
</div>
@@ -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" ng-click="opened = true"/>
+ <input id="popNameChoiceDate" class="form-control" datepicker-popup="dd/MM/yyyy" type="text" ng-model="choice.date" is-open="opened" ng-click="opened = true" focus-me="choice.choiceType == 'DATE'"/>
</div>
</div>
</div>
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository Pollen.
See http://git.None/Pollen.git
commit d250985c1ebc52f74c0b0c428562fb59acda3adf
Author: Adrien Garandel <a.garandel(a)dralagen.fr>
Date: Mon May 26 14:59:29 2014 +0200
create a page for result
---
pollen-ui-angular/src/main/webapp/js/app.js | 1 +
.../src/main/webapp/js/controllers/pollCtrl.js | 60 ++++++++++++++++++++--
.../src/main/webapp/partials/poll.html | 2 +-
3 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js
index 0794019..0cc6144 100644
--- a/pollen-ui-angular/src/main/webapp/js/app.js
+++ b/pollen-ui-angular/src/main/webapp/js/app.js
@@ -63,6 +63,7 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC
.when('/poll/create', {templateUrl: './partials/poll.html', controller: "PollCreateCtrl"})
.when('/poll/edit/:pollId', {templateUrl: './partials/poll.html', controller:"PollEditCtrl"})
.when('/poll/vote/:pollId', {templateUrl: './partials/poll.html', controller :"PollVoteCtrl"})
+ .when('/poll/result/:pollId', {templateUrl: './partials/poll.html', controller :"PollResultCtrl"})
.when('/poll/list', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"})
.when('/poll/list/:cmd', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"})
.when('/user/register', {templateUrl: './partials/user-register.html', controller:"UserRegisterCtrl"})
diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
index f19bd8e..d9eab78 100644
--- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
+++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
@@ -75,9 +75,11 @@ angular.module('pollControllers', [])
if (angular.isDefined($routeParams.pollId)) {
$scope.globalVariables.linkVote = $location.protocol()+'://'+$location.host()+'/#/poll/vote/'+$routeParams.pollId;
$scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId;
+ $scope.globalVariables.linkResult = $location.protocol()+'://'+$location.host()+'/#/poll/result/'+$routeParams.pollId;
if (angular.isDefined($scope.globalVariables.permission)) {
$scope.globalVariables.linkEdit += '?token='+$scope.globalVariables.permission;
+ $scope.globalVariables.linkResult += '?token='+$scope.globalVariables.permission;
}
}
@@ -113,7 +115,7 @@ angular.module('pollControllers', [])
}])
-.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', '$routeParams', function ($scope, $controller, $modal, $filter, $timeout, $routeParams) {
+.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$timeout', '$routeParams', function ($scope, $controller, $modal, $timeout, $routeParams) {
$controller('PollCtrl', {$scope:$scope});
if (angular.isDefined($routeParams.tab)) {
@@ -184,7 +186,7 @@ angular.module('pollControllers', [])
}
- var PollPopChoiceCtrl = function ($scope, $filter, $modalInstance, title, choice) {
+ var PollPopChoiceCtrl = function ($scope, $modalInstance, title, choice) {
$scope.title = title;
$scope.choice = choice;
@@ -363,7 +365,7 @@ angular.module('pollControllers', [])
}
}])
-.controller('PollVoteCtrl', ['$scope', '$q', '$filter', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $filter, $controller, $routeParams, Poll, PollChoice, PollVote) {
+.controller('PollVoteCtrl', ['$scope', '$q', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $controller, $routeParams, Poll, PollChoice, PollVote) {
$controller('PollCtrl', {$scope:$scope});
if (angular.isDefined($routeParams.tab)) {
@@ -373,8 +375,6 @@ angular.module('pollControllers', [])
$scope.tab = 'vote';
}
- $scope.globalVariables.results = true;
-
var initPoll = function () {
var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) {
$scope.data.poll = poll;
@@ -448,6 +448,56 @@ angular.module('pollControllers', [])
}
}])
+.controller('PollResultCtrl', ['$scope', '$q', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $controller, $routeParams, Poll, PollChoice, PollVote) {
+ $controller('PollCtrl', {$scope:$scope});
+
+ if (angular.isDefined($routeParams.tab)) {
+ $scope.tab = $routeParams.tab;
+ }
+ else {
+ $scope.tab = 'result';
+ }
+
+ var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) {
+ $scope.data.poll = poll;
+ }).$promise;
+
+ var choicesPromise = PollChoice.query({pollId:$routeParams.pollId}, function (choices) {
+ $scope.data.choices = choices;
+ }).$promise;
+
+
+ var votesPromise = PollVote.query({pollId:$routeParams.pollId}, function (votes) {
+ $scope.data.votants = votes;
+ angular.forEach($scope.data.votants, function (vote) {
+ angular.forEach(vote.choice, function (choice) {
+ if (choice.voteValue != null && choice.voteValue != 0.0) {
+ choice.voteValue = true;
+ }
+ else {
+ choice.voteValue = false;
+ }
+ })
+ })
+ }).$promise;
+
+ $q.all([choicesPromise, votesPromise]).then(function () {
+ Poll.get({pollId:$routeParams.pollId, cmd:'results'}, function (result) {
+ $scope.data.result = result;
+ angular.forEach(result.scores, function(value, key) {
+ for (var i = 0; i < $scope.data.choices.length; i++) {
+ if ($scope.data.choices[i].id == value.choiceId) {
+ value.choice = $scope.data.choices[i];
+ i = $scope.data.choices.length;
+ }
+ }
+ })
+ $scope.data.result.nbVotant = $scope.data.votants.length;
+ });
+ });
+
+}])
+
.controller('PollListCtrl', ['$scope', '$controller', '$routeParams', 'Poll', function ($scope, $controller, $routeParams, Poll) {
$controller('PollCtrl', {$scope:$scope});
diff --git a/pollen-ui-angular/src/main/webapp/partials/poll.html b/pollen-ui-angular/src/main/webapp/partials/poll.html
index f77abba..eb56255 100644
--- a/pollen-ui-angular/src/main/webapp/partials/poll.html
+++ b/pollen-ui-angular/src/main/webapp/partials/poll.html
@@ -26,7 +26,7 @@
<ul class="nav nav-tabs">
<li ng-class="{active: tab == 'home'}"><a href="{{url}}tab=home"> <span class="glyphicon glyphicon-home"></span> </a></li>
<li ng-class="{active: tab == 'vote'}" ng-show="data.poll.id"><a href="{{globalVariables.linkVote}}">Voter</a></li>
- <li ng-class="{active: tab == 'result'}" ng-show="!globalVariables.create"><a href="{{url}}tab=result">Résultat</a></li>
+ <li ng-class="{active: tab == 'result'}" ng-show="!globalVariables.create"><a href="{{globalVariables.linkResult}}">Résultat</a></li>
<li ng-class="{active: tab == 'edit'}" ng-show="globalVariables.create"><a href="#/poll/create">Créer</a></li>
<li ng-class="{active: tab == 'edit'}" ng-show="data.poll.permission"><a href="{{globalVariables.linkEdit}}">Editer</a></li>
<li ng-class="{active: tab == 'conf'}" ng-show="data.poll.permission || globalVariables.create"><a href="{{url}}tab=conf">Configuration</a></li>
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository Pollen.
See http://git.None/Pollen.git
commit 214d089987eb80136a30d776e5eecb48333c9aff
Author: Adrien Garandel <a.garandel(a)dralagen.fr>
Date: Mon May 26 14:37:21 2014 +0200
update tab and save permission on offline
---
.../src/main/webapp/js/controllers/pollCtrl.js | 65 ++++++++++++++++------
.../src/main/webapp/partials/poll.html | 12 ++--
2 files changed, 55 insertions(+), 22 deletions(-)
diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
index 202b551..f19bd8e 100644
--- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
+++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
@@ -23,12 +23,6 @@ angular.module('pollControllers', [])
}])
.controller('PollCtrl', ['$scope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', function ($scope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage) {
- if (angular.isDefined($routeParams.tab)) {
- $scope.tab = $routeParams.tab;
- }
- else {
- $scope.tab = 'poll';
- }
$scope.url = $location.protocol()+'://'+$location.host()+'/#'+$location.path();
if ($location.search().length != 0) {
@@ -51,7 +45,30 @@ angular.module('pollControllers', [])
$scope.globalVariables.saved = false;
}, 5000);
});
+
+ /**
+ * Sauvegarde du token si non connecté
+ */
+ var session = SessionStorage.get();
+ if (angular.isUndefined($routeParams.token) && angular.isUndefined(session.id)) { // pas de paramètre url et non connecté
+ if (angular.isDefined(session.permission) && session.permission != '') { // existe une permission
+ $scope.globalVariables.permission = session.permission;
+ }
+ else if (session.permission == '') {
+ SessionStorage.remove('permission');
+ }
+ }
+ else if (angular.isDefined(session.id)) { // connecté
+ if (angular.isDefined(session.permission)) { // connecté => pas besoin de permission
+ SessionStorage.remove('permission');
+ }
+ }
+ else { //token dans l'URL
+ SessionStorage.save({permission:$routeParams.token});
+ $scope.globalVariables.permission = $routeParams.token;
+ }
}
+
$scope.data = {};
$scope.data.poll = {};
@@ -59,8 +76,8 @@ angular.module('pollControllers', [])
$scope.globalVariables.linkVote = $location.protocol()+'://'+$location.host()+'/#/poll/vote/'+$routeParams.pollId;
$scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId;
- if (angular.isDefined($routeParams.token)) {
- $scope.globalVariables.linkEdit += '?token='+$routeParams.token;
+ if (angular.isDefined($scope.globalVariables.permission)) {
+ $scope.globalVariables.linkEdit += '?token='+$scope.globalVariables.permission;
}
}
@@ -96,9 +113,16 @@ angular.module('pollControllers', [])
}])
-.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', function ($scope, $controller, $modal, $filter, $timeout) {
+.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', '$routeParams', function ($scope, $controller, $modal, $filter, $timeout, $routeParams) {
$controller('PollCtrl', {$scope:$scope});
+ if (angular.isDefined($routeParams.tab)) {
+ $scope.tab = $routeParams.tab;
+ }
+ else {
+ $scope.tab = 'edit';
+ }
+
var initChoice = function () {
return {
name: '',
@@ -237,7 +261,7 @@ angular.module('pollControllers', [])
$scope.globalVariables.edit = true;
$scope.callBackAddChoice = function (choice) {
- PollChoice.add({pollId:$routeParams.pollId, permission:$routeParams.token}, choice, function (data) {
+ PollChoice.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, choice, function (data) {
delete choice.restError;
choice.topiaId = data.topiaId;
$scope.globalVariables.saved = true;
@@ -247,7 +271,7 @@ angular.module('pollControllers', [])
}
$scope.callBackEditChoice = function (choice) {
- PollChoice.update({pollId:$routeParams.pollId, permission:$routeParams.token}, choice, function() {
+ PollChoice.update({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, choice, function() {
delete choice.restError;
$scope.globalVariables.saved = true;
}, function (error) {
@@ -256,7 +280,7 @@ angular.module('pollControllers', [])
}
$scope.deleteChoice = function (choice) {
- PollChoice.remove({pollId:$routeParams.pollId, permission:$routeParams.token, choiceId: choice.id}, function () {
+ PollChoice.remove({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission, choiceId: choice.id}, function () {
$scope.globalVariables.saved = true;
var index = $scope.data.choices.indexOf(choice);
if (index > -1) {
@@ -268,14 +292,14 @@ angular.module('pollControllers', [])
}
var initPoll = function () {
- var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$routeParams.token}, function (poll) {
+ var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) {
if (angular.isUndefined(poll.permission)) {
$location.path('/');
}
$scope.data.poll = poll;
}).$promise;
- var choicesPromise = PollChoice.query({pollId:$routeParams.pollId, permission:$routeParams.token}).$promise.then(function (choices) {
+ var choicesPromise = PollChoice.query({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}).$promise.then(function (choices) {
$scope.data.choices = choices;
$scope.data.vote = {};
$scope.data.vote.choice = $scope.data.choices;
@@ -314,7 +338,7 @@ angular.module('pollControllers', [])
initPoll();
$scope.savePoll = function () {
- $scope.data.poll.$update({permission:$routeParams.token}, function (data) {
+ $scope.data.poll.$update({permission:$scope.globalVariables.permission}, function (data) {
$scope.globalVariables.saved = true;
}, function (error) {
angular.extend($scope.restError, error.data);
@@ -333,7 +357,7 @@ angular.module('pollControllers', [])
}
$scope.deletePoll = function () {
- $scope.data.poll.$remove({permission:$routeParams.token}, function() {
+ $scope.data.poll.$remove({permission:$scope.globalVariables.permission}, function() {
$location.path('/');
});
}
@@ -342,10 +366,17 @@ angular.module('pollControllers', [])
.controller('PollVoteCtrl', ['$scope', '$q', '$filter', '$controller', '$routeParams', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $filter, $controller, $routeParams, Poll, PollChoice, PollVote) {
$controller('PollCtrl', {$scope:$scope});
+ if (angular.isDefined($routeParams.tab)) {
+ $scope.tab = $routeParams.tab;
+ }
+ else {
+ $scope.tab = 'vote';
+ }
+
$scope.globalVariables.results = true;
var initPoll = function () {
- var pollPromise = Poll.get({pollId:$routeParams.pollId}, function (poll) {
+ var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$scope.globalVariables.permission}, function (poll) {
$scope.data.poll = poll;
}).$promise;
diff --git a/pollen-ui-angular/src/main/webapp/partials/poll.html b/pollen-ui-angular/src/main/webapp/partials/poll.html
index e20217c..f77abba 100644
--- a/pollen-ui-angular/src/main/webapp/partials/poll.html
+++ b/pollen-ui-angular/src/main/webapp/partials/poll.html
@@ -24,15 +24,17 @@
<alert type="success" class="alert-float" ng-if="!globalVariables.editMode && globalVariables.saved" close="globalVariables.saved = false"> Vote effectué..</alert>
<ul class="nav nav-tabs">
- <li ng-class="{active: tab == 'home'}" ng-click="tab = 'home'"><a href="{{url}}tab=home"> <span class="glyphicon glyphicon-home"></span> </a></li>
- <li ng-class="{active: tab == 'poll'}" ng-click="tab = 'poll'"><a href="{{url}}tab=poll">Sondage</a></li>
- <li ng-class="{active: tab == 'result'}" ng-click="tab = 'result'" ng-show="!globalVariables.create"><a href="{{url}}tab=result">Result</a></li>
- <li ng-class="{active: tab == 'conf'}" ng-click="tab = 'conf'" ng-show="globalVariables.editMode"><a href="{{url}}tab=conf">Configuration</a></li>
+ <li ng-class="{active: tab == 'home'}"><a href="{{url}}tab=home"> <span class="glyphicon glyphicon-home"></span> </a></li>
+ <li ng-class="{active: tab == 'vote'}" ng-show="data.poll.id"><a href="{{globalVariables.linkVote}}">Voter</a></li>
+ <li ng-class="{active: tab == 'result'}" ng-show="!globalVariables.create"><a href="{{url}}tab=result">Résultat</a></li>
+ <li ng-class="{active: tab == 'edit'}" ng-show="globalVariables.create"><a href="#/poll/create">Créer</a></li>
+ <li ng-class="{active: tab == 'edit'}" ng-show="data.poll.permission"><a href="{{globalVariables.linkEdit}}">Editer</a></li>
+ <li ng-class="{active: tab == 'conf'}" ng-show="data.poll.permission || globalVariables.create"><a href="{{url}}tab=conf">Configuration</a></li>
</ul>
<div ng-include="'partials/poll-link.html'" ng-if="tab == 'home'"></div>
-<div ng-if="tab == 'poll'">
+<div ng-if="tab == 'edit' || tab == 'vote'">
<div class="pollTitle" edit-me="showEditTitle">
<h1 ng-hide="showEditTitle">
{{data.poll.title || 'Click pour éditer'}}
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository Pollen.
See http://git.None/Pollen.git
commit c64514a5471fcb8d2d2b0c7151c69dd12abf2e6f
Author: Adrien Garandel <a.garandel(a)dralagen.fr>
Date: Fri May 23 17:13:01 2014 +0200
set home page for poll
---
.../src/main/webapp/js/controllers/pollCtrl.js | 77 ++++++++++++++++------
.../src/main/webapp/partials/poll-link.html | 24 +++++++
.../src/main/webapp/partials/poll.html | 26 ++++----
3 files changed, 96 insertions(+), 31 deletions(-)
diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
index 19526d4..202b551 100644
--- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
+++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
@@ -22,11 +22,29 @@ angular.module('pollControllers', [])
.controller('HomeCtrl', ['$scope', function ($scope) {
}])
-.controller('PollCtrl', ['$scope', '$controller', '$sce', '$timeout', '$cookies', function ($scope, $controller, $sce, $timeout, $cookies) {
+.controller('PollCtrl', ['$scope', '$controller', '$sce', '$timeout', '$routeParams', '$location', 'SessionStorage', function ($scope, $controller, $sce, $timeout, $routeParams, $location, SessionStorage) {
+ if (angular.isDefined($routeParams.tab)) {
+ $scope.tab = $routeParams.tab;
+ }
+ else {
+ $scope.tab = 'poll';
+ }
+
+ $scope.url = $location.protocol()+'://'+$location.host()+'/#'+$location.path();
+ if ($location.search().length != 0) {
+ $scope.url += '?';
+ angular.forEach($location.search(), function(value, key) {
+ if (key != 'tab')
+ $scope.url += key+'='+value+'&';
+ })
+ }
+ else {
+ $scope.url += '?';
+ }
- if (!angular.isDefined($scope.globalVariables)) {
- $scope.globalVariables = {saved : $cookies.saved};
- delete $cookies.saved
+ if (angular.isUndefined($scope.globalVariables)) {
+ $scope.globalVariables = {saved : SessionStorage.get().saved};
+ SessionStorage.remove('saved');
$scope.$watch('globalVariables.saved', function() {
$timeout(function () {
@@ -37,6 +55,15 @@ angular.module('pollControllers', [])
$scope.data = {};
$scope.data.poll = {};
+ if (angular.isDefined($routeParams.pollId)) {
+ $scope.globalVariables.linkVote = $location.protocol()+'://'+$location.host()+'/#/poll/vote/'+$routeParams.pollId;
+ $scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId;
+
+ if (angular.isDefined($routeParams.token)) {
+ $scope.globalVariables.linkEdit += '?token='+$routeParams.token;
+ }
+ }
+
$scope.toHTML = function (data) {
return $sce.trustAsHtml(data);
}
@@ -165,7 +192,7 @@ angular.module('pollControllers', [])
}
}])
-.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', '$cookies', function ($scope, $controller, $location, Poll, $cookies) {
+.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', 'SessionStorage', function ($scope, $controller, $location, Poll, SessionStorage) {
$controller('PollAdminCtrl', {$scope:$scope});
$scope.globalVariables.create = true;
@@ -185,7 +212,7 @@ angular.module('pollControllers', [])
var poll = angular.copy($scope.data.poll);
poll.choice = angular.copy($scope.data.choices);
Poll.add(poll, function (data) {
- $cookies.saved = true;
+ SessionStorage.save({saved: true});
$location.url('/poll/edit/'+data.id+'?token='+data.permission);
}, function (error) {
$scope.globalVariables.restError = true;
@@ -204,16 +231,10 @@ angular.module('pollControllers', [])
}])
-.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', '$location', '$timeout', 'Poll', 'PollChoice', 'PollVote', function ($scope, $controller, $routeParams, $location, $timeout, Poll, PollChoice, PollVote) {
+.controller('PollEditCtrl', ['$scope', '$q', '$controller', '$routeParams', '$location', '$timeout', 'Poll', 'PollChoice', 'PollVote', function ($scope, $q, $controller, $routeParams, $location, $timeout, Poll, PollChoice, PollVote) {
$controller('PollAdminCtrl', {$scope:$scope});
$scope.globalVariables.edit = true;
- $scope.globalVariables.hostName = $location.protocol()+'://'+$location.host();
-
- $scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId
- if (angular.isDefined($routeParams.token)) {
- $scope.globalVariables.linkEdit += '?token='+$routeParams.token;
- }
$scope.callBackAddChoice = function (choice) {
PollChoice.add({pollId:$routeParams.pollId, permission:$routeParams.token}, choice, function (data) {
@@ -247,18 +268,20 @@ angular.module('pollControllers', [])
}
var initPoll = function () {
- Poll.get({pollId:$routeParams.pollId, permission:$routeParams.token}, function (poll) {
+ var pollPromise = Poll.get({pollId:$routeParams.pollId, permission:$routeParams.token}, function (poll) {
if (angular.isUndefined(poll.permission)) {
$location.path('/');
}
$scope.data.poll = poll;
- });
- PollChoice.query({pollId:$routeParams.pollId, permission:$routeParams.token}).$promise.then(function (choices) {
+ }).$promise;
+
+ var choicesPromise = PollChoice.query({pollId:$routeParams.pollId, permission:$routeParams.token}).$promise.then(function (choices) {
$scope.data.choices = choices;
$scope.data.vote = {};
$scope.data.vote.choice = $scope.data.choices;
- });
- PollVote.query({pollId:$routeParams.pollId}, function (votes) {
+ }).$promise;
+
+ var votesPromise = PollVote.query({pollId:$routeParams.pollId}, function (votes) {
$scope.data.votants = votes;
angular.forEach($scope.data.votants, function (vote) {
angular.forEach(vote.choice, function (choice) {
@@ -270,7 +293,23 @@ angular.module('pollControllers', [])
}
})
})
- })
+ }).$promise;
+
+ $q.all([choicesPromise, votesPromise]).then(function () {
+ Poll.get({pollId:$routeParams.pollId, cmd:'results'}, function (result) {
+ $scope.data.result = result;
+ angular.forEach(result.scores, function(value, key) {
+ for (var i = 0; i < $scope.data.choices.length; i++) {
+ if ($scope.data.choices[i].id == value.choiceId) {
+ value.choice = $scope.data.choices[i];
+ i = $scope.data.choices.length;
+ }
+ }
+ })
+ $scope.data.result.nbVotant = $scope.data.votants.length;
+ });
+ });
+
}
initPoll();
diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-link.html b/pollen-ui-angular/src/main/webapp/partials/poll-link.html
new file mode 100644
index 0000000..0e00f8b
--- /dev/null
+++ b/pollen-ui-angular/src/main/webapp/partials/poll-link.html
@@ -0,0 +1,24 @@
+<!--
+ #%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%
+ -->
+<div>
+ <alert type="warning" ng-if="globalVariables.linkEdit && data.poll.permission"> Lien d'édition : <a href="{{globalVariables.linkEdit}}">{{globalVariables.linkEdit}}</a> </alert>
+ <alert type="success" ng-if="globalVariables.linkVote"> Lien de vote : <a href="{{globalVariables.linkVote}}"> {{globalVariables.linkVote}}</a> </alert>
+</div>
diff --git a/pollen-ui-angular/src/main/webapp/partials/poll.html b/pollen-ui-angular/src/main/webapp/partials/poll.html
index d8529fb..e20217c 100644
--- a/pollen-ui-angular/src/main/webapp/partials/poll.html
+++ b/pollen-ui-angular/src/main/webapp/partials/poll.html
@@ -23,11 +23,16 @@
<alert type="success" class="alert-float" ng-if="globalVariables.editMode && globalVariables.saved" close="globalVariables.saved = false"> Sondage sauvegardé..</alert>
<alert type="success" class="alert-float" ng-if="!globalVariables.editMode && globalVariables.saved" close="globalVariables.saved = false"> Vote effectué..</alert>
- <alert type="warning" ng-if="globalVariables.linkEdit"> Lien d'édition : <a href="{{globalVariables.linkEdit}}">{{globalVariables.linkEdit}}</a> </alert>
- <alert type="success" ng-if="globalVariables.edit"> Lien de vote : <a href="#/poll/vote/{{data.poll.id}}"> {{globalVariables.hostName}}/#/poll/vote/{{data.poll.id}}</a> </alert>
-<tabset>
-<tab heading="Sondage">
+ <ul class="nav nav-tabs">
+ <li ng-class="{active: tab == 'home'}" ng-click="tab = 'home'"><a href="{{url}}tab=home"> <span class="glyphicon glyphicon-home"></span> </a></li>
+ <li ng-class="{active: tab == 'poll'}" ng-click="tab = 'poll'"><a href="{{url}}tab=poll">Sondage</a></li>
+ <li ng-class="{active: tab == 'result'}" ng-click="tab = 'result'" ng-show="!globalVariables.create"><a href="{{url}}tab=result">Result</a></li>
+ <li ng-class="{active: tab == 'conf'}" ng-click="tab = 'conf'" ng-show="globalVariables.editMode"><a href="{{url}}tab=conf">Configuration</a></li>
+ </ul>
+<div ng-include="'partials/poll-link.html'" ng-if="tab == 'home'"></div>
+
+<div ng-if="tab == 'poll'">
<div class="pollTitle" edit-me="showEditTitle">
<h1 ng-hide="showEditTitle">
{{data.poll.title || 'Click pour éditer'}}
@@ -56,14 +61,6 @@
</div>
-</tab>
-<tab heading="Configuration" ng-show="globalVariables.editMode" >
- <div ng-include="'partials/poll-settings.html'"></div>
-</tab>
-</tabset>
-
- <div ng-include="'./partials/poll-result.html'" ng-if="globalVariables.results"></div>
-
<div ng-if="globalVariables.create">
<hr/>
<button type="button" class="btn btn-default" ng-model="globalVariables.editMode" btn-checkbox>Mode Edition</button>
@@ -75,5 +72,10 @@
<button type="button" class="btn btn-default" ng-model="globalVariables.editMode" btn-checkbox>Mode Edition</button>
<button class="btn btn-danger" ng-click="deletePoll();">Supprimer</button>
</div>
+</div>
+
+ <div ng-include="'partials/poll-settings.html'" ng-if="tab == 'conf'"></div>
+
+ <div ng-include="'./partials/poll-result.html'" ng-if="tab == 'result'"></div>
</form>
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
25 May '14
See <http://ci.chorem.org/jenkins/job/pollen-rest-api-ci/284/>
------------------------------------------
Started by an SCM change
Building in workspace <http://ci.chorem.org/jenkins/job/pollen-rest-api-ci/ws/>
Fetching changes from the remote Git repository
Fetching upstream changes from https://git.chorem.org/pollen.git
FATAL: Failed to fetch from https://git.chorem.org/pollen.git
hudson.plugins.git.GitException: Failed to fetch from https://git.chorem.org/pollen.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:623)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:855)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:880)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1251)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:605)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:514)
at hudson.model.Run.execute(Run.java:1703)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:525)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:231)
Caused by: hudson.plugins.git.GitException: Failed to connect to https://git.chorem.org/pollen.git (status = 404)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.checkCredentials(CliGitAPIImpl.java:1929)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1123)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:254)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:621)
... 10 more
1
15
This is an automated email from the git hooks/post-receive script.
unknown user pushed a commit to branch devel
in repository Pollen.
commit 9c9cf913a7a41448679d91fb405cf9a96bc99546
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Sat May 24 14:51:13 2014 +0200
introduce json helper + use a PollenEntityRef
---
.../persistence/PollenTopiaApplicationContext.java | 21 ++
.../pollen/persistence/entity/CommentTopiaDao.java | 21 ++
.../pollen/persistence/entity/VoteToChoices.java | 21 ++
.../pollen/persistence/entity/VoteTopiaDao.java | 21 ++
.../org/chorem/pollen/rest/api/JsonHelper.java | 254 +++++++++++++++++++++
.../org/chorem/pollen/rest/api/PollenRender.java | 50 +---
.../chorem/pollen/rest/api/PollenRestApiUtil.java | 145 ++----------
.../pollen/rest/api/converter/DateConverter.java | 21 ++
.../rest/api/converter/JsonArrayConverter.java | 43 +++-
.../pollen/rest/api/converter/JsonConverter.java | 15 +-
.../rest/api/injector/PollenBeanIdInjector.java | 21 ++
.../PollenRestApiRequestContextInjector.java | 21 ++
.../rest/api/injector/PollenServiceInjector.java | 21 ++
.../org/chorem/pollen/rest/api/v1/AuthApi.java | 7 +-
.../org/chorem/pollen/rest/api/v1/ChoiceApi.java | 6 +-
.../org/chorem/pollen/rest/api/v1/CommentApi.java | 6 +-
.../chorem/pollen/rest/api/v1/FavoriteListApi.java | 10 +-
.../org/chorem/pollen/rest/api/v1/PollApi.java | 12 +-
.../chorem/pollen/rest/api/v1/PollenUserApi.java | 10 +-
.../org/chorem/pollen/rest/api/v1/VoteApi.java | 6 +-
.../chorem/pollen/rest/api/v1/VoterListApi.java | 6 +-
.../pollen/rest/api/AbstractPollenRestApiTest.java | 14 ++
.../org/chorem/pollen/rest/api/AuthApiTest.java | 35 ++-
.../org/chorem/pollen/rest/api/PollApiTest.java | 33 ++-
.../chorem/pollen/rest/api/PollenUserApiTest.java | 19 +-
.../rest/api/converter/JsonArrayConverterTest.java | 21 ++
.../chorem/pollen/services/bean/ChoiceBean.java | 21 ++
.../chorem/pollen/services/bean/CommentBean.java | 21 ++
.../chorem/pollen/services/bean/CreateBeanRef.java | 105 ---------
.../pollen/services/bean/FavoriteListBean.java | 21 ++
.../services/bean/FavoriteListMemberBean.java | 21 ++
.../org/chorem/pollen/services/bean/PollBean.java | 21 ++
.../chorem/pollen/services/bean/PollenBean.java | 41 +++-
.../pollen/services/bean/PollenEntityId.java | 21 ++
.../pollen/services/bean/PollenEntityRef.java | 129 +++++++++++
.../pollen/services/bean/PollenUserBean.java | 21 ++
.../org/chorem/pollen/services/bean/VoteBean.java | 21 ++
.../pollen/services/bean/VoteToChoiceBean.java | 21 ++
.../chorem/pollen/services/bean/VoterListBean.java | 21 ++
.../pollen/services/bean/VoterListMemberBean.java | 21 ++
.../chorem/pollen/services/bean/package-info.java | 4 +-
.../pollen/services/service/ChoiceService.java | 6 +-
.../pollen/services/service/CommentService.java | 6 +-
.../services/service/FavoriteListService.java | 12 +-
.../pollen/services/service/FixturesService.java | 6 +-
.../pollen/services/service/PollService.java | 6 +-
.../pollen/services/service/PollenUserService.java | 6 +-
.../pollen/services/service/VoteService.java | 6 +-
.../pollen/services/service/VoterListService.java | 6 +-
.../services/service/security/SecurityService.java | 7 +-
.../pollen/services/AbstractPollenServiceTest.java | 5 +-
.../pollen/services/service/PollServiceTest.java | 69 +++---
.../services/service/PollenUserServiceTest.java | 10 +-
.../services/service/VoteCountingServiceTest.java | 28 ++-
.../pollen/services/service/VoteServiceTest.java | 21 ++
55 files changed, 1134 insertions(+), 430 deletions(-)
diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaApplicationContext.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaApplicationContext.java
index f19a22f..1e7779b 100644
--- a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaApplicationContext.java
+++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaApplicationContext.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.persistence;
+/*
+ * #%L
+ * Pollen :: Persistence
+ * %%
+ * 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%
+ */
+
import org.nuiton.topia.persistence.TopiaIdFactory;
import java.util.Map;
diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentTopiaDao.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentTopiaDao.java
index f4835cc..6ee2722 100644
--- a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentTopiaDao.java
+++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentTopiaDao.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.persistence.entity;
+/*
+ * #%L
+ * Pollen :: Persistence
+ * %%
+ * 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%
+ */
+
import java.util.List;
public class CommentTopiaDao extends AbstractCommentTopiaDao<Comment> {
diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteToChoices.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteToChoices.java
index 43762ff..03dc60f 100644
--- a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteToChoices.java
+++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteToChoices.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.persistence.entity;
+/*
+ * #%L
+ * Pollen :: Persistence
+ * %%
+ * 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%
+ */
+
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteTopiaDao.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteTopiaDao.java
index e6091e4..f2d675b 100644
--- a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteTopiaDao.java
+++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteTopiaDao.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.persistence.entity;
+/*
+ * #%L
+ * Pollen :: Persistence
+ * %%
+ * 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%
+ */
+
import java.util.List;
public class VoteTopiaDao extends AbstractVoteTopiaDao<Vote> {
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java
new file mode 100644
index 0000000..863a2b1
--- /dev/null
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java
@@ -0,0 +1,254 @@
+package org.chorem.pollen.rest.api;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
+import com.google.common.collect.Multimap;
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.PollenEntityRef;
+import org.chorem.pollen.services.service.InvalidFormException;
+import org.nuiton.topia.persistence.TopiaIdFactory;
+
+import java.lang.reflect.Type;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created on 5/24/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class JsonHelper {
+
+ private final Gson gson;
+
+ public JsonHelper(final TopiaIdFactory idFactory, boolean prettyPrint) {
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+
+ gsonBuilder.setExclusionStrategies(new ExclusionStrategy() {
+ @Override
+ public boolean shouldSkipField(FieldAttributes f) {
+ return false;
+ }
+
+ @Override
+ public boolean shouldSkipClass(Class<?> clazz) {
+ return clazz == Class.class;
+ }
+ });
+
+ gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
+
+ @Override
+ public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
+
+ JsonElement result;
+
+ if (src == null) {
+
+ result = JsonNull.INSTANCE;
+
+ } else {
+
+ result = new JsonPrimitive(src.getTime());
+
+ }
+
+ return result;
+
+ }
+
+ });
+
+ gsonBuilder.registerTypeAdapter(PollenEntityId.class, new JsonSerializer<PollenEntityId>() {
+
+ @Override
+ public JsonElement serialize(PollenEntityId src, Type typeOfSrc, JsonSerializationContext context) {
+
+ JsonElement result;
+
+ if (src == null || src.getEntityId() == null) {
+
+ result = JsonNull.INSTANCE;
+
+ } else {
+
+ src.encode(idFactory);
+ result = new JsonPrimitive(src.getReducedId());
+
+ }
+
+ return result;
+
+ }
+
+ });
+
+ gsonBuilder.registerTypeAdapter(PollenEntityRef.class, new JsonSerializer<PollenEntityRef>() {
+
+ @Override
+ public JsonElement serialize(PollenEntityRef src, Type typeOfSrc, JsonSerializationContext context) {
+
+ JsonElement result;
+
+ if (src == null || src.getEntityId() == null) {
+
+ result = JsonNull.INSTANCE;
+
+ } else {
+
+ src.encode(idFactory);
+
+ JsonObject object = new JsonObject();
+ object.add("permission", new JsonPrimitive(src.getPermission()));
+ object.add("id", new JsonPrimitive(src.getReducedId()));
+
+ result = object;
+
+ }
+
+ return result;
+
+ }
+
+ });
+
+ gsonBuilder.registerTypeAdapter(InvalidFormException.class, new JsonSerializer<InvalidFormException>() {
+
+ @Override
+ public JsonElement serialize(InvalidFormException src, Type typeOfSrc, JsonSerializationContext context) {
+
+
+ Multimap<String, String> errors = src.getErrors();
+
+ Map<String, Object> map = new HashMap<>();
+ for (String key : errors.keySet()) {
+ map.put(key, errors.get(key));
+ }
+
+ JsonElement result = context.serialize(map);
+
+ return result;
+
+ }
+
+ });
+
+ gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
+
+ @Override
+ public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+ return new Date(json.getAsLong());
+ }
+
+ });
+
+ gsonBuilder.registerTypeAdapter(PollenEntityId.class, new JsonDeserializer<PollenEntityId>() {
+
+ @Override
+ public PollenEntityId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+
+ PollenEntityId id = PollenEntityId.newId(typeOfT);
+
+ String asString = json.getAsString();
+
+ if (asString != null) {
+
+ id.setReducedId(asString);
+ id.decode(idFactory);
+
+ }
+
+ return id;
+
+ }
+
+ });
+
+ gsonBuilder.registerTypeAdapter(PollenEntityRef.class, new JsonDeserializer<PollenEntityRef>() {
+
+ @Override
+ public PollenEntityRef deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+
+ String id = ((JsonObject) json).get("id").getAsString();
+ String permission = ((JsonObject) json).get("permission").getAsString();
+
+ PollenEntityRef<?> ref = PollenEntityRef.newRef(typeOfT);
+
+ ref.setReducedId(id);
+ ref.setPermission(permission);
+ ref.decode(idFactory);
+
+
+ return ref;
+
+ }
+
+ });
+
+ if (prettyPrint) {
+
+ gsonBuilder.setPrettyPrinting();
+
+ }
+
+ this.gson = gsonBuilder.create();
+
+ }
+
+ public String toJson(Object model) {
+
+ String json = gson.toJson(model);
+ return json;
+
+ }
+
+ public <O> O fromJson(String json, Class<O> type) {
+
+ O o = gson.fromJson(json, type);
+ return o;
+
+ }
+
+ public <O> O fromJson(String json, Type type) {
+
+ O o = gson.fromJson(json, type);
+ return o;
+
+ }
+
+}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
index 71a5922..979f22b 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
@@ -23,10 +23,6 @@ package org.chorem.pollen.rest.api;
* #L%
*/
-import com.google.common.collect.Multimap;
-import com.google.gson.Gson;
-import org.chorem.pollen.services.bean.CreateBeanRef;
-import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.service.InvalidFormException;
import org.debux.webmotion.server.call.Call;
import org.debux.webmotion.server.call.HttpContext;
@@ -38,8 +34,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Map;
/**
* To render any entities.
@@ -64,9 +58,6 @@ public class PollenRender<T> extends Render {
PollenRestApiApplicationContext applicationContext =
PollenRestApiApplicationContext.getApplicationContext(context.getServletContext());
- TopiaIdFactory topiaIdFactory = applicationContext.getTopiaApplicationContext().getTopiaIdFactory();
-
- Object map;
if (model instanceof InvalidFormException) {
@@ -74,50 +65,15 @@ public class PollenRender<T> extends Render {
}
- map = toMap(topiaIdFactory, model);
-
-
+ TopiaIdFactory topiaIdFactory = applicationContext.getTopiaApplicationContext().getTopiaIdFactory();
boolean devMode = applicationContext.getApplicationConfig().isDevMode();
-
- Gson gson = PollenRestApiUtil.newGson(topiaIdFactory, devMode);
- String json = gson.toJson(map);
+ JsonHelper gson = new JsonHelper(topiaIdFactory, devMode);
+ String json = gson.toJson(model);
PrintWriter out = context.getOut();
out.print(json);
}
- protected <M> Object toMap(TopiaIdFactory topiaIdFactory, M model) {
-
- 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 CreateBeanRef) {
-
- // encode id
- CreateBeanRef createBeanRef = (CreateBeanRef) model;
- String encodeId = PollenEntityId.encode(topiaIdFactory, createBeanRef.getId());
-
- CreateBeanRef result = CreateBeanRef.of(encodeId, createBeanRef.getPermission());
- return result;
-
- }
-
- return model;
-
- }
-
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
index affba69..f95df3a 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
@@ -1,26 +1,31 @@
package org.chorem.pollen.rest.api;
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
import com.google.common.collect.Lists;
-import com.google.gson.ExclusionStrategy;
-import com.google.gson.FieldAttributes;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonNull;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.services.bean.PollenEntityId;
import org.debux.webmotion.server.call.HttpContext;
-import org.nuiton.topia.persistence.TopiaIdFactory;
import javax.servlet.http.HttpServletResponse;
-import java.lang.reflect.Type;
-import java.util.Date;
import java.util.List;
/**
@@ -47,12 +52,6 @@ public class PollenRestApiUtil {
return list;
}
- public static String entitiesToString(TopiaIdFactory topiaIdFactory, Object o) {
-
- return newGson(topiaIdFactory, true).toJson(o);
-
- }
-
public static void prepareResponse(HttpContext context) {
HttpServletResponse response = context.getResponse();
@@ -70,106 +69,4 @@ public class PollenRestApiUtil {
}
}
- public static Gson newGson(final TopiaIdFactory idFactory, boolean prettyPrint) {
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- gsonBuilder.setExclusionStrategies(new ExclusionStrategy() {
- @Override
- public boolean shouldSkipField(FieldAttributes f) {
- return false;
- }
-
- @Override
- public boolean shouldSkipClass(Class<?> clazz) {
- return clazz == Class.class;
- }
- });
-
- gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
-
- @Override
- public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
-
- JsonElement result;
-
- if (src == null) {
-
- result = JsonNull.INSTANCE;
-
- } else {
-
- result = new JsonPrimitive(src.getTime());
-
- }
-
- return result;
-
- }
-
- });
-
- gsonBuilder.registerTypeAdapter(PollenEntityId.class, new JsonSerializer<PollenEntityId>() {
-
- @Override
- public JsonElement serialize(PollenEntityId src, Type typeOfSrc, JsonSerializationContext context) {
-
- JsonElement result;
-
- if (src == null || src.getEntityId() == null) {
-
- result = JsonNull.INSTANCE;
-
- } else {
-
- src.encode(idFactory);
- result = new JsonPrimitive(src.getReducedId());
-
- }
-
- return result;
-
- }
-
- });
-
- gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
-
- @Override
- public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
- return new Date(json.getAsLong());
- }
-
- });
- gsonBuilder.registerTypeAdapter(PollenEntityId.class, new JsonDeserializer<PollenEntityId>() {
-
- @Override
- public PollenEntityId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
-
- PollenEntityId id = PollenEntityId.newId(typeOfT);
-
- String asString = json.getAsString();
-
- if (asString != null) {
-
- id.setReducedId(asString);
- id.decode(idFactory);
-
- }
-
- return id;
-
- }
-
- });
-
- if (prettyPrint) {
-
- gsonBuilder.setPrettyPrinting();
-
- }
-
- Gson gson = gsonBuilder.create();
- return gson;
-
- }
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/DateConverter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/DateConverter.java
index 590bc91..f6ccfd2 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/DateConverter.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/DateConverter.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.rest.api.converter;
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
import org.apache.commons.beanutils.converters.AbstractConverter;
import java.util.Date;
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonArrayConverter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonArrayConverter.java
index f7907b3..598a4ab 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonArrayConverter.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonArrayConverter.java
@@ -1,12 +1,32 @@
package org.chorem.pollen.rest.api.converter;
-import com.google.gson.Gson;
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
+import com.google.common.reflect.TypeParameter;
+import com.google.common.reflect.TypeToken;
import org.apache.commons.beanutils.converters.AbstractConverter;
-import org.chorem.pollen.rest.api.PollenRestApiUtil;
+import org.chorem.pollen.rest.api.JsonHelper;
import org.nuiton.topia.persistence.TopiaIdFactory;
-import java.lang.reflect.Array;
-
/**
* Created on 5/16/14.
*
@@ -17,19 +37,18 @@ public class JsonArrayConverter<O> extends AbstractConverter {
protected final Class<O[]> arrayType;
- protected final Gson gson;
+ protected final JsonHelper jsonHelper;
public static <O> JsonArrayConverter<O> newConverter(TopiaIdFactory topiaIdFactory, Class<O> objectType) {
return new JsonArrayConverter<>(topiaIdFactory, objectType);
}
public JsonArrayConverter(TopiaIdFactory topiaIdFactory, Class<O> entityType) {
- this.arrayType = getArrayClass(entityType);
- this.gson = PollenRestApiUtil.newGson(topiaIdFactory, false);
- }
- <T> Class<T[]> getArrayClass(Class<T> clazz) {
- return (Class<T[]>) Array.newInstance(clazz, 0).getClass();
+ this.arrayType = (Class<O[]>) new TypeToken<O[]>() {}
+ .where(new TypeParameter<O>() {}, entityType)
+ .getType();
+ this.jsonHelper = new JsonHelper(topiaIdFactory, false);
}
@Override
@@ -47,8 +66,8 @@ public class JsonArrayConverter<O> extends AbstractConverter {
}
- O[] values = gson.fromJson(stringValue, this.arrayType);
-// O[] values = mapper.readValue(stringValue, this.arrayType);
+ O[] values = jsonHelper.fromJson(stringValue, this.arrayType);
+
return (T) values;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonConverter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonConverter.java
index 8d2fc9e..7560194 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonConverter.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonConverter.java
@@ -21,10 +21,9 @@ package org.chorem.pollen.rest.api.converter;
* #L%
*/
-import com.google.gson.Gson;
import org.apache.commons.beanutils.converters.AbstractConverter;
import org.chorem.pollen.persistence.PollenEntityEnum;
-import org.chorem.pollen.rest.api.PollenRestApiUtil;
+import org.chorem.pollen.rest.api.JsonHelper;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaIdFactory;
@@ -40,13 +39,13 @@ public class JsonConverter<O> extends AbstractConverter {
protected Class<O> implementationClass;
- protected final Gson gson;
+ protected final JsonHelper jsonHelper;
- public static <O> JsonConverter<O> newConverter(TopiaIdFactory topiaIdFactory , Class<O> objectType) {
+ public static <O> JsonConverter<O> newConverter(TopiaIdFactory topiaIdFactory, Class<O> objectType) {
return newConverter(topiaIdFactory, objectType, objectType);
}
- public static <E extends TopiaEntity> JsonConverter<E> newEntityConverter(TopiaIdFactory topiaIdFactory , Class<E> objectType) {
+ public static <E extends TopiaEntity> JsonConverter<E> newEntityConverter(TopiaIdFactory topiaIdFactory, Class<E> objectType) {
Class<E> implementationClass = PollenEntityEnum.getImplementationClass(objectType);
return newConverter(topiaIdFactory, objectType, implementationClass);
}
@@ -58,14 +57,14 @@ public class JsonConverter<O> extends AbstractConverter {
public JsonConverter(TopiaIdFactory topiaIdFactory, Class<O> objectType, Class<O> implementationClass) {
this.objectType = objectType;
- this.gson = PollenRestApiUtil.newGson(topiaIdFactory, false);
+ this.jsonHelper = new JsonHelper(topiaIdFactory, false);
this.implementationClass = implementationClass;
}
@Override
protected String convertToString(Object value) throws Throwable {
- String result = gson.toJson(value);
+ String result = jsonHelper.toJson(value);
return result;
}
@@ -85,7 +84,7 @@ public class JsonConverter<O> extends AbstractConverter {
}
- T result = (T) gson.fromJson(stringValue, implementationClass);
+ T result = (T) jsonHelper.fromJson(stringValue, implementationClass);
return result;
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java
index 6ac37d3..5aa0d22 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.rest.api.injector;
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.services.bean.PollenEntityId;
import org.debux.webmotion.server.call.Call;
import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java
index 76fd593..30752a7 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.rest.api.injector;
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
import org.debux.webmotion.server.call.Call;
import org.debux.webmotion.server.call.HttpContext;
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java
index f35b2a0..4177582 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.rest.api.injector;
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
import org.chorem.pollen.services.PollenService;
import org.debux.webmotion.server.call.Call;
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java
index 8b8be04..717a580 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java
@@ -23,7 +23,8 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.security.PollenAuthenticationException;
import org.chorem.pollen.services.service.security.SecurityService;
import org.debux.webmotion.server.WebMotionController;
@@ -36,9 +37,9 @@ import org.debux.webmotion.server.WebMotionController;
*/
public class AuthApi extends WebMotionController {
- public CreateBeanRef login(SecurityService securityService, String login, String password, Boolean rememberMe) throws PollenAuthenticationException {
+ public PollenEntityRef<PollenUser> login(SecurityService securityService, String login, String password, Boolean rememberMe) throws PollenAuthenticationException {
- CreateBeanRef principalRef = securityService.login(login, password, rememberMe);
+ PollenEntityRef<PollenUser> principalRef = securityService.login(login, password, rememberMe);
return principalRef;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java
index d591990..96d8f2f 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java
@@ -26,8 +26,8 @@ package org.chorem.pollen.rest.api.v1;
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.services.bean.ChoiceBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.ChoiceService;
import org.chorem.pollen.services.service.InvalidFormException;
import org.debux.webmotion.server.WebMotionController;
@@ -56,9 +56,9 @@ public class ChoiceApi extends WebMotionController {
}
- public CreateBeanRef addChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, ChoiceBean choice) throws InvalidFormException {
+ public PollenEntityRef<Choice> addChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, ChoiceBean choice) throws InvalidFormException {
- CreateBeanRef principalRef = choiceService.addChoice(pollId.getEntityId(), choice);
+ PollenEntityRef<Choice> principalRef = choiceService.addChoice(pollId.getEntityId(), choice);
return principalRef;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java
index 7e2283b..7113148 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java
@@ -26,8 +26,8 @@ package org.chorem.pollen.rest.api.v1;
import org.chorem.pollen.persistence.entity.Comment;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.services.bean.CommentBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.CommentService;
import org.chorem.pollen.services.service.InvalidFormException;
import org.debux.webmotion.server.WebMotionController;
@@ -57,9 +57,9 @@ public class CommentApi extends WebMotionController {
}
- public CreateBeanRef addComment(CommentService commentService, PollenEntityId<Poll> pollId, CommentBean comment) throws InvalidFormException {
+ public PollenEntityRef<Comment> addComment(CommentService commentService, PollenEntityId<Poll> pollId, CommentBean comment) throws InvalidFormException {
- CreateBeanRef principalRef = commentService.addComment(pollId.getEntityId(), comment);
+ PollenEntityRef<Comment> principalRef = commentService.addComment(pollId.getEntityId(), comment);
return principalRef;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java
index f4e53ad..17d0e0f 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java
@@ -25,10 +25,10 @@ package org.chorem.pollen.rest.api.v1;
import org.chorem.pollen.persistence.entity.FavoriteList;
import org.chorem.pollen.persistence.entity.FavoriteListMember;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.FavoriteListBean;
import org.chorem.pollen.services.bean.FavoriteListMemberBean;
import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.FavoriteListImportException;
import org.chorem.pollen.services.service.FavoriteListService;
import org.chorem.pollen.services.service.InvalidFormException;
@@ -60,9 +60,9 @@ public class FavoriteListApi extends WebMotionController {
}
- public CreateBeanRef createFavoriteList(FavoriteListService favoriteListService, FavoriteListBean favoriteList) throws InvalidFormException {
+ public PollenEntityRef<FavoriteList> createFavoriteList(FavoriteListService favoriteListService, FavoriteListBean favoriteList) throws InvalidFormException {
- CreateBeanRef principalRef = favoriteListService.createFavoriteList(favoriteList);
+ PollenEntityRef<FavoriteList> principalRef = favoriteListService.createFavoriteList(favoriteList);
return principalRef;
}
@@ -108,9 +108,9 @@ public class FavoriteListApi extends WebMotionController {
}
- public CreateBeanRef addMember(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, FavoriteListMemberBean member) throws InvalidFormException {
+ public PollenEntityRef<FavoriteListMember> addMember(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, FavoriteListMemberBean member) throws InvalidFormException {
- CreateBeanRef principalRef = favoriteListService.addFavoriteListMember(favoriteListId.getEntityId(), member);
+ PollenEntityRef<FavoriteListMember> principalRef = favoriteListService.addFavoriteListMember(favoriteListId.getEntityId(), member);
return principalRef;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java
index a3a078b..2ca20ab 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java
@@ -26,9 +26,9 @@ package org.chorem.pollen.rest.api.v1;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.rest.api.PollenRestApiUtil;
import org.chorem.pollen.services.bean.ChoiceBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollBean;
import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.VoterListBean;
import org.chorem.pollen.services.service.InvalidFormException;
import org.chorem.pollen.services.service.PollService;
@@ -88,16 +88,16 @@ public class PollApi extends WebMotionController {
}
- public CreateBeanRef createPoll(PollService pollService,
- PollBean poll,
- ChoiceBean[] choices,
- VoterListBean[] voterLists) throws InvalidFormException {
+ public PollenEntityRef<Poll> createPoll(PollService pollService,
+ PollBean poll,
+ ChoiceBean[] choices,
+ VoterListBean[] voterLists) throws InvalidFormException {
List<ChoiceBean> choiceList = PollenRestApiUtil.toList(choices);
List<VoterListBean> voterListList = PollenRestApiUtil.toList(voterLists);
- CreateBeanRef principalRef = pollService.createPoll(poll, choiceList, voterListList);
+ PollenEntityRef<Poll> principalRef = pollService.createPoll(poll, choiceList, voterListList);
return principalRef;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java
index 325303b..4d42c3b 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java
@@ -24,8 +24,8 @@ package org.chorem.pollen.rest.api.v1;
*/
import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.PollenUserBean;
import org.chorem.pollen.services.service.InvalidFormException;
import org.chorem.pollen.services.service.PollenUserService;
@@ -57,11 +57,11 @@ public class PollenUserApi extends WebMotionController {
}
- public CreateBeanRef createUser(PollenUserService pollenUserService,
- PollenUserBean user,
- boolean generatePassword) throws InvalidFormException {
+ public PollenEntityRef<PollenUser> createUser(PollenUserService pollenUserService,
+ PollenUserBean user,
+ boolean generatePassword) throws InvalidFormException {
- CreateBeanRef principalRef = pollenUserService.createUser(user, generatePassword);
+ PollenEntityRef<PollenUser> principalRef = pollenUserService.createUser(user, generatePassword);
return principalRef;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java
index c1a1b19..072e758 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java
@@ -25,8 +25,8 @@ package org.chorem.pollen.rest.api.v1;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.Vote;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.VoteBean;
import org.chorem.pollen.services.service.InvalidFormException;
import org.chorem.pollen.services.service.VoteService;
@@ -56,9 +56,9 @@ public class VoteApi extends WebMotionController {
}
- public CreateBeanRef addVote(VoteService voteService, PollenEntityId<Poll> pollId, VoteBean vote) throws InvalidFormException {
+ public PollenEntityRef<Vote> addVote(VoteService voteService, PollenEntityId<Poll> pollId, VoteBean vote) throws InvalidFormException {
- CreateBeanRef principalRef = voteService.addVote(pollId.getEntityId(), vote);
+ PollenEntityRef<Vote> principalRef = voteService.addVote(pollId.getEntityId(), vote);
return principalRef;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java
index 231d8d0..d6c35d0 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java
@@ -27,8 +27,8 @@ import org.chorem.pollen.persistence.entity.FavoriteList;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListMember;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollenEntityId;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.VoterListBean;
import org.chorem.pollen.services.bean.VoterListMemberBean;
import org.chorem.pollen.services.service.InvalidFormException;
@@ -67,9 +67,9 @@ public class VoterListApi extends WebMotionController {
}
- public CreateBeanRef createVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, VoterListBean voterList) throws InvalidFormException {
+ public PollenEntityRef<VoterList> createVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, VoterListBean voterList) throws InvalidFormException {
- CreateBeanRef principalRef = voterListService.addVoterList(pollId.getEntityId(), voterList);
+ PollenEntityRef<VoterList> principalRef = voterListService.addVoterList(pollId.getEntityId(), voterList);
return principalRef;
}
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
index 939417f..523b001 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
@@ -60,11 +60,25 @@ public class AbstractPollenRestApiTest extends WebMotionTest {
@Rule
public final FakePollenApplicationContext application = new FakePollenApplicationContext("pollen-rest-api.properties");
+ protected JsonHelper jsonHelper;
+
@Override
protected int getPort() {
return application.getPort();
}
+ protected JsonHelper getJsonHelper() {
+
+ if (jsonHelper == null) {
+
+ TopiaIdFactory topiaIdFactory = application.getTopiaApplicationContext().getTopiaIdFactory();
+
+ jsonHelper = new JsonHelper(topiaIdFactory, true);
+ }
+
+ return jsonHelper;
+ }
+
protected void loadFixtures(String fixturesSetName) {
PollenTopiaPersistenceContext persistenceContext = application.newPersistenceContext();
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AuthApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AuthApiTest.java
index 89ad8ff..308447b 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AuthApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AuthApiTest.java
@@ -1,15 +1,36 @@
package org.chorem.pollen.rest.api;
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
+import com.google.common.reflect.TypeToken;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.fluent.Response;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.rest.api.converter.JsonConverter;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.topia.persistence.internal.DefaultTopiaIdFactory;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.net.URISyntaxException;
@@ -47,9 +68,9 @@ public class AuthApiTest extends AbstractPollenRestApiTest {
showTestResult(loginContent);
Assert.assertNotNull(loginContent);
- JsonConverter<CreateBeanRef> jsonConverter = JsonConverter.newConverter(new DefaultTopiaIdFactory(), CreateBeanRef.class);
- CreateBeanRef createBeanRef = jsonConverter.convert(CreateBeanRef.class, loginContent);
- Assert.assertNotNull(createBeanRef);
+ Type type = new TypeToken<PollenEntityRef<PollenUser>>() {}.getType();
+
+ PollenEntityRef createBeanRef = getJsonHelper().fromJson(loginContent, type);
Request logout = createRequest("/v1/logout").Get();
logout.addHeader(PollenRestApiRequestFilter.REQUEST_HEADER_SESSION_TOKEN, createBeanRef.getPermission());
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
index 1aa53fd..7bd1100 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
@@ -21,6 +21,7 @@ package org.chorem.pollen.rest.api;
* #L%
*/
+import org.apache.http.client.HttpResponseException;
import org.apache.http.client.fluent.Request;
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.ChoiceImpl;
@@ -35,7 +36,6 @@ import org.chorem.pollen.services.PollenFixtures;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import org.nuiton.topia.persistence.TopiaIdFactory;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -137,10 +137,35 @@ public class PollApiTest extends AbstractPollenRestApiTest {
choice2.setName("choiceB");
choices.add(choice2);
- TopiaIdFactory topiaIdFactory = application.getTopiaApplicationContext().getTopiaIdFactory();
+ String choiceStr = getJsonHelper().toJson(choices);
+ String pollStr = getJsonHelper().toJson(poll);
- String choiceStr = PollenRestApiUtil.entitiesToString(topiaIdFactory, choices);
- String pollStr = PollenRestApiUtil.entitiesToString(topiaIdFactory, poll);
+ Request request = createRequest("/v1/polls")
+ .addParameter("poll", pollStr)
+ .addParameter("choices", choiceStr)
+ .Post();
+
+ String content = request.execute().returnContent().asString();
+ showTestResult(content);
+ assertNotNull(content);
+
+ }
+
+ @Test(expected = HttpResponseException.class)
+ public void postBadPoll() 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");
+
+ List<Choice> choices = new ArrayList<>();
+
+ String choiceStr = getJsonHelper().toJson(choices);
+ String pollStr = getJsonHelper().toJson(poll);
Request request = createRequest("/v1/polls")
.addParameter("poll", pollStr)
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
index 1e7b9f1..18bf5bb 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
@@ -23,16 +23,17 @@ package org.chorem.pollen.rest.api;
* #L%
*/
+import com.google.common.reflect.TypeToken;
import org.apache.http.client.fluent.Request;
import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.rest.api.converter.JsonConverter;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityRef;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import org.nuiton.topia.persistence.internal.DefaultTopiaIdFactory;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.net.URISyntaxException;
import static org.junit.Assert.assertTrue;
@@ -59,9 +60,17 @@ public class PollenUserApiTest extends AbstractPollenRestApiTest {
.Post();
String loginContent = loginRequest.execute().returnContent().asString();
- JsonConverter<CreateBeanRef> jsonConverter = JsonConverter.newConverter(new DefaultTopiaIdFactory(), CreateBeanRef.class);
+ showTestResult(loginContent);
+
+ Type type = new TypeToken<PollenEntityRef<PollenUser>>() {
+ }.getType();
+
+ PollenEntityRef<PollenUser> createBeanRef = getJsonHelper().fromJson(loginContent, type);
+ Assert.assertNotNull(createBeanRef);
+ Assert.assertNotNull(createBeanRef.getEntityId());
+ Assert.assertNotNull(createBeanRef.getReducedId());
+ Assert.assertNotNull(createBeanRef.getPermission());
- CreateBeanRef createBeanRef = jsonConverter.convert(CreateBeanRef.class, loginContent);
return createBeanRef.getPermission();
}
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonArrayConverterTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonArrayConverterTest.java
index c216d62..78294be 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonArrayConverterTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonArrayConverterTest.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.rest.api.converter;
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.ChoiceType;
import org.chorem.pollen.services.bean.ChoiceBean;
import org.junit.Assert;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
index 746e055..c5ee22a 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.ChoiceImpl;
import org.chorem.pollen.persistence.entity.ChoiceType;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
index 513337e..262f3bf 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.Comment;
import org.chorem.pollen.persistence.entity.CommentImpl;
import org.chorem.pollen.persistence.entity.PollenPrincipalImpl;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java
deleted file mode 100644
index 5e5ff90..0000000
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.chorem.pollen.services.bean;
-
-import org.chorem.pollen.persistence.entity.Choice;
-import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.PollenToken;
-import org.chorem.pollen.persistence.entity.SessionToken;
-import org.chorem.pollen.persistence.entity.Vote;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-/**
- * Created on 5/15/14.
- *
- * @author Tony Chemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class CreateBeanRef {
-
- protected String id;
-
- protected String permission;
-
- public static CreateBeanRef of(Poll entity) {
-
- CreateBeanRef ref = of(entity, entity.getCreator().getPermission());
- return ref;
-
- }
-
- public static CreateBeanRef of(Choice entity) {
-
- CreateBeanRef ref = of(entity, entity.getCreator().getPermission());
- return ref;
-
- }
-
- public static CreateBeanRef of(Comment entity) {
-
- CreateBeanRef ref = of(entity, entity.getAuthor().getPermission());
- return ref;
-
- }
-
- public static CreateBeanRef of(Vote entity) {
-
- CreateBeanRef ref = of(entity, entity.getVoter().getPermission());
- return ref;
-
- }
-
- public static CreateBeanRef of(SessionToken result) {
-
- CreateBeanRef ref = of(result.getPollenUser(), result.getPollenToken());
- return ref;
-
- }
-
- public static CreateBeanRef of(TopiaEntity result) {
-
- CreateBeanRef ref = new CreateBeanRef(result);
- return ref;
-
- }
-
- public static CreateBeanRef of(TopiaEntity id, PollenToken permission) {
-
- CreateBeanRef ref = new CreateBeanRef(id.getTopiaId(), permission==null?null: permission.getToken());
- return ref;
-
- }
-
- public static CreateBeanRef of(String id, String permission) {
-
- CreateBeanRef ref = new CreateBeanRef(id, permission);
- return ref;
-
- }
-
- protected CreateBeanRef(TopiaEntity id) {
- this(id.getTopiaId(), null);
- }
-
- protected CreateBeanRef(String id, String permission) {
-
- setId(id);
- setPermission(permission);
-
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getPermission() {
- return permission;
- }
-
- public void setPermission(String permission) {
- this.permission = permission;
- }
-}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
index c6f961e..14ac766 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.FavoriteList;
import org.chorem.pollen.persistence.entity.FavoriteListImpl;
import org.chorem.pollen.persistence.entity.FavoriteListMember;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
index 97423c2..b27e338 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.FavoriteListMember;
import org.chorem.pollen.persistence.entity.FavoriteListMemberImpl;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
index 5013db7..0613f68 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.CommentVisibility;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.PollImpl;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
index 2883aa3..61789c7 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
@@ -1,5 +1,27 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
+import com.google.common.base.Preconditions;
import org.nuiton.topia.persistence.TopiaEntity;
/**
@@ -16,29 +38,24 @@ public abstract class PollenBean<E extends TopiaEntity> {
protected PollenBean(Class<E> entityType) {
this.entityType = entityType;
- }
-
- public PollenEntityId<E> getId() {
- if (id == null) {
- id = PollenEntityId.newId(entityType);
- }
- return id;
+ this.id = PollenEntityId.newId(entityType);
}
public void setId(PollenEntityId<E> id) {
+ Preconditions.checkNotNull("id can not be null", id);
this.id = id;
}
public boolean isPersisted() {
- return getId().isNotEmpty();
+ return id.isNotEmpty();
}
public String getEntityId() {
- return getId().getEntityId();
+ return id.getEntityId();
}
public void setEntityId(String id) {
- getId().setEntityId(id);
+ this.id.setEntityId(id);
}
public abstract void fromEntity(E entity);
@@ -52,12 +69,12 @@ public abstract class PollenBean<E extends TopiaEntity> {
PollenBean that = (PollenBean) o;
- return getId().equals(that.getId());
+ return id.equals(that.id);
}
@Override
public int hashCode() {
- return getId().hashCode();
+ return id.hashCode();
}
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java
index 98147a3..47c7638 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.nuiton.topia.persistence.TopiaEntity;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityRef.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityRef.java
new file mode 100644
index 0000000..f1e3c5c
--- /dev/null
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityRef.java
@@ -0,0 +1,129 @@
+package org.chorem.pollen.services.bean;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
+import org.chorem.pollen.persistence.PollenEntityEnum;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenToken;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.SessionToken;
+import org.chorem.pollen.persistence.entity.Vote;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+/**
+ * Created on 5/15/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenEntityRef<E extends TopiaEntity> extends PollenEntityId<E> {
+
+ protected String permission;
+
+ public static PollenEntityRef<Poll> of(Poll entity) {
+
+ PollenEntityRef<Poll> ref = of(entity, entity.getCreator().getPermission());
+ return ref;
+
+ }
+
+ public static PollenEntityRef<Choice> of(Choice entity) {
+
+ PollenEntityRef<Choice> ref = of(entity, entity.getCreator().getPermission());
+ return ref;
+
+ }
+
+ public static PollenEntityRef<Comment> of(Comment entity) {
+
+ PollenEntityRef<Comment> ref = of(entity, entity.getAuthor().getPermission());
+ return ref;
+
+ }
+
+ public static PollenEntityRef<Vote> of(Vote entity) {
+
+ PollenEntityRef<Vote> ref = of(entity, entity.getVoter().getPermission());
+ return ref;
+
+ }
+
+ public static PollenEntityRef<PollenUser> of(SessionToken result) {
+
+ PollenEntityRef<PollenUser> ref = of(result.getPollenUser(), result.getPollenToken());
+ return ref;
+
+ }
+
+ public static <E extends TopiaEntity> PollenEntityRef<E> of(E result) {
+
+ PollenEntityRef<E> ref = new PollenEntityRef<>(result, null);
+ return ref;
+
+ }
+
+ public static <E extends TopiaEntity> PollenEntityRef<E> of(E id, PollenToken permission) {
+
+ PollenEntityRef<E> ref = new PollenEntityRef<>(id, permission == null ? null : permission.getToken());
+ return ref;
+
+ }
+
+ public static <E extends TopiaEntity> PollenEntityRef<E> newRef(Type typeOfT) {
+
+ Type[] actualTypeArguments = ((ParameterizedType) typeOfT).getActualTypeArguments();
+ return newRef((Class<E>) actualTypeArguments[0]);
+
+ }
+
+ public static <E extends TopiaEntity> PollenEntityRef<E> newRef(Class<E> entityType) {
+
+ PollenEntityRef<E> ref = new PollenEntityRef<>(entityType);
+ return ref;
+
+ }
+
+ protected PollenEntityRef(E entity, String permission) {
+
+ this(PollenEntityEnum.getContractClass((Class) entity.getClass()));
+ setEntityId(entity.getTopiaId());
+ setPermission(permission);
+ }
+
+ protected PollenEntityRef(Class<E> entityType) {
+
+ super(entityType);
+ }
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public void setPermission(String permission) {
+ this.permission = permission;
+ }
+}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
index 98cd27a..5fb38d1 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.PollenUserImpl;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
index d1dad27..9f5cad2 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.persistence.entity.PollenPrincipalImpl;
import org.chorem.pollen.persistence.entity.Vote;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
index 2e29e35..dbbad5b 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.ChoiceImpl;
import org.chorem.pollen.persistence.entity.VoteToChoice;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
index 51ea9f7..f31ffe5 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListImpl;
import org.chorem.pollen.persistence.entity.VoterListMember;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
index 12facbe..b778ce0 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.bean;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.persistence.entity.VoterListMember;
import org.chorem.pollen.persistence.entity.VoterListMemberImpl;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/package-info.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/package-info.java
index 2efadbe..53cfd83 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/package-info.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/package-info.java
@@ -18,12 +18,12 @@ package org.chorem.pollen.services.bean;
* 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%
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
index 07ea92a..11a7f02 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
@@ -31,7 +31,7 @@ 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.services.bean.ChoiceBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.security.PermissionVerb;
import java.util.List;
@@ -111,7 +111,7 @@ public class ChoiceService extends PollenServiceSupport {
}
- public CreateBeanRef addChoice(String pollId, ChoiceBean choice) throws InvalidFormException {
+ public PollenEntityRef<Choice> addChoice(String pollId, ChoiceBean choice) throws InvalidFormException {
checkNotNull(pollId);
checkNotNull(choice);
@@ -132,7 +132,7 @@ public class ChoiceService extends PollenServiceSupport {
getNotificationService().onChoiceAdded(poll, result);
- CreateBeanRef createBeanRef = CreateBeanRef.of(result);
+ PollenEntityRef<Choice> createBeanRef = PollenEntityRef.of(result);
return createBeanRef;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
index 29cf6a9..8e20a02 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
@@ -27,7 +27,7 @@ import org.chorem.pollen.persistence.entity.Comment;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.services.bean.CommentBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.security.PermissionVerb;
import java.util.List;
@@ -77,7 +77,7 @@ public class CommentService extends PollenServiceSupport {
}
- public CreateBeanRef addComment(String pollId, CommentBean comment) throws InvalidFormException {
+ public PollenEntityRef<Comment> addComment(String pollId, CommentBean comment) throws InvalidFormException {
checkNotNull(pollId);
checkNotNull(comment);
@@ -93,7 +93,7 @@ public class CommentService extends PollenServiceSupport {
getNotificationService().onCommentAdded(poll, result);
- CreateBeanRef createBeanRef = CreateBeanRef.of(result);
+ PollenEntityRef<Comment> createBeanRef = PollenEntityRef.of(result);
return createBeanRef;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
index de556ba..48c1641 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
@@ -33,9 +33,9 @@ import org.chorem.pollen.persistence.entity.FavoriteListMemberTopiaDao;
import org.chorem.pollen.persistence.entity.FavoriteListTopiaDao;
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.services.PollenTechnicalException;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.FavoriteListBean;
import org.chorem.pollen.services.bean.FavoriteListMemberBean;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.nuiton.util.StringUtil;
import javax.naming.NamingEnumeration;
@@ -89,7 +89,7 @@ public class FavoriteListService extends PollenServiceSupport {
}
- public CreateBeanRef createFavoriteList(FavoriteListBean favoriteList) throws InvalidFormException {
+ public PollenEntityRef<FavoriteList> createFavoriteList(FavoriteListBean favoriteList) throws InvalidFormException {
checkIsConnected();
checkNotNull(favoriteList);
@@ -107,7 +107,7 @@ public class FavoriteListService extends PollenServiceSupport {
getNotificationService().onFavoriteListAdded(user, result);
- CreateBeanRef createBeanRef = CreateBeanRef.of(result);
+ PollenEntityRef<FavoriteList> createBeanRef = PollenEntityRef.of(result);
return createBeanRef;
}
@@ -182,8 +182,8 @@ public class FavoriteListService extends PollenServiceSupport {
}
- public CreateBeanRef addFavoriteListMember(String favoriteListId,
- FavoriteListMemberBean member) throws InvalidFormException {
+ public PollenEntityRef<FavoriteListMember> addFavoriteListMember(String favoriteListId,
+ FavoriteListMemberBean member) throws InvalidFormException {
checkIsConnected();
checkNotNull(favoriteListId);
@@ -202,7 +202,7 @@ public class FavoriteListService extends PollenServiceSupport {
FavoriteListMember result = saveFavoriteListMember(favoriteList, member);
commit();
- CreateBeanRef createBeanRef = CreateBeanRef.of(result);
+ PollenEntityRef<FavoriteListMember> createBeanRef = PollenEntityRef.of(result);
return createBeanRef;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java
index e20ba6e..87eab73 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java
@@ -37,8 +37,8 @@ import org.chorem.pollen.persistence.entity.PollenUserTopiaDao;
import org.chorem.pollen.services.PollenFixtures;
import org.chorem.pollen.services.PollenTechnicalException;
import org.chorem.pollen.services.bean.ChoiceBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollBean;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.security.SecurityService;
import java.util.ArrayList;
@@ -122,8 +122,8 @@ public class FixturesService extends PollenServiceSupport {
try {
PollBean pollBean = new PollBean();
pollBean.fromEntity(poll);
- CreateBeanRef createdPoll = pollService.createPoll(pollBean, choicesBean, null);
- poll.setTopiaId(createdPoll.getId());
+ PollenEntityRef<Poll> createdPoll = pollService.createPoll(pollBean, choicesBean, null);
+ poll.setTopiaId(createdPoll.getEntityId());
PollenPrincipal principal = securityService.getPollenPrincipalByPermissionToken(createdPoll.getPermission());
poll.setCreator(principal);
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
index de3811c..ceed97b 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
@@ -30,8 +30,8 @@ import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.services.bean.ChoiceBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollBean;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.VoterListBean;
import org.chorem.pollen.services.service.security.PermissionVerb;
@@ -147,7 +147,7 @@ public class PollService extends PollenServiceSupport {
}
- public CreateBeanRef createPoll(PollBean poll, List<ChoiceBean> choices, List<VoterListBean> voterLists) throws InvalidFormException {
+ public PollenEntityRef<Poll> createPoll(PollBean poll, List<ChoiceBean> choices, List<VoterListBean> voterLists) throws InvalidFormException {
checkNotNull(poll);
checkIsNotPersisted(poll);
@@ -162,7 +162,7 @@ public class PollService extends PollenServiceSupport {
getNotificationService().onPollCreated(savedPoll);
- CreateBeanRef createBeanRef = CreateBeanRef.of(savedPoll);
+ PollenEntityRef<Poll> createBeanRef = PollenEntityRef.of(savedPoll);
return createBeanRef;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java
index 6a8083a..dce5eca 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java
@@ -28,7 +28,7 @@ import org.chorem.pollen.persistence.entity.PollenToken;
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.PollenUserTopiaDao;
import org.chorem.pollen.services.PollenService;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.PollenUserBean;
import org.chorem.pollen.services.service.security.PollenInvalidEmailActivationTokenException;
import org.chorem.pollen.services.service.security.PollenInvalidPasswordException;
@@ -71,7 +71,7 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer
return getPollenUserDao().findByTopiaId(userId);
}
- public CreateBeanRef createUser(PollenUserBean user, boolean generatePassword) throws InvalidFormException {
+ public PollenEntityRef<PollenUser> createUser(PollenUserBean user, boolean generatePassword) throws InvalidFormException {
checkNotNull(user);
checkIsNotPersisted(user);
@@ -84,7 +84,7 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer
getNotificationService().onUserCreated(result, generatePassword);
- CreateBeanRef createBeanRef = CreateBeanRef.of(result);
+ PollenEntityRef<PollenUser> createBeanRef = PollenEntityRef.of(result);
return createBeanRef;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
index a608993..a753379 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
@@ -31,7 +31,7 @@ import org.chorem.pollen.persistence.entity.Polls;
import org.chorem.pollen.persistence.entity.Vote;
import org.chorem.pollen.persistence.entity.VoteToChoice;
import org.chorem.pollen.persistence.entity.VoteToChoiceTopiaDao;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.VoteBean;
import org.chorem.pollen.services.bean.VoteToChoiceBean;
import org.chorem.pollen.services.service.security.PermissionVerb;
@@ -85,7 +85,7 @@ public class VoteService extends PollenServiceSupport {
}
- public CreateBeanRef addVote(String pollId, VoteBean vote) throws InvalidFormException {
+ public PollenEntityRef<Vote> addVote(String pollId, VoteBean vote) throws InvalidFormException {
checkNotNull(pollId);
checkNotNull(vote);
@@ -102,7 +102,7 @@ public class VoteService extends PollenServiceSupport {
getNotificationService().onVoteAdded(poll, result);
- CreateBeanRef createBeanRef = CreateBeanRef.of(result);
+ PollenEntityRef<Vote> createBeanRef = PollenEntityRef.of(result);
return createBeanRef;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
index 398b642..fc91907 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
@@ -30,9 +30,9 @@ import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListMember;
import org.chorem.pollen.persistence.entity.VoterListMemberTopiaDao;
import org.chorem.pollen.persistence.entity.VoterListTopiaDao;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.FavoriteListBean;
import org.chorem.pollen.services.bean.FavoriteListMemberBean;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.VoterListBean;
import org.chorem.pollen.services.bean.VoterListMemberBean;
@@ -105,7 +105,7 @@ public class VoterListService extends PollenServiceSupport {
}
- public CreateBeanRef addVoterList(String pollId, VoterListBean voterList) throws InvalidFormException {
+ public PollenEntityRef<VoterList> addVoterList(String pollId, VoterListBean voterList) throws InvalidFormException {
checkNotNull(pollId);
checkNotNull(voterList);
@@ -124,7 +124,7 @@ public class VoterListService extends PollenServiceSupport {
//TODO Notify
- CreateBeanRef createBeanRef = CreateBeanRef.of(result);
+ PollenEntityRef<VoterList> createBeanRef = PollenEntityRef.of(result);
return createBeanRef;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java
index 595b9cf..562690e 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java
@@ -44,7 +44,7 @@ import org.chorem.pollen.persistence.entity.PollenTokenTopiaDao;
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.SessionToken;
import org.chorem.pollen.persistence.entity.Vote;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.PollenServiceSupport;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -66,7 +66,7 @@ public class SecurityService extends PollenServiceSupport {
/** Logger. */
private static final Log log = LogFactory.getLog(SecurityService.class);
- public CreateBeanRef login(String login, String password, Boolean rememberMe) throws PollenAuthenticationException {
+ public PollenEntityRef<PollenUser> login(String login, String password, Boolean rememberMe) throws PollenAuthenticationException {
Subject subject = getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(login, password);
@@ -93,14 +93,13 @@ public class SecurityService extends PollenServiceSupport {
Date endDate = calendar.getTime();
pollenToken.setEndDate(endDate);
-
// Create session Token
SessionToken sessionToken = getSessionTokenDao().create(
SessionToken.PROPERTY_POLLEN_TOKEN, pollenToken,
SessionToken.PROPERTY_POLLEN_USER, user);
commit();
- CreateBeanRef createBeanRef = CreateBeanRef.of(sessionToken);
+ PollenEntityRef<PollenUser> createBeanRef = PollenEntityRef.of(sessionToken);
return createBeanRef;
}
diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/AbstractPollenServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/AbstractPollenServiceTest.java
index 11ff686..648d503 100644
--- a/pollen-services/src/test/java/org/chorem/pollen/services/AbstractPollenServiceTest.java
+++ b/pollen-services/src/test/java/org/chorem/pollen/services/AbstractPollenServiceTest.java
@@ -24,8 +24,9 @@ package org.chorem.pollen.services;
*/
import com.google.common.collect.Multimap;
+import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.SessionToken;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.service.InvalidFormException;
import org.chorem.pollen.services.service.security.PollenAuthenticationException;
import org.chorem.pollen.services.service.security.PollenInvalidSessionTokenException;
@@ -90,7 +91,7 @@ public abstract class AbstractPollenServiceTest {
SecurityService securityService = newService(SecurityService.class);
- CreateBeanRef loginRef = securityService.login(login, password, null);
+ PollenEntityRef<PollenUser> loginRef = securityService.login(login, password, null);
SessionToken sessionToken = securityService.getSessionTokenByToken(loginRef.getPermission());
serviceContext.getSecurityContext().setSessionToken(sessionToken);
diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/service/PollServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/service/PollServiceTest.java
index 4fe1751..6679ee8 100644
--- a/pollen-services/src/test/java/org/chorem/pollen/services/service/PollServiceTest.java
+++ b/pollen-services/src/test/java/org/chorem/pollen/services/service/PollServiceTest.java
@@ -24,12 +24,13 @@ package org.chorem.pollen.services.service;
*/
import org.chorem.pollen.persistence.entity.ChoiceType;
+import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.PollType;
import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.services.AbstractPollenServiceTest;
import org.chorem.pollen.services.bean.ChoiceBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollBean;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.VoterListBean;
import org.chorem.pollen.services.bean.VoterListMemberBean;
import org.chorem.pollen.services.service.security.PollenInvalidPermissionException;
@@ -98,15 +99,16 @@ public class PollServiceTest extends AbstractPollenServiceTest {
choice2.setDescription("Choice B");
choices.add(choice2);
- CreateBeanRef createdPoll = service.createPoll(poll, choices, null);
+ PollenEntityRef<Poll> createdPoll = service.createPoll(poll, choices, null);
Assert.assertNotNull(createdPoll);
- Assert.assertNotNull(createdPoll.getId());
+ String createdPollId = createdPoll.getEntityId();
+ Assert.assertNotNull(createdPollId);
- PollBean reloadedPoll = service.getPoll(createdPoll.getId());
+ PollBean reloadedPoll = service.getPoll(createdPollId);
Assert.assertEquals(getServiceContext().getNow(), reloadedPoll.getBeginDate());
- List<ChoiceBean> createdChoices = choiceService.getChoices(createdPoll.getId());
+ List<ChoiceBean> createdChoices = choiceService.getChoices(createdPollId);
Assert.assertNotNull(createdChoices);
Assert.assertEquals(2, createdChoices.size());
@@ -116,7 +118,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdChoice1);
Assert.assertNotNull(createdChoice1.getEntityId());
- ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getEntityId());
+ ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPollId, createdChoice1.getEntityId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
Assert.assertEquals(choice1.getName(), createdChoice1.getName());
@@ -127,7 +129,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdChoice2);
Assert.assertNotNull(createdChoice2.getEntityId());
- ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getEntityId());
+ ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPollId, createdChoice2.getEntityId());
Assert.assertEquals(createdChoice2, reloadedChoice2);
Assert.assertEquals(choice2.getName(), createdChoice2.getName());
@@ -195,12 +197,13 @@ public class PollServiceTest extends AbstractPollenServiceTest {
choice2.setName("B");
- CreateBeanRef createdPoll = service.createPoll(poll, choices, null);
+ PollenEntityRef<Poll> createdPoll = service.createPoll(poll, choices, null);
Assert.assertNotNull(createdPoll);
- Assert.assertNotNull(createdPoll.getId());
+ String createdPollId = createdPoll.getEntityId();
+ Assert.assertNotNull(createdPollId);
- PollBean reloadedPoll = service.getPoll(createdPoll.getId());
- Assert.assertEquals(createdPoll.getId(), reloadedPoll.getEntityId());
+ PollBean reloadedPoll = service.getPoll(createdPollId);
+ Assert.assertEquals(createdPollId, reloadedPoll.getEntityId());
Assert.assertEquals(getServiceContext().getNow(), reloadedPoll.getBeginDate());
@@ -212,7 +215,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
// Assert.assertNull(createdPoll.getVote());
// Assert.assertNull(createdPoll.getVoterList());
- List<ChoiceBean> createdChoices = choiceService.getChoices(createdPoll.getId());
+ List<ChoiceBean> createdChoices = choiceService.getChoices(createdPollId);
Assert.assertNotNull(createdChoices);
Assert.assertEquals(2, createdChoices.size());
@@ -222,7 +225,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdChoice1);
Assert.assertNotNull(createdChoice1.getEntityId());
- ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getEntityId());
+ ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPollId, createdChoice1.getEntityId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
Assert.assertEquals(choice1.getName(), createdChoice1.getName());
@@ -232,7 +235,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdChoice2);
Assert.assertNotNull(createdChoice2.getEntityId());
- ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getEntityId());
+ ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPollId, createdChoice2.getEntityId());
Assert.assertEquals(createdChoice2, reloadedChoice2);
Assert.assertEquals(choice2.getName(), createdChoice2.getName());
@@ -286,12 +289,13 @@ public class PollServiceTest extends AbstractPollenServiceTest {
voterListMember2.setEmail("voter2(a)pollen.org");
voterListMember2.setWeight(0.7);
- CreateBeanRef createdPoll = service.createPoll(poll, choices, voterLists);
+ PollenEntityRef<Poll> createdPoll = service.createPoll(poll, choices, voterLists);
Assert.assertNotNull(createdPoll);
- Assert.assertNotNull(createdPoll.getId());
+ String createdPollId = createdPoll.getEntityId();
+ Assert.assertNotNull(createdPollId);
try {
- service.getPoll(createdPoll.getId());
+ service.getPoll(createdPollId);
Assert.fail();
} catch (PollenInvalidPermissionException e) {
Assert.assertTrue(true);
@@ -302,7 +306,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
PollenPrincipal principal = securityService.getPollenPrincipalByPermissionToken(createdPoll.getPermission());
securityContext.setMainPrincipal(principal);
- PollBean reloadedPoll = service.getPoll(createdPoll.getId());
+ PollBean reloadedPoll = service.getPoll(createdPollId);
// Assert.assertEquals(createdPoll, reloadedPoll);
Assert.assertEquals(getServiceContext().getNow(), reloadedPoll.getBeginDate());
@@ -312,7 +316,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
// Assert.assertNull(createdPoll.getCreator().getName());
// Assert.assertNull(createdPoll.getCreator().getEmail());
- List<ChoiceBean> createdChoices = choiceService.getChoices(createdPoll.getId());
+ List<ChoiceBean> createdChoices = choiceService.getChoices(createdPollId);
Assert.assertNotNull(createdChoices);
Assert.assertEquals(2, createdChoices.size());
@@ -321,7 +325,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdChoice1);
Assert.assertNotNull(createdChoice1.getEntityId());
- ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getEntityId());
+ ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPollId, createdChoice1.getEntityId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
Assert.assertEquals(choice1.getName(), createdChoice1.getName());
@@ -332,14 +336,14 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdChoice2);
Assert.assertNotNull(createdChoice2.getEntityId());
- ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getEntityId());
+ ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPollId, createdChoice2.getEntityId());
Assert.assertEquals(createdChoice2, reloadedChoice2);
Assert.assertEquals(choice2.getName(), createdChoice2.getName());
Assert.assertEquals(choice2.getDescription(), createdChoice2.getDescription());
// Assert.assertEquals(createdPoll.getCreator(), createdChoice2.getCreator());
- List<VoterListBean> createdVoterLists = voterListService.getVoterLists(createdPoll.getId());
+ List<VoterListBean> createdVoterLists = voterListService.getVoterLists(createdPollId);
Assert.assertNotNull(createdVoterLists);
Assert.assertEquals(1, createdVoterLists.size());
@@ -347,7 +351,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdVoterList);
Assert.assertNotNull(createdVoterList.getEntityId());
- VoterListBean reloadedVoterList = voterListService.getVoterList(createdPoll.getId(), createdVoterList.getEntityId());
+ VoterListBean reloadedVoterList = voterListService.getVoterList(createdPollId, createdVoterList.getEntityId());
Assert.assertEquals(createdVoterList, reloadedVoterList);
Assert.assertEquals(voterList.getName(), createdVoterList.getName());
@@ -454,12 +458,13 @@ public class PollServiceTest extends AbstractPollenServiceTest {
voterListMember2.setName("voter2");
voterListMember2.setEmail("voter2(a)pollen.org");
- CreateBeanRef createdPoll = service.createPoll(poll, choices, voterLists);
+ PollenEntityRef<Poll> createdPoll = service.createPoll(poll, choices, voterLists);
Assert.assertNotNull(createdPoll);
- Assert.assertNotNull(createdPoll.getId());
+ String createdPollId = createdPoll.getEntityId();
+ Assert.assertNotNull(createdPollId);
try {
- service.getPoll(createdPoll.getId());
+ service.getPoll(createdPollId);
Assert.fail();
} catch (PollenInvalidPermissionException e) {
Assert.assertTrue(true);
@@ -469,7 +474,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
FakePollenSecurityContext securityContext = (FakePollenSecurityContext) serviceContext.getSecurityContext();
securityContext.setMainPrincipal(principal);
- PollBean reloadedPoll = service.getPoll(createdPoll.getId());
+ PollBean reloadedPoll = service.getPoll(createdPollId);
// Assert.assertEquals(createdPoll, reloadedPoll);
Assert.assertEquals(getServiceContext().getNow(), reloadedPoll.getBeginDate());
@@ -481,7 +486,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
// Assert.assertNull(createdPoll.getComment());
// Assert.assertNull(createdPoll.getVote());
- List<ChoiceBean> createdChoices = choiceService.getChoices(createdPoll.getId());
+ List<ChoiceBean> createdChoices = choiceService.getChoices(createdPollId);
Assert.assertNotNull(createdChoices);
Assert.assertEquals(2, createdChoices.size());
@@ -490,7 +495,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdChoice1);
Assert.assertNotNull(createdChoice1.getEntityId());
- ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getEntityId());
+ ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPollId, createdChoice1.getEntityId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
Assert.assertEquals(choice1.getName(), createdChoice1.getName());
@@ -501,14 +506,14 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdChoice2);
Assert.assertNotNull(createdChoice2.getEntityId());
- ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getEntityId());
+ ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPollId, createdChoice2.getEntityId());
Assert.assertEquals(createdChoice2, reloadedChoice2);
Assert.assertEquals(choice2.getName(), createdChoice2.getName());
Assert.assertEquals(choice2.getDescription(), createdChoice2.getDescription());
// Assert.assertEquals(createdPoll.getCreator(), createdChoice2.getCreator());
- List<VoterListBean> createdVoterLists = voterListService.getVoterLists(createdPoll.getId());
+ List<VoterListBean> createdVoterLists = voterListService.getVoterLists(createdPollId);
Assert.assertNotNull(createdVoterLists);
Assert.assertEquals(1, createdVoterLists.size());
@@ -516,7 +521,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdVoterList);
Assert.assertNotNull(createdVoterList.getEntityId());
- VoterListBean reloadedVoterList = voterListService.getVoterList(createdPoll.getId(), createdVoterList.getEntityId());
+ VoterListBean reloadedVoterList = voterListService.getVoterList(createdPollId, createdVoterList.getEntityId());
Assert.assertEquals(createdVoterList, reloadedVoterList);
Assert.assertEquals(voterList.getName(), createdVoterList.getName());
diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/service/PollenUserServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/service/PollenUserServiceTest.java
index 461bfe2..43cb7e8 100644
--- a/pollen-services/src/test/java/org/chorem/pollen/services/service/PollenUserServiceTest.java
+++ b/pollen-services/src/test/java/org/chorem/pollen/services/service/PollenUserServiceTest.java
@@ -26,7 +26,7 @@ package org.chorem.pollen.services.service;
import org.apache.commons.collections4.CollectionUtils;
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.services.AbstractPollenServiceTest;
-import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.PollenUserBean;
import org.chorem.pollen.services.service.security.PollenAuthenticationException;
import org.chorem.pollen.services.service.security.PollenInvalidSessionTokenException;
@@ -110,9 +110,9 @@ public class PollenUserServiceTest extends AbstractPollenServiceTest {
newUser.setLogin("pollen");
newUser.setEmail("pollen(a)pollen.org");
- CreateBeanRef savedUser = service.createUser(newUser, true);
+ PollenEntityRef<PollenUser> savedUser = service.createUser(newUser, true);
Assert.assertNotNull(savedUser);
- Assert.assertNotNull(savedUser.getId());
+ Assert.assertNotNull(savedUser.getEntityId());
PollenUserBean newUser2 = new PollenUserBean();
newUser2.setLogin("pollen");
@@ -137,9 +137,9 @@ public class PollenUserServiceTest extends AbstractPollenServiceTest {
}
newUser2.setEmail("pollen2(a)pollen.org");
- CreateBeanRef savedUser2 = service.createUser(newUser2, true);
+ PollenEntityRef<PollenUser> savedUser2 = service.createUser(newUser2, true);
Assert.assertNotNull(savedUser2);
- Assert.assertNotNull(savedUser2.getId());
+ Assert.assertNotNull(savedUser2.getEntityId());
}
@Test
diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteCountingServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteCountingServiceTest.java
index 2a6e520..100a223 100644
--- a/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteCountingServiceTest.java
+++ b/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteCountingServiceTest.java
@@ -1,11 +1,33 @@
package org.chorem.pollen.services.service;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.apache.commons.lang3.time.DateUtils;
import org.chorem.pollen.persistence.entity.ChoiceType;
+import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.services.AbstractPollenServiceTest;
import org.chorem.pollen.services.bean.ChoiceBean;
-import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollBean;
+import org.chorem.pollen.services.bean.PollenEntityRef;
import org.chorem.pollen.services.bean.VoteBean;
import org.chorem.pollen.services.bean.VoteToChoiceBean;
import org.chorem.pollen.votecounting.model.ChoiceScore;
@@ -72,9 +94,9 @@ public class VoteCountingServiceTest extends AbstractPollenServiceTest {
choice2.setDescription("Choice B");
choices.add(choice2);
- CreateBeanRef createdPollRef = pollService.createPoll(poll, choices, null);
+ PollenEntityRef<Poll> createdPollRef = pollService.createPoll(poll, choices, null);
- String pollId = createdPollRef.getId();
+ String pollId = createdPollRef.getEntityId();
List<ChoiceBean> createdChoices = choiceService.getChoices(pollId);
ChoiceBean createdChoiceBean1 = createdChoices.get(0);
diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteServiceTest.java
index 78e69bc..a5ca140 100644
--- a/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteServiceTest.java
+++ b/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteServiceTest.java
@@ -1,5 +1,26 @@
package org.chorem.pollen.services.service;
+/*
+ * #%L
+ * Pollen :: Service
+ * %%
+ * 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%
+ */
+
import org.chorem.pollen.services.AbstractPollenServiceTest;
import org.chorem.pollen.services.service.security.SecurityService;
import org.junit.Test;
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
unknown user pushed a commit to branch devel
in repository Pollen.
commit 444f953dd0aeafcf12c3e18aef2e85a22b50ada3
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Fri May 23 21:31:23 2014 +0200
use everywhere PollenEntityId
---
.../org/chorem/pollen/rest/api/PollenRender.java | 4 +-
.../rest/api/PollenRestApiApplicationListener.java | 46 ++------
.../rest/api/PollenRestApiRequestFilter.java | 4 +-
.../chorem/pollen/rest/api/PollenRestApiUtil.java | 77 +++++++-------
.../rest/api/injector/PollenBeanIdInjector.java | 49 +++++++++
.../PollenRestApiRequestContextInjector.java | 32 ++++++
.../rest/api/injector/PollenServiceInjector.java | 34 ++++++
.../org/chorem/pollen/rest/api/v1/ChoiceApi.java | 23 ++--
.../org/chorem/pollen/rest/api/v1/CommentApi.java | 24 +++--
.../chorem/pollen/rest/api/v1/FavoriteListApi.java | 31 +++---
.../org/chorem/pollen/rest/api/v1/PollApi.java | 27 +++--
.../chorem/pollen/rest/api/v1/PollenUserApi.java | 18 ++--
.../org/chorem/pollen/rest/api/v1/VoteApi.java | 23 ++--
.../chorem/pollen/rest/api/v1/VoteCountingApi.java | 10 +-
.../chorem/pollen/rest/api/v1/VoterListApi.java | 49 +++++----
pollen-rest-api/src/main/resources/mapping | 25 +++++
.../src/main/resources/pollen-rest-api.properties | 1 +
.../pollen/rest/api/AbstractPollenRestApiTest.java | 10 ++
.../org/chorem/pollen/rest/api/PollApiTest.java | 10 +-
.../chorem/pollen/rest/api/PollenUserApiTest.java | 6 +-
.../rest/api/converter/JsonConverterTest.java | 4 +-
pollen-services/pom.xml | 10 ++
.../chorem/pollen/services/bean/ChoiceBean.java | 2 -
.../chorem/pollen/services/bean/CommentBean.java | 2 -
.../chorem/pollen/services/bean/CreateBeanRef.java | 55 +++-------
.../pollen/services/bean/FavoriteListBean.java | 2 -
.../services/bean/FavoriteListMemberBean.java | 2 -
.../org/chorem/pollen/services/bean/PollBean.java | 2 -
.../chorem/pollen/services/bean/PollenBean.java | 14 +--
.../chorem/pollen/services/bean/PollenBeanId.java | 104 ------------------
.../pollen/services/bean/PollenEntityId.java | 116 +++++++++++++++++++++
.../pollen/services/bean/PollenUserBean.java | 2 -
.../org/chorem/pollen/services/bean/VoteBean.java | 36 ++++---
.../pollen/services/bean/VoteToChoiceBean.java | 18 ++--
.../chorem/pollen/services/bean/VoterListBean.java | 2 -
.../pollen/services/bean/VoterListMemberBean.java | 2 -
.../services/config/PollenServiceConfig.java | 5 +
.../services/config/PollenServiceConfigOption.java | 7 ++
.../pollen/services/service/VoteService.java | 4 +-
.../src/test/resources/pollen-services.properties | 1 +
40 files changed, 527 insertions(+), 366 deletions(-)
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
index bae0a13..71a5922 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
@@ -26,7 +26,7 @@ package org.chorem.pollen.rest.api;
import com.google.common.collect.Multimap;
import com.google.gson.Gson;
import org.chorem.pollen.services.bean.CreateBeanRef;
-import org.chorem.pollen.services.bean.PollenBeanId;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.service.InvalidFormException;
import org.debux.webmotion.server.call.Call;
import org.debux.webmotion.server.call.HttpContext;
@@ -109,7 +109,7 @@ public class PollenRender<T> extends Render {
// encode id
CreateBeanRef createBeanRef = (CreateBeanRef) model;
- String encodeId = PollenBeanId.encodeId(topiaIdFactory, createBeanRef.getId());
+ String encodeId = PollenEntityId.encode(topiaIdFactory, createBeanRef.getId());
CreateBeanRef result = CreateBeanRef.of(encodeId, createBeanRef.getPermission());
return result;
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
index 832fdfd..886ce14 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
@@ -27,7 +27,9 @@ import com.google.common.collect.Sets;
import org.chorem.pollen.rest.api.converter.DateConverter;
import org.chorem.pollen.rest.api.converter.JsonArrayConverter;
import org.chorem.pollen.rest.api.converter.JsonConverter;
-import org.chorem.pollen.services.PollenService;
+import org.chorem.pollen.rest.api.injector.PollenBeanIdInjector;
+import org.chorem.pollen.rest.api.injector.PollenRestApiRequestContextInjector;
+import org.chorem.pollen.rest.api.injector.PollenServiceInjector;
import org.chorem.pollen.services.bean.ChoiceBean;
import org.chorem.pollen.services.bean.CommentBean;
import org.chorem.pollen.services.bean.FavoriteListBean;
@@ -37,14 +39,10 @@ import org.chorem.pollen.services.bean.PollenUserBean;
import org.chorem.pollen.services.bean.VoteBean;
import org.chorem.pollen.services.bean.VoteToChoiceBean;
import org.debux.webmotion.server.WebMotionServerListener;
-import org.debux.webmotion.server.call.Call;
-import org.debux.webmotion.server.call.HttpContext;
import org.debux.webmotion.server.call.ServerContext;
-import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
import org.debux.webmotion.server.mapping.Mapping;
import org.nuiton.topia.persistence.TopiaIdFactory;
-import java.lang.reflect.Type;
import java.util.Date;
import java.util.Set;
@@ -96,41 +94,9 @@ public class PollenRestApiApplicationListener implements WebMotionServerListener
// --- init injectors --- //
- 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();
-
- PollenRestApiRequestContext requestContext =
- PollenRestApiRequestContext.getRequestContext(httpContext);
- result = requestContext.getServiceContext().newService(type);
- }
-
- return result;
-
- }
- });
-
-
+ serverContext.addInjector(new PollenRestApiRequestContextInjector());
+ serverContext.addInjector(new PollenServiceInjector());
+ serverContext.addInjector(new PollenBeanIdInjector(topiaIdFactory));
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java
index 664a251..c96137d 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java
@@ -59,7 +59,7 @@ public class PollenRestApiRequestFilter extends WebMotionFilter {
public void inject(Call call, HttpContext context) throws PollenInvalidSessionTokenException {
- PollenRestApiRequestContext requestContext = prepareRequestContext(context);
+ prepareRequestContext(context);
doProcess();
@@ -77,7 +77,7 @@ public class PollenRestApiRequestFilter extends WebMotionFilter {
}
- PollenRestApiUtil.prepareResponse(context, requestContext);
+ PollenRestApiUtil.prepareResponse(context);
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
index 0fb1cdf..affba69 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
@@ -14,12 +14,11 @@ import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.services.bean.PollenBeanId;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.debux.webmotion.server.call.HttpContext;
import org.nuiton.topia.persistence.TopiaIdFactory;
import javax.servlet.http.HttpServletResponse;
-import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
@@ -36,7 +35,8 @@ public class PollenRestApiUtil {
public static final String HEADER_ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
- public static <O> List<O> toList(O[] array) {
+ @SafeVarargs
+ public static <O> List<O> toList(O... array) {
List<O> list = null;
@@ -55,30 +55,10 @@ public class PollenRestApiUtil {
public static void prepareResponse(HttpContext context) {
- PollenRestApiRequestContext requestContext = PollenRestApiRequestContext.getRequestContext(context);
-
- prepareResponse(context, requestContext);
-
- }
-
- public static void prepareResponse(HttpContext context, PollenRestApiRequestContext requestContext) {
-
HttpServletResponse response = context.getResponse();
response.addHeader(HttpContext.HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*");
response.addHeader(HttpContext.HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
-// PollenSecurityContext securityContext = requestContext.getSecurityContext();
-// SessionToken sessionToken = securityContext.getSessionToken();
-// if (sessionToken != null) {
-//
-// context.getResponse().setHeader(sessionToken.getPollenToken().getToken());
-//
-// } else {
-//
-// context.getResponse().setHeader(requestContext.getSession().setSessionToken(null);
-//
-// }
-
}
public static void addOptionCorsHeaders(HttpContext context) {
@@ -104,29 +84,54 @@ public class PollenRestApiUtil {
return clazz == Class.class;
}
});
+
gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
+
+ JsonElement result;
+
if (src == null) {
- return JsonNull.INSTANCE;
+
+ result = JsonNull.INSTANCE;
+
+ } else {
+
+ result = new JsonPrimitive(src.getTime());
+
}
- return new JsonPrimitive(src.getTime());
+
+ return result;
+
}
});
- gsonBuilder.registerTypeAdapter(PollenBeanId.class, new JsonSerializer<PollenBeanId>() {
+
+ gsonBuilder.registerTypeAdapter(PollenEntityId.class, new JsonSerializer<PollenEntityId>() {
@Override
- public JsonElement serialize(PollenBeanId src, Type typeOfSrc, JsonSerializationContext context) {
+ public JsonElement serialize(PollenEntityId src, Type typeOfSrc, JsonSerializationContext context) {
+
+ JsonElement result;
+
if (src == null || src.getEntityId() == null) {
- return JsonNull.INSTANCE;
+
+ result = JsonNull.INSTANCE;
+
+ } else {
+
+ src.encode(idFactory);
+ result = new JsonPrimitive(src.getReducedId());
+
}
- src.encodeId(idFactory);
- return new JsonPrimitive(src.getEncodedId());
+
+ return result;
+
}
});
+
gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
@@ -135,20 +140,19 @@ public class PollenRestApiUtil {
}
});
- gsonBuilder.registerTypeAdapter(PollenBeanId.class, new JsonDeserializer<PollenBeanId>() {
+ gsonBuilder.registerTypeAdapter(PollenEntityId.class, new JsonDeserializer<PollenEntityId>() {
@Override
- public PollenBeanId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+ public PollenEntityId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
- Type[] actualTypeArguments = ((ParameterizedType) typeOfT).getActualTypeArguments();
- PollenBeanId id = new PollenBeanId<>((Class) actualTypeArguments[0]);
+ PollenEntityId id = PollenEntityId.newId(typeOfT);
String asString = json.getAsString();
if (asString != null) {
- id.setEncodedId(asString);
- id.decodeId(idFactory);
+ id.setReducedId(asString);
+ id.decode(idFactory);
}
@@ -157,6 +161,7 @@ public class PollenRestApiUtil {
}
});
+
if (prettyPrint) {
gsonBuilder.setPrettyPrinting();
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java
new file mode 100644
index 0000000..6ac37d3
--- /dev/null
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java
@@ -0,0 +1,49 @@
+package org.chorem.pollen.rest.api.injector;
+
+import org.chorem.pollen.services.bean.PollenEntityId;
+import org.debux.webmotion.server.call.Call;
+import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
+import org.debux.webmotion.server.mapping.Mapping;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaIdFactory;
+
+import java.lang.reflect.Type;
+
+/**
+ * Created on 5/23/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenBeanIdInjector implements ExecutorParametersInjectorHandler.Injector {
+
+ protected final TopiaIdFactory topiaIdFactory;
+
+ public PollenBeanIdInjector(TopiaIdFactory topiaIdFactory) {
+ this.topiaIdFactory = topiaIdFactory;
+ }
+
+ @Override
+ public PollenEntityId<TopiaEntity> getValue(Mapping m, Call call, String name, Class type, Type generic) {
+
+ PollenEntityId<TopiaEntity> result = null;
+
+ if (PollenEntityId.class.isAssignableFrom(type)) {
+
+ result = PollenEntityId.newId(generic);
+ Call.ParameterTree parameterTree = call.getParameterTree().getTree().get(name);
+
+ if (parameterTree != null && parameterTree.getValue() != null) {
+
+ String encodedId = ((String[]) parameterTree.getValue())[0];
+ result.setReducedId(encodedId);
+ result.decode(topiaIdFactory);
+
+ }
+ }
+
+ return result;
+
+ }
+
+}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java
new file mode 100644
index 0000000..76fd593
--- /dev/null
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java
@@ -0,0 +1,32 @@
+package org.chorem.pollen.rest.api.injector;
+
+import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
+import org.debux.webmotion.server.call.Call;
+import org.debux.webmotion.server.call.HttpContext;
+import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
+import org.debux.webmotion.server.mapping.Mapping;
+
+import java.lang.reflect.Type;
+
+/**
+ * Created on 5/23/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenRestApiRequestContextInjector implements 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;
+
+ }
+}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java
new file mode 100644
index 0000000..f35b2a0
--- /dev/null
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java
@@ -0,0 +1,34 @@
+package org.chorem.pollen.rest.api.injector;
+
+import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
+import org.chorem.pollen.services.PollenService;
+import org.debux.webmotion.server.call.Call;
+import org.debux.webmotion.server.call.HttpContext;
+import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
+import org.debux.webmotion.server.mapping.Mapping;
+
+import java.lang.reflect.Type;
+
+/**
+ * Created on 5/23/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenServiceInjector implements 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();
+
+ PollenRestApiRequestContext requestContext =
+ PollenRestApiRequestContext.getRequestContext(httpContext);
+ result = requestContext.getServiceContext().newService(type);
+ }
+
+ return result;
+
+ }
+}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java
index 6f1b06c..d591990 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java
@@ -23,8 +23,11 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.services.bean.ChoiceBean;
import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.service.ChoiceService;
import org.chorem.pollen.services.service.InvalidFormException;
import org.debux.webmotion.server.WebMotionController;
@@ -39,37 +42,37 @@ import java.util.List;
*/
public class ChoiceApi extends WebMotionController {
- public List<ChoiceBean> getChoices(ChoiceService choiceService, String pollId) {
+ public List<ChoiceBean> getChoices(ChoiceService choiceService, PollenEntityId<Poll> pollId) {
- List<ChoiceBean> choices = choiceService.getChoices(pollId);
+ List<ChoiceBean> choices = choiceService.getChoices(pollId.getEntityId());
return choices;
}
- public ChoiceBean getChoice(ChoiceService choiceService, String pollId, String choiceId) {
+ public ChoiceBean getChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, PollenEntityId<Choice> choiceId) {
- ChoiceBean choice = choiceService.getChoice(pollId, choiceId);
+ ChoiceBean choice = choiceService.getChoice(pollId.getEntityId(), choiceId.getEntityId());
return choice;
}
- public CreateBeanRef addChoice(ChoiceService choiceService, String pollId, ChoiceBean choice) throws InvalidFormException {
+ public CreateBeanRef addChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, ChoiceBean choice) throws InvalidFormException {
- CreateBeanRef principalRef = choiceService.addChoice(pollId, choice);
+ CreateBeanRef principalRef = choiceService.addChoice(pollId.getEntityId(), choice);
return principalRef;
}
- public ChoiceBean editChoice(ChoiceService choiceService, String pollId, ChoiceBean choice) throws InvalidFormException {
+ public ChoiceBean editChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, ChoiceBean choice) throws InvalidFormException {
- ChoiceBean editChoice = choiceService.editChoice(pollId, choice);
+ ChoiceBean editChoice = choiceService.editChoice(pollId.getEntityId(), choice);
return editChoice;
}
- public void deleteChoice(ChoiceService choiceService, String pollId, String choiceId) throws InvalidFormException {
+ public void deleteChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, PollenEntityId<Choice> choiceId) throws InvalidFormException {
- choiceService.deleteChoice(pollId, choiceId);
+ choiceService.deleteChoice(pollId.getEntityId(), choiceId.getEntityId());
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java
index d80404c..7e2283b 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java
@@ -23,14 +23,18 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.services.bean.CommentBean;
import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.service.CommentService;
import org.chorem.pollen.services.service.InvalidFormException;
import org.debux.webmotion.server.WebMotionController;
import java.util.List;
+
/**
* TODO
*
@@ -39,37 +43,37 @@ import java.util.List;
*/
public class CommentApi extends WebMotionController {
- public List<CommentBean> getComments(CommentService commentService, String pollId) {
+ public List<CommentBean> getComments(CommentService commentService, PollenEntityId<Poll> pollId) {
- List<CommentBean> comments = commentService.getComments(pollId);
+ List<CommentBean> comments = commentService.getComments(pollId.getEntityId());
return comments;
}
- public CommentBean getComment(CommentService commentService, String pollId, String commentId) {
+ public CommentBean getComment(CommentService commentService, PollenEntityId<Poll> pollId, PollenEntityId<Comment> commentId) {
- CommentBean comment = commentService.getComment(pollId, commentId);
+ CommentBean comment = commentService.getComment(pollId.getEntityId(), commentId.getReducedId());
return comment;
}
- public CreateBeanRef addComment(CommentService commentService, String pollId, CommentBean comment) throws InvalidFormException {
+ public CreateBeanRef addComment(CommentService commentService, PollenEntityId<Poll> pollId, CommentBean comment) throws InvalidFormException {
- CreateBeanRef principalRef = commentService.addComment(pollId, comment);
+ CreateBeanRef principalRef = commentService.addComment(pollId.getEntityId(), comment);
return principalRef;
}
- public CommentBean editComment(CommentService commentService, String pollId, CommentBean comment) throws InvalidFormException {
+ public CommentBean editComment(CommentService commentService, PollenEntityId<Poll> pollId, CommentBean comment) throws InvalidFormException {
- CommentBean editComment = commentService.editComment(pollId, comment);
+ CommentBean editComment = commentService.editComment(pollId.getEntityId(), comment);
return editComment;
}
- public void deleteComment(CommentService commentService, String pollId, String commentId) {
+ public void deleteComment(CommentService commentService, PollenEntityId<Poll> pollId, PollenEntityId<Comment> commentId) {
- commentService.deleteComment(pollId, commentId);
+ commentService.deleteComment(pollId.getEntityId(), commentId.getEntityId());
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java
index 77306bd..f4e53ad 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java
@@ -23,9 +23,12 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
+import org.chorem.pollen.persistence.entity.FavoriteList;
+import org.chorem.pollen.persistence.entity.FavoriteListMember;
import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.FavoriteListBean;
import org.chorem.pollen.services.bean.FavoriteListMemberBean;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.service.FavoriteListImportException;
import org.chorem.pollen.services.service.FavoriteListService;
import org.chorem.pollen.services.service.InvalidFormException;
@@ -50,9 +53,9 @@ public class FavoriteListApi extends WebMotionController {
}
- public FavoriteListBean getFavoriteList(FavoriteListService favoriteListService, String favoriteListId) {
+ public FavoriteListBean getFavoriteList(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId) {
- FavoriteListBean favoriteList = favoriteListService.getFavoriteList(favoriteListId);
+ FavoriteListBean favoriteList = favoriteListService.getFavoriteList(favoriteListId.getEntityId());
return favoriteList;
}
@@ -71,43 +74,43 @@ public class FavoriteListApi extends WebMotionController {
}
- public void deleteFavoriteList(FavoriteListService favoriteListService, String favoriteListId) {
+ public void deleteFavoriteList(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId) {
- favoriteListService.deleteFavoriteList(favoriteListId);
+ favoriteListService.deleteFavoriteList(favoriteListId.getEntityId());
}
- public int importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, String favoriteListId, File csvFile) throws FavoriteListImportException {
+ public int importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, File csvFile) throws FavoriteListImportException {
- int i = favoriteListService.importFavoriteListMembersFromCsv(favoriteListId, csvFile);
+ int i = favoriteListService.importFavoriteListMembersFromCsv(favoriteListId.getEntityId(), csvFile);
return i;
}
- public int importFavoriteListMembersFromLdap(FavoriteListService favoriteListService, String favoriteListId, String ldap) throws FavoriteListImportException {
+ public int importFavoriteListMembersFromLdap(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, String ldap) throws FavoriteListImportException {
- int i = favoriteListService.importFavoriteListMembersFromLdap(favoriteListId, ldap);
+ int i = favoriteListService.importFavoriteListMembersFromLdap(favoriteListId.getEntityId(), ldap);
return i;
}
- public Set<FavoriteListMemberBean> getMembers(FavoriteListService favoriteListService, String favoriteListId) {
+ public Set<FavoriteListMemberBean> getMembers(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId) {
- Set<FavoriteListMemberBean> members = favoriteListService.getFavoriteListMembers(favoriteListId);
+ Set<FavoriteListMemberBean> members = favoriteListService.getFavoriteListMembers(favoriteListId.getEntityId());
return members;
}
- public FavoriteListMemberBean getMember(FavoriteListService favoriteListService, String favoriteListId, String memberId) {
+ public FavoriteListMemberBean getMember(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, PollenEntityId<FavoriteListMember> memberId) {
- FavoriteListMemberBean member = favoriteListService.getFavoriteListMember(favoriteListId, memberId);
+ FavoriteListMemberBean member = favoriteListService.getFavoriteListMember(favoriteListId.getEntityId(), memberId.getEntityId());
return member;
}
- public CreateBeanRef addMember(FavoriteListService favoriteListService, String favoriteListId, FavoriteListMemberBean member) throws InvalidFormException {
+ public CreateBeanRef addMember(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, FavoriteListMemberBean member) throws InvalidFormException {
- CreateBeanRef principalRef = favoriteListService.addFavoriteListMember(favoriteListId, member);
+ CreateBeanRef principalRef = favoriteListService.addFavoriteListMember(favoriteListId.getEntityId(), member);
return principalRef;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java
index aefc3ea..a3a078b 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java
@@ -23,10 +23,12 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
+import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.rest.api.PollenRestApiUtil;
import org.chorem.pollen.services.bean.ChoiceBean;
import org.chorem.pollen.services.bean.CreateBeanRef;
import org.chorem.pollen.services.bean.PollBean;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.bean.VoterListBean;
import org.chorem.pollen.services.service.InvalidFormException;
import org.chorem.pollen.services.service.PollService;
@@ -79,14 +81,17 @@ public class PollApi extends WebMotionController {
}
- public PollBean getPoll(PollService pollService, String pollId) {
+ public PollBean getPoll(PollService pollService, PollenEntityId<Poll> pollId) {
- PollBean poll = pollService.getPoll(pollId);
+ PollBean poll = pollService.getPoll(pollId.getEntityId());
return poll;
}
- public CreateBeanRef createPoll(PollService pollService, PollBean poll, ChoiceBean[] choices, VoterListBean[] voterLists) throws InvalidFormException {
+ public CreateBeanRef createPoll(PollService pollService,
+ PollBean poll,
+ ChoiceBean[] choices,
+ VoterListBean[] voterLists) throws InvalidFormException {
List<ChoiceBean> choiceList = PollenRestApiUtil.toList(choices);
@@ -104,28 +109,28 @@ public class PollApi extends WebMotionController {
}
- public void deletePoll(PollService pollService, String pollId) {
+ public void deletePoll(PollService pollService, PollenEntityId<Poll> pollId) {
- pollService.deletePoll(pollId);
+ pollService.deletePoll(pollId.getEntityId());
}
- public PollBean clonePoll(PollService pollService, String pollId) {
+ public PollBean clonePoll(PollService pollService, PollenEntityId<Poll> pollId) {
- PollBean clonedPoll = pollService.clonePoll(pollId);
+ PollBean clonedPoll = pollService.clonePoll(pollId.getEntityId());
return clonedPoll;
}
- public void closePoll(PollService pollService, String pollId) {
+ public void closePoll(PollService pollService, PollenEntityId<Poll> pollId) {
- pollService.closePoll(pollId);
+ pollService.closePoll(pollId.getEntityId());
}
- public File exportPoll(PollService pollService, String pollId) {
+ public File exportPoll(PollService pollService, PollenEntityId<Poll> pollId) {
- File exportedPollFile = pollService.exportPoll(pollId);
+ File exportedPollFile = pollService.exportPoll(pollId.getEntityId());
return exportedPollFile;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java
index e38eec7..325303b 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java
@@ -23,7 +23,9 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
+import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.bean.PollenUserBean;
import org.chorem.pollen.services.service.InvalidFormException;
import org.chorem.pollen.services.service.PollenUserService;
@@ -48,9 +50,9 @@ public class PollenUserApi extends WebMotionController {
}
- public PollenUserBean getUser(PollenUserService pollenUserService, String userId) {
+ public PollenUserBean getUser(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId) {
- PollenUserBean user = pollenUserService.getUser(userId);
+ PollenUserBean user = pollenUserService.getUser(userId.getEntityId());
return user;
}
@@ -72,26 +74,26 @@ public class PollenUserApi extends WebMotionController {
}
- public void deleteUser(PollenUserService pollenUserService, String userId) throws InvalidFormException {
+ public void deleteUser(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId) throws InvalidFormException {
- pollenUserService.deleteUser(userId);
+ pollenUserService.deleteUser(userId.getEntityId());
}
public void validateUserEmail(PollenUserService pollenUserService,
- String userId,
+ PollenEntityId<PollenUser> userId,
String token) throws PollenInvalidEmailActivationTokenException {
- pollenUserService.validateUserEmail(userId, token);
+ pollenUserService.validateUserEmail(userId.getEntityId(), token);
}
public void changePassword(PollenUserService pollenUserService,
- String userId,
+ PollenEntityId<PollenUser> userId,
String oldPassword,
String newPassword) throws PollenInvalidPasswordException {
- pollenUserService.changePassword(userId, oldPassword, newPassword);
+ pollenUserService.changePassword(userId.getEntityId(), oldPassword, newPassword);
}
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java
index 446a59d..c1a1b19 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java
@@ -23,7 +23,10 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.Vote;
import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.bean.VoteBean;
import org.chorem.pollen.services.service.InvalidFormException;
import org.chorem.pollen.services.service.VoteService;
@@ -39,37 +42,37 @@ import java.util.List;
*/
public class VoteApi extends WebMotionController {
- public List<VoteBean> getVotes(VoteService voteService, String pollId) {
+ public List<VoteBean> getVotes(VoteService voteService, PollenEntityId<Poll> pollId) {
- List<VoteBean> votes = voteService.getVotes(pollId);
+ List<VoteBean> votes = voteService.getVotes(pollId.getEntityId());
return votes;
}
- public VoteBean getVote(VoteService voteService, String pollId, String voteId) {
+ public VoteBean getVote(VoteService voteService, PollenEntityId<Poll> pollId, PollenEntityId<Vote> voteId) {
- VoteBean vote = voteService.getVote(pollId, voteId);
+ VoteBean vote = voteService.getVote(pollId.getEntityId(), voteId.getEntityId());
return vote;
}
- public CreateBeanRef addVote(VoteService voteService, String pollId, VoteBean vote) throws InvalidFormException {
+ public CreateBeanRef addVote(VoteService voteService, PollenEntityId<Poll> pollId, VoteBean vote) throws InvalidFormException {
- CreateBeanRef principalRef = voteService.addVote(pollId, vote);
+ CreateBeanRef principalRef = voteService.addVote(pollId.getEntityId(), vote);
return principalRef;
}
- public VoteBean editVote(VoteService voteService, String pollId, VoteBean vote) throws InvalidFormException {
+ public VoteBean editVote(VoteService voteService, PollenEntityId<Poll> pollId, VoteBean vote) throws InvalidFormException {
- VoteBean editedVote = voteService.editVote(pollId, vote);
+ VoteBean editedVote = voteService.editVote(pollId.getEntityId(), vote);
return editedVote;
}
- public void deleteVote(VoteService voteService, String pollId, String voteId) {
+ public void deleteVote(VoteService voteService, PollenEntityId<Poll> pollId, PollenEntityId<Vote> voteId) {
- voteService.deleteVote(pollId, voteId);
+ voteService.deleteVote(pollId.getEntityId(), voteId.getEntityId());
}
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java
index 2db98ed..a4b83ac 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java
@@ -23,6 +23,8 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.service.VoteCountingService;
import org.chorem.pollen.votecounting.model.GroupVoteCountingResult;
import org.chorem.pollen.votecounting.model.VoteCountingResult;
@@ -36,16 +38,16 @@ import org.debux.webmotion.server.WebMotionController;
*/
public class VoteCountingApi extends WebMotionController {
- public VoteCountingResult getMainResult(VoteCountingService voteCountingService, String pollId) {
+ public VoteCountingResult getMainResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) {
- VoteCountingResult result = voteCountingService.getMainResult(pollId);
+ VoteCountingResult result = voteCountingService.getMainResult(pollId.getEntityId());
return result;
}
- public GroupVoteCountingResult getGroupResult(VoteCountingService voteCountingService, String pollId) {
+ public GroupVoteCountingResult getGroupResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) {
- GroupVoteCountingResult result = voteCountingService.getGroupResult(pollId);
+ GroupVoteCountingResult result = voteCountingService.getGroupResult(pollId.getEntityId());
return result;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java
index f081ca7..231d8d0 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java
@@ -23,7 +23,12 @@ package org.chorem.pollen.rest.api.v1;
* #L%
*/
+import org.chorem.pollen.persistence.entity.FavoriteList;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.VoterList;
+import org.chorem.pollen.persistence.entity.VoterListMember;
import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.bean.VoterListBean;
import org.chorem.pollen.services.bean.VoterListMemberBean;
import org.chorem.pollen.services.service.InvalidFormException;
@@ -41,78 +46,78 @@ import java.util.Set;
*/
public class VoterListApi extends WebMotionController {
- public VoterListBean importFavoriteList(VoterListService voterListService, String pollId, String favoriteListId) {
+ public VoterListBean importFavoriteList(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<FavoriteList> favoriteListId) {
- VoterListBean importVoterList = voterListService.importFavoriteList(pollId, favoriteListId);
+ VoterListBean importVoterList = voterListService.importFavoriteList(pollId.getEntityId(), favoriteListId.getEntityId());
return importVoterList;
}
- public List<VoterListBean> getVoterLists(VoterListService voterListService, String pollId) {
+ public List<VoterListBean> getVoterLists(VoterListService voterListService, PollenEntityId<Poll> pollId) {
- List<VoterListBean> voterLists = voterListService.getVoterLists(pollId);
+ List<VoterListBean> voterLists = voterListService.getVoterLists(pollId.getEntityId());
return voterLists;
}
- public VoterListBean getVoterList(VoterListService voterListService, String pollId, String voterListId) {
+ public VoterListBean getVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId) {
- VoterListBean voterList = voterListService.getVoterList(pollId, voterListId);
+ VoterListBean voterList = voterListService.getVoterList(pollId.getEntityId(), voterListId.getEntityId());
return voterList;
}
- public CreateBeanRef createVoterList(VoterListService voterListService, String pollId, VoterListBean voterList) throws InvalidFormException {
+ public CreateBeanRef createVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, VoterListBean voterList) throws InvalidFormException {
- CreateBeanRef principalRef = voterListService.addVoterList(pollId, voterList);
+ CreateBeanRef principalRef = voterListService.addVoterList(pollId.getEntityId(), voterList);
return principalRef;
}
- public VoterListBean editVoterList(VoterListService voterListService, String pollId, VoterListBean voterList) throws InvalidFormException {
+ public VoterListBean editVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, VoterListBean voterList) throws InvalidFormException {
- VoterListBean editedVoterList = voterListService.editVoterList(pollId, voterList);
+ VoterListBean editedVoterList = voterListService.editVoterList(pollId.getEntityId(), voterList);
return editedVoterList;
}
- public void deleteVoterList(VoterListService voterListService, String pollId, String voterListId) {
+ public void deleteVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId) {
- voterListService.deleteVoterList(pollId, voterListId);
+ voterListService.deleteVoterList(pollId.getEntityId(), voterListId.getEntityId());
}
- public Set<VoterListMemberBean> getMembers(VoterListService voterListService, String pollId, String voterListId) {
+ public Set<VoterListMemberBean> getMembers(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId) {
- Set<VoterListMemberBean> members = voterListService.getVoterListMembers(pollId, voterListId);
+ Set<VoterListMemberBean> members = voterListService.getVoterListMembers(pollId.getEntityId(), voterListId.getEntityId());
return members;
}
- public VoterListMemberBean getMember(VoterListService voterListService, String pollId, String voterListId, String memberId) {
+ public VoterListMemberBean getMember(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId, PollenEntityId<VoterListMember> memberId) {
- VoterListMemberBean member = voterListService.getVoterListMember(pollId, voterListId, memberId);
+ VoterListMemberBean member = voterListService.getVoterListMember(pollId.getEntityId(), voterListId.getEntityId(), memberId.getEntityId());
return member;
}
- public VoterListMemberBean addMember(VoterListService voterListService, String pollId, String voterListId, VoterListMemberBean member) throws InvalidFormException {
+ public VoterListMemberBean addMember(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId, VoterListMemberBean member) throws InvalidFormException {
- VoterListMemberBean principalRef = voterListService.addVoterListMember(pollId, voterListId, member);
+ VoterListMemberBean principalRef = voterListService.addVoterListMember(pollId.getEntityId(), voterListId.getEntityId(), member);
return principalRef;
}
- public VoterListMemberBean editMember(VoterListService voterListService, String pollId, String voterListId, VoterListMemberBean member) throws InvalidFormException {
+ public VoterListMemberBean editMember(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId, VoterListMemberBean member) throws InvalidFormException {
- VoterListMemberBean editedMember = voterListService.editVoterListMember(pollId, voterListId, member);
+ VoterListMemberBean editedMember = voterListService.editVoterListMember(pollId.getEntityId(), voterListId.getEntityId(), member);
return editedMember;
}
- public void deleteMember(VoterListService voterListService, String pollId, String voterListId, String memberId) {
+ public void deleteMember(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId, PollenEntityId<VoterListMember> memberId) {
- voterListService.deleteVoterListMember(pollId, voterListId, memberId);
+ voterListService.deleteVoterListMember(pollId.getEntityId(), voterListId.getEntityId(), memberId.getEntityId());
}
diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping
index 38cd416..c60deeb 100644
--- a/pollen-rest-api/src/main/resources/mapping
+++ b/pollen-rest-api/src/main/resources/mapping
@@ -1,3 +1,28 @@
+###
+# #%L
+# Pollen :: Rest Api
+# %%
+# 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%
+###
+
+###
+# Pollen version : ${project.version}
+###
+
[config]
package.filters=org.chorem.pollen.rest.api
package.actions=org.chorem.pollen.rest.api.v1
diff --git a/pollen-rest-api/src/main/resources/pollen-rest-api.properties b/pollen-rest-api/src/main/resources/pollen-rest-api.properties
index 21cc829..80bb25e 100644
--- a/pollen-rest-api/src/main/resources/pollen-rest-api.properties
+++ b/pollen-rest-api/src/main/resources/pollen-rest-api.properties
@@ -24,3 +24,4 @@ hibernate.connection.username=sa
hibernate.connection.password=sa
hibernate.connection.driver_class=org.h2.Driver
hibernate.hbm2ddl.auto=update
+pollen.version=${project.version}
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
index 7fafbbe..939417f 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
@@ -30,6 +30,7 @@ import org.chorem.pollen.persistence.PollenTopiaPersistenceContext;
import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.persistence.entity.SessionToken;
import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.bean.PollenEntityId;
import org.chorem.pollen.services.service.security.PollenSecurityContext;
import org.chorem.pollen.services.test.FakePollenApplicationContext;
import org.chorem.pollen.services.test.FakePollenSecurityContext;
@@ -38,6 +39,7 @@ import org.debux.webmotion.unittest.WebMotionTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
+import org.nuiton.topia.persistence.TopiaIdFactory;
import org.nuiton.util.DateUtil;
import java.io.File;
@@ -79,6 +81,14 @@ public class AbstractPollenRestApiTest extends WebMotionTest {
}
+ protected String encodeId(String entityId) {
+
+ TopiaIdFactory topiaIdFactory = application.getTopiaApplicationContext().getTopiaIdFactory();
+ String encode = PollenEntityId.encode(topiaIdFactory, entityId);
+ return encode;
+
+ }
+
@Before
public void startServer() throws Exception {
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
index 07bfec7..1aa53fd 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
@@ -108,7 +108,7 @@ public class PollApiTest extends AbstractPollenRestApiTest {
public void getPoll() throws URISyntaxException, IOException {
Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID);
- String pollId = poll.getTopiaId();
+ String pollId = encodeId(poll.getTopiaId());
Request request = createRequest("/v1/polls/" + pollId).Get();
String content = request.execute().returnContent().asString();
showTestResult(content);
@@ -167,7 +167,7 @@ public class PollApiTest extends AbstractPollenRestApiTest {
@Test
public void deletePoll() throws URISyntaxException, IOException {
Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID);
- String pollId = poll.getTopiaId();
+ String pollId = encodeId(poll.getTopiaId());
Request request = createRequest("/v1/polls/" + pollId)
.addParameter(PollenRestApiRequestFilter.REQUEST_PERMISSION_PARAMETER, poll.getCreator().getPermission().getToken())
.Delete();
@@ -180,7 +180,7 @@ public class PollApiTest extends AbstractPollenRestApiTest {
@Test
public void clonePoll() throws URISyntaxException, IOException {
Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID);
- String pollId = poll.getTopiaId();
+ String pollId = encodeId(poll.getTopiaId());
Request request = createRequest("/v1/polls/" + pollId).Post();
String content = request.execute().returnContent().asString();
showTestResult(content);
@@ -191,7 +191,7 @@ public class PollApiTest extends AbstractPollenRestApiTest {
@Test
public void exportPoll() throws URISyntaxException, IOException {
Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID);
- String pollId = poll.getTopiaId();
+ String pollId = encodeId(poll.getTopiaId());
Request request = createRequest("/v1/polls/" + pollId + "/export").Get();
String content = request.execute().returnContent().asString();
showTestResult(content);
@@ -202,7 +202,7 @@ public class PollApiTest extends AbstractPollenRestApiTest {
@Test
public void closePoll() throws URISyntaxException, IOException {
Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID);
- String pollId = poll.getTopiaId();
+ String pollId = encodeId(poll.getTopiaId());
Request request = createRequest("/v1/polls/" + pollId + "/close").Post();
String content = request.execute().returnContent().asString();
showTestResult(content);
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
index 2fa7fad..1e7b9f1 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
@@ -85,7 +85,7 @@ public class PollenUserApiTest extends AbstractPollenRestApiTest {
String sessionToken = login("admin", "admin");
PollenUser pollenUser = fixture("user_jean");
- String userId = pollenUser.getTopiaId();
+ String userId = encodeId(pollenUser.getTopiaId());
Request request = createRequest("/v1/users/" + userId).Get();
request.addHeader(PollenRestApiRequestFilter.REQUEST_HEADER_SESSION_TOKEN, sessionToken);
String content = request.execute().returnContent().asString();
@@ -124,7 +124,7 @@ public class PollenUserApiTest extends AbstractPollenRestApiTest {
public void deleteUser() throws Exception {
PollenUser pollenUser = fixture("user_jean");
- String userId = pollenUser.getTopiaId();
+ String userId = encodeId(pollenUser.getTopiaId());
Request request = createRequest("/v1/users/" + userId).Delete();
String content = request.execute().returnContent().asString();
showTestResult(content);
@@ -137,7 +137,7 @@ public class PollenUserApiTest extends AbstractPollenRestApiTest {
public void validateUserEmail() throws Exception {
PollenUser pollenUser = fixture("user_jean");
- String userId = pollenUser.getTopiaId();
+ String userId = encodeId(pollenUser.getTopiaId());
String token = "";
Request request = createRequest("/v1/users/" + userId + "?token=" + token).Put();
String content = request.execute().returnContent().asString();
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java
index b34e74d..35bd59d 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java
@@ -46,14 +46,14 @@ public class JsonConverterTest {
Assert.assertEquals(true, voteBean.getAnonymous());
Assert.assertEquals("toto", voteBean.getVoterName());
- Assert.assertEquals("voterId", voteBean.getVoterId());
+ Assert.assertEquals("voterId", voteBean.getVoterId().getReducedId());
Assert.assertNotNull(voteBean.getChoice());
Assert.assertEquals(1, voteBean.getChoice().size());
VoteToChoiceBean voteToChoiceBean = voteBean.getChoice().iterator().next();
Assert.assertNotNull(voteToChoiceBean);
Assert.assertEquals(1.5, voteToChoiceBean.getVoteValue(), 0);
- Assert.assertEquals("AA", voteToChoiceBean.getChoiceId());
+ Assert.assertEquals("AA", voteToChoiceBean.getChoiceId().getReducedId());
String convert = converter.convert(String.class, voteBean);
Assert.assertNotNull(convert);
diff --git a/pollen-services/pom.xml b/pollen-services/pom.xml
index bb00f0a..19c8c13 100644
--- a/pollen-services/pom.xml
+++ b/pollen-services/pom.xml
@@ -151,6 +151,16 @@
</dependencies>
<build>
+
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <includes>
+ <include>**/*.properties</include>
+ </includes>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
<plugins>
<plugin>
<groupId>org.nuiton.i18n</groupId>
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
index dc5ceff..746e055 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
@@ -12,8 +12,6 @@ import org.chorem.pollen.persistence.entity.ChoiceType;
*/
public class ChoiceBean extends PollenBean<Choice> {
- private static final long serialVersionUID = 1L;
-
protected String permission;
protected int choiceOrder;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
index 7f03bb3..513337e 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
@@ -14,8 +14,6 @@ import java.util.Date;
*/
public class CommentBean extends PollenBean<Comment> {
- private static final long serialVersionUID = 1L;
-
protected String permission;
protected String authorName;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java
index 08d8cfe..5e5ff90 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java
@@ -2,15 +2,11 @@ package org.chorem.pollen.services.bean;
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.persistence.entity.FavoriteList;
-import org.chorem.pollen.persistence.entity.FavoriteListMember;
import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.PollenToken;
import org.chorem.pollen.persistence.entity.SessionToken;
import org.chorem.pollen.persistence.entity.Vote;
-import org.chorem.pollen.persistence.entity.VoterList;
-
-import java.io.Serializable;
+import org.nuiton.topia.persistence.TopiaEntity;
/**
* Created on 5/15/14.
@@ -18,9 +14,7 @@ import java.io.Serializable;
* @author Tony Chemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class CreateBeanRef implements Serializable {
-
- private static final long serialVersionUID = 1L;
+public class CreateBeanRef {
protected String id;
@@ -28,68 +22,49 @@ public class CreateBeanRef implements Serializable {
public static CreateBeanRef of(Poll entity) {
- CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(),
- entity.getCreator().getPermission().getToken());
+ CreateBeanRef ref = of(entity, entity.getCreator().getPermission());
return ref;
}
public static CreateBeanRef of(Choice entity) {
- CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(),
- entity.getCreator().getPermission().getToken());
+ CreateBeanRef ref = of(entity, entity.getCreator().getPermission());
return ref;
}
public static CreateBeanRef of(Comment entity) {
- CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(),
- entity.getAuthor().getPermission().getToken());
+ CreateBeanRef ref = of(entity, entity.getAuthor().getPermission());
return ref;
}
public static CreateBeanRef of(Vote entity) {
- CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(),
- entity.getVoter().getPermission().getToken());
- return ref;
-
- }
-
- public static CreateBeanRef of(VoterList entity) {
-
- CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(), null);
- return ref;
-
- }
-
- public static CreateBeanRef of(PollenUser result) {
-
- CreateBeanRef ref = new CreateBeanRef(result.getTopiaId(), null);
+ CreateBeanRef ref = of(entity, entity.getVoter().getPermission());
return ref;
}
- public static CreateBeanRef of(FavoriteList result) {
+ public static CreateBeanRef of(SessionToken result) {
- CreateBeanRef ref = new CreateBeanRef(result.getTopiaId(), null);
+ CreateBeanRef ref = of(result.getPollenUser(), result.getPollenToken());
return ref;
}
- public static CreateBeanRef of(FavoriteListMember result) {
+ public static CreateBeanRef of(TopiaEntity result) {
- CreateBeanRef ref = new CreateBeanRef(result.getTopiaId(), null);
+ CreateBeanRef ref = new CreateBeanRef(result);
return ref;
}
- public static CreateBeanRef of(SessionToken result) {
+ public static CreateBeanRef of(TopiaEntity id, PollenToken permission) {
- CreateBeanRef ref = new CreateBeanRef(result.getPollenUser().getTopiaId(),
- result.getPollenToken().getToken());
+ CreateBeanRef ref = new CreateBeanRef(id.getTopiaId(), permission==null?null: permission.getToken());
return ref;
}
@@ -101,6 +76,10 @@ public class CreateBeanRef implements Serializable {
}
+ protected CreateBeanRef(TopiaEntity id) {
+ this(id.getTopiaId(), null);
+ }
+
protected CreateBeanRef(String id, String permission) {
setId(id);
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
index 03b6fdb..c6f961e 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
@@ -15,8 +15,6 @@ import java.util.Set;
*/
public class FavoriteListBean extends PollenBean<FavoriteList> {
- private static final long serialVersionUID = 1L;
-
protected String name;
protected double weight;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
index 17b2be8..97423c2 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
@@ -11,8 +11,6 @@ import org.chorem.pollen.persistence.entity.FavoriteListMemberImpl;
*/
public class FavoriteListMemberBean extends PollenBean<FavoriteListMember> {
- private static final long serialVersionUID = 1L;
-
protected String name;
protected String email;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
index c154074..5013db7 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
@@ -20,8 +20,6 @@ import java.util.Objects;
*/
public class PollBean extends PollenBean<Poll> {
- private static final long serialVersionUID = 1L;
-
public PollBean() {
super(Poll.class);
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
index f2e3448..2883aa3 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
@@ -2,34 +2,30 @@ package org.chorem.pollen.services.bean;
import org.nuiton.topia.persistence.TopiaEntity;
-import java.io.Serializable;
-
/**
* Created on 5/15/14.
*
* @author Tony Chemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public abstract class PollenBean<E extends TopiaEntity> implements Serializable {
-
- private static final long serialVersionUID = 1L;
+public abstract class PollenBean<E extends TopiaEntity> {
protected final Class<E> entityType;
- protected PollenBeanId<E> id;
+ protected PollenEntityId<E> id;
protected PollenBean(Class<E> entityType) {
this.entityType = entityType;
}
- public PollenBeanId<E> getId() {
+ public PollenEntityId<E> getId() {
if (id == null) {
- id = new PollenBeanId<>(entityType);
+ id = PollenEntityId.newId(entityType);
}
return id;
}
- public void setId(PollenBeanId<E> id) {
+ public void setId(PollenEntityId<E> id) {
this.id = id;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java
deleted file mode 100644
index 1f57427..0000000
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.chorem.pollen.services.bean;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang3.StringUtils;
-import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.topia.persistence.TopiaIdFactory;
-
-import java.io.Serializable;
-
-/**
- * Created on 5/23/14.
- *
- * @author Tony Chemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenBeanId<E extends TopiaEntity> implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- protected final Class<E> entityType;
-
- protected String encodedId;
-
- protected String entityId;
-
- public static String encodeId(TopiaIdFactory topiaIdFactory, String entityId) {
-
- String randomPart = topiaIdFactory.getRandomPart(entityId);
- String encodedId = new String(Base64.encodeBase64URLSafe(randomPart.getBytes()));
- return encodedId;
-
- }
-
- public PollenBeanId(Class<E> entityType) {
- this.entityType = entityType;
- }
-
- public boolean isNotEmpty() {
- return StringUtils.isNotEmpty(encodedId) || StringUtils.isNotEmpty(entityId);
- }
-
- public String getEncodedId() {
- return encodedId;
- }
-
- public String getEntityId() {
- return entityId;
- }
-
- public void setEncodedId(String encodedId) {
- this.encodedId = encodedId;
- }
-
- public void setEntityId(String entityId) {
- this.entityId = entityId;
- }
-
- public void encodeId(TopiaIdFactory topiaIdFactory) {
-
- if (entityId != null) {
-
- String id = encodeId(topiaIdFactory, entityId);
- setEncodedId(id);
-
- }
-
- }
-
- public void decodeId(TopiaIdFactory topiaIdFactory) {
-
- if (encodedId != null) {
-
- String decodedId = new String(Base64.decodeBase64(encodedId));
- String id = topiaIdFactory.newTopiaId(entityType, decodedId);
- setEntityId(id);
-
- }
-
- }
-
- @Override
- public boolean equals(Object o) {
-
- if (this == o) return true;
- if (!(o instanceof PollenBeanId)) return false;
-
- PollenBeanId that = (PollenBeanId) o;
-
- return entityType.equals(that.entityType)
- && encodedId != null && encodedId.equals(that.encodedId)
- || entityId != null && entityId.equals(that.entityId);
-
- }
-
- @Override
- public int hashCode() {
-
- int result = entityType.hashCode();
- result = 31 * result + (encodedId != null ? encodedId.hashCode() : 0);
- result = 31 * result + (entityId != null ? entityId.hashCode() : 0);
- return result;
-
- }
-}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java
new file mode 100644
index 0000000..98147a3
--- /dev/null
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java
@@ -0,0 +1,116 @@
+package org.chorem.pollen.services.bean;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaIdFactory;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+/**
+ * Created on 5/23/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenEntityId<E extends TopiaEntity> {
+
+ protected final Class<E> entityType;
+
+ protected String entityId;
+
+ protected String reducedId;
+
+ public static <E extends TopiaEntity> PollenEntityId<E> newId(Type typeOfT) {
+
+ Type[] actualTypeArguments = ((ParameterizedType) typeOfT).getActualTypeArguments();
+ return newId((Class<E>) actualTypeArguments[0]);
+
+ }
+
+ public static <E extends TopiaEntity> PollenEntityId<E> newId(Class<E> entityType) {
+
+ return new PollenEntityId<>(entityType);
+
+ }
+
+ public static String encode(TopiaIdFactory topiaIdFactory, String entityId) {
+
+ String randomPart = topiaIdFactory.getRandomPart(entityId);
+ String encodedId = new String(Base64.encodeBase64URLSafe(randomPart.getBytes()));
+ return encodedId;
+
+ }
+
+ public PollenEntityId(Class<E> entityType) {
+ this.entityType = entityType;
+ }
+
+ public boolean isNotEmpty() {
+ return StringUtils.isNotEmpty(reducedId) || StringUtils.isNotEmpty(entityId);
+ }
+
+ public String getReducedId() {
+ return reducedId;
+ }
+
+ public String getEntityId() {
+ return entityId;
+ }
+
+ public void setReducedId(String reducedId) {
+ this.reducedId = reducedId;
+ }
+
+ public void setEntityId(String entityId) {
+ this.entityId = entityId;
+ }
+
+ public void encode(TopiaIdFactory topiaIdFactory) {
+
+ if (entityId != null) {
+
+ String id = encode(topiaIdFactory, entityId);
+ setReducedId(id);
+
+ }
+
+ }
+
+ public void decode(TopiaIdFactory topiaIdFactory) {
+
+ if (reducedId != null) {
+
+ String decodedId = new String(Base64.decodeBase64(reducedId));
+ String id = topiaIdFactory.newTopiaId(entityType, decodedId);
+ setEntityId(id);
+
+ }
+
+ }
+
+ @Override
+ public boolean equals(Object o) {
+
+ if (this == o) return true;
+ if (!(o instanceof PollenEntityId)) return false;
+
+ PollenEntityId that = (PollenEntityId) o;
+
+ return entityType.equals(that.entityType)
+ && (reducedId != null && reducedId.equals(that.reducedId)
+ || entityId != null && entityId.equals(that.entityId));
+
+ }
+
+ @Override
+ public int hashCode() {
+
+ int result = entityType.hashCode();
+ result = 31 * result + (reducedId == null ? 0 : reducedId.hashCode());
+ result = 31 * result + (entityId == null ? 0 : entityId.hashCode());
+ return result;
+
+ }
+}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
index 4ee51bb..98cd27a 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
@@ -11,8 +11,6 @@ import org.chorem.pollen.persistence.entity.PollenUserImpl;
*/
public class PollenUserBean extends PollenBean<PollenUser> {
- private static final long serialVersionUID = 1L;
-
protected String login;
protected String name;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
index 62ef064..d1dad27 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
@@ -1,6 +1,5 @@
package org.chorem.pollen.services.bean;
-import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.persistence.entity.PollenPrincipalImpl;
import org.chorem.pollen.persistence.entity.Vote;
@@ -23,11 +22,9 @@ import java.util.Set;
*/
public class VoteBean extends PollenBean<Vote> {
- private static final long serialVersionUID = 1L;
+ protected PollenEntityId<PollenPrincipal> voterId;
- protected String voterId;
-
- protected String voterListMemberId;
+ protected PollenEntityId<VoterListMember> voterListMemberId;
protected String voterName;
@@ -93,9 +90,10 @@ public class VoteBean extends PollenBean<Vote> {
PollenPrincipal voter = new PollenPrincipalImpl();
entity.setVoter(voter);
- voter.setTopiaId(getVoterId());
+ voter.setTopiaId(getVoterId().getEntityId());
voter.setName(getVoterName());
+
for (VoteToChoiceBean choiceBean : choice) {
VoteToChoice voteToChoice = choiceBean.toEntity();
@@ -103,11 +101,11 @@ public class VoteBean extends PollenBean<Vote> {
}
- if (StringUtils.isNotBlank(voterListMemberId)) {
+ if (getVoterListMemberId().getEntityId() != null) {
// FIXME
VoterListMember member = new VoterListMemberImpl();
- member.setTopiaId(voterListMemberId);
+ member.setTopiaId(getVoterListMemberId().getEntityId());
}
@@ -123,14 +121,21 @@ public class VoteBean extends PollenBean<Vote> {
this.voterName = voterName;
}
- public String getVoterId() {
+ public PollenEntityId<PollenPrincipal> getVoterId() {
+ if (voterId == null) {
+ voterId = PollenEntityId.newId(PollenPrincipal.class);
+ }
return voterId;
}
- public void setVoterId(String voterId) {
+ public void setVoterId(PollenEntityId<PollenPrincipal> voterId) {
this.voterId = voterId;
}
+ public void setVoterId(String voterId) {
+ getVoterId().setEntityId(voterId);
+ }
+
public String getPermission() {
return permission;
}
@@ -159,14 +164,21 @@ public class VoteBean extends PollenBean<Vote> {
return anonymous != null && anonymous;
}
- public String getVoterListMemberId() {
+ public PollenEntityId<VoterListMember> getVoterListMemberId() {
+ if (voterListMemberId == null) {
+ voterListMemberId = PollenEntityId.newId(VoterListMember.class);
+ }
return voterListMemberId;
}
- public void setVoterListMemberId(String voterListMemberId) {
+ public void setVoterListMemberId(PollenEntityId<VoterListMember> voterListMemberId) {
this.voterListMemberId = voterListMemberId;
}
+ public void setVoterListMemberId(String voterListMemberId) {
+ getVoterListMemberId().setEntityId(voterListMemberId);
+ }
+
public double getWeight() {
return weight;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
index 2251190..2e29e35 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
@@ -1,5 +1,6 @@
package org.chorem.pollen.services.bean;
+import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.ChoiceImpl;
import org.chorem.pollen.persistence.entity.VoteToChoice;
import org.chorem.pollen.persistence.entity.VoteToChoiceImpl;
@@ -12,9 +13,7 @@ import org.chorem.pollen.persistence.entity.VoteToChoiceImpl;
*/
public class VoteToChoiceBean extends PollenBean<VoteToChoice> {
- private static final long serialVersionUID = 1L;
-
- protected String choiceId;
+ protected PollenEntityId<Choice> choiceId;
protected Double voteValue;
@@ -38,20 +37,27 @@ public class VoteToChoiceBean extends PollenBean<VoteToChoice> {
entity.setTopiaId(getEntityId());
entity.setVoteValue(getVoteValue());
entity.setChoice(new ChoiceImpl());
- entity.getChoice().setTopiaId(getChoiceId());
+ entity.getChoice().setTopiaId(getChoiceId().getEntityId());
return entity;
}
- public String getChoiceId() {
+ public PollenEntityId<Choice> getChoiceId() {
+ if (choiceId == null) {
+ choiceId = PollenEntityId.newId(Choice.class);
+ }
return choiceId;
}
- public void setChoiceId(String choiceId) {
+ public void setChoiceId(PollenEntityId<Choice> choiceId) {
this.choiceId = choiceId;
}
+ public void setChoiceId(String choiceId) {
+ getChoiceId().setEntityId(choiceId);
+ }
+
public Double getVoteValue() {
return voteValue;
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
index 1fb2679..51ea9f7 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
@@ -15,8 +15,6 @@ import java.util.Set;
*/
public class VoterListBean extends PollenBean<VoterList> {
- private static final long serialVersionUID = 1L;
-
protected String name;
protected double weight;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
index 85ca451..12facbe 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
@@ -11,8 +11,6 @@ import org.chorem.pollen.persistence.entity.VoterListMemberImpl;
*/
public class VoterListMemberBean extends PollenBean<VoterListMember> {
- private static final long serialVersionUID = 1L;
-
protected String name;
protected String email;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java
index 7fd20d9..706bb94 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java
@@ -37,6 +37,7 @@ import org.chorem.pollen.persistence.entity.VoteVisibility;
import org.chorem.pollen.services.PollenTechnicalException;
import org.nuiton.config.ApplicationConfig;
import org.nuiton.config.ArgumentsParserException;
+import org.nuiton.util.Version;
import java.io.File;
import java.util.List;
@@ -194,4 +195,8 @@ public class PollenServiceConfig {
public String getHashAlgorithmName() {
return Sha512Hash.ALGORITHM_NAME;
}
+
+ public Version getVersion() {
+ return applicationConfig.getOptionAsVersion(PollenServiceConfigOption.APPLICATION_VERSION.key);
+ }
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java
index 89d79cd..58c4623 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java
@@ -29,6 +29,7 @@ import org.chorem.pollen.persistence.entity.PollType;
import org.chorem.pollen.persistence.entity.ResultVisibility;
import org.chorem.pollen.persistence.entity.VoteVisibility;
import org.nuiton.config.ConfigOptionDef;
+import org.nuiton.util.Version;
import java.io.File;
@@ -155,6 +156,12 @@ public enum PollenServiceConfigOption implements ConfigOptionDef {
"Chemin vers le fichier de configuration des journaux",
null,
String.class),
+
+ APPLICATION_VERSION(
+ "pollen.version",
+ "Version de l'application",
+ null,
+ Version.class),
;
protected final String key;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
index 51b5d72..a608993 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
@@ -198,7 +198,7 @@ public class VoteService extends PollenServiceSupport {
double weight;
- if (StringUtils.isBlank(vote.getVoterListMemberId())) {
+ if (StringUtils.isBlank(vote.getVoterListMemberId().getEntityId())) {
// not link to a member, use default value
@@ -291,7 +291,7 @@ public class VoteService extends PollenServiceSupport {
result = voteToChoiceDao.create();
- String choiceId = source.getChoiceId();
+ String choiceId = source.getChoiceId().getEntityId();
Choice choiceLoaded = getChoiceDao().findByTopiaId(choiceId);
diff --git a/pollen-services/src/test/resources/pollen-services.properties b/pollen-services/src/test/resources/pollen-services.properties
index e7c2eae..a9d9843 100644
--- a/pollen-services/src/test/resources/pollen-services.properties
+++ b/pollen-services/src/test/resources/pollen-services.properties
@@ -24,3 +24,4 @@ hibernate.connection.username=sa
hibernate.connection.password=sa
hibernate.connection.driver_class=org.h2.Driver
hibernate.hbm2ddl.auto=update
+pollen.version=${project.version}
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
unknown user pushed a commit to branch devel
in repository Pollen.
commit d74003c1a7ca877cd6bd7e8d86cebbb267187005
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Fri May 23 18:46:54 2014 +0200
encode ids
---
.../persistence/PollenTopiaApplicationContext.java | 22 +++++
.../org/chorem/pollen/rest/api/PollenRender.java | 28 +++++-
.../rest/api/PollenRestApiApplicationListener.java | 21 +++--
.../chorem/pollen/rest/api/PollenRestApiUtil.java | 56 ++++++++++-
.../rest/api/converter/JsonArrayConverter.java | 9 +-
.../pollen/rest/api/converter/JsonConverter.java | 17 ++--
.../org/chorem/pollen/rest/api/AuthApiTest.java | 5 +-
.../org/chorem/pollen/rest/api/PollApiTest.java | 7 +-
.../chorem/pollen/rest/api/PollenUserApiTest.java | 3 +-
.../rest/api/converter/JsonArrayConverterTest.java | 7 +-
.../rest/api/converter/JsonConverterTest.java | 5 +-
.../chorem/pollen/services/bean/ChoiceBean.java | 8 +-
.../chorem/pollen/services/bean/CommentBean.java | 8 +-
.../chorem/pollen/services/bean/CreateBeanRef.java | 7 ++
.../pollen/services/bean/FavoriteListBean.java | 8 +-
.../services/bean/FavoriteListMemberBean.java | 6 +-
.../org/chorem/pollen/services/bean/PollBean.java | 8 +-
.../chorem/pollen/services/bean/PollenBean.java | 35 +++++--
.../chorem/pollen/services/bean/PollenBeanId.java | 104 +++++++++++++++++++++
.../pollen/services/bean/PollenUserBean.java | 8 +-
.../org/chorem/pollen/services/bean/VoteBean.java | 8 +-
.../pollen/services/bean/VoteToChoiceBean.java | 8 +-
.../chorem/pollen/services/bean/VoterListBean.java | 8 +-
.../pollen/services/bean/VoterListMemberBean.java | 6 +-
.../pollen/services/service/ChoiceService.java | 10 +-
.../pollen/services/service/CommentService.java | 8 +-
.../services/service/FavoriteListService.java | 6 +-
.../pollen/services/service/PollService.java | 12 ++-
.../services/service/PollenServiceSupport.java | 36 -------
.../pollen/services/service/PollenUserService.java | 4 +-
.../pollen/services/service/VoteService.java | 10 +-
.../pollen/services/service/VoterListService.java | 8 +-
.../pollen/services/service/PollServiceTest.java | 44 ++++-----
.../services/service/PollenUserServiceTest.java | 2 +-
.../services/service/VoteCountingServiceTest.java | 10 +-
35 files changed, 393 insertions(+), 159 deletions(-)
diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaApplicationContext.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaApplicationContext.java
new file mode 100644
index 0000000..f19a22f
--- /dev/null
+++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaApplicationContext.java
@@ -0,0 +1,22 @@
+package org.chorem.pollen.persistence;
+
+import org.nuiton.topia.persistence.TopiaIdFactory;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class PollenTopiaApplicationContext extends AbstractPollenTopiaApplicationContext {
+
+ public PollenTopiaApplicationContext(Properties properties) {
+ super(properties);
+ }
+
+ public PollenTopiaApplicationContext(Map<String, String> configuration) {
+ super(configuration);
+ }
+
+ @Override
+ public TopiaIdFactory getTopiaIdFactory() {
+ return super.getTopiaIdFactory();
+ }
+}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
index e2ee51a..bae0a13 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
@@ -25,11 +25,14 @@ package org.chorem.pollen.rest.api;
import com.google.common.collect.Multimap;
import com.google.gson.Gson;
+import org.chorem.pollen.services.bean.CreateBeanRef;
+import org.chorem.pollen.services.bean.PollenBeanId;
import org.chorem.pollen.services.service.InvalidFormException;
import org.debux.webmotion.server.call.Call;
import org.debux.webmotion.server.call.HttpContext;
import org.debux.webmotion.server.mapping.Mapping;
import org.debux.webmotion.server.render.Render;
+import org.nuiton.topia.persistence.TopiaIdFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
@@ -59,6 +62,10 @@ public class PollenRender<T> extends Render {
HttpServletResponse response = context.getResponse();
response.setContentType("application/json");
+ PollenRestApiApplicationContext applicationContext =
+ PollenRestApiApplicationContext.getApplicationContext(context.getServletContext());
+ TopiaIdFactory topiaIdFactory = applicationContext.getTopiaApplicationContext().getTopiaIdFactory();
+
Object map;
if (model instanceof InvalidFormException) {
@@ -67,13 +74,13 @@ public class PollenRender<T> extends Render {
}
- map = toMap(model);
+ map = toMap(topiaIdFactory, model);
+
- PollenRestApiApplicationContext applicationContext =
- PollenRestApiApplicationContext.getApplicationContext(context.getServletContext());
boolean devMode = applicationContext.getApplicationConfig().isDevMode();
- Gson gson = PollenRestApiUtil.newGson(devMode);
+
+ Gson gson = PollenRestApiUtil.newGson(topiaIdFactory, devMode);
String json = gson.toJson(map);
PrintWriter out = context.getOut();
@@ -81,7 +88,7 @@ public class PollenRender<T> extends Render {
}
- protected <M> Object toMap(M model) {
+ protected <M> Object toMap(TopiaIdFactory topiaIdFactory, M model) {
if (model instanceof InvalidFormException) {
@@ -98,6 +105,17 @@ public class PollenRender<T> extends Render {
}
+ if (model instanceof CreateBeanRef) {
+
+ // encode id
+ CreateBeanRef createBeanRef = (CreateBeanRef) model;
+ String encodeId = PollenBeanId.encodeId(topiaIdFactory, createBeanRef.getId());
+
+ CreateBeanRef result = CreateBeanRef.of(encodeId, createBeanRef.getPermission());
+ return result;
+
+ }
+
return model;
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
index d5be352..832fdfd 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
@@ -42,6 +42,7 @@ import org.debux.webmotion.server.call.HttpContext;
import org.debux.webmotion.server.call.ServerContext;
import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
import org.debux.webmotion.server.mapping.Mapping;
+import org.nuiton.topia.persistence.TopiaIdFactory;
import java.lang.reflect.Type;
import java.util.Date;
@@ -70,15 +71,25 @@ public class PollenRestApiApplicationListener implements WebMotionServerListener
@Override
public void onStart(Mapping mapping, ServerContext serverContext) {
+ // --- init application context --- //
+
+ PollenRestApiApplicationContext applicationContext =
+ PollenRestApiApplicationContext.getApplicationContext();
+
+ PollenRestApiApplicationContext.setApplicationContext(
+ serverContext.getServletContext(), applicationContext);
+
+ TopiaIdFactory topiaIdFactory = applicationContext.getTopiaApplicationContext().getTopiaIdFactory();
+
// --- init converters --- //
serverContext.addConverter(new DateConverter(), Date.class);
for (Class<?> beanType : BEAN_TYPES) {
- serverContext.addConverter(JsonConverter.newConverter(beanType), beanType);
+ serverContext.addConverter(JsonConverter.newConverter(topiaIdFactory, beanType), beanType);
- JsonArrayConverter<?> converter = JsonArrayConverter.newConverter(beanType);
+ JsonArrayConverter<?> converter = JsonArrayConverter.newConverter(topiaIdFactory, beanType);
serverContext.addConverter(converter, converter.getDefaultType());
}
@@ -119,13 +130,7 @@ public class PollenRestApiApplicationListener implements WebMotionServerListener
}
});
- // --- init application context --- //
- PollenRestApiApplicationContext applicationContext =
- PollenRestApiApplicationContext.getApplicationContext();
-
- PollenRestApiApplicationContext.setApplicationContext(
- serverContext.getServletContext(), applicationContext);
}
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
index 5a9c6ae..0fb1cdf 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java
@@ -1,6 +1,8 @@
package org.chorem.pollen.rest.api;
import com.google.common.collect.Lists;
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
@@ -12,9 +14,12 @@ import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.services.bean.PollenBeanId;
import org.debux.webmotion.server.call.HttpContext;
+import org.nuiton.topia.persistence.TopiaIdFactory;
import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
@@ -42,9 +47,9 @@ public class PollenRestApiUtil {
return list;
}
- public static String entitiesToString(Object o) {
+ public static String entitiesToString(TopiaIdFactory topiaIdFactory, Object o) {
- return newGson(true).toJson(o);
+ return newGson(topiaIdFactory, true).toJson(o);
}
@@ -85,9 +90,20 @@ public class PollenRestApiUtil {
}
}
- public static Gson newGson(boolean prettyPrint) {
+ public static Gson newGson(final TopiaIdFactory idFactory, boolean prettyPrint) {
GsonBuilder gsonBuilder = new GsonBuilder();
+ gsonBuilder.setExclusionStrategies(new ExclusionStrategy() {
+ @Override
+ public boolean shouldSkipField(FieldAttributes f) {
+ return false;
+ }
+
+ @Override
+ public boolean shouldSkipClass(Class<?> clazz) {
+ return clazz == Class.class;
+ }
+ });
gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
@Override
@@ -99,6 +115,18 @@ public class PollenRestApiUtil {
}
});
+ gsonBuilder.registerTypeAdapter(PollenBeanId.class, new JsonSerializer<PollenBeanId>() {
+
+ @Override
+ public JsonElement serialize(PollenBeanId src, Type typeOfSrc, JsonSerializationContext context) {
+ if (src == null || src.getEntityId() == null) {
+ return JsonNull.INSTANCE;
+ }
+ src.encodeId(idFactory);
+ return new JsonPrimitive(src.getEncodedId());
+ }
+
+ });
gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
@@ -107,6 +135,28 @@ public class PollenRestApiUtil {
}
});
+ gsonBuilder.registerTypeAdapter(PollenBeanId.class, new JsonDeserializer<PollenBeanId>() {
+
+ @Override
+ public PollenBeanId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+
+ Type[] actualTypeArguments = ((ParameterizedType) typeOfT).getActualTypeArguments();
+ PollenBeanId id = new PollenBeanId<>((Class) actualTypeArguments[0]);
+
+ String asString = json.getAsString();
+
+ if (asString != null) {
+
+ id.setEncodedId(asString);
+ id.decodeId(idFactory);
+
+ }
+
+ return id;
+
+ }
+
+ });
if (prettyPrint) {
gsonBuilder.setPrettyPrinting();
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonArrayConverter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonArrayConverter.java
index 6dac6ca..f7907b3 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonArrayConverter.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonArrayConverter.java
@@ -3,6 +3,7 @@ package org.chorem.pollen.rest.api.converter;
import com.google.gson.Gson;
import org.apache.commons.beanutils.converters.AbstractConverter;
import org.chorem.pollen.rest.api.PollenRestApiUtil;
+import org.nuiton.topia.persistence.TopiaIdFactory;
import java.lang.reflect.Array;
@@ -18,13 +19,13 @@ public class JsonArrayConverter<O> extends AbstractConverter {
protected final Gson gson;
- public static <O> JsonArrayConverter<O> newConverter(Class<O> objectType) {
- return new JsonArrayConverter<>(objectType);
+ public static <O> JsonArrayConverter<O> newConverter(TopiaIdFactory topiaIdFactory, Class<O> objectType) {
+ return new JsonArrayConverter<>(topiaIdFactory, objectType);
}
- public JsonArrayConverter(Class<O> entityType) {
+ public JsonArrayConverter(TopiaIdFactory topiaIdFactory, Class<O> entityType) {
this.arrayType = getArrayClass(entityType);
- this.gson = PollenRestApiUtil.newGson(false);
+ this.gson = PollenRestApiUtil.newGson(topiaIdFactory, false);
}
<T> Class<T[]> getArrayClass(Class<T> clazz) {
diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonConverter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonConverter.java
index abe3f4d..8d2fc9e 100644
--- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonConverter.java
+++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/JsonConverter.java
@@ -26,6 +26,7 @@ import org.apache.commons.beanutils.converters.AbstractConverter;
import org.chorem.pollen.persistence.PollenEntityEnum;
import org.chorem.pollen.rest.api.PollenRestApiUtil;
import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaIdFactory;
/**
* Created on 5/6/14.
@@ -41,23 +42,23 @@ public class JsonConverter<O> extends AbstractConverter {
protected final Gson gson;
- public static <O> JsonConverter<O> newConverter(Class<O> objectType) {
- return newConverter(objectType, objectType);
+ public static <O> JsonConverter<O> newConverter(TopiaIdFactory topiaIdFactory , Class<O> objectType) {
+ return newConverter(topiaIdFactory, objectType, objectType);
}
- public static <E extends TopiaEntity> JsonConverter<E> newEntityConverter(Class<E> objectType) {
+ public static <E extends TopiaEntity> JsonConverter<E> newEntityConverter(TopiaIdFactory topiaIdFactory , Class<E> objectType) {
Class<E> implementationClass = PollenEntityEnum.getImplementationClass(objectType);
- return newConverter(objectType, implementationClass);
+ return newConverter(topiaIdFactory, objectType, implementationClass);
}
- public static <O> JsonConverter<O> newConverter(Class<O> objectType, Class<O> implementationClass) {
- return new JsonConverter<>(objectType, implementationClass);
+ public static <O> JsonConverter<O> newConverter(TopiaIdFactory topiaIdFactory, Class<O> objectType, Class<O> implementationClass) {
+ return new JsonConverter<>(topiaIdFactory, objectType, implementationClass);
}
- public JsonConverter(Class<O> objectType, Class<O> implementationClass) {
+ public JsonConverter(TopiaIdFactory topiaIdFactory, Class<O> objectType, Class<O> implementationClass) {
this.objectType = objectType;
- this.gson = PollenRestApiUtil.newGson(false);
+ this.gson = PollenRestApiUtil.newGson(topiaIdFactory, false);
this.implementationClass = implementationClass;
}
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AuthApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AuthApiTest.java
index 94bb6af..89ad8ff 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AuthApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AuthApiTest.java
@@ -2,10 +2,12 @@ package org.chorem.pollen.rest.api;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.fluent.Response;
+import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.rest.api.converter.JsonConverter;
import org.chorem.pollen.services.bean.CreateBeanRef;
import org.junit.Assert;
import org.junit.Test;
+import org.nuiton.topia.persistence.internal.DefaultTopiaIdFactory;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -45,7 +47,7 @@ public class AuthApiTest extends AbstractPollenRestApiTest {
showTestResult(loginContent);
Assert.assertNotNull(loginContent);
- JsonConverter<CreateBeanRef> jsonConverter = JsonConverter.newConverter(CreateBeanRef.class);
+ JsonConverter<CreateBeanRef> jsonConverter = JsonConverter.newConverter(new DefaultTopiaIdFactory(), CreateBeanRef.class);
CreateBeanRef createBeanRef = jsonConverter.convert(CreateBeanRef.class, loginContent);
Assert.assertNotNull(createBeanRef);
@@ -56,7 +58,6 @@ public class AuthApiTest extends AbstractPollenRestApiTest {
showTestResult(logoutContent);
Assert.assertNotNull(logoutContent);
-
}
@Test
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
index df703a1..07bfec7 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java
@@ -35,6 +35,7 @@ import org.chorem.pollen.services.PollenFixtures;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.nuiton.topia.persistence.TopiaIdFactory;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -136,8 +137,10 @@ public class PollApiTest extends AbstractPollenRestApiTest {
choice2.setName("choiceB");
choices.add(choice2);
- String choiceStr = PollenRestApiUtil.entitiesToString(choices);
- String pollStr = PollenRestApiUtil.entitiesToString(poll);
+ TopiaIdFactory topiaIdFactory = application.getTopiaApplicationContext().getTopiaIdFactory();
+
+ String choiceStr = PollenRestApiUtil.entitiesToString(topiaIdFactory, choices);
+ String pollStr = PollenRestApiUtil.entitiesToString(topiaIdFactory, poll);
Request request = createRequest("/v1/polls")
.addParameter("poll", pollStr)
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
index 234e267..2fa7fad 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java
@@ -30,6 +30,7 @@ import org.chorem.pollen.services.bean.CreateBeanRef;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.nuiton.topia.persistence.internal.DefaultTopiaIdFactory;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -58,7 +59,7 @@ public class PollenUserApiTest extends AbstractPollenRestApiTest {
.Post();
String loginContent = loginRequest.execute().returnContent().asString();
- JsonConverter<CreateBeanRef> jsonConverter = JsonConverter.newConverter(CreateBeanRef.class);
+ JsonConverter<CreateBeanRef> jsonConverter = JsonConverter.newConverter(new DefaultTopiaIdFactory(), CreateBeanRef.class);
CreateBeanRef createBeanRef = jsonConverter.convert(CreateBeanRef.class, loginContent);
return createBeanRef.getPermission();
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonArrayConverterTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonArrayConverterTest.java
index 89128e1..c216d62 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonArrayConverterTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonArrayConverterTest.java
@@ -4,16 +4,17 @@ import org.chorem.pollen.persistence.entity.ChoiceType;
import org.chorem.pollen.services.bean.ChoiceBean;
import org.junit.Assert;
import org.junit.Test;
+import org.nuiton.topia.persistence.internal.DefaultTopiaIdFactory;
public class JsonArrayConverterTest {
@Test
public void convertToType() throws Exception {
- String choicesStr = "[ {name: \"choice1\", choiceType: \"TEXT\", choiceOrder: 1}, " +
- "{name: \"choice2\", choiceType: \"IMAGE\", choiceOrder: 2} ]";
+ String choicesStr = "[ {id: \"AAAA\", name: \"choice1\", choiceType: \"TEXT\", choiceOrder: 1}, " +
+ " {id: \"BBBB\", name: \"choice2\", choiceType: \"IMAGE\", choiceOrder: 2} ]";
- JsonArrayConverter converter = JsonArrayConverter.newConverter(ChoiceBean.class);
+ JsonArrayConverter converter = JsonArrayConverter.newConverter(new DefaultTopiaIdFactory(), ChoiceBean.class);
ChoiceBean[] choices = converter.convert(ChoiceBean[].class, choicesStr);
Assert.assertNotNull(choices);
diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java
index b98812b..b34e74d 100644
--- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java
+++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java
@@ -29,6 +29,7 @@ import org.chorem.pollen.services.bean.VoteBean;
import org.chorem.pollen.services.bean.VoteToChoiceBean;
import org.junit.Assert;
import org.junit.Test;
+import org.nuiton.topia.persistence.internal.DefaultTopiaIdFactory;
public class JsonConverterTest {
@@ -37,7 +38,7 @@ public class JsonConverterTest {
String pollStr = "{voterId:\"voterId\",voterName:\"toto\",anonymous:true,choice:[{voteValue:1.5,choiceId:\"AA\"}]}";
- JsonConverter<VoteBean> converter = JsonConverter.newConverter(VoteBean.class);
+ JsonConverter<VoteBean> converter = JsonConverter.newConverter(new DefaultTopiaIdFactory(), VoteBean.class);
VoteBean voteBean = converter.convert(VoteBean.class, pollStr);
@@ -67,7 +68,7 @@ public class JsonConverterTest {
"{name: \"choice2\", choiceType: \"IMAGE\"} ], voteVisibility: \"ANONYMOUS\", " +
"commentVisibility:\"NOBODY\", pollType: \"FREE\" }";
- JsonConverter<Poll> converter = JsonConverter.newEntityConverter(Poll.class);
+ JsonConverter<Poll> converter = JsonConverter.newEntityConverter(new DefaultTopiaIdFactory(), Poll.class);
Poll poll = converter.convert(Poll.class, pollStr);
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
index 59666d5..dc5ceff 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java
@@ -24,10 +24,14 @@ public class ChoiceBean extends PollenBean<Choice> {
protected String description;
+ public ChoiceBean() {
+ super(Choice.class);
+ }
+
@Override
public void fromEntity(Choice entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
if (entity.getCreator() == null || entity.getCreator().getPermission() == null) {
setPermission(null);
@@ -50,7 +54,7 @@ public class ChoiceBean extends PollenBean<Choice> {
Choice entity = new ChoiceImpl();
- entity.setTopiaId(getId());
+ entity.setTopiaId(getEntityId());
entity.setName(getName());
entity.setDescription(getDescription());
entity.setChoiceType(getChoiceType());
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
index c05aa21..7f03bb3 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java
@@ -24,10 +24,14 @@ public class CommentBean extends PollenBean<Comment> {
protected Date postDate;
+ public CommentBean() {
+ super(Comment.class);
+ }
+
@Override
public void fromEntity(Comment entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
if (entity.getAuthor() == null || entity.getAuthor().getPermission() == null) {
@@ -55,7 +59,7 @@ public class CommentBean extends PollenBean<Comment> {
Comment entity = new CommentImpl();
- entity.setTopiaId(getId());
+ entity.setTopiaId(getEntityId());
entity.setText(getText());
entity.setPostDate(getPostDate());
PollenPrincipalImpl author = new PollenPrincipalImpl();
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java
index f34ec39..08d8cfe 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java
@@ -94,6 +94,13 @@ public class CreateBeanRef implements Serializable {
}
+ public static CreateBeanRef of(String id, String permission) {
+
+ CreateBeanRef ref = new CreateBeanRef(id, permission);
+ return ref;
+
+ }
+
protected CreateBeanRef(String id, String permission) {
setId(id);
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
index 0b65831..03b6fdb 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java
@@ -23,10 +23,14 @@ public class FavoriteListBean extends PollenBean<FavoriteList> {
protected Set<FavoriteListMemberBean> member = new HashSet<>();
+ public FavoriteListBean() {
+ super(FavoriteList.class);
+ }
+
@Override
public void fromEntity(FavoriteList entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
setName(entity.getName());
member.clear();
@@ -43,7 +47,7 @@ public class FavoriteListBean extends PollenBean<FavoriteList> {
public FavoriteList toEntity() {
FavoriteList entity = new FavoriteListImpl();
- entity.setTopiaId(getId());
+ entity.setTopiaId(getEntityId());
entity.setName(getName());
for (FavoriteListMemberBean voterListMemberBean : member) {
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
index 5b482e2..17b2be8 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java
@@ -17,10 +17,14 @@ public class FavoriteListMemberBean extends PollenBean<FavoriteListMember> {
protected String email;
+ public FavoriteListMemberBean() {
+ super(FavoriteListMember.class);
+ }
+
@Override
public void fromEntity(FavoriteListMember entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
setName(entity.getName());
setEmail(entity.getEmail());
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
index 89c80c3..c154074 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java
@@ -22,6 +22,10 @@ public class PollBean extends PollenBean<Poll> {
private static final long serialVersionUID = 1L;
+ public PollBean() {
+ super(Poll.class);
+ }
+
public static boolean isPollFree(PollBean poll) {
return Objects.equals(PollType.FREE, poll.getPollType());
}
@@ -73,7 +77,7 @@ public class PollBean extends PollenBean<Poll> {
@Override
public void fromEntity(Poll entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
if (entity.getCreator() == null || entity.getCreator().getPermission() == null) {
@@ -114,7 +118,7 @@ public class PollBean extends PollenBean<Poll> {
public Poll toEntity() {
Poll entity = new PollImpl();
- entity.setTopiaId(getId());
+ entity.setTopiaId(getEntityId());
PollenPrincipal creator = new PollenPrincipalImpl();
creator.setName(getCreatorName());
creator.setEmail(getCreatorEmail());
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
index b0e9dc2..f2e3448 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java
@@ -1,6 +1,5 @@
package org.chorem.pollen.services.bean;
-import org.apache.commons.lang3.StringUtils;
import org.nuiton.topia.persistence.TopiaEntity;
import java.io.Serializable;
@@ -15,38 +14,54 @@ public abstract class PollenBean<E extends TopiaEntity> implements Serializable
private static final long serialVersionUID = 1L;
- protected String id;
+ protected final Class<E> entityType;
- public boolean isPersisted() {
- return StringUtils.isNotBlank(id);
+ protected PollenBeanId<E> id;
+
+ protected PollenBean(Class<E> entityType) {
+ this.entityType = entityType;
}
- public String getId() {
+ public PollenBeanId<E> getId() {
+ if (id == null) {
+ id = new PollenBeanId<>(entityType);
+ }
return id;
}
- public void setId(String id) {
+ public void setId(PollenBeanId<E> id) {
this.id = id;
}
+ public boolean isPersisted() {
+ return getId().isNotEmpty();
+ }
+
+ public String getEntityId() {
+ return getId().getEntityId();
+ }
+
+ public void setEntityId(String id) {
+ getId().setEntityId(id);
+ }
+
public abstract void fromEntity(E entity);
public abstract E toEntity();
-
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PollenBean)) return false;
- PollenBean pollenBean = (PollenBean) o;
+ PollenBean that = (PollenBean) o;
- return id != null && id.equals(pollenBean.id);
+ return getId().equals(that.getId());
}
@Override
public int hashCode() {
- return id != null ? id.hashCode() : 0;
+ return getId().hashCode();
}
}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java
new file mode 100644
index 0000000..1f57427
--- /dev/null
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java
@@ -0,0 +1,104 @@
+package org.chorem.pollen.services.bean;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaIdFactory;
+
+import java.io.Serializable;
+
+/**
+ * Created on 5/23/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenBeanId<E extends TopiaEntity> implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final Class<E> entityType;
+
+ protected String encodedId;
+
+ protected String entityId;
+
+ public static String encodeId(TopiaIdFactory topiaIdFactory, String entityId) {
+
+ String randomPart = topiaIdFactory.getRandomPart(entityId);
+ String encodedId = new String(Base64.encodeBase64URLSafe(randomPart.getBytes()));
+ return encodedId;
+
+ }
+
+ public PollenBeanId(Class<E> entityType) {
+ this.entityType = entityType;
+ }
+
+ public boolean isNotEmpty() {
+ return StringUtils.isNotEmpty(encodedId) || StringUtils.isNotEmpty(entityId);
+ }
+
+ public String getEncodedId() {
+ return encodedId;
+ }
+
+ public String getEntityId() {
+ return entityId;
+ }
+
+ public void setEncodedId(String encodedId) {
+ this.encodedId = encodedId;
+ }
+
+ public void setEntityId(String entityId) {
+ this.entityId = entityId;
+ }
+
+ public void encodeId(TopiaIdFactory topiaIdFactory) {
+
+ if (entityId != null) {
+
+ String id = encodeId(topiaIdFactory, entityId);
+ setEncodedId(id);
+
+ }
+
+ }
+
+ public void decodeId(TopiaIdFactory topiaIdFactory) {
+
+ if (encodedId != null) {
+
+ String decodedId = new String(Base64.decodeBase64(encodedId));
+ String id = topiaIdFactory.newTopiaId(entityType, decodedId);
+ setEntityId(id);
+
+ }
+
+ }
+
+ @Override
+ public boolean equals(Object o) {
+
+ if (this == o) return true;
+ if (!(o instanceof PollenBeanId)) return false;
+
+ PollenBeanId that = (PollenBeanId) o;
+
+ return entityType.equals(that.entityType)
+ && encodedId != null && encodedId.equals(that.encodedId)
+ || entityId != null && entityId.equals(that.entityId);
+
+ }
+
+ @Override
+ public int hashCode() {
+
+ int result = entityType.hashCode();
+ result = 31 * result + (encodedId != null ? encodedId.hashCode() : 0);
+ result = 31 * result + (entityId != null ? entityId.hashCode() : 0);
+ return result;
+
+ }
+}
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
index e7b0fca..4ee51bb 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java
@@ -25,10 +25,14 @@ public class PollenUserBean extends PollenBean<PollenUser> {
protected String password;
+ public PollenUserBean() {
+ super(PollenUser.class);
+ }
+
@Override
public void fromEntity(PollenUser entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
setName(entity.getName());
setLogin(entity.getLogin());
@@ -44,7 +48,7 @@ public class PollenUserBean extends PollenBean<PollenUser> {
PollenUser entity = new PollenUserImpl();
- entity.setTopiaId(getId());
+ entity.setTopiaId(getEntityId());
entity.setName(getName());
entity.setLanguage(getLogin());
entity.setAdministrator(isAdministrator());
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
index 6cf20cd..62ef064 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java
@@ -39,10 +39,14 @@ public class VoteBean extends PollenBean<Vote> {
protected Set<VoteToChoiceBean> choice = new LinkedHashSet<>();
+ public VoteBean() {
+ super(Vote.class);
+ }
+
@Override
public void fromEntity(Vote vote) {
- setId(vote.getTopiaId());
+ setEntityId(vote.getTopiaId());
if (vote.getVoter() == null || vote.getVoter().getPermission() == null) {
@@ -83,7 +87,7 @@ public class VoteBean extends PollenBean<Vote> {
Vote entity = new VoteImpl();
- entity.setTopiaId(getId());
+ entity.setTopiaId(getEntityId());
entity.setAnonymous(getAnonymous() != null && getAnonymous());
entity.setWeight(getWeight());
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
index 6ed4dbf..2251190 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java
@@ -18,10 +18,14 @@ public class VoteToChoiceBean extends PollenBean<VoteToChoice> {
protected Double voteValue;
+ public VoteToChoiceBean() {
+ super(VoteToChoice.class);
+ }
+
@Override
public void fromEntity(VoteToChoice entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
setVoteValue(entity.getVoteValue());
setChoiceId(entity.getChoice().getTopiaId());
@@ -31,7 +35,7 @@ public class VoteToChoiceBean extends PollenBean<VoteToChoice> {
public VoteToChoice toEntity() {
VoteToChoice entity = new VoteToChoiceImpl();
- entity.setTopiaId(getId());
+ entity.setTopiaId(getEntityId());
entity.setVoteValue(getVoteValue());
entity.setChoice(new ChoiceImpl());
entity.getChoice().setTopiaId(getChoiceId());
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
index 0c3baaa..1fb2679 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java
@@ -23,10 +23,14 @@ public class VoterListBean extends PollenBean<VoterList> {
protected Set<VoterListMemberBean> member = new HashSet<>();
+ public VoterListBean() {
+ super(VoterList.class);
+ }
+
@Override
public void fromEntity(VoterList entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
setName(entity.getName());
setWeight(entity.getWeight());
@@ -44,7 +48,7 @@ public class VoterListBean extends PollenBean<VoterList> {
public VoterList toEntity() {
VoterList entity = new VoterListImpl();
- entity.setTopiaId(getId());
+ entity.setTopiaId(getEntityId());
entity.setName(getName());
entity.setWeight(getWeight());
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
index f926424..85ca451 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java
@@ -19,10 +19,14 @@ public class VoterListMemberBean extends PollenBean<VoterListMember> {
protected double weight;
+ public VoterListMemberBean() {
+ super(VoterListMember.class);
+ }
+
@Override
public void fromEntity(VoterListMember entity) {
- setId(entity.getTopiaId());
+ setEntityId(entity.getTopiaId());
setName(entity.getName());
setEmail(entity.getEmail());
setWeight(entity.getWeight());
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
index 2be031d..07ea92a 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
@@ -56,7 +56,7 @@ public class ChoiceService extends PollenServiceSupport {
for (ChoiceBean choiceBean : choiceBeans) {
- if (isNotPermitted(PermissionVerb.editChoice, choiceBean.getId())) {
+ if (isNotPermitted(PermissionVerb.editChoice, choiceBean.getEntityId())) {
choiceBean.setPermission(null);
}
@@ -77,7 +77,7 @@ public class ChoiceService extends PollenServiceSupport {
Choice choice = getChoice(poll, choiceId);
ChoiceBean choiceBean = copy(ChoiceBean.class, choice);
- if (isNotPermitted(PermissionVerb.editChoice, choiceBean.getId())) {
+ if (isNotPermitted(PermissionVerb.editChoice, choiceBean.getEntityId())) {
choiceBean.setPermission(null);
}
@@ -141,7 +141,7 @@ public class ChoiceService extends PollenServiceSupport {
checkNotNull(choice);
checkIsPersisted(choice);
- checkPermission(PermissionVerb.editChoice, choice.getId());
+ checkPermission(PermissionVerb.editChoice, choice.getEntityId());
Poll poll = getPollService().getPoll0(pollId);
List<Choice> existingChoices = getChoiceDao().findAll(poll);
@@ -211,7 +211,7 @@ public class ChoiceService extends PollenServiceSupport {
// get existing choice
- toSave = getChoice(poll, choice.getId());
+ toSave = getChoice(poll, choice.getEntityId());
} else {
@@ -275,7 +275,7 @@ public class ChoiceService extends PollenServiceSupport {
for (Choice choice1 : existingChoices) {
if (choiceExists &&
- choice1.getTopiaId().equals(choice.getId())) {
+ choice1.getTopiaId().equals(choice.getEntityId())) {
continue;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
index 5add5c0..29cf6a9 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
@@ -49,7 +49,7 @@ public class CommentService extends PollenServiceSupport {
List<CommentBean> commentBeans = copyAsList(CommentBean.class, comments);
for (CommentBean commentBean : commentBeans) {
- if (isNotPermitted(PermissionVerb.readComment, commentBean.getId())) {
+ if (isNotPermitted(PermissionVerb.readComment, commentBean.getEntityId())) {
commentBean.setPermission(null);
}
}
@@ -69,7 +69,7 @@ public class CommentService extends PollenServiceSupport {
Comment comment = getComment(poll, commentId);
CommentBean commentBean = copy(CommentBean.class, comment);
- if (isNotPermitted(PermissionVerb.readComment, commentBean.getId())) {
+ if (isNotPermitted(PermissionVerb.readComment, commentBean.getEntityId())) {
commentBean.setPermission(null);
}
@@ -103,7 +103,7 @@ public class CommentService extends PollenServiceSupport {
checkNotNull(pollId);
checkNotNull(comment);
checkIsPersisted(comment);
- checkPermission(PermissionVerb.editComment, comment.getId());
+ checkPermission(PermissionVerb.editComment, comment.getEntityId());
ErrorMap errorMap = checkComment(comment);
errorMap.failIfNotEmpty();
@@ -169,7 +169,7 @@ public class CommentService extends PollenServiceSupport {
if (commentExists) {
- toSave = getCommentDao().findByTopiaId(comment.getId());
+ toSave = getCommentDao().findByTopiaId(comment.getEntityId());
} else {
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
index 0f940c8..de556ba 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
@@ -479,7 +479,7 @@ public class FavoriteListService extends PollenServiceSupport {
if (persisted) {
// get existing favorite list
- toSave = getFavoriteList(user, favoriteList.getId());
+ toSave = getFavoriteList(user, favoriteList.getEntityId());
} else {
@@ -506,7 +506,7 @@ public class FavoriteListService extends PollenServiceSupport {
if (persisted) {
// get existing favorite list
- toSave = getFavoriteListMember(favoriteList, favoriteListMember.getId());
+ toSave = getFavoriteListMember(favoriteList, favoriteListMember.getEntityId());
} else {
@@ -542,7 +542,7 @@ public class FavoriteListService extends PollenServiceSupport {
for (FavoriteList favoriteList1 : existingFavoriteLists) {
if (favoriteListExists &&
- favoriteList1.getTopiaId().equals(favoriteList.getId())) {
+ favoriteList1.getTopiaId().equals(favoriteList.getEntityId())) {
continue;
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
index b0f74dd..de3811c 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
@@ -105,7 +105,7 @@ public class PollService extends PollenServiceSupport {
Poll poll = getPoll0(pollId);
PollBean pollBean = copy(PollBean.class, poll);
- if (isNotPermitted(PermissionVerb.editPoll, pollBean.getId())) {
+ if (isNotPermitted(PermissionVerb.editPoll, pollBean.getEntityId())) {
pollBean.setPermission(null);
pollBean.setCreatorEmail(null);
pollBean.setCreatorName(null);
@@ -142,7 +142,8 @@ public class PollService extends PollenServiceSupport {
}
- return copy(PollBean.class, result);
+ PollBean pollBean = copy(PollBean.class, result);
+ return pollBean;
}
@@ -171,7 +172,7 @@ public class PollService extends PollenServiceSupport {
checkNotNull(poll);
checkIsPersisted(poll);
- checkPermission(PermissionVerb.editPoll, poll.getId());
+ checkPermission(PermissionVerb.editPoll, poll.getEntityId());
ErrorMap errorMap = checkPoll(poll);
errorMap.failIfNotEmpty();
@@ -181,7 +182,8 @@ public class PollService extends PollenServiceSupport {
getNotificationService().onPollEdited(savedPoll);
- return copy(PollBean.class, savedPoll);
+ PollBean pollBean = copy(PollBean.class, savedPoll);
+ return pollBean;
}
@@ -251,7 +253,7 @@ public class PollService extends PollenServiceSupport {
if (pollExists) {
- toSave = getPoll0(poll.getId());
+ toSave = getPoll0(poll.getEntityId());
existingChoices = getChoiceDao().findAll(toSave);
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java
index 6e1d273..daab70b 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java
@@ -46,7 +46,6 @@ import org.chorem.pollen.persistence.entity.VoterListTopiaDao;
import org.chorem.pollen.services.PollenService;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.PollenTechnicalException;
-import org.chorem.pollen.services.TopiaEntityCopyVisitor;
import org.chorem.pollen.services.bean.PollenBean;
import org.chorem.pollen.services.config.PollenServiceConfig;
import org.chorem.pollen.services.service.mail.EmailService;
@@ -385,41 +384,6 @@ public abstract class PollenServiceSupport implements PollenService {
}
- protected <T extends TopiaEntity> T copy(T entity) {
-
- T copy = null;
-
- if (entity != null) {
-
- copy = TopiaEntityCopyVisitor.copy(serviceContext.getTopiaApplicationContext(), entity);
- }
-
- return copy;
-
- }
-
- protected <T extends TopiaEntity> ImmutableList<T> copyAsList(Collection<T> entity) {
-
- Collection<T> copy = TopiaEntityCopyVisitor.copy(serviceContext.getTopiaApplicationContext(), entity);
-
- ImmutableList<T> result = ImmutableList.copyOf(copy);
-
- return result;
-
- }
-
- protected <T extends TopiaEntity> ImmutableSet<T> copyAsSet(Collection<T> entity) {
-
- Collection<T> copy = TopiaEntityCopyVisitor.copy(serviceContext.getTopiaApplicationContext(), entity);
-
- copy = ImmutableSet.copyOf(copy);
-
- ImmutableSet<T> result = ImmutableSet.copyOf(copy);
-
- return result;
-
- }
-
protected <T extends TopiaEntity, B extends PollenBean<T>> B copy(Class<B> beanType, T entity) {
try {
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java
index fcb1f55..6a8083a 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java
@@ -192,7 +192,7 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer
ErrorMap errors = new ErrorMap();
boolean userExists = user.isPersisted();
- PollenUser persisted = userExists ? getUser0(user.getId()) : null;
+ PollenUser persisted = userExists ? getUser0(user.getEntityId()) : null;
PollenUserTopiaDao dao = getPollenUserDao();
String userLogin = user.getLogin();
@@ -264,7 +264,7 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer
if (userExists) {
- toSave = getUser0(user.getId());
+ toSave = getUser0(user.getEntityId());
boolean emailChanged = !Objects.equals(toSave.getEmail(), cleanMail);
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
index 129cc61..51b5d72 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
@@ -58,7 +58,7 @@ public class VoteService extends PollenServiceSupport {
List<VoteBean> voteBeans = copyAsList(VoteBean.class, votes);
for (VoteBean voteBean : voteBeans) {
- if (isNotPermitted(PermissionVerb.editVote, voteBean.getId())) {
+ if (isNotPermitted(PermissionVerb.editVote, voteBean.getEntityId())) {
voteBean.setPermission(null);
}
@@ -77,7 +77,7 @@ public class VoteService extends PollenServiceSupport {
Vote result = getVote(poll, voteId);
VoteBean voteBean = copy(VoteBean.class, result);
- if (isNotPermitted(PermissionVerb.editVote, voteBean.getId())) {
+ if (isNotPermitted(PermissionVerb.editVote, voteBean.getEntityId())) {
voteBean.setPermission(null);
}
@@ -111,7 +111,7 @@ public class VoteService extends PollenServiceSupport {
checkNotNull(vote);
checkIsPersisted(vote);
- checkPermission(PermissionVerb.editVote, vote.getId());
+ checkPermission(PermissionVerb.editVote, vote.getEntityId());
Poll poll = getPollService().getPoll0(pollId);
@@ -174,7 +174,7 @@ public class VoteService extends PollenServiceSupport {
//TODO Finish save
if (voteExist) {
- toSave = getVote(poll, vote.getId());
+ toSave = getVote(poll, vote.getEntityId());
} else {
@@ -285,7 +285,7 @@ public class VoteService extends PollenServiceSupport {
if (source.isPersisted()) {
- result = getVoteToChoice(vote, source.getId());
+ result = getVoteToChoice(vote, source.getEntityId());
} else {
diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
index dd6ceb9..398b642 100644
--- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
+++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
@@ -305,7 +305,7 @@ public class VoterListService extends PollenServiceSupport {
if (voterListExists) {
- toSave = getVoterList(poll, voterList.getId());
+ toSave = getVoterList(poll, voterList.getEntityId());
} else {
@@ -336,7 +336,7 @@ public class VoterListService extends PollenServiceSupport {
if (voterListMemberExists) {
- toSave = getVoterListMember(voterList, voterListMember.getId());
+ toSave = getVoterListMember(voterList, voterListMember.getEntityId());
} else {
@@ -368,7 +368,7 @@ public class VoterListService extends PollenServiceSupport {
for (VoterList voterList1 : existingVoterLists) {
if (voterListExists &&
- voterList1.getTopiaId().equals(voterList.getId())) {
+ voterList1.getTopiaId().equals(voterList.getEntityId())) {
continue;
}
@@ -435,7 +435,7 @@ public class VoterListService extends PollenServiceSupport {
for (VoterListMember voterListMember1 : existingVoterListMembers) {
if (voterListMemberExists &&
- voterListMember1.getTopiaId().equals(voterListMember.getId())) {
+ voterListMember1.getTopiaId().equals(voterListMember.getEntityId())) {
continue;
}
diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/service/PollServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/service/PollServiceTest.java
index ba5960f..4fe1751 100644
--- a/pollen-services/src/test/java/org/chorem/pollen/services/service/PollServiceTest.java
+++ b/pollen-services/src/test/java/org/chorem/pollen/services/service/PollServiceTest.java
@@ -114,9 +114,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
ChoiceBean createdChoice1 = createdChoices.get(0);
Assert.assertNotNull(createdChoice1);
- Assert.assertNotNull(createdChoice1.getId());
+ Assert.assertNotNull(createdChoice1.getEntityId());
- ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getId());
+ ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getEntityId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
Assert.assertEquals(choice1.getName(), createdChoice1.getName());
@@ -125,9 +125,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
ChoiceBean createdChoice2 = createdChoices.get(1);
Assert.assertNotNull(createdChoice2);
- Assert.assertNotNull(createdChoice2.getId());
+ Assert.assertNotNull(createdChoice2.getEntityId());
- ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getId());
+ ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getEntityId());
Assert.assertEquals(createdChoice2, reloadedChoice2);
Assert.assertEquals(choice2.getName(), createdChoice2.getName());
@@ -200,7 +200,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertNotNull(createdPoll.getId());
PollBean reloadedPoll = service.getPoll(createdPoll.getId());
- Assert.assertEquals(createdPoll.getId(), reloadedPoll.getId());
+ Assert.assertEquals(createdPoll.getId(), reloadedPoll.getEntityId());
Assert.assertEquals(getServiceContext().getNow(), reloadedPoll.getBeginDate());
@@ -220,9 +220,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
ChoiceBean createdChoice1 = createdChoices.get(0);
Assert.assertNotNull(createdChoice1);
- Assert.assertNotNull(createdChoice1.getId());
+ Assert.assertNotNull(createdChoice1.getEntityId());
- ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getId());
+ ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getEntityId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
Assert.assertEquals(choice1.getName(), createdChoice1.getName());
@@ -230,9 +230,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
ChoiceBean createdChoice2 = createdChoices.get(1);
Assert.assertNotNull(createdChoice2);
- Assert.assertNotNull(createdChoice2.getId());
+ Assert.assertNotNull(createdChoice2.getEntityId());
- ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getId());
+ ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getEntityId());
Assert.assertEquals(createdChoice2, reloadedChoice2);
Assert.assertEquals(choice2.getName(), createdChoice2.getName());
@@ -297,7 +297,7 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertTrue(true);
}
- FakePollenSecurityContext securityContext = (FakePollenSecurityContext) serviceContext.getSecurityContext();
+ FakePollenSecurityContext securityContext = serviceContext.getSecurityContext();
PollenPrincipal principal = securityService.getPollenPrincipalByPermissionToken(createdPoll.getPermission());
securityContext.setMainPrincipal(principal);
@@ -319,9 +319,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
ChoiceBean createdChoice1 = createdChoices.get(0);
Assert.assertNotNull(createdChoice1);
- Assert.assertNotNull(createdChoice1.getId());
+ Assert.assertNotNull(createdChoice1.getEntityId());
- ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getId());
+ ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getEntityId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
Assert.assertEquals(choice1.getName(), createdChoice1.getName());
@@ -330,9 +330,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
ChoiceBean createdChoice2 = createdChoices.get(1);
Assert.assertNotNull(createdChoice2);
- Assert.assertNotNull(createdChoice2.getId());
+ Assert.assertNotNull(createdChoice2.getEntityId());
- ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getId());
+ ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getEntityId());
Assert.assertEquals(createdChoice2, reloadedChoice2);
Assert.assertEquals(choice2.getName(), createdChoice2.getName());
@@ -345,9 +345,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertEquals(1, createdVoterLists.size());
VoterListBean createdVoterList = createdVoterLists.get(0);
Assert.assertNotNull(createdVoterList);
- Assert.assertNotNull(createdVoterList.getId());
+ Assert.assertNotNull(createdVoterList.getEntityId());
- VoterListBean reloadedVoterList = voterListService.getVoterList(createdPoll.getId(), createdVoterList.getId());
+ VoterListBean reloadedVoterList = voterListService.getVoterList(createdPoll.getId(), createdVoterList.getEntityId());
Assert.assertEquals(createdVoterList, reloadedVoterList);
Assert.assertEquals(voterList.getName(), createdVoterList.getName());
@@ -488,9 +488,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
ChoiceBean createdChoice1 = createdChoices.get(0);
Assert.assertNotNull(createdChoice1);
- Assert.assertNotNull(createdChoice1.getId());
+ Assert.assertNotNull(createdChoice1.getEntityId());
- ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getId());
+ ChoiceBean reloadedChoice1 = choiceService.getChoice(createdPoll.getId(), createdChoice1.getEntityId());
Assert.assertEquals(createdChoice1, reloadedChoice1);
Assert.assertEquals(choice1.getName(), createdChoice1.getName());
@@ -499,9 +499,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
ChoiceBean createdChoice2 = createdChoices.get(1);
Assert.assertNotNull(createdChoice2);
- Assert.assertNotNull(createdChoice2.getId());
+ Assert.assertNotNull(createdChoice2.getEntityId());
- ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getId());
+ ChoiceBean reloadedChoice2 = choiceService.getChoice(createdPoll.getId(), createdChoice2.getEntityId());
Assert.assertEquals(createdChoice2, reloadedChoice2);
Assert.assertEquals(choice2.getName(), createdChoice2.getName());
@@ -514,9 +514,9 @@ public class PollServiceTest extends AbstractPollenServiceTest {
Assert.assertEquals(1, createdVoterLists.size());
VoterListBean createdVoterList = createdVoterLists.get(0);
Assert.assertNotNull(createdVoterList);
- Assert.assertNotNull(createdVoterList.getId());
+ Assert.assertNotNull(createdVoterList.getEntityId());
- VoterListBean reloadedVoterList = voterListService.getVoterList(createdPoll.getId(), createdVoterList.getId());
+ VoterListBean reloadedVoterList = voterListService.getVoterList(createdPoll.getId(), createdVoterList.getEntityId());
Assert.assertEquals(createdVoterList, reloadedVoterList);
Assert.assertEquals(voterList.getName(), createdVoterList.getName());
diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/service/PollenUserServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/service/PollenUserServiceTest.java
index 3449281..461bfe2 100644
--- a/pollen-services/src/test/java/org/chorem/pollen/services/service/PollenUserServiceTest.java
+++ b/pollen-services/src/test/java/org/chorem/pollen/services/service/PollenUserServiceTest.java
@@ -171,7 +171,7 @@ public class PollenUserServiceTest extends AbstractPollenServiceTest {
user.setPassword("fake");
service.editUser(user);
- PollenUserBean savedUser = service.getUser(user.getId());
+ PollenUserBean savedUser = service.getUser(user.getEntityId());
Assert.assertNotNull(savedUser);
Assert.assertEquals(originalLogin, savedUser.getLogin());
Assert.assertEquals(email, savedUser.getEmail());
diff --git a/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteCountingServiceTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteCountingServiceTest.java
index 15c8554..2a6e520 100644
--- a/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteCountingServiceTest.java
+++ b/pollen-services/src/test/java/org/chorem/pollen/services/service/VoteCountingServiceTest.java
@@ -2,7 +2,6 @@ package org.chorem.pollen.services.service;
import org.apache.commons.lang3.time.DateUtils;
import org.chorem.pollen.persistence.entity.ChoiceType;
-import org.chorem.pollen.persistence.entity.PollType;
import org.chorem.pollen.services.AbstractPollenServiceTest;
import org.chorem.pollen.services.bean.ChoiceBean;
import org.chorem.pollen.services.bean.CreateBeanRef;
@@ -15,7 +14,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
@@ -87,7 +85,7 @@ public class VoteCountingServiceTest extends AbstractPollenServiceTest {
vote1.setVoterName("voter1");
VoteToChoiceBean vote1Choice1 = new VoteToChoiceBean();
- vote1Choice1.setChoiceId(createdChoiceBean1.getId());
+ vote1Choice1.setChoiceId(createdChoiceBean1.getEntityId());
vote1Choice1.setVoteValue(1d);
vote1.addChoice(vote1Choice1);
voteService.addVote(pollId, vote1);
@@ -96,7 +94,7 @@ public class VoteCountingServiceTest extends AbstractPollenServiceTest {
VoteBean vote2 = new VoteBean();
vote2.setVoterName("voter2");
VoteToChoiceBean vote2Choice2 = new VoteToChoiceBean();
- vote2Choice2.setChoiceId(createdChoiceBean2.getId());
+ vote2Choice2.setChoiceId(createdChoiceBean2.getEntityId());
vote2Choice2.setVoteValue(1d);
vote2.addChoice(vote2Choice2);
voteService.addVote(pollId, vote2);
@@ -105,7 +103,7 @@ public class VoteCountingServiceTest extends AbstractPollenServiceTest {
VoteBean vote3 = new VoteBean();
vote3.setVoterName("voter3");
VoteToChoiceBean vote3Choice1 = new VoteToChoiceBean();
- vote3Choice1.setChoiceId(createdChoiceBean1.getId());
+ vote3Choice1.setChoiceId(createdChoiceBean1.getEntityId());
vote3Choice1.setVoteValue(1d);
vote3.addChoice(vote3Choice1);
voteService.addVote(pollId, vote3);
@@ -118,7 +116,7 @@ public class VoteCountingServiceTest extends AbstractPollenServiceTest {
Assert.assertEquals(1, mainResult.getTopRanking().size());
ChoiceScore choiceScore = mainResult.getTopRanking().get(0);
- Assert.assertEquals(createdChoiceBean1.getId(), choiceScore.getChoiceId());
+ Assert.assertEquals(createdChoiceBean1.getEntityId(), choiceScore.getChoiceId());
Assert.assertEquals(2, choiceScore.getScoreValue().intValue());
}
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
unknown user pushed a commit to branch devel
in repository Pollen.
commit 1dd04392cb2279b008b82328d8749dc3cd73a820
Author: Adrien Garandel <a.garandel(a)dralagen.fr>
Date: Fri May 23 15:50:46 2014 +0200
print good link for edit. Print vote in edit mode
---
.../src/main/webapp/js/controllers/pollCtrl.js | 18 ++++++++++++++++--
.../src/main/webapp/partials/inline-poll.html | 2 +-
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
index 1601454..19526d4 100644
--- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
+++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
@@ -204,14 +204,15 @@ angular.module('pollControllers', [])
}])
-.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', '$location', '$timeout', 'Poll', 'PollChoice', function ($scope, $controller, $routeParams, $location, $timeout, Poll, PollChoice) {
+.controller('PollEditCtrl', ['$scope', '$controller', '$routeParams', '$location', '$timeout', 'Poll', 'PollChoice', 'PollVote', function ($scope, $controller, $routeParams, $location, $timeout, Poll, PollChoice, PollVote) {
$controller('PollAdminCtrl', {$scope:$scope});
$scope.globalVariables.edit = true;
$scope.globalVariables.hostName = $location.protocol()+'://'+$location.host();
+ $scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId
if (angular.isDefined($routeParams.token)) {
- $scope.globalVariables.linkEdit = $location.protocol()+'://'+$location.host()+'/#/poll/edit/'+$routeParams.pollId;
+ $scope.globalVariables.linkEdit += '?token='+$routeParams.token;
}
$scope.callBackAddChoice = function (choice) {
@@ -257,6 +258,19 @@ angular.module('pollControllers', [])
$scope.data.vote = {};
$scope.data.vote.choice = $scope.data.choices;
});
+ PollVote.query({pollId:$routeParams.pollId}, function (votes) {
+ $scope.data.votants = votes;
+ angular.forEach($scope.data.votants, function (vote) {
+ angular.forEach(vote.choice, function (choice) {
+ if (choice.voteValue != null && choice.voteValue != 0.0) {
+ choice.voteValue = true;
+ }
+ else {
+ choice.voteValue = false;
+ }
+ })
+ })
+ })
}
initPoll();
diff --git a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html
index 9d18149..528aab7 100644
--- a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html
+++ b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html
@@ -64,7 +64,7 @@
<!-- end input vote -->
<!-- begin print vote -->
- <tr ng-repeat="vote in data.votants track by $index" class="pollAnim" ng-show="!globalVariables.editMode">
+ <tr ng-repeat="vote in data.votants track by $index" class="pollAnim">
<td class="pollChoice"> {{vote.voterName}}</td>
<td ng-repeat="choice in vote.choice" class="pollChoice">
<input type="checkbox" ng-model="choice.voteValue" disabled />
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0