1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.impl.action.application;
20
21 import java.util.Date;
22
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.security.access.annotation.Secured;
27 import org.springframework.stereotype.Service;
28 import org.springframework.transaction.annotation.Propagation;
29 import org.springframework.transaction.annotation.Transactional;
30
31 import com.hack23.cia.model.internal.application.system.impl.ApplicationSession;
32 import com.hack23.cia.model.internal.application.system.impl.ApplicationSession_;
33 import com.hack23.cia.service.api.action.application.DestroyApplicationSessionRequest;
34 import com.hack23.cia.service.api.action.application.DestroyApplicationSessionResponse;
35 import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
36 import com.hack23.cia.service.data.api.ApplicationSessionDAO;
37 import com.hack23.cia.service.impl.action.common.AbstractBusinessServiceImpl;
38 import com.hack23.cia.service.impl.action.common.BusinessService;
39
40
41
42
43 @Service
44 @Transactional(propagation = Propagation.REQUIRED)
45 public final class DestroyApplicationSessionService
46 extends AbstractBusinessServiceImpl<DestroyApplicationSessionRequest, DestroyApplicationSessionResponse>
47 implements BusinessService<DestroyApplicationSessionRequest, DestroyApplicationSessionResponse> {
48
49
50 private static final Logger LOGGER = LoggerFactory
51 .getLogger(DestroyApplicationSessionService.class);
52
53
54
55 @Autowired
56 private ApplicationSessionDAO applicationSessionDAO;
57
58
59
60
61 public DestroyApplicationSessionService() {
62 super(DestroyApplicationSessionRequest.class);
63 }
64
65 @Secured({ "ROLE_ANONYMOUS" })
66 @Override
67 public DestroyApplicationSessionResponse processService(final DestroyApplicationSessionRequest serviceRequest) {
68 final ApplicationSession applicationSession = applicationSessionDAO.findFirstByProperty(ApplicationSession_.sessionId, serviceRequest.getSessionId());
69
70 if (applicationSession != null) {
71 LOGGER.info("Destroy Application session: {}",applicationSession.getSessionId());
72 applicationSession.setDestroyedDate(new Date());
73 applicationSessionDAO.persist(applicationSession);
74 return new DestroyApplicationSessionResponse(ServiceResult.SUCCESS);
75 } else {
76 LOGGER.warn("Failed to destroy Application session, no session found for id: {}",serviceRequest.getSessionId());
77 return new DestroyApplicationSessionResponse(ServiceResult.FAILURE);
78 }
79 }
80
81 }