@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; } }
private int indexOf(List<FieldEntity> fields, final Long fieldId) { for (int i = 0; i < fields.size(); i++) { FieldEntity field = fields.get(i); if (field.getId().equals(fieldId)) { return i; } } return -1; }
@Override public void remove(List<String> ids) { if (ids.size() > 0) { FieldEntity field = null; FormEntity form = null; for (String id : ids) { field = getDao().getFieldDao().getById(Long.valueOf(id)); if (field != null) { form = getDao().getFormDao().getById(field.getFormId()); break; } } if (form == null) { return; } getDao().getFieldDao().remove(StrUtil.toLong(ids)); getBusiness().getFieldBusiness().checkOrder(form); } }