View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   package com.hack23.cia.service.impl.user;
6   
7   import java.util.Date;
8   import java.util.List;
9   
10  import com.hack23.cia.model.application.dto.common.UserSessionDTO;
11  import com.hack23.cia.model.application.impl.common.ActionEvent;
12  import com.hack23.cia.model.application.impl.common.UserSession;
13  import com.hack23.cia.model.application.impl.user.BallotActionEvent;
14  import com.hack23.cia.model.sweden.impl.Ballot;
15  import com.hack23.cia.model.sweden.impl.Vote;
16  import com.hack23.cia.service.api.common.ServiceResponse;
17  import com.hack23.cia.service.api.user.BallotRequest;
18  import com.hack23.cia.service.api.user.BallotResponse;
19  import com.hack23.cia.service.impl.common.ParliamentService;
20  import com.hack23.cia.service.impl.common.UserSessionService;
21  
22  /***
23   * The Class BallotRequestService.
24   */
25  public class BallotRequestService extends
26          AbstractParliamentRequestService<BallotRequest> {
27  
28      /***
29       * Instantiates a new ballot request service.
30       *
31       * @param userSessionService the user session service
32       * @param parliamentService the parliament service
33       */
34      public BallotRequestService(final UserSessionService userSessionService,
35              final ParliamentService parliamentService) {
36          super(userSessionService, parliamentService);
37      }
38  
39      /*
40       * (non-Javadoc)
41       * 
42       * @see
43       * com.hack23.cia.service.impl.common.AbstractGenericService#createActionEvent
44       * (com.hack23.cia.service.api.common.AbstractServiceRequest,
45       * com.hack23.cia.model.application.UserSession)
46       */
47      @Override
48      public final ActionEvent createActionEvent(final BallotRequest request,
49              final UserSession userSession) {
50          return new BallotActionEvent(new Date(), userSession, request
51                  .getBallotId());
52      }
53  
54      /*
55       * (non-Javadoc)
56       * 
57       * @see com.hack23.cia.service.common.ServiceHandler#getSupportedService()
58       */
59      @SuppressWarnings("unchecked")
60      @Override
61      public final Class getSupportedService() {
62          return BallotRequest.class;
63      }
64  
65      /*
66       * (non-Javadoc)
67       * 
68       * @seecom.hack23.cia.service.common.AbstractGenericServiceHandler#
69       * handleServiceRequest(com.hack23.cia.service.api.AbstractServiceRequest)
70       */
71      @Override
72      public final ServiceResponse handleServiceRequest(
73              final BallotRequest request, final UserSessionDTO userSession) {
74      	final Ballot ballot = getParliamentService().loadBallotById(request.getBallotId());
75          final List<Vote> findLastVotesByBallotId = this.getParliamentService()
76                  .findLastVotesByBallotId(ballot.getId());
77          final BallotResponse ballotResponse = new BallotResponse(userSession,
78                  findLastVotesByBallotId);
79          return ballotResponse;
80      }
81  }