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

Fix properties #251

Merged
merged 11 commits into from
Dec 6, 2022
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<http.proxyPort/>
<jacoco.out.paths>${project.build.directory}</jacoco.out.paths>
<sonar.jacoco.reportPath>${jacoco.out.path}/jacoco.exec</sonar.jacoco.reportPath>
<jacoco.version>0.8.2</jacoco.version>
<jacoco.version>0.8.8</jacoco.version>
<jsonwebtoken.version>0.11.5</jsonwebtoken.version>
<jackson.databind.version>2.13.2</jackson.databind.version>
<log4j2.version>2.17.1</log4j2.version>
Expand Down
48 changes: 41 additions & 7 deletions src/main/java/io/boomerang/service/EventProcessorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.Optional;
import org.apache.http.HttpStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -29,11 +31,14 @@
import io.boomerang.model.FlowActivity;
import io.boomerang.model.FlowExecutionRequest;
import io.boomerang.model.eventing.EventResponse;
import io.boomerang.mongo.entity.WorkflowEntity;
import io.boomerang.mongo.model.KeyValuePair;
import io.boomerang.mongo.model.Triggers;
import io.boomerang.mongo.model.WorkflowProperty;
import io.boomerang.service.crud.WorkflowService;
import io.boomerang.service.refactor.TaskService;
import io.boomerang.util.ParameterMapper;
import io.boomerang.util.DataAdapterUtil.FieldType;
import io.cloudevents.CloudEvent;
import io.cloudevents.v1.AttributesImpl;
import io.cloudevents.v1.CloudEventBuilder;
Expand Down Expand Up @@ -199,7 +204,7 @@ private EventResponse processEvent(CloudEvent<AttributesImpl, JsonNode> event, S
property.setKey("eventId");
property.setValue(event.getAttributes().getId());
cloudEventLabels.add(property);
executionRequest.setLabels(cloudEventLabels);
// executionRequest.setLabels(cloudEventLabels);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amhudson how does not setting the labels on a CloudEvent (listener triggered) execution affect the webhook?

executionRequest.setProperties(processProperties(eventData, workflowId));

FlowActivity activity = executionService.executeWorkflow(workflowId, Optional.of(trigger),
Expand Down Expand Up @@ -273,14 +278,43 @@ private Map<String, String> processProperties(JsonNode eventData, String workflo
logger.error(e.toString());
}
}
ObjectMapper mapper = new ObjectMapper();
Map<String, String> payloadProperties = mapper.convertValue(eventData.get("properties"),
new TypeReference<Map<String, String>>() {});
if (payloadProperties != null) {
properties.putAll(payloadProperties);
}

properties.put("eventPayload", eventData.toString());

properties.forEach((k, v) -> {
logger.info("processProperties() - " + k + "=" + v);
});
// properties.put("eventPayload", eventData.toString());

WorkflowEntity workflow = workflowService.getWorkflow(workflowId);
Map<String, String> finalProperties = new HashMap<>();

if (!properties.isEmpty()) {
List<KeyValuePair> propertyList = ParameterMapper.mapToKeyValuePairList(properties);
Map<String, WorkflowProperty> workflowPropMap = workflow.getProperties().stream().collect(
Collectors.toMap(WorkflowProperty::getKey, WorkflowProperty -> WorkflowProperty));
// Use default value for password-type parameter when user input value is null when executing
// workflow.
propertyList.stream().forEach(p -> {
if (workflowPropMap.get(p.getKey()) != null
&& FieldType.PASSWORD.value().equals(workflowPropMap.get(p.getKey()).getType())
&& p.getValue() == null) {
p.setValue(workflowPropMap.get(p.getKey()).getDefaultValue());
}
});

for (KeyValuePair prop : propertyList) {
logger.info("processProperties() - " + prop.getKey() + "=" + prop.getValue());
finalProperties.put(prop.getKey(), prop.getValue());
}
} else {

return properties;
for (WorkflowProperty property : workflow.getProperties()) {
finalProperties.put(property.getKey(), property.getDefaultValue());
}
}
return finalProperties;
}

private Boolean isTriggerEnabled(String trigger, String workflowId, String topic) {
Expand Down