@SuppressWarnings("unchecked") @Test public void testGetAutoLoadFiles() throws UnknownHostException { Map<String, Object> tenantsForPreloading = new HashMap<String, Object>(); tenantsForPreloading.put(lzPath1, Arrays.asList("smallDataSet.xml", "mediumDataSet.xml")); Entity tenant = createTenantEntity(); List<Map<String, Object>> landingZone = (List<Map<String, Object>>) tenant.getBody().get( TenantMongoDA.LANDING_ZONE); Map<String, Object> preloadDef = new HashMap<String, Object>(); preloadDef.put(TenantMongoDA.PRELOAD_STATUS, "ready"); preloadDef.put(TenantMongoDA.PRELOAD_FILES, Arrays.asList("smallDataSet.xml", "mediumDataSet.xml")); landingZone.get(0).put(TenantMongoDA.PRELOAD_DATA, preloadDef); when(mockRepository.findAll(eq("tenant"), any(NeutralQuery.class))).thenReturn(Arrays.asList(tenant)); when(mockRepository.doUpdate(eq("tenant"), any(NeutralQuery.class), any(Update.class))).thenReturn(true); assertEquals(tenantsForPreloading, tenantDA.getPreloadFiles("ingestion_server_host")); verify(mockRepository).doUpdate(eq("tenant"), any(NeutralQuery.class), argThat(new ArgumentMatcher<Update>() { @Override public boolean matches(Object argument) { Update expectedUpdate = Update.update("body." + TenantMongoDA.LANDING_ZONE + ".$." + TenantMongoDA.PRELOAD_DATA + "." + TenantMongoDA.PRELOAD_STATUS, "started"); return ((Update) argument).getUpdateObject().equals(expectedUpdate.getUpdateObject()); } })); }
@SuppressWarnings("unchecked") @Override public Map<String, List<String>> getPreloadFiles(String ingestionServer) { Iterable<Entity> tenants = entityRepository.findAll( TENANT_COLLECTION, new NeutralQuery(byServerQuery(ingestionServer)).addCriteria(PRELOAD_READY_CRITERIA).setIncludeFields( Arrays.asList(LANDING_ZONE + "." + PRELOAD_DATA, LANDING_ZONE_PATH, LANDING_ZONE_INGESTION_SERVER))); Map<String, List<String>> fileMap = new HashMap<String, List<String>>(); for (Entity tenant : tenants) { if (markPreloadStarted(tenant)) { List<Map<String, Object>> landingZones = (List<Map<String, Object>>) tenant.getBody().get(LANDING_ZONE); for (Map<String, Object> landingZone : landingZones) { if (landingZone.get(INGESTION_SERVER).equals(ingestionServer)) { List<String> files = new ArrayList<String>(); Map<String, Object> preloadData = (Map<String, Object>) landingZone.get(PRELOAD_DATA); if (preloadData != null) { if ("ready".equals(preloadData.get(PRELOAD_STATUS))) { files.addAll((Collection<? extends String>) preloadData.get(PRELOAD_FILES)); } fileMap.put((String) landingZone.get(PATH), files); } } } } } return fileMap; }
TenantMongoDA implements TenantDA { @SuppressWarnings("unchecked") @Override public Map<String, List<String>> getPreloadFiles(String ingestionServer) { Iterable<Entity> tenants = entityRepository.findAll( TENANT_COLLECTION, new NeutralQuery(byServerQuery(ingestionServer)).addCriteria(PRELOAD_READY_CRITERIA).setIncludeFields( Arrays.asList(LANDING_ZONE + "." + PRELOAD_DATA, LANDING_ZONE_PATH, LANDING_ZONE_INGESTION_SERVER))); Map<String, List<String>> fileMap = new HashMap<String, List<String>>(); for (Entity tenant : tenants) { if (markPreloadStarted(tenant)) { List<Map<String, Object>> landingZones = (List<Map<String, Object>>) tenant.getBody().get(LANDING_ZONE); for (Map<String, Object> landingZone : landingZones) { if (landingZone.get(INGESTION_SERVER).equals(ingestionServer)) { List<String> files = new ArrayList<String>(); Map<String, Object> preloadData = (Map<String, Object>) landingZone.get(PRELOAD_DATA); if (preloadData != null) { if ("ready".equals(preloadData.get(PRELOAD_STATUS))) { files.addAll((Collection<? extends String>) preloadData.get(PRELOAD_FILES)); } fileMap.put((String) landingZone.get(PATH), files); } } } } } return fileMap; } }
TenantMongoDA implements TenantDA { @SuppressWarnings("unchecked") @Override public Map<String, List<String>> getPreloadFiles(String ingestionServer) { Iterable<Entity> tenants = entityRepository.findAll( TENANT_COLLECTION, new NeutralQuery(byServerQuery(ingestionServer)).addCriteria(PRELOAD_READY_CRITERIA).setIncludeFields( Arrays.asList(LANDING_ZONE + "." + PRELOAD_DATA, LANDING_ZONE_PATH, LANDING_ZONE_INGESTION_SERVER))); Map<String, List<String>> fileMap = new HashMap<String, List<String>>(); for (Entity tenant : tenants) { if (markPreloadStarted(tenant)) { List<Map<String, Object>> landingZones = (List<Map<String, Object>>) tenant.getBody().get(LANDING_ZONE); for (Map<String, Object> landingZone : landingZones) { if (landingZone.get(INGESTION_SERVER).equals(ingestionServer)) { List<String> files = new ArrayList<String>(); Map<String, Object> preloadData = (Map<String, Object>) landingZone.get(PRELOAD_DATA); if (preloadData != null) { if ("ready".equals(preloadData.get(PRELOAD_STATUS))) { files.addAll((Collection<? extends String>) preloadData.get(PRELOAD_FILES)); } fileMap.put((String) landingZone.get(PATH), files); } } } } } return fileMap; }  }
TenantMongoDA implements TenantDA { @SuppressWarnings("unchecked") @Override public Map<String, List<String>> getPreloadFiles(String ingestionServer) { Iterable<Entity> tenants = entityRepository.findAll( TENANT_COLLECTION, new NeutralQuery(byServerQuery(ingestionServer)).addCriteria(PRELOAD_READY_CRITERIA).setIncludeFields( Arrays.asList(LANDING_ZONE + "." + PRELOAD_DATA, LANDING_ZONE_PATH, LANDING_ZONE_INGESTION_SERVER))); Map<String, List<String>> fileMap = new HashMap<String, List<String>>(); for (Entity tenant : tenants) { if (markPreloadStarted(tenant)) { List<Map<String, Object>> landingZones = (List<Map<String, Object>>) tenant.getBody().get(LANDING_ZONE); for (Map<String, Object> landingZone : landingZones) { if (landingZone.get(INGESTION_SERVER).equals(ingestionServer)) { List<String> files = new ArrayList<String>(); Map<String, Object> preloadData = (Map<String, Object>) landingZone.get(PRELOAD_DATA); if (preloadData != null) { if ("ready".equals(preloadData.get(PRELOAD_STATUS))) { files.addAll((Collection<? extends String>) preloadData.get(PRELOAD_FILES)); } fileMap.put((String) landingZone.get(PATH), files); } } } } } return fileMap; }  @Override List<String> getLzPaths(); @Override String getTenantId(String lzPath); @Override void insertTenant(TenantRecord tenant); @Override @SuppressWarnings("unchecked") String getTenantEdOrg(String lzPath); Repository<Entity> getEntityRepository(); void setEntityRepository(Repository<Entity> entityRepository); @SuppressWarnings("unchecked") @Override Map<String, List<String>> getPreloadFiles(String ingestionServer); @Override boolean tenantDbIsReady(String tenantId); @Override void setTenantReadyFlag(String tenantId); @Override void unsetTenantReadyFlag(String tenantId); @Override boolean updateAndAquireOnboardingLock(String tenantId); @Override void removeInvalidTenant(String lzPath); @Override Map<String, List<String>> getPreloadFiles(); @Override List<String> getAllTenantDbs(); }
TenantMongoDA implements TenantDA { @SuppressWarnings("unchecked") @Override public Map<String, List<String>> getPreloadFiles(String ingestionServer) { Iterable<Entity> tenants = entityRepository.findAll( TENANT_COLLECTION, new NeutralQuery(byServerQuery(ingestionServer)).addCriteria(PRELOAD_READY_CRITERIA).setIncludeFields( Arrays.asList(LANDING_ZONE + "." + PRELOAD_DATA, LANDING_ZONE_PATH, LANDING_ZONE_INGESTION_SERVER))); Map<String, List<String>> fileMap = new HashMap<String, List<String>>(); for (Entity tenant : tenants) { if (markPreloadStarted(tenant)) { List<Map<String, Object>> landingZones = (List<Map<String, Object>>) tenant.getBody().get(LANDING_ZONE); for (Map<String, Object> landingZone : landingZones) { if (landingZone.get(INGESTION_SERVER).equals(ingestionServer)) { List<String> files = new ArrayList<String>(); Map<String, Object> preloadData = (Map<String, Object>) landingZone.get(PRELOAD_DATA); if (preloadData != null) { if ("ready".equals(preloadData.get(PRELOAD_STATUS))) { files.addAll((Collection<? extends String>) preloadData.get(PRELOAD_FILES)); } fileMap.put((String) landingZone.get(PATH), files); } } } } } return fileMap; }  @Override List<String> getLzPaths(); @Override String getTenantId(String lzPath); @Override void insertTenant(TenantRecord tenant); @Override @SuppressWarnings("unchecked") String getTenantEdOrg(String lzPath); Repository<Entity> getEntityRepository(); void setEntityRepository(Repository<Entity> entityRepository); @SuppressWarnings("unchecked") @Override Map<String, List<String>> getPreloadFiles(String ingestionServer); @Override boolean tenantDbIsReady(String tenantId); @Override void setTenantReadyFlag(String tenantId); @Override void unsetTenantReadyFlag(String tenantId); @Override boolean updateAndAquireOnboardingLock(String tenantId); @Override void removeInvalidTenant(String lzPath); @Override Map<String, List<String>> getPreloadFiles(); @Override List<String> getAllTenantDbs(); static final String TENANT_ID; static final String DB_NAME; static final String INGESTION_SERVER; static final String PATH; static final String LANDING_ZONE; static final String PRELOAD_DATA; static final String PRELOAD_STATUS; static final String PRELOAD_FILES; static final String TENANT_COLLECTION; static final String TENANT_TYPE; static final String EDUCATION_ORGANIZATION; static final String DESC; static final String ALL_STATUS_FIELDS; static final String STATUS_FIELD; }