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.ArrayList;
22 import java.util.Date;
23
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.security.access.annotation.Secured;
28 import org.springframework.stereotype.Service;
29 import org.springframework.transaction.annotation.Propagation;
30 import org.springframework.transaction.annotation.Transactional;
31
32 import com.hack23.cia.model.internal.application.system.impl.ApplicationSession;
33 import com.hack23.cia.model.internal.application.system.impl.ApplicationSessionType;
34 import com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest;
35 import com.hack23.cia.service.api.action.application.CreateApplicationSessionResponse;
36 import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
37 import com.hack23.cia.service.data.api.ApplicationSessionDAO;
38 import com.hack23.cia.service.impl.action.common.AbstractBusinessServiceImpl;
39 import com.hack23.cia.service.impl.action.common.BusinessService;
40
41
42
43
44 @Service
45 @Transactional(propagation = Propagation.REQUIRED)
46 public final class CreateApplicationSessionService
47 extends AbstractBusinessServiceImpl<CreateApplicationSessionRequest, CreateApplicationSessionResponse>
48 implements BusinessService<CreateApplicationSessionRequest, CreateApplicationSessionResponse> {
49
50
51 private static final Logger LOGGER = LoggerFactory
52 .getLogger(CreateApplicationSessionService.class);
53
54
55
56 @Autowired
57 private ApplicationSessionDAO applicationSessionDAO;
58
59
60
61
62 public CreateApplicationSessionService() {
63 super(CreateApplicationSessionRequest.class);
64 }
65
66 @Secured({ "ROLE_ANONYMOUS" })
67 @Override
68 public CreateApplicationSessionResponse processService(final CreateApplicationSessionRequest serviceRequest) {
69 final ApplicationSession applicationSession = new ApplicationSession();
70 applicationSession.setCreatedDate(new Date());
71
72 applicationSession.setSessionId(serviceRequest.getSessionId());
73 applicationSession.setIpInformation(serviceRequest.getIpInformation());
74 applicationSession.setLocale(serviceRequest.getLocale());
75 applicationSession.setOperatingSystem(serviceRequest.getOperatingSystem());
76 applicationSession.setUserAgentInformation(serviceRequest.getUserAgentInformation());
77 applicationSession.setSessionType(serviceRequest.getSessionType());
78 applicationSession.setEvents(new ArrayList<>());
79 applicationSession.setSessionType(ApplicationSessionType.ANONYMOUS);
80 applicationSessionDAO.persist(applicationSession);
81
82 LOGGER.info("Create application session:{}",applicationSession);
83
84 return new CreateApplicationSessionResponse(ServiceResult.SUCCESS);
85 }
86
87 }