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.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.security.access.annotation.Secured;
25 import org.springframework.stereotype.Service;
26 import org.springframework.transaction.annotation.Propagation;
27 import org.springframework.transaction.annotation.Transactional;
28
29 import com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent;
30 import com.hack23.cia.model.internal.application.system.impl.ApplicationSession;
31 import com.hack23.cia.model.internal.application.system.impl.ApplicationSessionType;
32 import com.hack23.cia.model.internal.application.system.impl.ApplicationSession_;
33 import com.hack23.cia.service.api.action.application.CreateApplicationEventRequest;
34 import com.hack23.cia.service.api.action.application.CreateApplicationEventResponse;
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 CreateApplicationEventService
46 extends AbstractBusinessServiceImpl<CreateApplicationEventRequest, CreateApplicationEventResponse>
47 implements BusinessService<CreateApplicationEventRequest, CreateApplicationEventResponse> {
48
49
50 @Autowired
51 private ApplicationSessionDAO applicationSessionDAO;
52
53
54
55
56 public CreateApplicationEventService() {
57 super(CreateApplicationEventRequest.class);
58 }
59
60 @Secured({ "ROLE_ANONYMOUS","ROLE_USER","ROLE_ADMIN" })
61 @Override
62 public CreateApplicationEventResponse processService(final CreateApplicationEventRequest serviceRequest) {
63 final ApplicationSession applicationSession = applicationSessionDAO.findFirstByProperty(ApplicationSession_.sessionId, serviceRequest.getSessionId());
64
65 if (applicationSession != null) {
66 final ApplicationActionEvent applicationActionEvent = new ApplicationActionEvent();
67
68 applicationActionEvent.setEventGroup(serviceRequest.getEventGroup());
69 applicationActionEvent.setCreatedDate(new Date());
70 applicationActionEvent.setSessionId(serviceRequest.getSessionId());
71
72 applicationActionEvent.setPage(serviceRequest.getPage());
73 applicationActionEvent.setPageMode(serviceRequest.getPageMode());
74 applicationActionEvent.setElementId(serviceRequest.getElementId());
75
76 applicationActionEvent.setUserId(serviceRequest.getUserId());
77 if (serviceRequest.getUserId() != null && ApplicationSessionType.ANONYMOUS == applicationSession.getSessionType()) {
78 applicationSession.setSessionType(ApplicationSessionType.REGISTERED_USER);
79 applicationSession.setUserId(serviceRequest.getUserId());
80 }
81
82 applicationActionEvent.setApplicationOperation(serviceRequest.getApplicationOperation());
83 applicationActionEvent.setActionName(serviceRequest.getActionName());
84
85 applicationActionEvent.setApplicationMessage(serviceRequest.getApplicationMessage());
86 applicationActionEvent.setErrorMessage(serviceRequest.getErrorMessage());
87
88 applicationSession.getEvents().add(applicationActionEvent);
89
90 applicationSessionDAO.persist(applicationSession);
91 return new CreateApplicationEventResponse(ServiceResult.SUCCESS);
92 } else {
93 return new CreateApplicationEventResponse(ServiceResult.FAILURE);
94 }
95 }
96
97 }