View Javadoc
1   /*
2    * Copyright 2014 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.web.impl.ui.application.action;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.springframework.beans.factory.annotation.Autowired;
23  import org.springframework.stereotype.Service;
24  import org.springframework.web.context.request.RequestContextHolder;
25  
26  import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
27  import com.hack23.cia.model.internal.application.system.impl.ApplicationOperationType;
28  import com.hack23.cia.service.api.ApplicationManager;
29  import com.hack23.cia.service.api.action.application.CreateApplicationEventRequest;
30  import com.hack23.cia.web.impl.ui.application.util.UserContextUtil;
31  
32  /**
33   * The Class PageActionEventHelperImpl.
34   */
35  @Service
36  public final class PageActionEventHelperImpl implements PageActionEventHelper {
37  
38  	/** The application manager. */
39  	@Autowired
40  	private ApplicationManager applicationManager;
41  
42  	/**
43  	 * Instantiates a new page action event helper impl.
44  	 */
45  	public PageActionEventHelperImpl() {
46  		super();
47  	}
48  
49  
50  	@Override
51  	public void createPageEvent(final ViewAction viewAction,final ApplicationEventGroup applicationEventGroup,final String page, final String pageMode, final String elementId) {
52  
53  
54  
55  		String pageModeToUse;
56  
57  		if (pageMode != null && elementId != null && pageMode.contains(elementId)) {
58  			pageModeToUse= pageMode.replace(elementId, "").replace("/", "");
59  		} else {
60  			pageModeToUse = pageMode;
61  		}
62  
63  		if ((pageModeToUse == null || "".equals(pageModeToUse)) && ApplicationEventGroup.USER == applicationEventGroup) {
64  			pageModeToUse="Overview";
65  		}
66  
67  		final CreateApplicationEventRequest serviceRequest = new CreateApplicationEventRequest();
68  		serviceRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
69  
70  		serviceRequest.setEventGroup(applicationEventGroup);
71  		serviceRequest.setApplicationOperation(ApplicationOperationType.READ);
72  
73  		serviceRequest.setPage(StringUtils.defaultString(page));
74  		serviceRequest.setPageMode(StringUtils.defaultString(pageModeToUse));
75  		serviceRequest.setElementId(StringUtils.defaultString(elementId));
76  
77  		serviceRequest.setActionName(viewAction.toString());
78  
79  		serviceRequest.setUserId(UserContextUtil.getUserIdFromSecurityContext());
80  
81  		serviceRequest.setApplicationMessage(viewAction.toString());
82  
83  		applicationManager
84  				.service(serviceRequest);
85  	}
86  
87  }