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  
23  import org.springframework.beans.factory.annotation.Autowired;
24  import org.springframework.stereotype.Service;
25  import org.springframework.transaction.annotation.Propagation;
26  import org.springframework.transaction.annotation.Transactional;
27  
28  import com.hack23.cia.model.internal.application.system.impl.LanguageContentData;
29  import com.hack23.cia.model.internal.application.system.impl.LanguageContentType;
30  import com.hack23.cia.service.data.api.LanguageContentDataDAO;
31  import com.hack23.cia.service.data.api.LanguageContentService;
32  
33  /**
34   * The Class LanguageContentServiceImpl.
35   */
36  @Service
37  @Transactional(propagation=Propagation.REQUIRES_NEW)
38  final class LanguageContentServiceImpl implements LanguageContentService {
39  
40  
41  	/** The language content data dao. */
42  	@Autowired
43  	private LanguageContentDataDAO languageContentDataDAO;
44  
45  	/**
46  	 * Instantiates a new language content service impl.
47  	 */
48  	public LanguageContentServiceImpl() {
49  		super();
50  	}
51  
52  	@Override
53  	public String getLanguageResource(String key, String keyGroup,String language, String defaultEnglishValue) {
54  		final LanguageContentData findTranslation = languageContentDataDAO.findTranslation(key, language, language);
55  
56  		if (findTranslation != null) {
57  			return findTranslation.getLanguageValue();
58  		} else {
59  			final LanguageContentData newDefaultValue = new LanguageContentData().withCreatedDate(new Date()).withFromLanguage("en").withToLanguage("en").withLanguageContentType(LanguageContentType.HUMAN_TRANSLATION).withLanguageValue(defaultEnglishValue).withRefKey(key);
60  			languageContentDataDAO.persist(newDefaultValue);
61  			return newDefaultValue.getLanguageValue();
62  		}
63  	}
64  
65  }