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.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   * The Class RefreshDataViewsService.
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  	/** The View data manager. */
50  	@Autowired
51  	private ViewDataManager viewDataManager;
52  
53  	/** The create application event service. */
54  	@Autowired
55  	private BusinessService<CreateApplicationEventRequest, CreateApplicationEventResponse> createApplicationEventService;
56  
57  	/**
58  	 * Instantiates a new refresh data views service.
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  }