Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
add select parameter type
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardW98 authored and openshift-merge-robot committed Apr 17, 2023
1 parent dad7aee commit 3d3f875
Show file tree
Hide file tree
Showing 45 changed files with 304 additions and 484 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.redhat.parodos.workflow.annotation;

import com.redhat.parodos.workflow.parameter.WorkFlowParameterType;
import com.redhat.parodos.workflow.parameter.WorkParameterType;

import static java.lang.annotation.ElementType.METHOD;

Expand All @@ -38,7 +38,7 @@

String description();

WorkFlowParameterType type();
WorkParameterType type();

boolean optional();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WorkFlowParameter {
public class WorkParameter {

private String key;

private WorkFlowParameterType type;
private WorkParameterType type;

private String description;

private boolean optional;

private List<String> selectOptions;

private Map<String, Object> jsonSchemaOptions;

public Map<String, Object> getAsJsonSchema() {
if (this.getType() == null) {
return Map.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.redhat.parodos.workflow.parameter;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -24,9 +25,17 @@
* @author Annel Ketcha (Github: anludke)
*
*/
public enum WorkFlowParameterType {
public enum WorkParameterType {

PASSWORD, TEXT, EMAIL, DATE, NUMBER, URL;
PASSWORD, TEXT, EMAIL, DATE, NUMBER, URL, SELECT, MULTI_SELECT;

private EnumSet<WorkParameterType> selectedTypes() {
return EnumSet.of(SELECT, MULTI_SELECT);
}

public boolean isSelect() {
return selectedTypes().contains(this);
}

public Map<String, Object> getAsJsonSchema() {
Map<String, Object> properties = new HashMap<>();
Expand Down Expand Up @@ -54,6 +63,12 @@ public Map<String, Object> getAsJsonSchema() {
properties.put("type", "string");
properties.put("format", "date");
break;
case SELECT:
properties.put("type", "select");
break;
case MULTI_SELECT:
properties.put("type", "multi-select");
break;
default:
throw new IllegalArgumentException("Invalid parameter type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@
*/
package com.redhat.parodos.workflow.task;

import com.redhat.parodos.workflow.task.enums.WorkFlowTaskOutput;
import com.redhat.parodos.workflow.parameter.WorkParameter;
import com.redhat.parodos.workflows.work.Work;
import lombok.NonNull;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.redhat.parodos.workflow.task.enums.WorkFlowTaskOutput;
import com.redhat.parodos.workflow.task.parameter.WorkFlowTaskParameter;
import com.redhat.parodos.workflows.work.Work;

import lombok.NonNull;

/**
* Basic Contract for Work in the Infrastructure Service
*
* @author Luke Shannon (Github: lshannon)
* @author Richard Wang (Github: richardW98)
*
*/
public interface WorkFlowTask extends Work {

Expand All @@ -43,7 +41,7 @@ public interface WorkFlowTask extends Work {
* WorkContext
*/
@NonNull
default List<WorkFlowTaskParameter> getWorkFlowTaskParameters() {
default List<WorkParameter> getWorkFlowTaskParameters() {
return Collections.emptyList();
}

Expand All @@ -59,22 +57,21 @@ default List<WorkFlowTaskOutput> getWorkFlowTaskOutputs() {

default HashMap<String, Map<String, Object>> getAsJsonSchema() {
HashMap<String, Map<String, Object>> result = new HashMap<>();
for (WorkFlowTaskParameter workFlowTaskParameter : this.getWorkFlowTaskParameters()) {
if (workFlowTaskParameter == null) {
for (WorkParameter workParameter : this.getWorkFlowTaskParameters()) {
if (workParameter == null || workParameter.getType() == null) {
continue;
}

if (workFlowTaskParameter.getType() == null) {
continue;
Map<String, Object> properties = workParameter.getType().getAsJsonSchema();
properties.put("required", !workParameter.isOptional());
properties.put("description", workParameter.getDescription());
if (workParameter.getType().isSelect() && workParameter.getSelectOptions() != null) {
properties.put("enum", workParameter.getSelectOptions());
}

Map<String, Object> properties = workFlowTaskParameter.getType().getAsJsonSchema();
properties.put("required", !workFlowTaskParameter.isOptional());
properties.put("description", workFlowTaskParameter.getDescription());
if (workFlowTaskParameter.getJsonSchemaOptions() != null) {
properties.putAll(workFlowTaskParameter.getJsonSchemaOptions());
if (workParameter.getJsonSchemaOptions() != null) {
properties.putAll(workParameter.getJsonSchemaOptions());
}
result.put(workFlowTaskParameter.getKey(), properties);
result.put(workParameter.getKey(), properties);
}
return result;
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.util.Map;

public class WorkFlowParameterTest extends TestCase {
public class WorkParameterTest extends TestCase {

String key = "key";

Expand All @@ -13,8 +13,8 @@ public class WorkFlowParameterTest extends TestCase {
public void testGetAsJsonSchemaWithValidData() {

// given
WorkFlowParameter parameters = WorkFlowParameter.builder().key(key).description(description)
.type(WorkFlowParameterType.TEXT).build();
WorkParameter parameters = WorkParameter.builder().key(key).description(description)
.type(WorkParameterType.TEXT).build();
// when
Map<String, Object> result = parameters.getAsJsonSchema();
// then
Expand All @@ -28,7 +28,7 @@ public void testGetAsJsonSchemaWithValidData() {

public void testGetAsJsonSchemaWithoutType() {
// given
WorkFlowParameter parameters = WorkFlowParameter.builder().key(key).description(description).build();
WorkParameter parameters = WorkParameter.builder().key(key).description(description).build();
// when
Map<String, Object> result = parameters.getAsJsonSchema();
// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import java.util.List;
import java.util.Map;

public class WorkFlowParameterTypeTest extends TestCase {
public class WorkParameterTypeTest extends TestCase {

@Test
public void testJsonSchema() {
WorkFlowParameterType[] inputValues = { WorkFlowParameterType.PASSWORD, WorkFlowParameterType.TEXT,
WorkFlowParameterType.EMAIL, WorkFlowParameterType.NUMBER, WorkFlowParameterType.URL,
WorkFlowParameterType.DATE };
WorkParameterType[] inputValues = { WorkParameterType.PASSWORD, WorkParameterType.TEXT, WorkParameterType.EMAIL,
WorkParameterType.NUMBER, WorkParameterType.URL, WorkParameterType.DATE, WorkParameterType.SELECT,
WorkParameterType.MULTI_SELECT };

List<Map<String, Object>> outputs = new ArrayList<>();
for (WorkFlowParameterType inputValue : inputValues) {
for (WorkParameterType inputValue : inputValues) {
outputs.add(inputValue.getAsJsonSchema());
}
assertEquals(inputValues.length, outputs.size());
Expand Down Expand Up @@ -51,6 +51,16 @@ public void testJsonSchema() {
expectedDateOutput.put("format", "date");
assertEquals(expectedDateOutput, outputs.get(5));

Map<String, String> expectedSelectOutput = new HashMap<>();
expectedSelectOutput.put("type", "select");
assertTrue(WorkParameterType.SELECT.isSelect());
assertEquals(expectedSelectOutput, outputs.get(6));

Map<String, String> expectedMultiSelectOutput = new HashMap<>();
expectedMultiSelectOutput.put("type", "multi-select");
assertTrue(WorkParameterType.MULTI_SELECT.isSelect());
assertEquals(expectedMultiSelectOutput, outputs.get(7));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.redhat.parodos.workflow.task;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
Expand All @@ -29,8 +30,8 @@

import com.redhat.parodos.workflow.context.WorkContextDelegate;
import com.redhat.parodos.workflow.exception.MissingParameterException;
import com.redhat.parodos.workflow.task.parameter.WorkFlowTaskParameter;
import com.redhat.parodos.workflow.task.parameter.WorkFlowTaskParameterType;
import com.redhat.parodos.workflow.parameter.WorkParameter;
import com.redhat.parodos.workflow.parameter.WorkParameterType;
import com.redhat.parodos.workflows.work.DefaultWorkReport;
import com.redhat.parodos.workflows.work.Work;
import com.redhat.parodos.workflows.work.WorkContext;
Expand All @@ -47,9 +48,12 @@ private class TestTask extends BaseWorkFlowTask {
private boolean executed;

@Override
public @NonNull List<WorkFlowTaskParameter> getWorkFlowTaskParameters() {
return List.of(WorkFlowTaskParameter.builder().key("username").type(WorkFlowTaskParameterType.TEXT)
.optional(false).description("A username").build());
public @NonNull List<WorkParameter> getWorkFlowTaskParameters() {
return List.of(
WorkParameter.builder().key("username").type(WorkParameterType.TEXT).optional(false)
.description("A username").build(),
WorkParameter.builder().key("test-select").type(WorkParameterType.SELECT).optional(false)
.description("A test").selectOptions(List.of("test1", "test2")).build());
}

@Override
Expand Down Expand Up @@ -119,9 +123,14 @@ public void compareOutpout() {
@Test
public void checkTaskParams() {
TestTask task = new TestTask();
List<WorkFlowTaskParameter> params = task.getWorkFlowTaskParameters();
List<WorkParameter> params = task.getWorkFlowTaskParameters();

assertEquals(WorkFlowTaskParameterType.TEXT, params.get(0).getType());
assertEquals(WorkParameterType.TEXT, params.get(0).getType());
assertEquals(WorkParameterType.SELECT, params.get(1).getType());

HashMap<String, Map<String, Object>> jsonSchema = task.getAsJsonSchema();
assertThat(jsonSchema.get(params.get(1).getKey()).get("enum")).isInstanceOf(List.class)
.isEqualTo(List.of("test1", "test2"));
}

}
Loading

0 comments on commit 3d3f875

Please sign in to comment.