Skip to content
Snippets Groups Projects

Add View-specific post-initialization

Files

@@ -17,19 +17,49 @@
*/
package nl.tudelft.librador.dto.create;
import nl.tudelft.librador.dto.Validated;
import org.modelmapper.ModelMapper;
public abstract class Create<D> extends GenericCreate<D> {
public abstract class Create<D> extends Validated {
@Override
public void validate() {
// leave empty
}
/**
* Converts the DTO into the entity.
*
* @return the entity
* @return The created entity.
*/
public D apply() {
ModelMapper mapper = createMapper();
public D apply(ModelMapper mapper) {
D data = mapper.map(this, clazz());
postApply(data);
return data;
}
/**
* Configures the {@link ModelMapper} that will be used by the Create application.
*
* @return The {@link ModelMapper} created for mapping the Create DTO.
*/
protected ModelMapper createMapper() {
return new ModelMapper();
}
/**
* Returns the class of the entity.
*
* @return the class of the entity
*/
public abstract Class<D> clazz();
/**
* Does an action after the data is created but before it is returned in apply.
*
* @param data the data that was created
*/
protected void postApply(D data) {
// leave empty
}
}
Loading