This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit 1d5a09cfb674c05f1c9f0c92a2f39ccf56ae5101 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Nov 7 11:59:03 2016 +0100 Ajout d'un objet pour détecter les référentiels manquants --- .../topia/service/ReferentialsShellBuilder.java | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/services-topia/src/main/java/fr/ird/observe/services/topia/service/ReferentialsShellBuilder.java b/services-topia/src/main/java/fr/ird/observe/services/topia/service/ReferentialsShellBuilder.java new file mode 100644 index 0000000..a2c919f --- /dev/null +++ b/services-topia/src/main/java/fr/ird/observe/services/topia/service/ReferentialsShellBuilder.java @@ -0,0 +1,116 @@ +package fr.ird.observe.services.topia.service; + +import com.google.common.cache.AbstractLoadingCache; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimaps; +import com.google.common.collect.SetMultimap; +import fr.ird.observe.ObserveEntityEnum; +import fr.ird.observe.entities.referentiel.ObserveReferentialEntity; +import fr.ird.observe.services.dto.referential.ReferentialDto; +import fr.ird.observe.services.topia.binder.BinderEngine; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaEntityVisitor; + +import java.util.Set; +import java.util.TreeSet; + +/** + * Created on 07/11/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 5.1 + */ +public class ReferentialsShellBuilder { + + public static ReferentialsShellBuilder builder(SetMultimap<Class<? extends ReferentialDto>, String> incomingReferentialIds) { + return new ReferentialsShellBuilder(incomingReferentialIds); + } + + private final GetEntityReferentialsShellVisitor visitor; + + public ReferentialsShellBuilder scan(TopiaEntity entity) { + entity.accept(visitor); + return this; + } + + public SetMultimap<Class<? extends ReferentialDto>, String> build() { + return Multimaps.unmodifiableSetMultimap(visitor.missingreferentialIds); + } + + private ReferentialsShellBuilder(SetMultimap<Class<? extends ReferentialDto>, String> incomingReferentialIds) { + visitor = new GetEntityReferentialsShellVisitor(incomingReferentialIds); + } + + private static class GetEntityReferentialsShellVisitor implements TopiaEntityVisitor { + + private final Set<String> hitIds; + private final SetMultimap<Class<? extends ReferentialDto>, String> incomingReferentialIds; + private final SetMultimap<Class<? extends ReferentialDto>, String> missingreferentialIds; + private final LoadingCache<Class<? extends ObserveReferentialEntity>, Class<? extends ReferentialDto>> typeCache; + + public GetEntityReferentialsShellVisitor(SetMultimap<Class<? extends ReferentialDto>, String> incomingReferentialIds) { + this.incomingReferentialIds = incomingReferentialIds; + this.typeCache = new AbstractLoadingCache<Class<? extends ObserveReferentialEntity>, Class<? extends ReferentialDto>>() { + @Override + public Class<? extends ReferentialDto> get(Class<? extends ObserveReferentialEntity> key) { + Class<? extends TopiaEntity> entityType = ObserveEntityEnum.getContractClass(key); + return BinderEngine.get().getReferentialDtoType((Class) entityType); + } + + @Override + public Class<? extends ReferentialDto> getIfPresent(Object key) { + return get((Class) key); + } + }; + this.hitIds = new TreeSet<>(); + this.missingreferentialIds = HashMultimap.create(); + } + + @Override + public void start(TopiaEntity entity) { + if (entity instanceof ObserveReferentialEntity) { + String topiaId = entity.getTopiaId(); + if (hitIds.contains(topiaId)) { + return; + } + hitIds.add(topiaId); + Class<? extends ReferentialDto> dtoType = typeCache.getUnchecked(((ObserveReferentialEntity) entity).getClass()); + if (!incomingReferentialIds.containsEntry(dtoType, topiaId)) { + missingreferentialIds.put(dtoType, topiaId); + } + } + } + + @Override + public void end(TopiaEntity entity) { + + } + + @Override + public void visit(TopiaEntity entity, String propertyName, Class<?> type, Object value) { + if (value instanceof TopiaEntity) { + ((TopiaEntity) value).accept(this); + } + } + + @Override + public void visit(TopiaEntity entity, String propertyName, Class<?> collectionType, Class<?> type, Object value) { + + } + + @Override + public void visit(TopiaEntity entity, String propertyName, Class<?> collectionType, Class<?> type, int index, Object value) { + if (value instanceof TopiaEntity) { + ((TopiaEntity) value).accept(this); + } + } + + @Override + public void clear() { + hitIds.clear(); + typeCache.invalidateAll(); + } + } + +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.