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

adding support for dot and bracket parameter notation #200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -803,8 +803,16 @@ private List<String> buildAvailableParamList(String workFlowId, RevisionEntity r
propertyManager.buildGlobalProperties(globalProperties);

for (Map.Entry<String, String> globalProperty : globalProperties.entrySet()) {
parameters.add("global.params." + globalProperty.getKey());
parameters.add("params." + globalProperty.getKey());
if (!globalProperty.getKey().contains(".")) {
parameters.add("global.params." + globalProperty.getKey());
parameters.add("params." + globalProperty.getKey());
}

parameters.add("global.params['" + globalProperty.getKey() + "']");
parameters.add("params['" + globalProperty.getKey() + "']");

parameters.add("global.params[\"" + globalProperty.getKey() + "\"]");
parameters.add("params[\"" + globalProperty.getKey() + "\"]");
}
}

Expand All @@ -814,23 +822,47 @@ private List<String> buildAvailableParamList(String workFlowId, RevisionEntity r
propertyManager.buildTeamProperties(teamProperties, workflow.getId());

for (Map.Entry<String, String> teamProperty : teamProperties.entrySet()) {
parameters.add("team.params." + teamProperty.getKey());
parameters.add("params." + teamProperty.getKey());
if (!teamProperty.getKey().contains(".")) {
parameters.add("team.params." + teamProperty.getKey());
parameters.add("params." + teamProperty.getKey());
}

parameters.add("team.params['" + teamProperty.getKey() + "']");
parameters.add("params['" + teamProperty.getKey() + "']");

parameters.add("team.params[\"" + teamProperty.getKey() + "\"]");
parameters.add("params[\"" + teamProperty.getKey() + "\"]");
}
}

Map<String, String> workflowProperties = new HashMap<>();
propertyManager.buildWorkflowProperties(workflowProperties, null, workflow.getId());
for (Map.Entry<String, String> workflowProperty : workflowProperties.entrySet()) {
parameters.add("workflow.params." + workflowProperty.getKey());
parameters.add("params." + workflowProperty.getKey());
if (!workflowProperty.getKey().contains(".")) {
parameters.add("workflow.params." + workflowProperty.getKey());
parameters.add("params." + workflowProperty.getKey());
}

parameters.add("workflow.params['" + workflowProperty.getKey() + "']");
parameters.add("params['" + workflowProperty.getKey() + "']");

parameters.add("workflow.params[\"" + workflowProperty.getKey() + "\"]");
parameters.add("params[\"" + workflowProperty.getKey() + "\"]");
}

