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.application;
20  
21  import java.util.ArrayList;
22  import java.util.Date;
23  
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.security.access.annotation.Secured;
28  import org.springframework.stereotype.Service;
29  import org.springframework.transaction.annotation.Propagation;
30  import org.springframework.transaction.annotation.Transactional;
31  
32  import com.hack23.cia.model.internal.application.system.impl.ApplicationSession;
33  import com.hack23.cia.model.internal.application.system.impl.ApplicationSessionType;
34  import com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest;
35  import com.hack23.cia.service.api.action.application.CreateApplicationSessionResponse;
36  import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
37  import com.hack23.cia.service.data.api.ApplicationSessionDAO;
38  import com.hack23.cia.service.impl.action.common.AbstractBusinessServiceImpl;
39  import com.hack23.cia.service.impl.action.common.BusinessService;
40  
41  /**
42   * The Class CreateApplicationSessionService.
43   */
44  @Service
45  @Transactional(propagation = Propagation.REQUIRED)
46  public final class CreateApplicationSessionService
47  		extends AbstractBusinessServiceImpl<CreateApplicationSessionRequest, CreateApplicationSessionResponse>
48  		implements BusinessService<CreateApplicationSessionRequest, CreateApplicationSessionResponse> {
49  
50  	/** The Constant LOGGER. */
51  	private static final Logger LOGGER = LoggerFactory
52  			.getLogger(CreateApplicationSessionService.class);
53  
54  
55  	/** The application session dao. */
56  	@Autowired
57  	private ApplicationSessionDAO applicationSessionDAO;
58  
59  	/**
60  	 * Instantiates a new creates the application session service.
61  	 */
62  	public CreateApplicationSessionService() {
63  		super(CreateApplicationSessionRequest.class);
64  	}
65  
66  	@Secured({ "ROLE_ANONYMOUS" })
67  	@Override
68  	public CreateApplicationSessionResponse processService(final CreateApplicationSessionRequest serviceRequest) {
69  		final ApplicationSession applicationSession = new ApplicationSession();
70  		applicationSession.setCreatedDate(new Date());
71  
72  		applicationSession.setSessionId(serviceRequest.getSessionId());
73  		applicationSession.setIpInformation(serviceRequest.getIpInformation());
74  		applicationSession.setLocale(serviceRequest.getLocale());
75  		applicationSession.setOperatingSystem(serviceRequest.getOperatingSystem());
76  		applicationSession.setUserAgentInformation(serviceRequest.getUserAgentInformation());
77  		applicationSession.setSessionType(serviceRequest.getSessionType());
78  		applicationSession.setEvents(new ArrayList<>());
79  		applicationSession.setSessionType(ApplicationSessionType.ANONYMOUS);
80  		applicationSessionDAO.persist(applicationSession);
81  
82  		LOGGER.info("Create application session:{}",applicationSession);
83  
84  		return new CreateApplicationSessionResponse(ServiceResult.SUCCESS);
85  	}
86  
87  }