private void createInputRepository(Repository<Entity> inputRepository) { // Add the original input dataset to database dataService.getMeta().addEntityType(inputRepository.getEntityType()); Repository<Entity> target = dataService.getRepository(inputRepository.getName()); inputRepository.forEachBatched(entities -> target.add(entities.stream()), BATCH_SIZE); }
@Override public void update(Stream<EntityType> entities) { delegate() .update( entities.filter( entityType -> { entityTypeValidator.validate(entityType); return true; })); }
long applyMappingToRepo(EntityMapping sourceMapping, Repository<Entity> targetRepo, Progress progress) { progress.status(format("Mapping source [%s]...", sourceMapping.getLabel())); AtomicLong counter = new AtomicLong(); boolean canAdd = targetRepo.count() == 0; dataService.getRepository(sourceMapping.getName()).forEachBatched( entities -> processBatch(sourceMapping, targetRepo, progress, counter, canAdd, entities), MAPPING_BATCH_SIZE); progress.status(format("Mapped %s [%s] entities.", counter, sourceMapping.getLabel())); return counter.get(); }
private void processBatch(EntityMapping sourceMapping, Repository<Entity> targetRepo, Progress progress, AtomicLong counter, boolean canAdd, List<Entity> entities) { List<Entity> mappedEntities = mapEntities(sourceMapping, targetRepo.getEntityType(), entities); if (canAdd) { targetRepo.add(mappedEntities.stream()); } else { targetRepo.upsertBatch(mappedEntities); } progress.increment(1); counter.addAndGet(entities.size()); }
@Override @PreAuthorize("hasAnyRole('ROLE_SU, ROLE_PLUGIN_READ_indexmanager')") public List<EntityType> getIndexedEntities() { // collect indexed repos List<EntityType> indexedEntityTypeList = new ArrayList<>(); dataService .getEntityTypeIds() .forEach( entityTypeId -> { Repository<Entity> repository = dataService.getRepository(entityTypeId); if (repository != null && repository.getCapabilities().contains(RepositoryCapability.INDEXABLE)) { indexedEntityTypeList.add(repository.getEntityType()); } }); // sort indexed repos by entity label indexedEntityTypeList.sort(Comparator.comparing(EntityType::getLabel)); return indexedEntityTypeList; }
@Override public Integer add(Stream<EntityType> entities) { return delegate() .add( entities.filter( entityType -> { entityTypeValidator.validate(entityType); return true; })); } }
if (annotator instanceof EffectCreatingAnnotator) entityTypeId = ((EffectCreatingAnnotator) annotator).getTargetEntityType(repository.getEntityType()) .getId(); entityTypeId = repository.getName();
private boolean validateFileHeader(Repository<Entity> repository) { return StreamSupport.stream(repository.getEntityType().getAttributes().spliterator(), false) .map(Attribute::getName) .anyMatch(name -> name.equalsIgnoreCase(SortaServiceImpl.DEFAULT_MATCHING_NAME_FIELD)); }
private void annotate(RepositoryAnnotator annotator, Repository<Entity> repository, DatabaseAction action) if (!repository.getCapabilities().contains(WRITABLE)) EntityType entityType = dataService.getMeta().getEntityType(repository.getName()); runAsSystem(() -> dataService.getMeta().updateEntityType(externalRepository.getEntityType())); annotator))); iterateOverEntitiesAndAnnotate(dataService.getRepository(repository.getName()), annotator, action);
/** * Searches the repository if it is available. * * @param q the {@link Query} to use * @return {@link Entity}s found * @throws NullPointerException if the repository is not available */ @Override public Iterable<Entity> findAll(Query<Entity> q) { return () -> getRepository().findAll(q).iterator(); }
@Override public void delete(Stream<Package> packageStream) { delegate() .delete( packageStream.filter( aPackage -> { packageValidator.validate(aPackage); return true; })); }
@Override public void deleteAll(Stream<Object> ids) { delegate() .deleteAll( ids.filter( id -> { if (id instanceof String) { String entityId = (String) id; scheduler.unschedule(entityId); } return true; })); }
Repository repository) EntityMetaData originalRepositoryMetaData = repository.getEntityMetaData(); DefaultAttributeMetaData repositoryCompoundAttribute = new DefaultAttributeMetaData(repository.getName(), MolgenisFieldTypes.FieldTypeEnum.COMPOUND); List<AttributeMetaData> attributeParts = new ArrayList<>();
@Override public void deleteById(Object id) { if (id instanceof String) { String entityId = (String) id; scheduler.unschedule(entityId); } delegate().deleteById(id); }
/** * Create a label for an attribute based on the attribute label in the original repository and the original * repository name itself. */ private String getMergedAttributeLabel(Repository repository, String attributeLabel) { return attributeLabel + "(" + repository.getName() + ")"; }
/** * Retrieves a single identifier from the {@link L3Cache} if the {@link Repository} is cacheable * and hasn't been touched in this transaction. * * @param query The {@link Query} * @return A single {@link Entity} or null if not found */ @Override public Entity findOne(Query<Entity> query) { if (transactionInformation.isRepositoryCompletelyClean(getEntityType()) && cacheable) { // pageSize is irrelevant for findOne, would be a waste to cache them in different entries // sort may affect which of the results is the first result, so cannot ignore that. QueryImpl<Entity> cacheKey = new QueryImpl<>(query).setPageSize(1); List<Object> ids = l3Cache.get(delegate(), cacheKey); if (ids.isEmpty()) { return null; } return delegate().findOneById(ids.get(0), query.getFetch()); } return delegate().findOne(query); } }
@Override public long count(Query<Entity> query) { query = query != null ? transformQuery(query) : null; return delegate().count(query); }
@Override public Entity findOne(Query<Entity> query) { query = query != null ? transformQuery(query) : null; return delegate().findOne(query); }
@Override public Integer add(Stream<Attribute> attrs) { return delegate() .add( attrs.filter( attr -> { attributeValidator.validate(attr, ValidationMode.ADD); return true; })); } }