Map<String, String> systemProperties = new HashMap<>();
propertyManager.buildSystemProperties(null, null, workflow.getId(), systemProperties);
for (Map.Entry<String, String> systemProperty : systemProperties.entrySet()) {
parameters.add("system.params." + systemProperty.getKey());
parameters.add("params." + systemProperty.getKey());
if (!systemProperty.getKey().contains(".")) {
parameters.add("system.params." + systemProperty.getKey());
parameters.add("params." + systemProperty.getKey());
}

parameters.add("system.params['" + systemProperty.getKey() + "']");
parameters.add("params['" + systemProperty.getKey() + "']");

parameters.add("system.params[\"" + systemProperty.getKey() + "\"]");
parameters.add("params[\"" + systemProperty.getKey() + "\"]");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,34 @@ public class WorkflowControllerTests extends FlowTests {
public void testInternalWorkflowListing() {
List<WorkflowShortSummary> summaryList = internalController.getAllWorkflows();

assertNotNull(summaryList);
assertEquals(18, summaryList.size());
assertNotNull(summaryList);
assertEquals(18, summaryList.size());
}

@Test
public void testGetWorkflowLatestVersion() {

FlowWorkflowRevision entity = controller.getWorkflowLatestVersion("5d1a188af6ca2c00014c4314");

assertEquals("5d1a188af6ca2c00014c4314", entity.getWorkFlowId());
assertEquals("5d1a188af6ca2c00014c4314", entity.getWorkFlowId());
}

@Test
public void testGetWorkflowVersion() {
FlowWorkflowRevision entity = controller.getWorkflowVersion("5d1a188af6ca2c00014c4314", 1L);
assertEquals(1L, entity.getVersion());
assertEquals("5d1a188af6ca2c00014c4314", entity.getWorkFlowId());
assertEquals(1L, entity.getVersion());
assertEquals("5d1a188af6ca2c00014c4314", entity.getWorkFlowId());
}

@Test
public void testGetWorkflowWithId() {
WorkflowSummary summary = controller.getWorkflowWithId("5d1a188af6ca2c00014c4314");
assertEquals("5d1a188af6ca2c00014c4314", summary.getId());
Optional<WorkflowProperty> passProp = summary.getProperties().stream()
.filter(f -> FieldType.PASSWORD.value().equals(f.getType())).findAny();
if (passProp.isPresent()) {
assertNull(passProp.get().getDefaultValue());
}
assertEquals("5d1a188af6ca2c00014c4314", summary.getId());
Optional<WorkflowProperty> passProp = summary.getProperties().stream()
.filter(f -> FieldType.PASSWORD.value().equals(f.getType())).findAny();
if (passProp.isPresent()) {
assertNull(passProp.get().getDefaultValue());
}
}

@Test
Expand All @@ -107,8 +107,8 @@ public void testInsertWorkflow() {
entity.setName("TestWorkflow");
entity.setStatus(WorkflowStatus.deleted);
WorkflowSummary summary = controller.insertWorkflow(entity);
assertEquals("TestWorkflow", summary.getName());
assertEquals(WorkflowStatus.active, summary.getStatus());
assertEquals("TestWorkflow", summary.getName());
assertEquals(WorkflowStatus.active, summary.getStatus());

}

Expand All @@ -123,8 +123,8 @@ public void testinsertWorkflow() throws IOException {

FlowWorkflowRevision revisionEntity =
controller.insertWorkflow("5d1a188af6ca2c00014c4314", revision);
assertEquals(2L, revisionEntity.getVersion());
assertEquals("test", revisionEntity.getMarkdown());
assertEquals(2L, revisionEntity.getVersion());
assertEquals("test", revisionEntity.getMarkdown());
}

@Test
Expand All @@ -135,8 +135,8 @@ public void testUpdateWorkflow() {
entity.setStorage(new Storage());
entity.getStorage().setActivity(new ActivityStorage());
WorkflowSummary updatedEntity = controller.updateWorkflow(entity);
assertEquals("5d1a188af6ca2c00014c4314", updatedEntity.getId());
assertEquals("TestUpdateWorkflow", updatedEntity.getName());
assertEquals("5d1a188af6ca2c00014c4314", updatedEntity.getId());
assertEquals("TestUpdateWorkflow", updatedEntity.getName());
}

@Test
Expand All @@ -155,15 +155,15 @@ public void testUpdateWorkflowProperties() {
WorkflowEntity entity =
controller.updateWorkflowProperties("5d1a188af6ca2c00014c4314", properties);

assertNotNull(entity.getProperties());
assertEquals(1, entity.getProperties().size());
assertEquals("testDescription", entity.getProperties().get(0).getDescription());
assertNotNull(entity.getProperties());
assertEquals(1, entity.getProperties().size());
assertEquals("testDescription", entity.getProperties().get(0).getDescription());

}

@Test
public void testUpdateWorkflowPasswordProperty() {

WorkflowProperty passProperty = new WorkflowProperty();
passProperty.setKey("myPassword");
passProperty.setDescription("testDescriptionPass");
Expand All @@ -177,17 +177,18 @@ public void testUpdateWorkflowPasswordProperty() {

WorkflowEntity entity =
controller.updateWorkflowProperties("5d1a188af6ca2c00014c4314", properties);
Optional<WorkflowProperty> passProp = entity.getProperties().stream().filter(f->FieldType.PASSWORD.value().equals(f.getType())).findAny();
assertTrue(passProp.isPresent());
assertNull(passProp.get().getDefaultValue());
assertTrue(passProp.get().isHiddenValue());
Optional<WorkflowProperty> passProp = entity.getProperties().stream()
.filter(f -> FieldType.PASSWORD.value().equals(f.getType())).findAny();
assertTrue(passProp.isPresent());
assertNull(passProp.get().getDefaultValue());
assertTrue(passProp.get().isHiddenValue());
}

@Test
public void testExportWorkflow() {
ResponseEntity<InputStreamResource> export =
controller.exportWorkflow("5d1a188af6ca2c00014c4314");
assertEquals(HttpStatus.OK, export.getStatusCode());
assertEquals(HttpStatus.OK, export.getStatusCode());
}

@Test
Expand Down Expand Up @@ -221,7 +222,7 @@ public void testImportWorkflowUpdate() throws IOException {
controller.importWorkflow(export, true, "", WorkflowScope.team);

WorkflowSummary summary = controller.getWorkflowWithId("5d1a188af6ca2c00014c4314");
assertEquals("test", summary.getDescription());
assertEquals("test", summary.getDescription());
}

@Test
Expand All @@ -232,20 +233,20 @@ public void testImportWorkflow() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
WorkflowExport importedWorkflow = objectMapper.readValue(json, WorkflowExport.class);
controller.importWorkflow(importedWorkflow, false, "", WorkflowScope.team);
assertTrue(true);
assertTrue(true);
}

@Test
public void testGenerateWebhookToken() {

GenerateTokenResponse response = controller.createToken("5d1a188af6ca2c00014c4314", "Token");
assertNotEquals("", response.getToken());
assertNotEquals("", response.getToken());
}

@Test
public void testDeleteWorkflow() {
controller.deleteWorkflowWithId("5d1a188af6ca2c00014c4314");
assertEquals(WorkflowStatus.deleted,
assertEquals(WorkflowStatus.deleted,
controller.getWorkflowWithId("5d1a188af6ca2c00014c4314").getStatus());
}

Expand All @@ -254,8 +255,8 @@ public void testViewChangeLog() {
List<RevisionResponse> response =
controller.viewChangelog(getOptionalString("5d1a188af6ca2c00014c4314"),
getOptionalOrder(Direction.ASC), getOptionalString("sort"), 0, 2147483647);
assertEquals(1, response.size());
assertEquals(1, response.get(0).getVersion());
assertEquals(1, response.size());
assertEquals(1, response.get(0).getVersion());
}

@Test
Expand All @@ -269,11 +270,11 @@ public void testUpdateWorkflowTriggers() {
webhook.setToken("token");

WorkflowSummary entity = controller.getWorkflowWithId("5d1a188af6ca2c00014c4314");
assertNotNull(entity.getTriggers());
assertNotNull(entity.getTriggers().getWebhook());
assertEquals(false, entity.getTriggers().getScheduler().getEnable());
assertEquals(true, entity.getTriggers().getWebhook().getEnable());
assertEquals("A5DF2F840C0DFF496D516B4F75BD947C9BC44756A8AE8571FC45FCB064323641",
assertNotNull(entity.getTriggers());
assertNotNull(entity.getTriggers().getWebhook());
assertEquals(false, entity.getTriggers().getScheduler().getEnable());
assertEquals(true, entity.getTriggers().getWebhook().getEnable());
assertEquals("A5DF2F840C0DFF496D516B4F75BD947C9BC44756A8AE8571FC45FCB064323641",
entity.getTriggers().getWebhook().getToken());


Expand All @@ -282,26 +283,26 @@ public void testUpdateWorkflowTriggers() {

WorkflowSummary updatedEntity = controller.updateWorkflow(entity);

assertEquals("5d1a188af6ca2c00014c4314", updatedEntity.getId());
assertEquals("5d1a188af6ca2c00014c4314", updatedEntity.getId());

assertEquals(true, updatedEntity.getTriggers().getScheduler().getEnable());
assertEquals(false, updatedEntity.getTriggers().getWebhook().getEnable());
assertEquals("token", updatedEntity.getTriggers().getWebhook().getToken());
assertEquals(true, updatedEntity.getTriggers().getScheduler().getEnable());
assertEquals(false, updatedEntity.getTriggers().getWebhook().getEnable());
assertEquals("token", updatedEntity.getTriggers().getWebhook().getToken());
}

@Test
@Disabled
public void testUpdateWorkflowTriggerNull() {

WorkflowSummary entity = controller.getWorkflowWithId("5d1a188af6ca2c00014c4314");
assertEquals(false, entity.getTriggers().getScheduler().getEnable());
assertEquals(false, entity.getTriggers().getScheduler().getEnable());
entity.setTriggers(null);
assertNull(entity.getTriggers());
assertNull(entity.getTriggers());

WorkflowSummary updatedEntity = controller.updateWorkflow(entity);

assertEquals("5d1a188af6ca2c00014c4314", updatedEntity.getId());
assertEquals(false, updatedEntity.getTriggers().getScheduler().getEnable());
assertEquals("5d1a188af6ca2c00014c4314", updatedEntity.getId());
assertEquals(false, updatedEntity.getTriggers().getScheduler().getEnable());

}

Expand All @@ -323,36 +324,45 @@ Optional<Direction> getOptionalOrder(Direction direction) {
public void testMissingTemplateVersionRevision() {

FlowWorkflowRevision entity = controller.getWorkflowVersion("5d7177af2c57250007e3d7a1", 1l);
assertNotNull(entity);
assertNotNull(entity);
verifyTemplateVersions(entity);
}

@Test
public void testMissingTemplateVersionLatestRevision() {

FlowWorkflowRevision entity = controller.getWorkflowLatestVersion("5d7177af2c57250007e3d7a1");
assertNotNull(entity);
assertNotNull(entity);
verifyTemplateVersions(entity);
}

@Test
public void testAvaliableParameters() {
List<String> parameters = controller.getWorkflowParameters("5d1a188af6ca2c00014c4314");
assertEquals(16, parameters.size());
assertEquals("workflow.params.password", parameters.get(0));
assertEquals("params.password", parameters.get(1));
assertEquals("workflow.params.hello", parameters.get(2));
assertEquals("params.hello", parameters.get(3));
assertEquals("system.params.workflow-id", parameters.get(4));
assertEquals("params.workflow-id", parameters.get(5));
assertEquals(52, parameters.size());

assertEquals("workflow.params['my.param']", parameters.get(0));
assertEquals("params['my.param']", parameters.get(1));
assertEquals("workflow.params[\"my.param\"]", parameters.get(2));
assertEquals("params[\"my.param\"]", parameters.get(3));
assertEquals("workflow.params.password", parameters.get(4));
assertEquals("params.password", parameters.get(5));
assertEquals("workflow.params['password']", parameters.get(6));
assertEquals("params['password']", parameters.get(7));
assertEquals("workflow.params[\"password\"]", parameters.get(8));
assertEquals("params[\"password\"]", parameters.get(9));
assertEquals("workflow.params.hello", parameters.get(10));
assertEquals("params.hello", parameters.get(11));
assertEquals("system.params.workflow-id", parameters.get(16));
assertEquals("params.workflow-id", parameters.get(17));

}

private void verifyTemplateVersions(FlowWorkflowRevision entity) {
RestConfig config = entity.getConfig();
for (io.boomerang.model.projectstormv5.ConfigNodes taskNode : config.getNodes()) {
if (taskNode.getTaskId() != null) {
assertNotNull(taskNode.getTaskVersion());
assertNotNull(taskNode.getTaskVersion());
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/db/flow_workflows/workflow1.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"type": "text",
"required": false
},
{
"description": "test param",
"key": "my.param",
"label": "test param",
"type": "text",
"required": false
},
{
"required": false,
"placeholder": null,
Expand Down