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.ApplicationConfiguration;
28 import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
29 import com.hack23.cia.model.internal.application.system.impl.ApplicationOperationType;
30 import com.hack23.cia.model.internal.application.user.impl.UserAccount;
31 import com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationRequest;
32 import com.hack23.cia.service.api.action.admin.UpdateApplicationConfigurationResponse;
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.ApplicationConfigurationDAO;
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 @Secured({ "ROLE_ADMIN" })
46 public final class UpdateApplicationConfigurationService extends
47 AbstractBusinessServiceImpl<UpdateApplicationConfigurationRequest, UpdateApplicationConfigurationResponse>
48 implements BusinessService<UpdateApplicationConfigurationRequest, UpdateApplicationConfigurationResponse> {
49
50
51 @Autowired
52 private BusinessService<CreateApplicationEventRequest, CreateApplicationEventResponse> createApplicationEventService;
53
54
55 @Autowired
56 private ApplicationConfigurationDAO applicationConfigurationDAO;
57
58
59
60
61 public UpdateApplicationConfigurationService() {
62 super(UpdateApplicationConfigurationRequest.class);
63 }
64
65 @Override
66 public UpdateApplicationConfigurationResponse processService(final UpdateApplicationConfigurationRequest serviceRequest) {
67
68 final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
69 eventRequest.setEventGroup(ApplicationEventGroup.ADMIN);
70 eventRequest.setApplicationOperation(ApplicationOperationType.UPDATE);
71 eventRequest.setActionName(UpdateApplicationConfigurationRequest.class.getSimpleName());
72 eventRequest.setSessionId(serviceRequest.getSessionId());
73
74 final UserAccount userAccount = getUserAccountFromSecurityContext();
75
76 if (userAccount != null) {
77
78 eventRequest.setUserId(userAccount.getUserId());
79 }
80
81 UpdateApplicationConfigurationResponse response;
82
83 final ApplicationConfiguration applicationConfiguration = applicationConfigurationDAO
84 .load(serviceRequest.getApplicationConfigurationId());
85
86 if (applicationConfiguration != null) {
87 eventRequest.setElementId(serviceRequest.getApplicationConfigurationId().toString());
88
89 applicationConfiguration.setConfigTitle(serviceRequest.getConfigTitle());
90 applicationConfiguration.setConfigDescription(serviceRequest.getConfigDescription());
91 applicationConfiguration.setComponentTitle(serviceRequest.getComponentTitle());
92 applicationConfiguration.setComponentDescription(serviceRequest.getComponentDescription());
93 applicationConfiguration.setPropertyValue(serviceRequest.getPropertyValue());
94
95 applicationConfigurationDAO.persist(applicationConfiguration);
96
97 response = new UpdateApplicationConfigurationResponse(ServiceResult.SUCCESS);
98 } else {
99 response = new UpdateApplicationConfigurationResponse(ServiceResult.FAILURE);
100 }
101
102 eventRequest.setApplicationMessage(response.getResult().toString());
103 createApplicationEventService.processService(eventRequest);
104
105 return response;
106
107 }
108
109 }