@Override public ServiceResponse updateField(Map<String, String> fieldMap) { FieldEntity field = new FieldEntity(); List<String> errors = getBusiness().getFieldBusiness().convertFromVO(field, fieldMap); if (errors.isEmpty()) { List<String> validateErrors = getBusiness().getFieldBusiness().validateBeforeUpdate(field); if (validateErrors.isEmpty()) { boolean newField = field.getId() == null; getDao().getFieldDao().save(field); if (newField) { FormEntity form = getDao().getFormDao().getById(field.getFormId()); getBusiness().getFieldBusiness().checkOrder(form); } return ServiceResponse.createSuccessResponse(Messages.get("form.field_success_update")); } else { ServiceResponse resp = ServiceResponse.createErrorResponse(Messages.get("validation_errors")); resp.setMessages(validateErrors); return resp; } } else { ServiceResponse resp = ServiceResponse.createErrorResponse(Messages.get("convertation_errors")); resp.setMessages(errors); return resp; } }
@Override public List<String> validateBeforeUpdate(final FileEntity entity) { List<String> errors = new ArrayList<String>(); if (StringUtils.isEmpty(entity.getFilename())) { errors.add(Messages.get("filename_is_empty")); } else { FileEntity file = getDao().getFileDao().getByName(entity.getFolderId(), entity.getFilename()); if (file != null && (entity.isNew() || (!entity.isNew() && !file.getId().equals(entity.getId())))) { errors.add(Messages.get("file_already_exists")); } } if (StringUtils.isEmpty(entity.getTitle())) { errors.add(Messages.get("title_is_empty")); } return errors; }
private List<String> validate(SeoUrlEntity entity) { List<String> errors = new ArrayList<String>(); SeoUrlEntity found = getDao().getSeoUrlDao().getByFrom(entity.getFromLink()); if (found != null && !found.getId().equals(entity.getId())) { errors.add(Messages.get("seo_urls.already_exists")); } return errors; }
@Override public ServiceResponse save(Map<String, String> vo) { try { GroupEntity group = getDao().getGroupDao().getById(Long.valueOf((vo.get("groupId")))); if (group == null) { throw new ServiceException(Messages.get("group_not_found")); } String url = vo.get("url"); ContentPermissionType perm = ContentPermissionType.valueOf(vo.get("permission")); String languages = StringUtils.isEmpty(vo.get("languages")) ? null : vo.get("languages"); getBusiness().getContentPermissionBusiness().setPermission(url, group, perm, languages); return ServiceResponse.createSuccessResponse( Messages.get("content_permissions_success_save")); } catch (Exception e) { return ServiceResponse.createErrorResponse(e.toString() + " " + e.getMessage()); } }
@Override public ServiceResponse save(Map<String, String> vo) { SeoUrlEntity seoUrl = null; if (!StringUtils.isEmpty(vo.get("id"))) { seoUrl = getDao().getSeoUrlDao().getById(Long.valueOf(vo.get("id"))); } if (seoUrl == null) { seoUrl = new SeoUrlEntity(); } seoUrl.setFromLink(vo.get("fromLink")); seoUrl.setToLink(vo.get("toLink")); List<String> errors = validate(seoUrl); if (errors.isEmpty()) { getDao().getSeoUrlDao().save(seoUrl); return ServiceResponse.createSuccessResponse(Messages.get("seo_urls.success_save")); } else { return ServiceResponse.createErrorResponse(Messages.get("errors_occured"), errors); } }
@Override public ServiceResponse remove(List<String> ids) { List<Long> idList = new ArrayList<Long>(); for (String id : ids) { idList.add(Long.valueOf(id)); } getDao().getContentPermissionDao().remove(idList); return ServiceResponse.createSuccessResponse( Messages.get("content_permissions_success_delete")); }
@Override public List<String> validateBeforeUpdate(final TemplateEntity template) { List<String> errors = new ArrayList<String>(); if (template.getId() == null) { TemplateEntity myTemplate = getDao().getTemplateDao().getByUrl(template.getUrl()); if (myTemplate != null) { errors.add(Messages.get("template.already_exists")); } } if (StringUtil.isEmpty(template.getUrl())) { errors.add(Messages.get("url_is_empty")); } if (StringUtil.isEmpty(template.getTitle())) { errors.add(Messages.get("title_is_empty")); } if (StringUtil.isEmpty(template.getContent())) { errors.add(Messages.get("content_is_empty")); } return errors; }
@Override public List<String> remove(List<Long> ids) { List<String> result = new ArrayList<String>(); for (Long id : ids) { TemplateEntity template = getDao().getTemplateDao().getById(id); if (template == null) { continue; } List<PageEntity> pages = getDao().getPageDao().selectByTemplate(id); if (pages.size() > 0) { result.add( Messages.get( "template.has_references", template.getTitle(), pages.get(0).getFriendlyURL())); } else { getDao().getTemplateDao().remove(id); } } return result; }
@Override public ServiceResponse remove(List<String> ids) { getDao().getSeoUrlDao().remove(StrUtil.toLong(ids)); return ServiceResponse.createSuccessResponse(Messages.get("seo_urls.success_delete")); }