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;
}
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;
}
Aggregations