diff --git a/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/VocabularyRepository.java b/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/VocabularyRepository.java index 5d142f62..35526e71 100644 --- a/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/VocabularyRepository.java +++ b/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/VocabularyRepository.java @@ -18,13 +18,39 @@ public class VocabularyRepository { Datastore datastore; private static final String ID = "id"; + + private List europeanaRoles; + + public List getEuropeanaRoles() { + synchronized(this) { + if(europeanaRoles==null) { + europeanaRoles=new ArrayList<>(); + europeanaRoles.addAll( + datastore.find(Vocabulary.class) + .iterator() + .toList()); + } + return europeanaRoles; + } + } /** - * retrieve records by their id - * @param vocabularyIds - * @return + * retrieve records by their id, from the in-memory collection + * @param vocabularyIds ids to search for + * @return list of Vocabularies */ public List findByUri(List vocabularyIds) { + return getEuropeanaRoles().stream() + .filter(el -> vocabularyIds.contains(el.getId())) + .toList(); + } + + /** + * retrieve records by their id + * @param vocabularyIds ids to search for + * @return list of Vocabularies + */ + public List findInDbByUri(List vocabularyIds) { List filters = new ArrayList<>(); filters.add(in(ID, vocabularyIds)); return datastore.find(Vocabulary.class) @@ -65,4 +91,5 @@ public void dropCollection() { public long countRecords() { return datastore.find(Vocabulary.class).count(); } + } \ No newline at end of file diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/config/AppAutoconfig.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/config/AppAutoconfig.java index 77b5bbbd..27dc563d 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/config/AppAutoconfig.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/config/AppAutoconfig.java @@ -86,7 +86,7 @@ public void ensureDatabaseInitialization() throws ApplicationInitializationExcep roles.add(vocab); } vocabRepository.saveBulk(roles); - } + } } @Bean(name = BEAN_EM_DATA_SOURCES)