r3910 - in trunk: pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity pollen-persistence/src/main/xmi pollen-rest-api/src/main/java/org/chorem/pollen/rest/api pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1 pollen-rest-api/src/test/java/org/chorem/pollen/rest/api pollen-services/src/main/java/org/chorem/pollen/services/service pollen-services/src/main/java/org/chorem/pollen/services/service/security
Author: tchemit Date: 2014-05-05 11:17:44 +0200 (Mon, 05 May 2014) New Revision: 3910 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3910 Log: reformat rest api + use PollenPrincipalRef for create operations Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenPrincipals.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenPrincipalRef.java Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenPrincipals.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenPrincipals.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenPrincipals.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -0,0 +1,42 @@ +package org.chorem.pollen.persistence.entity; + +import org.nuiton.topia.persistence.TopiaEntity; + +/** + * Created on 5/5/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenPrincipals { + + public static <E extends TopiaEntity> PollenPrincipal getPrincipal(E entity) { + + PollenPrincipal principal = null; + + if (entity instanceof Poll) { + + principal = ((Poll) entity).getCreator(); + + } else if (entity instanceof Choice) { + + principal = ((Choice) entity).getCreator(); + + } else if (entity instanceof Comment) { + + principal = ((Comment) entity).getAuthor(); + + } else if (entity instanceof Vote) { + + principal = ((Vote) entity).getVoter(); + + } else if (entity instanceof FavoriteList) { + + principal = ((FavoriteList) entity).getOwner(); + + } + + return principal; + + } +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenPrincipals.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -36,7 +36,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.persistence.PollenEntityEnum; +import org.chorem.pollen.services.PollenTechnicalException; import org.chorem.pollen.services.service.InvalidFormException; +import org.chorem.pollen.services.service.PollenPrincipalRef; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; import org.debux.webmotion.server.mapping.Mapping; @@ -104,11 +106,16 @@ } Object map; + if (model instanceof InvalidFormException) { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); map = toMap(((InvalidFormException) model).getErrors()); + } else { + map = toMap(model, includeCollection); + } GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @@ -121,7 +128,9 @@ } else { result = new JsonPrimitive(src.getTime()); } + return result; + } }); @@ -147,6 +156,19 @@ } protected <M> Object toMap(M model, String... includeCollection) { + + if (model instanceof PollenPrincipalRef<?>) { + + PollenPrincipalRef<?> pollenEntityRef = (PollenPrincipalRef<?>) model; + + Map<String, Object> result = Maps.newTreeMap(); + result.put("topiaId", pollenEntityRef.getEntity().getTopiaId()); + result.put("permission", pollenEntityRef.getPrincipal().getPermission().getToken()); + + return result; + + } + if (model instanceof Iterable<?>) { // collection of objects @@ -156,7 +178,9 @@ Object objectMap = toMap(object, includeCollection); result.add(objectMap); } + return result; + } // single object @@ -181,6 +205,7 @@ } result.put(propertyName, propertyValue); + } // treat collections @@ -259,10 +284,8 @@ if (read != null) { result.put(sourceProperty, read); } - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new PollenTechnicalException(e); } } return result; @@ -273,10 +296,8 @@ Method readMethod = model.getSourceReadMethod(sourceProperty); Object result = readMethod.invoke(source); return (Iterable<?>) result; - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new PollenTechnicalException(e); } } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -46,7 +46,7 @@ */ public class PollenRestApiRequestFilter extends WebMotionFilter { - public static final String REQUEST_CREDENTIAL_PARAMETER = "credential"; + public static final String REQUEST_PERMISSION_PARAMETER = "permission"; public static final String POLLEN_SESSION = "pollenSession"; @@ -122,7 +122,7 @@ // --- get mainPrincipal (from request parameters) --- // Map<String, String[]> parameters = httpContext.getParameters(); - String[] strings = parameters.get(REQUEST_CREDENTIAL_PARAMETER); + String[] strings = parameters.get(REQUEST_PERMISSION_PARAMETER); String credentialParam = strings == null || strings.length < 1 ? null : strings[0]; PollenPrincipal mainPrincipal = securityService.getPollenPrincipalById(credentialParam); Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -37,14 +37,21 @@ public class AuthApi extends WebMotionController { public SessionToken login(AuthService authService, String login, String password, Boolean rememberMe) throws PollenAuthenticationException { - return authService.login(login, password, rememberMe); + + SessionToken sessionToken = authService.login(login, password, rememberMe); + return sessionToken; + } public void logout(AuthService authService) { + authService.logout(); + } public void lostPassword(AuthService authService, String login) { + authService.lostPassword(login); + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -24,8 +24,9 @@ */ import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.services.service.ChoiceService; import org.chorem.pollen.services.service.InvalidFormException; -import org.chorem.pollen.services.service.ChoiceService; +import org.chorem.pollen.services.service.PollenPrincipalRef; import org.debux.webmotion.server.WebMotionController; import java.util.List; @@ -39,26 +40,37 @@ public class ChoiceApi extends WebMotionController { public List<Choice> getChoices(ChoiceService choiceService, String pollId) { + List<Choice> choices = choiceService.getChoices(pollId); return choices; + } public Choice getChoice(ChoiceService choiceService, String pollId, String choiceId) { + Choice choice = choiceService.getChoice(pollId, choiceId); return choice; + } - public Choice addChoice(ChoiceService choiceService, String pollId, Choice choice) throws InvalidFormException { + public PollenPrincipalRef<Choice> addChoice(ChoiceService choiceService, String pollId, Choice choice) throws InvalidFormException { + Choice createdChoice = choiceService.addChoice(pollId, choice); - return createdChoice; + PollenPrincipalRef<Choice> principalRef = PollenPrincipalRef.newRef(createdChoice); + return principalRef; + } public Choice editChoice(ChoiceService choiceService, String pollId, Choice choice) throws InvalidFormException { + Choice editedChoice = choiceService.editChoice(pollId, choice); return editedChoice; + } public void deleteChoice(ChoiceService choiceService, String pollId, String choiceId) { + choiceService.deleteChoice(pollId, choiceId); + } } \ No newline at end of file Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -24,8 +24,9 @@ */ import org.chorem.pollen.persistence.entity.Comment; +import org.chorem.pollen.services.service.CommentService; import org.chorem.pollen.services.service.InvalidFormException; -import org.chorem.pollen.services.service.CommentService; +import org.chorem.pollen.services.service.PollenPrincipalRef; import org.debux.webmotion.server.WebMotionController; import java.util.List; @@ -39,26 +40,37 @@ public class CommentApi extends WebMotionController { public List<Comment> getComments(CommentService commentService, String pollId) { + List<Comment> comments = commentService.getComments(pollId); return comments; + } public Comment getComment(CommentService commentService, String pollId, String commentId) { + Comment comment = commentService.getComment(pollId, commentId); return comment; + } - public Comment addComment(CommentService commentService, String pollId, Comment comment) throws InvalidFormException { + public PollenPrincipalRef<Comment> addComment(CommentService commentService, String pollId, Comment comment) throws InvalidFormException { + Comment createdComment = commentService.addComment(pollId, comment); - return createdComment; + PollenPrincipalRef<Comment> principalRef = PollenPrincipalRef.newRef(createdComment); + return principalRef; + } public Comment editComment(CommentService commentService, String pollId, Comment comment) throws InvalidFormException { + Comment editedComment = commentService.editComment(pollId, comment); return editedComment; + } public void deleteComment(CommentService commentService, String pollId, String commentId) { + commentService.deleteComment(pollId, commentId); + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -22,6 +22,7 @@ */ import org.apache.commons.io.IOUtils; +import org.chorem.pollen.services.PollenTechnicalException; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; @@ -39,11 +40,16 @@ public Render showMapping() { InputStream mappingUrl = getClass().getResourceAsStream("/mapping"); + try { + String content = IOUtils.toString(mappingUrl); return renderContent(content, "text/plain"); + } catch (IOException e) { - throw new RuntimeException(e); + + throw new PollenTechnicalException(e); + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -39,23 +39,37 @@ public InvalidFormException on400Form(InvalidFormException e) { + // just return the exception, return e; + } public Render on404(Exception e) { - return renderError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); + + Render render = renderError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); + return render; + } public Render on401(Exception e) { - return renderError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); + + Render render = renderError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); + return render; + } public Render on403(Exception e) { - return renderError(HttpServletResponse.SC_FORBIDDEN, e.getMessage()); + + Render render = renderError(HttpServletResponse.SC_FORBIDDEN, e.getMessage()); + return render; + } public Render on500(Exception e) { - return renderError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); + + Render render = renderError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); + return render; + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -26,8 +26,9 @@ import org.chorem.pollen.persistence.entity.FavoriteList; import org.chorem.pollen.persistence.entity.FavoriteListMember; import org.chorem.pollen.services.service.FavoriteListImportException; +import org.chorem.pollen.services.service.FavoriteListService; import org.chorem.pollen.services.service.InvalidFormException; -import org.chorem.pollen.services.service.FavoriteListService; +import org.chorem.pollen.services.service.PollenPrincipalRef; import org.debux.webmotion.server.WebMotionController; import java.io.File; @@ -43,60 +44,86 @@ public class FavoriteListApi extends WebMotionController { public List<FavoriteList> getFavoriteLists(FavoriteListService favoriteListService) { + List<FavoriteList> favoriteLists = favoriteListService.getFavoriteLists(); return favoriteLists; + } public FavoriteList getFavoriteList(FavoriteListService favoriteListService, String favoriteListId) { + FavoriteList favoriteList = favoriteListService.getFavoriteList(favoriteListId); return favoriteList; + } - public FavoriteList createFavoriteList(FavoriteListService favoriteListService, FavoriteList favoriteList) throws InvalidFormException { + public PollenPrincipalRef<FavoriteList> createFavoriteList(FavoriteListService favoriteListService, FavoriteList favoriteList) throws InvalidFormException { + FavoriteList createdFavoriteList = favoriteListService.createFavoriteList(favoriteList); - return createdFavoriteList; + PollenPrincipalRef<FavoriteList> principalRef = PollenPrincipalRef.newRef(createdFavoriteList); + return principalRef; + } public FavoriteList editFavoriteList(FavoriteListService favoriteListService, FavoriteList favoriteList) throws InvalidFormException { + FavoriteList editedFavoriteList = favoriteListService.editFavoriteList(favoriteList); return editedFavoriteList; + } public void deleteFavoriteList(FavoriteListService favoriteListService, String favoriteListId) { + favoriteListService.deleteFavoriteList(favoriteListId); + } public int importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, String favoriteListId, File csvFile) throws FavoriteListImportException { + int i = favoriteListService.importFavoriteListMembersFromCsv(favoriteListId, csvFile); return i; + } public int importFavoriteListMembersFromLdap(FavoriteListService favoriteListService, String favoriteListId, String ldap) throws FavoriteListImportException { + int i = favoriteListService.importFavoriteListMembersFromLdap(favoriteListId, ldap); return i; + } public LinkedHashSet<FavoriteListMember> getMembers(FavoriteListService favoriteListService, String favoriteListId) { + LinkedHashSet<FavoriteListMember> members = favoriteListService.getFavoriteListMembers(favoriteListId); return members; + } public FavoriteListMember getMember(FavoriteListService favoriteListService, String favoriteListId, String memberId) { + FavoriteListMember member = favoriteListService.getFavoriteListMember(favoriteListId, memberId); return member; + } - public FavoriteListMember addMember(FavoriteListService favoriteListService, String favoriteListId, FavoriteListMember member) throws InvalidFormException { + public PollenPrincipalRef<FavoriteListMember> addMember(FavoriteListService favoriteListService, String favoriteListId, FavoriteListMember member) throws InvalidFormException { + FavoriteListMember createdMember = favoriteListService.addFavoriteListMember(favoriteListId, member); - return createdMember; + PollenPrincipalRef<FavoriteListMember> principalRef = PollenPrincipalRef.newRef(createdMember); + return principalRef; + } public FavoriteListMember editMember(FavoriteListService favoriteListService, String favoriteListId, FavoriteListMember member) throws InvalidFormException { + FavoriteListMember editedMember = favoriteListService.editFavoriteListMember(favoriteListId, member); return editedMember; + } public void removeMember(FavoriteListService favoriteListService, String favoriteListId, String memberId) { + favoriteListService.removeFavoriteListMember(favoriteListId, memberId); + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -26,6 +26,7 @@ import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.services.service.InvalidFormException; import org.chorem.pollen.services.service.PollService; +import org.chorem.pollen.services.service.PollenPrincipalRef; import org.debux.webmotion.server.WebMotionController; import java.io.File; @@ -40,60 +41,85 @@ public class PollApi extends WebMotionController { public Poll getNewPoll(PollService pollService) { + Poll newPoll = pollService.getNewPoll(); return newPoll; + } public Set<Poll> getPolls(PollService pollService) { + Set<Poll> polls = pollService.getPolls(); return polls; + } public Set<Poll> getCreatedPolls(PollService pollService) { + Set<Poll> polls = pollService.getCreatedPolls(); return polls; + } public Set<Poll> getInvitedPolls(PollService pollService) { + Set<Poll> polls = pollService.getInvitedPolls(); return polls; + } public Set<Poll> getParticipatedPolls(PollService pollService) { + Set<Poll> polls = pollService.getParticipatedPolls(); return polls; + } public Poll getPoll(PollService pollService, String pollId) { + Poll poll = pollService.getPoll(pollId); return poll; + } - public Poll createPoll(PollService pollService, Poll poll) throws InvalidFormException { + public PollenPrincipalRef<Poll> createPoll(PollService pollService, Poll poll) throws InvalidFormException { + Poll createdPoll = pollService.createPoll(poll); - return createdPoll; + PollenPrincipalRef<Poll> principalRef = PollenPrincipalRef.newRef(createdPoll); + return principalRef; + } public Poll editPoll(PollService pollService, Poll poll) throws InvalidFormException { + Poll editedPoll = pollService.editPoll(poll); return editedPoll; + } public void deletePoll(PollService pollService, String pollId) { + pollService.deletePoll(pollId); + } public Poll clonePoll(PollService pollService, String pollId) { + Poll clonedPoll = pollService.clonePoll(pollId); return clonedPoll; + } public void closePoll(PollService pollService, String pollId) { + pollService.closePoll(pollId); + } public File exportPoll(PollService pollService, String pollId) { + File exportedPollFile = pollService.exportPoll(pollId); return exportedPollFile; + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -25,6 +25,7 @@ import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.services.service.InvalidFormException; +import org.chorem.pollen.services.service.PollenPrincipalRef; import org.chorem.pollen.services.service.PollenUserService; import org.chorem.pollen.services.service.security.PollenInvalidEmailActivationTokenException; import org.chorem.pollen.services.service.security.PollenInvalidPasswordException; @@ -41,43 +42,57 @@ public class PollenUserApi extends WebMotionController { public List<PollenUser> getUsers(PollenUserService pollenUserService) { + List<PollenUser> users = pollenUserService.getUsers(); return users; + } public PollenUser getUser(PollenUserService pollenUserService, String userId) { + PollenUser user = pollenUserService.getUser(userId); return user; + } - public PollenUser createUser(PollenUserService pollenUserService, - PollenUser user, - boolean generatePassword) throws InvalidFormException { + public PollenPrincipalRef<PollenUser> createUser(PollenUserService pollenUserService, + PollenUser user, + boolean generatePassword) throws InvalidFormException { + PollenUser createdUser = pollenUserService.createUser(user, generatePassword); - return createdUser; + PollenPrincipalRef<PollenUser> principalRef = PollenPrincipalRef.newRef(createdUser); + return principalRef; } public PollenUser editUser(PollenUserService pollenUserService, PollenUser user) throws InvalidFormException { + PollenUser editedUser = pollenUserService.editUser(user); return editedUser; + } public void deleteUser(PollenUserService pollenUserService, String userId) throws InvalidFormException { + pollenUserService.deleteUser(userId); + } public void validateUserEmail(PollenUserService pollenUserService, String userId, String token) throws PollenInvalidEmailActivationTokenException { + pollenUserService.validateUserEmail(userId, token); + } public void changePassword(PollenUserService pollenUserService, String userId, String oldPassword, String newPassword) throws PollenInvalidPasswordException { + pollenUserService.changePassword(userId, oldPassword, newPassword); + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -25,6 +25,7 @@ import org.chorem.pollen.persistence.entity.Vote; import org.chorem.pollen.services.service.InvalidFormException; +import org.chorem.pollen.services.service.PollenPrincipalRef; import org.chorem.pollen.services.service.VoteService; import org.debux.webmotion.server.WebMotionController; @@ -39,26 +40,37 @@ public class VoteApi extends WebMotionController { public List<Vote> getVotes(VoteService voteService, String pollId) { + List<Vote> votes = voteService.getVotes(pollId); return votes; + } public Vote getVote(VoteService voteService, String pollId, String voteId) { + Vote vote = voteService.getVote(pollId, voteId); return vote; + } - public Vote addVote(VoteService voteService, String pollId, Vote vote) throws InvalidFormException { + public PollenPrincipalRef<Vote> addVote(VoteService voteService, String pollId, Vote vote) throws InvalidFormException { + Vote createdVote = voteService.addVote(pollId, vote); - return createdVote; + PollenPrincipalRef<Vote> principalRef = PollenPrincipalRef.newRef(createdVote); + return principalRef; + } public Vote editVote(VoteService voteService, String pollId, Vote vote) throws InvalidFormException { + Vote editedVote = voteService.editVote(pollId, vote); return editedVote; + } public void deleteVote(VoteService voteService, String pollId, String voteId) { + voteService.deleteVote(pollId, voteId); + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -36,7 +36,9 @@ public class VoteCountingApi extends WebMotionController { public PollResult getResult(VoteCountingService voteCountingService, String pollId) { + PollResult result = voteCountingService.getResult(pollId); return result; + } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -26,6 +26,7 @@ import org.chorem.pollen.persistence.entity.VoterList; import org.chorem.pollen.persistence.entity.VoterListMember; import org.chorem.pollen.services.service.InvalidFormException; +import org.chorem.pollen.services.service.PollenPrincipalRef; import org.chorem.pollen.services.service.VoterListService; import org.debux.webmotion.server.WebMotionController; @@ -41,55 +42,79 @@ public class VoterListApi extends WebMotionController { public VoterList importFavoriteList(VoterListService voterListService, String pollId, String favoriteListId) { + VoterList importVoterList = voterListService.importFavoriteList(pollId, favoriteListId); return importVoterList; + } public List<VoterList> getVoterLists(VoterListService voterListService, String pollId) { + List<VoterList> voterLists = voterListService.getVoterLists(pollId); return voterLists; + } - public VoterList getVoterList(VoterListService voterListService, String pollId, String voterListId) { + public PollenPrincipalRef<VoterList> getVoterList(VoterListService voterListService, String pollId, String voterListId) { + VoterList voterList = voterListService.getVoterList(pollId, voterListId); - return voterList; + PollenPrincipalRef<VoterList> principalRef = PollenPrincipalRef.newRef(voterList); + return principalRef; + } public VoterList createVoterList(VoterListService voterListService, String pollId, VoterList voterList) throws InvalidFormException { + VoterList createdVoterList = voterListService.addVoterList(pollId, voterList); return createdVoterList; + } public VoterList editVoterList(VoterListService voterListService, String pollId, VoterList voterList) throws InvalidFormException { + VoterList editedVoterList = voterListService.editVoterList(pollId, voterList); return editedVoterList; + } public void deleteVoterList(VoterListService voterListService, String pollId, String voterListId) { + voterListService.deleteVoterList(pollId, voterListId); + } public Set<VoterListMember> getMembers(VoterListService voterListService, String pollId, String voterListId) { + Set<VoterListMember> members = voterListService.getVoterListMembers(pollId, voterListId); return members; + } public VoterListMember getMember(VoterListService voterListService, String pollId, String voterListId, String memberId) { + VoterListMember member = voterListService.getVoterListMember(pollId, voterListId, memberId); return member; + } - public VoterListMember addMember(VoterListService voterListService, String pollId, String voterListId, VoterListMember member) throws InvalidFormException { + public PollenPrincipalRef<VoterListMember> addMember(VoterListService voterListService, String pollId, String voterListId, VoterListMember member) throws InvalidFormException { + VoterListMember createdMember = voterListService.addVoterListMember(pollId, voterListId, member); - return createdMember; + PollenPrincipalRef<VoterListMember> principalRef = PollenPrincipalRef.newRef(createdMember); + return principalRef; + } public VoterListMember editMember(VoterListService voterListService, String pollId, String voterListId, VoterListMember member) throws InvalidFormException { + VoterListMember editedMember = voterListService.editVoterListMember(pollId, voterListId, member); return editedMember; + } public void deleteMember(VoterListService voterListService, String pollId, String voterListId, String memberId) { + voterListService.deleteVoterListMember(pollId, voterListId, memberId); + } } Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -40,6 +40,7 @@ import org.junit.Rule; import org.nuiton.util.DateUtil; +import java.io.File; import java.io.IOException; import java.util.Locale; @@ -116,6 +117,14 @@ } + @Override + protected String getServerBaseDirectory() { + + return new File(application.getTestBasedir(), + "tomcat_" + application.getPort()).getAbsolutePath(); + + } + @After public void stopServer() throws Exception { Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -141,7 +141,7 @@ Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID); String pollId = poll.getTopiaId(); Request request = createRequest("/v1/polls/" + pollId) - .addParameter(PollenRestApiRequestFilter.REQUEST_CREDENTIAL_PARAMETER, poll.getCreator().getTopiaId()) + .addParameter(PollenRestApiRequestFilter.REQUEST_PERMISSION_PARAMETER, poll.getCreator().getPermission().getToken()) .Delete(); String content = request.execute().returnContent().asString(); showTestResult(content); Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenPrincipalRef.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenPrincipalRef.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenPrincipalRef.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -0,0 +1,48 @@ +package org.chorem.pollen.services.service; + +import org.chorem.pollen.persistence.entity.PollenPrincipal; +import org.chorem.pollen.persistence.entity.PollenPrincipals; +import org.nuiton.topia.persistence.TopiaEntity; + +/** + * To box a entity within his principal. + * <p/> + * Created on 5/5/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenPrincipalRef<E extends TopiaEntity> { + + protected E entity; + + protected PollenPrincipal principal; + + public static <E extends TopiaEntity> PollenPrincipalRef<E> newRef(E entity) { + + PollenPrincipalRef<E> result = new PollenPrincipalRef<>(); + result.setEntity(entity); + + PollenPrincipal principal = PollenPrincipals.getPrincipal(entity); + result.setPrincipal(principal); + + return result; + + } + + public E getEntity() { + return entity; + } + + public void setEntity(E entity) { + this.entity = entity; + } + + public PollenPrincipal getPrincipal() { + return principal; + } + + public void setPrincipal(PollenPrincipal principal) { + this.principal = principal; + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenPrincipalRef.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java 2014-05-05 06:24:12 UTC (rev 3909) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java 2014-05-05 09:17:44 UTC (rev 3910) @@ -120,7 +120,7 @@ // Generate token PollenToken token = generateNewToken(); - principal.setToken(token); + principal.setPermission(token); // Persist dao.create(principal); @@ -318,6 +318,7 @@ List<PollenPrincipal> allByPollenUser = getPollenPrincipalDao().forPollenUserEquals(user).findAll(); principals.addAll(allByPollenUser); + } PrincipalByType principalByType = resolvePrincipals(principals); @@ -335,6 +336,7 @@ // can only read or edit the choice (only poll creator can delete a choice) permissions.add(createSubjectPermission(PermissionVerb.readChoice, choice)); permissions.add(createSubjectPermission(PermissionVerb.editChoice, choice)); + } for (Poll poll : principalByType.polls) { @@ -357,6 +359,7 @@ permissions.add(createSubjectPermission(PermissionVerb.readVote, vote)); } } + } return permissions;
participants (1)
-
tchemit@users.chorem.org