Search in sources :

Example 1 with TranslationProperty

use of org.hisp.dhis.translation.TranslationProperty in project dhis2-core by dhis2.

the class TranslationPropertyUserType method nullSafeGet.

@Override
public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor impl, Object owner) throws HibernateException, SQLException {
    String name = resultSet.getString(names[0]);
    TranslationProperty result = null;
    if (!resultSet.wasNull()) {
        result = TranslationProperty.fromValue(name);
    }
    return result;
}
Also used : TranslationProperty(org.hisp.dhis.translation.TranslationProperty)

Example 2 with TranslationProperty

use of org.hisp.dhis.translation.TranslationProperty in project dhis2-core by dhis2.

the class TranslateAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    className = className != null && CLASS_ALIAS.containsKey(className) ? CLASS_ALIAS.get(className) : className;
    log.info("Classname: " + className + ", uid: " + uid + ", loc: " + loc);
    IdentifiableObject object = identifiableObjectManager.getObject(uid, className);
    HttpServletRequest request = ServletActionContext.getRequest();
    Set<ObjectTranslation> listObjectTranslation = new HashSet<>(object.getTranslations());
    for (TranslationProperty p : TranslationProperty.values()) {
        Enumeration<String> paramNames = request.getParameterNames();
        Collections.list(paramNames).forEach(paramName -> {
            if (paramName.equalsIgnoreCase(p.getName())) {
                String[] paramValues = request.getParameterValues(paramName);
                if (!ArrayUtils.isEmpty(paramValues) && StringUtils.isNotEmpty(paramValues[0])) {
                    listObjectTranslation.removeIf(o -> o.getProperty().equals(p) && o.getLocale().equalsIgnoreCase(loc));
                    listObjectTranslation.add(new ObjectTranslation(loc, p, paramValues[0]));
                }
            }
        });
    }
    identifiableObjectManager.updateTranslations(object, listObjectTranslation);
    return SUCCESS;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TranslationProperty(org.hisp.dhis.translation.TranslationProperty) ObjectTranslation(org.hisp.dhis.translation.ObjectTranslation) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) HashSet(java.util.HashSet)

Aggregations

TranslationProperty (org.hisp.dhis.translation.TranslationProperty)2 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 ObjectTranslation (org.hisp.dhis.translation.ObjectTranslation)1