Commit d4a9b699 authored by LAVENIER's avatar LAVENIER
Browse files

[fix] Referential: ignore some classes when computing lastUpdateDate...

[fix] Referential: ignore some classes when computing lastUpdateDate (ExtractionProduct, SystemVersion, etc.)
parent c83fe22b
......@@ -23,7 +23,6 @@ package net.sumaris.core.dao.referential;
*/
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import net.sumaris.core.dao.technical.SortDirection;
import net.sumaris.core.model.administration.programStrategy.AcquisitionLevel;
import net.sumaris.core.model.administration.programStrategy.Program;
......@@ -56,11 +55,11 @@ import net.sumaris.core.vo.referential.ReferentialTypeVO;
import net.sumaris.core.vo.referential.ReferentialVO;
import java.util.*;
import java.util.stream.Collectors;
public interface ReferentialDao {
Map<String, Class<? extends IReferentialEntity>> REFERENTIAL_CLASSES = Maps.uniqueIndex(
ImmutableList.of(
List<Class<? extends IReferentialEntity>> REFERENTIAL_CLASSES = ImmutableList.of(
Status.class,
Department.class,
Location.class,
......@@ -113,17 +112,30 @@ public interface ReferentialDao {
// Technical
SystemVersion.class,
OriginItemType.class
), Class::getSimpleName);
//interface QueryVisitor<R, T> {
// Expression<Boolean> apply(CriteriaQuery<R> query, Root<T> root);
//}
);
List<Class<? extends IReferentialEntity>> LAST_UPDATE_DATE_CLASSES_EXCLUDES = ImmutableList.of(
// Product
ExtractionProduct.class,
ExtractionProductTable.class,
// Software
Software.class,
// Technical
SystemVersion.class
);
Collection<String> LAST_UPDATE_DATE_ENTITY_NAMES = REFERENTIAL_CLASSES
.stream().filter(c -> !LAST_UPDATE_DATE_CLASSES_EXCLUDES.contains(c))
.map(Class::getSimpleName)
.collect(Collectors.toList());
ReferentialVO get(String entityName, int id);
ReferentialVO get(Class<? extends IReferentialEntity> entityClass, int id);
Date getLastUpdateDate();
default Date getLastUpdateDate() {
return getLastUpdateDate(LAST_UPDATE_DATE_ENTITY_NAMES);
}
Date getLastUpdateDate(Collection<String> entityNames);
......
......@@ -24,6 +24,7 @@ package net.sumaris.core.dao.referential;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import net.sumaris.core.dao.cache.CacheNames;
import net.sumaris.core.dao.technical.Daos;
import net.sumaris.core.dao.technical.SortDirection;
......@@ -84,7 +85,9 @@ public class ReferentialDaoImpl
private static final Logger log = LoggerFactory.getLogger(ReferentialDaoImpl.class);
private final Map<String, Class<? extends IReferentialEntity>> REFERENTIAL_CLASSES_BY_NAME = Maps.uniqueIndex(
REFERENTIAL_CLASSES,
Class::getSimpleName);
private final Map<String, PropertyDescriptor> levelPropertyNameMap = initLevelPropertyNameMap();
......@@ -128,7 +131,7 @@ public class ReferentialDaoImpl
Map<String, PropertyDescriptor> result = new HashMap<>();
// Detect level properties, by name
REFERENTIAL_CLASSES.values().forEach((clazz) -> {
REFERENTIAL_CLASSES.forEach((clazz) -> {
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(clazz);
Arrays.stream(pds)
.filter(propertyDescriptor -> propertyDescriptor.getName().matches("^.*[Ll]evel([A−Z].*)?$"))
......@@ -219,11 +222,6 @@ public class ReferentialDaoImpl
return result == null ? Optional.empty() : Optional.of(toVO(entityName, result));
}
@Override
public Date getLastUpdateDate() {
return getLastUpdateDate(REFERENTIAL_CLASSES.keySet());
}
@Override
public Date getLastUpdateDate(Collection<String> entityNames) {
return entityNames.parallelStream()
......@@ -243,7 +241,7 @@ public class ReferentialDaoImpl
@Override
@Cacheable(cacheNames = CacheNames.REFERENTIAL_TYPES)
public List<ReferentialTypeVO> getAllTypes() {
return REFERENTIAL_CLASSES.keySet().stream()
return REFERENTIAL_CLASSES_BY_NAME.keySet().stream()
.map(this::getTypeByEntityName)
.collect(Collectors.toList());
}
......@@ -770,7 +768,7 @@ public class ReferentialDaoImpl
Preconditions.checkNotNull(entityName);
// Get entity class from entityName
Class<? extends IReferentialEntity> entityClass = REFERENTIAL_CLASSES.get(entityName);
Class<? extends IReferentialEntity> entityClass = REFERENTIAL_CLASSES_BY_NAME.get(entityName);
if (entityClass == null)
throw new IllegalArgumentException(String.format("Referential entity [%s] not exists", entityName));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment