Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/harmonization options #677

Merged
merged 2 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ public ResponseEntity<?> runHarmonizeFlow(
int batchSize = json.get("batchSize").asInt();
int threadCount = json.get("threadCount").asInt();
Map<String, Object> options = new HashMap<>();
Iterator<Map.Entry<String, JsonNode>> optionIter = json.get("options").fields();
Map.Entry<String, JsonNode> current;

while (optionIter.hasNext())
{
current = optionIter.next();
options.put(current.getKey(), current.getValue());
//verify that we have options, if not, pass on an empty map
if(json.get("options") != null && json.get("options").size() > 0) {
Iterator<Map.Entry<String, JsonNode>> optionIter = json.get("options").fields();
Map.Entry<String, JsonNode> current;
while (optionIter.hasNext()) {
current = optionIter.next();
options.put(current.getKey(), current.getValue());
}
}

ResponseEntity<?> resp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,47 @@ public void getInputFlowOptionsWin() throws Exception {
JSONAssert.assertEquals("{ \"input_file_path\": \"C:\\\\some\\\\crazy\\\\path\\\\to\\\\project\" }", new ObjectMapper().writeValueAsString(options), true);
}

@Test
public void runHarmonizeNoOptions() throws IOException, InterruptedException {
// Set up (not needed for other tests)
baseSetUp();
installHub();

Path projectDir = Paths.get(".", PROJECT_PATH);
Scaffolding scaffolding = new Scaffolding(projectDir.toString(), stagingClient);

scaffolding.createFlow(ENTITY, "sjs-json-harmonization-flow", FlowType.HARMONIZE,
CodeFormat.JAVASCRIPT, DataFormat.JSON);

Path harmonizeDir = projectDir.resolve("plugins/entities/" + ENTITY + "/harmonize");
FileUtil.copy(getResourceStream("flow-manager/sjs-harmonize-flow/headers.sjs"), harmonizeDir.resolve("sjs-json-harmonization-flow/headers.sjs").toFile());

getDataHub().installUserModules(true);

DocumentMetadataHandle meta = new DocumentMetadataHandle();
meta.getCollections().add(ENTITY);
installStagingDoc("/staged.json", meta, "flow-manager/staged.json");

EnvironmentConfig envConfig = new EnvironmentConfig(PROJECT_PATH, "local", "admin", "admin");
envConfig.setMlSettings(HubConfig.hubFromEnvironment(PROJECT_PATH, null));
setEnvConfig(envConfig);

ObjectMapper mapper = new ObjectMapper();
JsonNode body = mapper.readTree("{\"batchSize\":1, \"threadCount\": 1}");

ResponseEntity<?> responseEntity = ec.runHarmonizeFlow(ENTITY, "sjs-json-harmonization-flow", body);

Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
DocumentRecord doc = finalDocMgr.read("/staged.json").next();
JsonNode root = doc.getContent(new JacksonHandle()).get();
JsonNode env = root.path("envelope");
JsonNode headers = env.path("headers");
JsonNode optionNode = headers.path("test-option");
Assert.assertTrue(optionNode.isMissingNode());

uninstallHub();
}

@Test
public void runHarmonizeFlowWithOptions() throws IOException, InterruptedException {
// Set up (not needed for other tests)
Expand Down