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.admin;
20
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.security.access.annotation.Secured;
23 import org.springframework.stereotype.Service;
24 import org.springframework.transaction.annotation.Propagation;
25 import org.springframework.transaction.annotation.Transactional;
26
27 import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
28 import com.hack23.cia.model.internal.application.system.impl.ApplicationOperationType;
29 import com.hack23.cia.model.internal.application.user.impl.UserAccount;
30 import com.hack23.cia.service.api.action.admin.RefreshDataViewsRequest;
31 import com.hack23.cia.service.api.action.admin.RefreshDataViewsResponse;
32 import com.hack23.cia.service.api.action.application.CreateApplicationEventRequest;
33 import com.hack23.cia.service.api.action.application.CreateApplicationEventResponse;
34 import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
35 import com.hack23.cia.service.data.api.ViewDataManager;
36 import com.hack23.cia.service.impl.action.common.AbstractBusinessServiceImpl;
37 import com.hack23.cia.service.impl.action.common.BusinessService;
38
39
40
41
42 @Service
43 @Transactional(propagation = Propagation.REQUIRED,timeout=600)
44 @Secured({ "ROLE_USER", "ROLE_ADMIN" })
45 public final class RefreshDataViewsService extends
46 AbstractBusinessServiceImpl<RefreshDataViewsRequest, RefreshDataViewsResponse>
47 implements BusinessService<RefreshDataViewsRequest, RefreshDataViewsResponse> {
48
49
50 @Autowired
51 private ViewDataManager viewDataManager;
52
53
54 @Autowired
55 private BusinessService<CreateApplicationEventRequest, CreateApplicationEventResponse> createApplicationEventService;
56
57
58
59
60 public RefreshDataViewsService() {
61 super(RefreshDataViewsRequest.class);
62 }
63
64
65 @Override
66 public RefreshDataViewsResponse processService(
67 final RefreshDataViewsRequest serviceRequest) {
68
69 final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
70 eventRequest.setEventGroup(ApplicationEventGroup.ADMIN);
71 eventRequest.setApplicationOperation(ApplicationOperationType.UPDATE);
72 eventRequest.setActionName(RefreshDataViewsRequest.class.getSimpleName());
73 eventRequest.setSessionId(serviceRequest.getSessionId());
74
75 final UserAccount userAccount = getUserAccountFromSecurityContext();
76
77
78 if (userAccount != null) {
79
80 eventRequest.setUserId(userAccount.getUserId());
81 }
82
83 final RefreshDataViewsResponse response = new RefreshDataViewsResponse(ServiceResult.SUCCESS);
84 viewDataManager.refreshViews();
85
86 eventRequest.setApplicationMessage(response.getResult().toString());
87 createApplicationEventService.processService(eventRequest);
88
89 return response;
90 }
91
92
93
94 }