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.Date;
22  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import org.springframework.beans.factory.annotation.Autowired;
26  import org.springframework.security.access.annotation.Secured;
27  import org.springframework.stereotype.Service;
28  import org.springframework.transaction.annotation.Propagation;
29  import org.springframework.transaction.annotation.Transactional;
30  
31  import com.hack23.cia.model.internal.application.system.impl.ApplicationSession;
32  import com.hack23.cia.model.internal.application.system.impl.ApplicationSession_;
33  import com.hack23.cia.service.api.action.application.DestroyApplicationSessionRequest;
34  import com.hack23.cia.service.api.action.application.DestroyApplicationSessionResponse;
35  import com.hack23.cia.service.api.action.common.ServiceResponse.ServiceResult;
36  import com.hack23.cia.service.data.api.ApplicationSessionDAO;
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 DestroyApplicationSessionService.
42   */
43  @Service
44  @Transactional(propagation = Propagation.REQUIRED)
45  public final class DestroyApplicationSessionService
46  		extends AbstractBusinessServiceImpl<DestroyApplicationSessionRequest, DestroyApplicationSessionResponse>
47  		implements BusinessService<DestroyApplicationSessionRequest, DestroyApplicationSessionResponse> {
48  
49  	/** The Constant LOGGER. */
50  	private static final Logger LOGGER = LoggerFactory
51  			.getLogger(DestroyApplicationSessionService.class);
52  
53  
54  	/** The application session dao. */
55  	@Autowired
56  	private ApplicationSessionDAO applicationSessionDAO;
57  
58  	/**
59  	 * Instantiates a new destroy application session service.
60  	 */
61  	public DestroyApplicationSessionService() {
62  		super(DestroyApplicationSessionRequest.class);
63  	}
64  
65  	@Secured({ "ROLE_ANONYMOUS" })
66  	@Override
67  	public DestroyApplicationSessionResponse processService(final DestroyApplicationSessionRequest serviceRequest) {
68  		final ApplicationSession applicationSession = applicationSessionDAO.findFirstByProperty(ApplicationSession_.sessionId, serviceRequest.getSessionId());
69  
70  		if (applicationSession != null) {
71  			LOGGER.info("Destroy Application session: {}",applicationSession.getSessionId());
72  			applicationSession.setDestroyedDate(new Date());
73  			applicationSessionDAO.persist(applicationSession);
74  			return new DestroyApplicationSessionResponse(ServiceResult.SUCCESS);
75  		} else {
76  			LOGGER.warn("Failed to destroy Application session, no session found for id: {}",serviceRequest.getSessionId());
77  			return new DestroyApplicationSessionResponse(ServiceResult.FAILURE);
78  		}
79  	}
80  
81  }