@Test public void testProcessOfflineConfiguration() { File configFile = new File(ConfigOptions.OFFLINE_DATA_PROCESSING_RESOLVED_PATH + ConfigOptions.FILE_SEPERATOR + ConfigOptions.DATA_ENRICHMENT_TEMPLATE); Boolean resultFlag = executor.processOfflineConfiguration(configFile); assertTrue(resultFlag); }
public Boolean processOfflineConfiguration(File jsonFile) { try { try (BufferedReader reader = new BufferedReader(new FileReader(jsonFile))) { DataEnrichmentModel[] dataEnrichmentModelArray = new Gson().fromJson(reader, DataEnrichmentModel[].class); List<DataEnrichmentModel> dataEnrichmentModels = Arrays.asList(dataEnrichmentModelArray); for (DataEnrichmentModel dataEnrichmentModel : dataEnrichmentModels) { String cypherQuery = dataEnrichmentModel.getCypherQuery(); Long runSchedule = dataEnrichmentModel.getRunSchedule(); if (cypherQuery == null || cypherQuery.isEmpty() || runSchedule == null ) { log.error(dataEnrichmentModel.getQueryName() + " doesn't have either cypherQuery or runSchedule attribute."); continue; } if (isQueryScheduledToRun(dataEnrichmentModel.getRunSchedule(), dataEnrichmentModel.getLastExecutionTime(), dataEnrichmentModel.getCronSchedule())) { Boolean successFlag = executeCypherQuery(cypherQuery, dataEnrichmentModel); if (successFlag) { updateLastExecutionTime(dataEnrichmentModel); } } } try (JsonWriter writer = new JsonWriter(new FileWriter(jsonFile))) { writer.setIndent(" "); new GsonBuilder().disableHtmlEscaping().create().toJson(dataEnrichmentModels.toArray(), DataEnrichmentModel[].class, writer); } catch (IOException e) { log.error("Unable to update offline configuration file.", e); } } catch (FileNotFoundException e) { log.error("offline configuration file not found.", e); } catch (IOException e) { log.error("Unable to read offline configuration file.", e); } } catch (IllegalStateException | JsonSyntaxException ex) { log.error(jsonFile.getName() + " file is not as per expected format", ex); return Boolean.FALSE; } return Boolean.TRUE; }
OfflineDataProcessingExecutor extends TimerTask { public Boolean processOfflineConfiguration(File jsonFile) { try { try (BufferedReader reader = new BufferedReader(new FileReader(jsonFile))) { DataEnrichmentModel[] dataEnrichmentModelArray = new Gson().fromJson(reader, DataEnrichmentModel[].class); List<DataEnrichmentModel> dataEnrichmentModels = Arrays.asList(dataEnrichmentModelArray); for (DataEnrichmentModel dataEnrichmentModel : dataEnrichmentModels) { String cypherQuery = dataEnrichmentModel.getCypherQuery(); Long runSchedule = dataEnrichmentModel.getRunSchedule(); if (cypherQuery == null || cypherQuery.isEmpty() || runSchedule == null ) { log.error(dataEnrichmentModel.getQueryName() + " doesn't have either cypherQuery or runSchedule attribute."); continue; } if (isQueryScheduledToRun(dataEnrichmentModel.getRunSchedule(), dataEnrichmentModel.getLastExecutionTime(), dataEnrichmentModel.getCronSchedule())) { Boolean successFlag = executeCypherQuery(cypherQuery, dataEnrichmentModel); if (successFlag) { updateLastExecutionTime(dataEnrichmentModel); } } } try (JsonWriter writer = new JsonWriter(new FileWriter(jsonFile))) { writer.setIndent(" "); new GsonBuilder().disableHtmlEscaping().create().toJson(dataEnrichmentModels.toArray(), DataEnrichmentModel[].class, writer); } catch (IOException e) { log.error("Unable to update offline configuration file.", e); } } catch (FileNotFoundException e) { log.error("offline configuration file not found.", e); } catch (IOException e) { log.error("Unable to read offline configuration file.", e); } } catch (IllegalStateException | JsonSyntaxException ex) { log.error(jsonFile.getName() + " file is not as per expected format", ex); return Boolean.FALSE; } return Boolean.TRUE; } }
OfflineDataProcessingExecutor extends TimerTask { public Boolean processOfflineConfiguration(File jsonFile) { try { try (BufferedReader reader = new BufferedReader(new FileReader(jsonFile))) { DataEnrichmentModel[] dataEnrichmentModelArray = new Gson().fromJson(reader, DataEnrichmentModel[].class); List<DataEnrichmentModel> dataEnrichmentModels = Arrays.asList(dataEnrichmentModelArray); for (DataEnrichmentModel dataEnrichmentModel : dataEnrichmentModels) { String cypherQuery = dataEnrichmentModel.getCypherQuery(); Long runSchedule = dataEnrichmentModel.getRunSchedule(); if (cypherQuery == null || cypherQuery.isEmpty() || runSchedule == null ) { log.error(dataEnrichmentModel.getQueryName() + " doesn't have either cypherQuery or runSchedule attribute."); continue; } if (isQueryScheduledToRun(dataEnrichmentModel.getRunSchedule(), dataEnrichmentModel.getLastExecutionTime(), dataEnrichmentModel.getCronSchedule())) { Boolean successFlag = executeCypherQuery(cypherQuery, dataEnrichmentModel); if (successFlag) { updateLastExecutionTime(dataEnrichmentModel); } } } try (JsonWriter writer = new JsonWriter(new FileWriter(jsonFile))) { writer.setIndent(" "); new GsonBuilder().disableHtmlEscaping().create().toJson(dataEnrichmentModels.toArray(), DataEnrichmentModel[].class, writer); } catch (IOException e) { log.error("Unable to update offline configuration file.", e); } } catch (FileNotFoundException e) { log.error("offline configuration file not found.", e); } catch (IOException e) { log.error("Unable to read offline configuration file.", e); } } catch (IllegalStateException | JsonSyntaxException ex) { log.error(jsonFile.getName() + " file is not as per expected format", ex); return Boolean.FALSE; } return Boolean.TRUE; }  }
OfflineDataProcessingExecutor extends TimerTask { public Boolean processOfflineConfiguration(File jsonFile) { try { try (BufferedReader reader = new BufferedReader(new FileReader(jsonFile))) { DataEnrichmentModel[] dataEnrichmentModelArray = new Gson().fromJson(reader, DataEnrichmentModel[].class); List<DataEnrichmentModel> dataEnrichmentModels = Arrays.asList(dataEnrichmentModelArray); for (DataEnrichmentModel dataEnrichmentModel : dataEnrichmentModels) { String cypherQuery = dataEnrichmentModel.getCypherQuery(); Long runSchedule = dataEnrichmentModel.getRunSchedule(); if (cypherQuery == null || cypherQuery.isEmpty() || runSchedule == null ) { log.error(dataEnrichmentModel.getQueryName() + " doesn't have either cypherQuery or runSchedule attribute."); continue; } if (isQueryScheduledToRun(dataEnrichmentModel.getRunSchedule(), dataEnrichmentModel.getLastExecutionTime(), dataEnrichmentModel.getCronSchedule())) { Boolean successFlag = executeCypherQuery(cypherQuery, dataEnrichmentModel); if (successFlag) { updateLastExecutionTime(dataEnrichmentModel); } } } try (JsonWriter writer = new JsonWriter(new FileWriter(jsonFile))) { writer.setIndent(" "); new GsonBuilder().disableHtmlEscaping().create().toJson(dataEnrichmentModels.toArray(), DataEnrichmentModel[].class, writer); } catch (IOException e) { log.error("Unable to update offline configuration file.", e); } } catch (FileNotFoundException e) { log.error("offline configuration file not found.", e); } catch (IOException e) { log.error("Unable to read offline configuration file.", e); } } catch (IllegalStateException | JsonSyntaxException ex) { log.error(jsonFile.getName() + " file is not as per expected format", ex); return Boolean.FALSE; } return Boolean.TRUE; }  @Override void run(); int executeOfflineProcessing(); Boolean hasJsonFileExtension(String fileName); Boolean processOfflineConfiguration(File jsonFile); DataEnrichmentModel updateLastExecutionTime(DataEnrichmentModel dataEnrichmentModel); Boolean executeCypherQuery(String cypherQuery, DataEnrichmentModel dataEnrichmentModel); Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule); }
OfflineDataProcessingExecutor extends TimerTask { public Boolean processOfflineConfiguration(File jsonFile) { try { try (BufferedReader reader = new BufferedReader(new FileReader(jsonFile))) { DataEnrichmentModel[] dataEnrichmentModelArray = new Gson().fromJson(reader, DataEnrichmentModel[].class); List<DataEnrichmentModel> dataEnrichmentModels = Arrays.asList(dataEnrichmentModelArray); for (DataEnrichmentModel dataEnrichmentModel : dataEnrichmentModels) { String cypherQuery = dataEnrichmentModel.getCypherQuery(); Long runSchedule = dataEnrichmentModel.getRunSchedule(); if (cypherQuery == null || cypherQuery.isEmpty() || runSchedule == null ) { log.error(dataEnrichmentModel.getQueryName() + " doesn't have either cypherQuery or runSchedule attribute."); continue; } if (isQueryScheduledToRun(dataEnrichmentModel.getRunSchedule(), dataEnrichmentModel.getLastExecutionTime(), dataEnrichmentModel.getCronSchedule())) { Boolean successFlag = executeCypherQuery(cypherQuery, dataEnrichmentModel); if (successFlag) { updateLastExecutionTime(dataEnrichmentModel); } } } try (JsonWriter writer = new JsonWriter(new FileWriter(jsonFile))) { writer.setIndent(" "); new GsonBuilder().disableHtmlEscaping().create().toJson(dataEnrichmentModels.toArray(), DataEnrichmentModel[].class, writer); } catch (IOException e) { log.error("Unable to update offline configuration file.", e); } } catch (FileNotFoundException e) { log.error("offline configuration file not found.", e); } catch (IOException e) { log.error("Unable to read offline configuration file.", e); } } catch (IllegalStateException | JsonSyntaxException ex) { log.error(jsonFile.getName() + " file is not as per expected format", ex); return Boolean.FALSE; } return Boolean.TRUE; }  @Override void run(); int executeOfflineProcessing(); Boolean hasJsonFileExtension(String fileName); Boolean processOfflineConfiguration(File jsonFile); DataEnrichmentModel updateLastExecutionTime(DataEnrichmentModel dataEnrichmentModel); Boolean executeCypherQuery(String cypherQuery, DataEnrichmentModel dataEnrichmentModel); Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule);  }