Search in sources :

Example 1 with LanguageContentData

use of com.hack23.cia.model.internal.application.system.impl.LanguageContentData in project cia by Hack23.

the class AdminLanguageContentPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout content = createPanelContent();
    final String pageId = getPageId(parameters);
    final int pageNr = getPageNr(parameters);
    getMenuItemFactory().createMainPageMenuBar(menuBar);
    LabelFactory.createHeader2Label(content, ADMIN_LANGUAGE_CONTENT);
    final DataContainer<LanguageContentData, Long> dataContainer = getApplicationManager().getDataContainer(LanguageContentData.class);
    final List<LanguageContentData> pageOrderBy = dataContainer.getPageOrderBy(pageNr, DEFAULT_RESULTS_PER_PAGE, LanguageContentData_.toLanguage);
    createPagingControls(content, NAME, pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);
    getGridFactory().createBasicBeanItemGrid(content, LanguageContentData.class, pageOrderBy, LANGUAGE_CONTENT_DATA, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, null);
    if (pageId != null && !pageId.isEmpty()) {
        final LanguageContentData languageContentData = dataContainer.load(Long.valueOf(pageId));
        if (languageContentData != null) {
            getFormFactory().addFormPanelTextFields(content, languageContentData, LanguageContentData.class, AS_LIST);
        }
    }
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_LANGUAGE_CONTENT_VIEW, ApplicationEventGroup.ADMIN, NAME, null, pageId);
    return content;
}
Also used : LanguageContentData(com.hack23.cia.model.internal.application.system.impl.LanguageContentData) VerticalLayout(com.vaadin.ui.VerticalLayout) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with LanguageContentData

use of com.hack23.cia.model.internal.application.system.impl.LanguageContentData in project cia by Hack23.

the class LanguageContentDataDAOImpl method findTranslation.

@Override
public LanguageContentData findTranslation(final String key, final String fromLanguage, final String toLanguage) {
    final CriteriaQuery<LanguageContentData> criteriaQuery = getCriteriaBuilder().createQuery(getPersistentClass());
    final Root<LanguageContentData> root = criteriaQuery.from(getPersistentClass());
    criteriaQuery.select(root);
    final Predicate keyCondition = getCriteriaBuilder().equal(root.get(LanguageContentData_.refKey), key);
    final Predicate fromCondition = getCriteriaBuilder().equal(root.get(LanguageContentData_.fromLanguage), fromLanguage);
    final Predicate toCondition = getCriteriaBuilder().equal(root.get(LanguageContentData_.toLanguage), toLanguage);
    final Predicate and = getCriteriaBuilder().and(keyCondition, fromCondition, toCondition);
    criteriaQuery.where(and);
    final TypedQuery<LanguageContentData> typedQuery = getEntityManager().createQuery(criteriaQuery);
    addCacheHints(typedQuery, "findTranslation");
    final List<LanguageContentData> resultList = typedQuery.getResultList();
    if (resultList.isEmpty()) {
        return null;
    } else {
        return resultList.get(0);
    }
}
Also used : LanguageContentData(com.hack23.cia.model.internal.application.system.impl.LanguageContentData) Predicate(javax.persistence.criteria.Predicate)

Example 3 with LanguageContentData

use of com.hack23.cia.model.internal.application.system.impl.LanguageContentData in project cia by Hack23.

the class LanguageContentServiceImpl method getLanguageResource.

@Override
public String getLanguageResource(final String key, final String keyGroup, final String language, final String defaultEnglishValue) {
    final LanguageContentData findTranslation = languageContentDataDAO.findTranslation(key, language, language);
    if (findTranslation != null) {
        return findTranslation.getLanguageValue();
    } else {
        final LanguageContentData newDefaultValue = new LanguageContentData().withCreatedDate(new Date()).withFromLanguage("en").withToLanguage("en").withLanguageContentType(LanguageContentType.HUMAN_TRANSLATION).withLanguageValue(defaultEnglishValue).withRefKey(key);
        languageContentDataDAO.persist(newDefaultValue);
        return newDefaultValue.getLanguageValue();
    }
}
Also used : LanguageContentData(com.hack23.cia.model.internal.application.system.impl.LanguageContentData) Date(java.util.Date)

Aggregations

LanguageContentData (com.hack23.cia.model.internal.application.system.impl.LanguageContentData)3 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Date (java.util.Date)1 Predicate (javax.persistence.criteria.Predicate)1 Secured (org.springframework.security.access.annotation.Secured)1