return getBusiness().getPageAttributeBusiness().getByPage(pageUrl);
}
@Override
public ServiceResponse save(Map<String, String> vo) {
PageAttributeEntity attr;
if (StringUtils.isEmpty(vo.get("id"))) {
attr = new PageAttributeEntity();
}
else {
attr = getDao().getPageAttributeDao().getById(Long.valueOf(
vo.get("id")));
}
attr.setPageUrl(vo.get("url"));
attr.setName(vo.get("name"));
attr.setTitle(vo.get("title"));
attr.setDefaultValue(vo.get("defaultValue"));
attr.setInherited(Boolean.valueOf(vo.get("inherited")));
// validating
List<String> errors = getBusiness().getPageAttributeBusiness()
.validateBeforeUpdate(attr);
if (!errors.isEmpty()) {
return ServiceResponse.createErrorResponse(Messages.get("error"),
errors);
}
getDao().getPageAttributeDao().save(attr);
// set default value to all children
if (attr.isInherited()
&& StringUtils.isNotEmpty(attr.getDefaultValue())) {
PageEntity page = getDao().getPageDao().getByUrl(attr.getPageUrl());
ConfigEntity config = VosaoContext.getInstance().getConfig();
getBusiness().getPageAttributeBusiness().setAttribute(page,
attr.getName(), config.getDefaultLanguage(),
attr.getDefaultValue(), true);
}
return ServiceResponse.createSuccessResponse(Messages.get("success"));
}