LanguageContentServiceImpl.java

  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. import java.util.Date;

  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Propagation;
  24. import org.springframework.transaction.annotation.Transactional;

  25. import com.hack23.cia.model.internal.application.system.impl.LanguageContentData;
  26. import com.hack23.cia.model.internal.application.system.impl.LanguageContentType;
  27. import com.hack23.cia.service.data.api.LanguageContentDataDAO;
  28. import com.hack23.cia.service.data.api.LanguageContentService;

  29. /**
  30.  * The Class LanguageContentServiceImpl.
  31.  */
  32. @Service
  33. @Transactional(propagation=Propagation.REQUIRES_NEW)
  34. final class LanguageContentServiceImpl implements LanguageContentService {


  35.     /** The language content data dao. */
  36.     @Autowired
  37.     private LanguageContentDataDAO languageContentDataDAO;

  38.     /**
  39.      * Instantiates a new language content service impl.
  40.      */
  41.     public LanguageContentServiceImpl() {
  42.         super();
  43.     }

  44.     @Override
  45.     public String getLanguageResource(String key, String keyGroup,String language, String defaultEnglishValue) {
  46.         final LanguageContentData findTranslation = languageContentDataDAO.findTranslation(key, language, language);

  47.         if (findTranslation != null) {
  48.             return findTranslation.getLanguageValue();
  49.         } else {
  50.             final LanguageContentData newDefaultValue = new LanguageContentData().withCreatedDate(new Date()).withFromLanguage("en").withToLanguage("en").withLanguageContentType(LanguageContentType.HUMAN_TRANSLATION).withLanguageValue(defaultEnglishValue).withRefKey(key);
  51.             languageContentDataDAO.persist(newDefaultValue);
  52.             return newDefaultValue.getLanguageValue();
  53.         }
  54.     }

  55. }