use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method validateForCreate.
private TypeReport validateForCreate(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle) {
TypeReport typeReport = new TypeReport(klass);
if (objects == null || objects.isEmpty()) {
return typeReport;
}
Iterator<IdentifiableObject> iterator = objects.iterator();
int idx = 0;
while (iterator.hasNext()) {
IdentifiableObject identifiableObject = iterator.next();
IdentifiableObject object = bundle.getPreheat().get(bundle.getPreheatIdentifier(), identifiableObject);
if (object != null && object.getId() > 0) {
ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
objectReport.addErrorReport(new ErrorReport(klass, ErrorCode.E5000, bundle.getPreheatIdentifier(), bundle.getPreheatIdentifier().getIdentifiersWithName(identifiableObject)).setMainId(identifiableObject.getUid()));
typeReport.addObjectReport(objectReport);
typeReport.getStats().incIgnored();
iterator.remove();
}
idx++;
}
return typeReport;
}
use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.
the class ObjectBundleCommitReport method getErrorReportsByCode.
//-----------------------------------------------------------------------------------
// Utility Methods
//-----------------------------------------------------------------------------------
public List<ErrorReport> getErrorReportsByCode(Class<?> klass, ErrorCode errorCode) {
List<ErrorReport> errorReports = new ArrayList<>();
if (!typeReportMap.containsKey(klass)) {
return errorReports;
}
List<ObjectReport> objectReports = typeReportMap.get(klass).getObjectReports();
for (ObjectReport objectReport : objectReports) {
List<ErrorReport> byCode = objectReport.getErrorReportsByCode().get(errorCode);
if (byCode != null) {
errorReports.addAll(byCode);
}
}
return errorReports;
}
use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.
the class DefaultAclService method verifySharing.
@Override
public <T extends IdentifiableObject> List<ErrorReport> verifySharing(T object, User user) {
List<ErrorReport> errorReports = new ArrayList<>();
if (object == null || !isShareable(object.getClass()) || user == null) {
return errorReports;
}
if (!AccessStringHelper.isValid(object.getPublicAccess())) {
errorReports.add(new ErrorReport(object.getClass(), ErrorCode.E3010, object.getPublicAccess()));
return errorReports;
}
boolean canMakePublic = canMakePublic(user, object.getClass());
boolean canMakePrivate = canMakePrivate(user, object.getClass());
boolean canMakeExternal = canMakeExternal(user, object.getClass());
if (object.getExternalAccess()) {
if (!canMakeExternal) {
errorReports.add(new ErrorReport(object.getClass(), ErrorCode.E3006, user.getUsername(), object.getClass()));
}
}
if (AccessStringHelper.DEFAULT.equals(object.getPublicAccess())) {
if (canMakePublic || canMakePrivate) {
return errorReports;
}
errorReports.add(new ErrorReport(object.getClass(), ErrorCode.E3009, user.getUsername(), object.getClass()));
} else {
if (canMakePublic) {
return errorReports;
}
errorReports.add(new ErrorReport(object.getClass(), ErrorCode.E3008, user.getUsername(), object.getClass()));
}
return errorReports;
}
use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.
the class DefaultSchemaValidator method validateString.
private List<? extends ErrorReport> validateString(Class<?> klass, Object propertyObject, Property property) {
List<ErrorReport> errorReports = new ArrayList<>();
// TODO How should empty strings be handled? they are not valid color, password, url, etc of course.
if (!String.class.isInstance(propertyObject) || StringUtils.isEmpty(propertyObject)) {
return errorReports;
}
String value = (String) propertyObject;
// check column max length
if (value.length() > property.getLength()) {
errorReports.add(new ErrorReport(klass, ErrorCode.E4001, property.getName(), property.getLength(), value.length()).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
return errorReports;
}
if (value.length() < property.getMin() || value.length() > property.getMax()) {
errorReports.add(new ErrorReport(klass, ErrorCode.E4002, property.getName(), property.getMin(), property.getMax(), value.length()).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
}
if (PropertyType.EMAIL == property.getPropertyType() && !GenericValidator.isEmail(value)) {
errorReports.add(new ErrorReport(klass, ErrorCode.E4003, property.getName(), value).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
} else if (PropertyType.URL == property.getPropertyType() && !isUrl(value)) {
errorReports.add(new ErrorReport(klass, ErrorCode.E4004, property.getName(), value).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
} else if (!BCRYPT_PATTERN.matcher(value).matches() && PropertyType.PASSWORD == property.getPropertyType() && !ValidationUtils.passwordIsValid(value)) {
errorReports.add(new ErrorReport(klass, ErrorCode.E4005, property.getName(), value).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
} else if (PropertyType.COLOR == property.getPropertyType() && !ValidationUtils.isValidHexColor(value)) {
errorReports.add(new ErrorReport(klass, ErrorCode.E4006, property.getName(), value).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
}
return errorReports;
}
use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.
the class DefaultSchemaValidator method validate.
@Override
public List<ErrorReport> validate(Object object, boolean persisted) {
List<ErrorReport> errorReports = new ArrayList<>();
if (object == null) {
return errorReports;
}
Schema schema = schemaService.getDynamicSchema(object.getClass());
if (schema == null) {
return errorReports;
}
Class<?> klass = object.getClass();
for (Property property : schema.getProperties()) {
if (persisted && !property.isPersisted()) {
continue;
}
Object value = ReflectionUtils.invokeMethod(object, property.getGetterMethod());
if (value == null) {
if (property.isRequired() && !Preheat.isDefaultClass(property.getKlass())) {
errorReports.add(new ErrorReport(klass, ErrorCode.E4000, property.getName()).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
}
continue;
}
errorReports.addAll(validateString(klass, value, property));
errorReports.addAll(validateCollection(klass, value, property));
errorReports.addAll(validateInteger(klass, value, property));
errorReports.addAll(validateFloat(klass, value, property));
errorReports.addAll(validateDouble(klass, value, property));
}
if (User.class.isInstance(object)) {
User user = (User) object;
if (user.getUserCredentials() != null) {
errorReports.addAll(validate(user.getUserCredentials(), persisted));
}
}
return errorReports;
}
Aggregations