In the new versions of the structure of devon4j i have been having issues with code reiteration caused by not being able to create a save(Entity). Creating this method is not possible because the entities are generated in the core project and not in the api project. This fact forces me to transform to ETO
to call a save method that will later transform to ENTITY
with bean mapper. Example:
I want to decrease the queue customers by one when deleting an accesscode. This is located in UseCaseManageAccessCodeImpl
.
@Override
public Boolean deleteAccessCode(long accessCodeId) {
AccessCodeEntity accessCodeEntity = getAccessCodeRepository().find(accessCodeId);
// Forced to map to ETO because I can't use entity in my QueueManagement
QueueEto queueEto = getBeanMapper().map(accessCodeEntity.getQueue(),QueueEto.class);
queueEto.setCustomers(queueEto.getCustomers() -1);
getQueuemanagement().saveQueue(queueEto);
LOG.debug("The queue with id '{}' has decreased its customers to: {}.", queueEto.getId(),
queueEto.getCustomers());
// we delete the accesscode
getAccessCodeRepository().delete(accessCodeEntity);
LOG.debug("The accesscode with id '{}' has been deleted.", accessCodeId);
return true;
}
This is the saveQueue(QueueEto queue)
located in the UseCaseManageQueueImpl
@Override
public QueueEto saveQueue(QueueEto queue) {
Objects.requireNonNull(queue, "queue");
// Transformation from QueueEto to QueueEntity
QueueEntity queueEntity = getBeanMapper().map(queue, QueueEntity.class);
// initialize, validate queueEntity here if necessary
QueueEntity resultEntity = getQueueRepository().save(queueEntity);
LOG.debug("Queue with id '{}' has been created.", resultEntity.getId());
return getBeanMapper().map(resultEntity, QueueEto.class);
}
If i try to make a new method in the UseCaseManageQueue
interface to later implement it:
QueueEto saveQueue(QueueEntity queue);
the QueueEntity
can not be found because the UseCaseManageQueue
is in the api and the QueueEntity
is in the core. This is feasible in the previous structure (Devon dist 2.4.0) because both the interface and the implementation were in the core. Using my-thai-star:
In the Dishmanagement
:
...
DishEto saveDish(DishEto dish);
/**
* Saves a dish and store it in the database.
*
* @param dish the {@link DishEntity} to create.
* @return the new {@link DishEto} that has been saved with ID and version.
*/
DishEntity saveDish(DishEntity dish) ;
....
In the DishmanagementImpl
....
@Override
public DishEntity saveDish(DishEntity dish) {
Objects.requireNonNull(dish, "dish");
// initialize, validate dishEntity here if necessary
DishEntity resultEntity = getDishDao().save(dish);
LOG.debug("Dish with id '{}' has been created.", resultEntity.getId());
return resultEntity ;
}
....
Doing it in this way, we are going to avoid two mappings. One to transform from ENTITY
to ETO
to use the save and then, inside the save from ETO
to ENTITY
. If there is a way to do this in the previous structure i would like to see if there is a way to do it in the new one.