use of org.molgenis.util.HugeSet in project molgenis by molgenis.
the class RepositoryValidationDecorator method initReferenceValidation.
private void initReferenceValidation(ValidationResource validationResource) {
// get reference attrs
List<Attribute> refAttrs;
if (!getCapabilities().contains(VALIDATE_REFERENCE_CONSTRAINT)) {
// get reference attrs
refAttrs = stream(getEntityType().getAtomicAttributes().spliterator(), false).filter(attr -> isReferenceType(attr) && attr.getExpression() == null).collect(toList());
} else {
// validate cross-repository collection reference constraints. the decorated repository takes care of
// validating other reference constraints
String backend = dataService.getMeta().getBackend(getEntityType()).getName();
refAttrs = stream(getEntityType().getAtomicAttributes().spliterator(), false).filter(attr -> isReferenceType(attr) && attr.getExpression() == null && isDifferentBackend(backend, attr)).collect(toList());
}
// get referenced entity ids
if (!refAttrs.isEmpty()) {
Map<String, HugeSet<Object>> refEntitiesIds = new HashMap<>();
refAttrs.forEach(refAttr -> {
EntityType refEntityType = refAttr.getRefEntity();
String refEntityName = refEntityType.getId();
HugeSet<Object> refEntityIds = refEntitiesIds.get(refEntityName);
if (refEntityIds == null) {
refEntityIds = new HugeSet<>();
refEntitiesIds.put(refEntityName, refEntityIds);
Query<Entity> q = new QueryImpl<>().fetch(new Fetch().field(refEntityType.getIdAttribute().getName()));
for (Iterator<Entity> it = dataService.findAll(refEntityName, q).iterator(); it.hasNext(); ) {
refEntityIds.add(it.next().getIdValue());
}
}
});
validationResource.setRefEntitiesIds(refEntitiesIds);
}
validationResource.setSelfReferencing(refAttrs.stream().anyMatch(refAttr -> refAttr.getRefEntity().getId().equals(getEntityType().getId())));
validationResource.setRefAttrs(refAttrs);
}
Aggregations