io.github.rayexpresslibraries.ddd.domain.validation.handler.Notification Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ddd Show documentation
Show all versions of ddd Show documentation
a libary that contain comon classes about ddd
The newest version!
package io.github.rayexpresslibraries.ddd.domain.validation.handler;
import io.github.rayexpresslibraries.ddd.domain.validation.Error;
import io.github.rayexpresslibraries.ddd.domain.validation.ValidatorHandler;
import io.github.rayexpresslibraries.ddd.domain.exceptions.DomainException;
import java.util.ArrayList;
import java.util.List;
public class Notification implements ValidatorHandler {
private final List errors;
private Notification(final List errors) {
this.errors = errors;
}
public static Notification create() {
return new Notification(new ArrayList<>());
}
public static Notification create(final Error error) {
return new Notification(new ArrayList<>()).append(error);
}
public static Notification create(final Throwable error) {
return create(new Error(error.getMessage()));
}
@Override
public Notification append(final Error error) {
this.errors.add(error);
return this;
}
@Override
public Notification append(final ValidatorHandler handler) {
this.errors.addAll(handler.getErrors());
return this;
}
@Override
public T validate(final Validation handler) {
try {
return handler.validate();
} catch (final DomainException e) {
this.errors.addAll(e.getErrors());
} catch (final Exception e) {
this.errors.add(new Error(e.getMessage()));
}
return null;
}
@Override
public List getErrors() {
return errors;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy