fr.ird.observe.spi.initializer.EntitiesBinderInitializerSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-persistence Show documentation
Show all versions of common-persistence Show documentation
ObServe Toolkit Common Persistence module
package fr.ird.observe.spi.initializer;
/*-
* #%L
* ObServe Toolkit :: Common Persistence
* %%
* Copyright (C) 2017 - 2019 IRD, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import fr.ird.observe.binder.data.DataEntityDtoBinderSupport;
import fr.ird.observe.binder.data.DataEntityReferenceBinderSupport;
import fr.ird.observe.binder.referential.ReferentialEntityDtoBinderSupport;
import fr.ird.observe.binder.referential.ReferentialEntityReferenceBinderSupport;
import fr.ird.observe.dto.IdHelper;
import fr.ird.observe.dto.data.DataDto;
import fr.ird.observe.dto.reference.DataDtoReference;
import fr.ird.observe.dto.reference.ReferentialDtoReference;
import fr.ird.observe.dto.referential.ReferentialDto;
import fr.ird.observe.entities.data.ObserveDataEntity;
import fr.ird.observe.entities.referential.ObserveReferentialEntity;
import fr.ird.observe.spi.map.DtoToEntityClassMap;
import fr.ird.observe.spi.map.EntityToDtoClassMap;
import fr.ird.observe.spi.map.ImmutableDtoMap;
import fr.ird.observe.spi.map.ImmutableEntityMap;
public abstract class EntitiesBinderInitializerSupport {
private ImmutableDtoMap entityReferenceReferentialBinders;
private ImmutableDtoMap entityReferenceDataBinders;
private ImmutableDtoMap entityDtoReferentialBinders;
private ImmutableDtoMap entityDtoDataBinders;
private EntityToDtoClassMap entityToDtoClassMapping;
private DtoToEntityClassMap dtoToEntityClassMapping;
private final ImmutableDtoMap.Builder entityReferenceReferentialBindersBuilder = ImmutableDtoMap.builder();
private final ImmutableDtoMap.Builder entityReferenceDataBindersBuilder = ImmutableDtoMap.builder();
private final ImmutableDtoMap.Builder entityDtoReferentialBindersBuilder = ImmutableDtoMap.builder();
private final ImmutableDtoMap.Builder entityDtoDataBindersBuilder = ImmutableDtoMap.builder();
private final ImmutableEntityMap.Builder entityToDtoClassMappingBuilder = ImmutableEntityMap.builder();
private final ImmutableDtoMap.Builder dtoToEntityClassMappingBuilder = ImmutableDtoMap.builder();
public void end() {
this.entityReferenceDataBinders = entityReferenceDataBindersBuilder.build();
this.entityReferenceReferentialBinders = entityReferenceReferentialBindersBuilder.build();
this.entityDtoReferentialBinders = entityDtoReferentialBindersBuilder.build();
this.entityDtoDataBinders = entityDtoDataBindersBuilder.build();
this.entityToDtoClassMapping = new EntityToDtoClassMap(entityToDtoClassMappingBuilder.build());
this.dtoToEntityClassMapping = new DtoToEntityClassMap(dtoToEntityClassMappingBuilder.build());
}
protected , E extends ObserveReferentialEntity, B extends ReferentialEntityReferenceBinderSupport> void registerReferenceReferentialBinder(B binder) {
entityReferenceReferentialBindersBuilder.put(binder.getDtoType(), binder);
}
protected , E extends ObserveDataEntity, B extends DataEntityReferenceBinderSupport> void registerReferenceDataBinder(B binder) {
entityReferenceDataBindersBuilder.put(binder.getDtoType(), binder);
}
protected > void registerDtoReferentialBinder(B binder) {
entityDtoReferentialBindersBuilder.put(binder.getDtoType(), binder);
dtoToEntityClassMappingBuilder.put(binder.getDtoType(), binder.getEntityType());
if (IdHelper.cleanId(binder.getDtoType().getSimpleName()).equals(IdHelper.cleanId(binder.getEntityType().getSimpleName()))) {
entityToDtoClassMappingBuilder.put(binder.getEntityType(), binder.getDtoType());
}
}
protected > void registerDtoDataBinder(B binder) {
entityDtoDataBindersBuilder.put(binder.getDtoType(), binder);
dtoToEntityClassMappingBuilder.put(binder.getDtoType(), binder.getEntityType());
if (IdHelper.cleanId(binder.getDtoType().getSimpleName()).equals(IdHelper.cleanId(binder.getEntityType().getSimpleName()))) {
entityToDtoClassMappingBuilder.put(binder.getEntityType(), binder.getDtoType());
}
}
public ImmutableDtoMap getEntityReferenceReferentialBinders() {
return entityReferenceReferentialBinders;
}
public ImmutableDtoMap getEntityReferenceDataBinders() {
return entityReferenceDataBinders;
}
public ImmutableDtoMap getEntityDtoReferentialBinders() {
return entityDtoReferentialBinders;
}
public ImmutableDtoMap getEntityDtoDataBinders() {
return entityDtoDataBinders;
}
public EntityToDtoClassMap getEntityToDtoClassMapping() {
return entityToDtoClassMapping;
}
public DtoToEntityClassMap getDtoToEntityClassMapping() {
return dtoToEntityClassMapping;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy