View Javadoc
1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
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   * The Class UpdateApplicationConfigurationService.
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  	/** The create application event service. */
51  	@Autowired
52  	private BusinessService<CreateApplicationEventRequest, CreateApplicationEventResponse> createApplicationEventService;
53  
54  	/** The application configuration dao. */
55  	@Autowired
56  	private ApplicationConfigurationDAO applicationConfigurationDAO;
57  
58  	/**
59  	 * Instantiates a new update application configuration service.
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 }