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.data.impl;
20  
21  import java.util.Date;
22  import java.util.List;
23  
24  import org.springframework.beans.factory.annotation.Autowired;
25  import org.springframework.stereotype.Service;
26  import org.springframework.transaction.annotation.Propagation;
27  import org.springframework.transaction.annotation.Transactional;
28  
29  import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration;
30  import com.hack23.cia.model.internal.application.system.impl.ApplicationConfiguration_;
31  import com.hack23.cia.model.internal.application.system.impl.ConfigurationGroup;
32  import com.hack23.cia.service.data.api.ApplicationConfigurationDAO;
33  import com.hack23.cia.service.data.api.ApplicationConfigurationService;
34  
35  /**
36   * The Class ApplicationConfigurationServiceImpl.
37   */
38  @Service
39  @Transactional(propagation=Propagation.REQUIRES_NEW)
40  final class ApplicationConfigurationServiceImpl implements ApplicationConfigurationService {
41  
42  
43  	/** The application configuration dao. */
44  	@Autowired
45  	private ApplicationConfigurationDAO applicationConfigurationDAO;
46  
47  	/**
48  	 * Instantiates a new application configuration service impl.
49  	 */
50  	public ApplicationConfigurationServiceImpl() {
51  		super();
52  	}
53  
54  	@Override
55  	public ApplicationConfiguration checkValueOrLoadDefault(final String configTitle, final String configDescription,
56  			final ConfigurationGroup configurationGroup, final String component, final String componentTitle, final String componentDescription,
57  			final String propertyId, final String propertyValue) {
58  
59  		final List<ApplicationConfiguration> findListByProperty = applicationConfigurationDAO.findListByProperty(new Object[]{component,configurationGroup,propertyId}, ApplicationConfiguration_.component,ApplicationConfiguration_.configurationGroup,ApplicationConfiguration_.propertyId);
60  
61  		if (findListByProperty.isEmpty()) {
62  			final ApplicationConfiguration applicationConfiguration = new ApplicationConfiguration();
63  			applicationConfiguration.setCreatedDate(new Date());
64  			applicationConfiguration.setUpdatedDate(new Date());
65  
66  			applicationConfiguration.setConfigTitle(configTitle);
67  			applicationConfiguration.setConfigDescription(configDescription);
68  			applicationConfiguration.setConfigurationGroup(configurationGroup);
69  
70  			applicationConfiguration.setComponent(component);
71  			applicationConfiguration.setComponentTitle(componentTitle);
72  			applicationConfiguration.setComponentDescription(componentDescription);
73  
74  			applicationConfiguration.setPropertyId(propertyId);
75  			applicationConfiguration.setPropertyValue(propertyValue);
76  
77  			applicationConfigurationDAO.persist(applicationConfiguration);
78  
79  			return applicationConfiguration;
80  		} else {
81  			return findListByProperty.get(0);
82  		}
83  
84  	}
85  
86  }