protected void filterEntities(Map<String,File> entityNameFileMap) { Set<String> entityNameFileMapKeys = entityNameFileMap.keySet(); //filter on entityNames parameter if specified if (entityNames!=null&&!entityNames.isEmpty()) { List<String> entityNamesAsList = Arrays.asList(entityNames.split(",")); logger.info("Entities specified for TDE Generation: {} " + entityNamesAsList); //this will only keep keys in the map that are also in the entityNamesAsList entityNameFileMapKeys.retainAll(entityNamesAsList); if (entityNameFileMapKeys.isEmpty()) { logger.warn("No entities files found under {} or its sub-directories with the entity name(s) {}", hubConfig.getHubEntitiesDir(),entityNamesAsList); } } }
@Override public List<Flow> getLocalFlows() { List<Flow> flows = new ArrayList<>(); Path entitiesDir = hubConfig.getHubEntitiesDir(); File[] entities = entitiesDir.toFile().listFiles((pathname -> pathname.isDirectory())); if (entities != null) { for (File entity : entities) { String entityName = entity.getName(); flows.addAll(getLocalFlowsForEntity(entityName)); } } return flows; }
@Override public List<String> updateLegacyFlows(String fromVersion) { List<String> updatedFlows = new ArrayList<>(); File[] entityDirs = hubConfig.getHubEntitiesDir().toFile().listFiles(pathname -> pathname.isDirectory()); if (entityDirs != null) { for (File entityDir : entityDirs) { updatedFlows.addAll(scaffolding.updateLegacyFlows(fromVersion, entityDir.getName())); } } return updatedFlows; }
protected List<File> findEntityFiles() { List<File> entities = new ArrayList<>(); Path entitiesPath = hubConfig.getHubEntitiesDir(); File[] entityDirectories = entitiesPath.toFile().listFiles(pathname -> pathname.isDirectory() && !pathname.isHidden()); List<String> entityNames; if (entityDirectories != null) { entityNames = Arrays.stream(entityDirectories) .map(file -> file.getName()) .collect(Collectors.toList()); for (String entityName : entityNames) { File[] entityDefs = entitiesPath.resolve(entityName).toFile().listFiles((dir, name) -> name.endsWith(ENTITY_FILE_EXTENSION)); if (entityDefs!=null) { entities.addAll(Arrays.asList(entityDefs)); } } } return entities; }
@Override public List<String> getLegacyFlows() { List<String> oldFlows = new ArrayList<>(); Path entitiesDir = hubConfig.getHubEntitiesDir(); File[] entityDirs = entitiesDir.toFile().listFiles(pathname -> pathname.isDirectory()); if (entityDirs != null) { for (File entityDir : entityDirs) { Path inputDir = entityDir.toPath().resolve("input"); Path harmonizeDir = entityDir.toPath().resolve("harmonize"); File[] inputFlows = inputDir.toFile().listFiles((pathname) -> pathname.isDirectory() && !pathname.getName().equals("REST")); addLegacyFlowToList(oldFlows, entityDir, inputFlows); File[] harmonizeFlows = harmonizeDir.toFile().listFiles((pathname) -> pathname.isDirectory() && !pathname.getName().equals("REST")); addLegacyFlowToList(oldFlows, entityDir, harmonizeFlows); } } return oldFlows; }
private List<JsonNode> getAllEntities() { List<JsonNode> entities = new ArrayList<>(); Path entitiesPath = hubConfig.getHubEntitiesDir(); File[] entityFiles = entitiesPath.toFile().listFiles(pathname -> pathname.isDirectory() && !pathname.isHidden()); List<String> entityNames; if (entityFiles != null) { entityNames = Arrays.stream(entityFiles) .map(file -> file.getName()) .collect(Collectors.toList()); ObjectMapper objectMapper = new ObjectMapper(); try { for (String entityName : entityNames) { File[] entityDefs = entitiesPath.resolve(entityName).toFile().listFiles((dir, name) -> name.endsWith(ENTITY_FILE_EXTENSION)); for (File entityDef : entityDefs) { FileInputStream fileInputStream = new FileInputStream(entityDef); entities.add(objectMapper.readTree(fileInputStream)); fileInputStream.close(); } } } catch (IOException e) { throw new RuntimeException(e); } } return entities; }
Path entitiesPath = hubConfig.getHubEntitiesDir(); File[] entityFiles = entitiesPath.toFile().listFiles(pathname -> pathname.isDirectory() && !pathname.isHidden()); List<String> entityNames;
@Override public List<Flow> getLocalFlowsForEntity(String entityName, FlowType flowType) { Path entitiesDir = hubConfig.getHubEntitiesDir(); Path entityDir = entitiesDir.resolve(entityName); Path inputDir = entityDir.resolve("input");
@Override public void execute(CommandContext context) { AppConfig appConfig = context.getAppConfig(); DatabaseClient client = appConfig.newDatabaseClient(); EntityServicesManager mgr = new EntityServicesManager(client); CodeGenerationRequest request = createCodeGenerationRequest(); List<File> entityFiles = findEntityFiles(); if (!entityFiles.isEmpty()) { //create map of entity name -> entity definition file Map<String,File> entityNameFileMap = createEntityNameFileMap(entityFiles); logger.debug("Found the following entities->files: {} " + entityNameFileMap); filterEntities(entityNameFileMap); if (!entityNameFileMap.isEmpty()) { logger.warn("About to generate a template for the following entities: {} into directory {} ", entityNameFileMap.keySet(), hubConfig.getAppConfig().getSchemasPath()); for (File f : entityNameFileMap.values()) { GeneratedCode code = loadModelDefinition(request, f, mgr); generateExtractionTemplate(appConfig, code); } } } else { logger.info("No data hub entity files found under {} or its sub-directories.", hubConfig.getHubEntitiesDir()); } }