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

kie-issues#1677: [serverless-workflow-diagram-editor] marshallers (json/yaml) must support stateExecTimeout.(total/single) properties #2795

Open
wants to merge 3 commits 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
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/


package org.kie.workbench.common.stunner.sw.definition;

import jsinterop.annotations.JsType;
import org.kie.j2cl.tools.json.mapper.annotation.JSONMapper;
import org.kie.j2cl.tools.processors.annotations.GWT3Export;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YAMLMapper;

@JSONMapper
@YAMLMapper
@JsType
@GWT3Export
public class StateExecTimeout {

private String single;
private String total;

public final String getSingle() {
return single;
}

public final void setSingle(String single) {
this.single = single;
}

public final String getTotal() {
return total;
}

public final void setTotal(String total) {
this.total = total;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YAMLMapper;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YamlTypeDeserializer;
import org.kie.j2cl.tools.yaml.mapper.api.annotation.YamlTypeSerializer;
import org.kie.workbench.common.stunner.sw.marshall.json.StateExecTimeoutJsonSerializer;
import org.kie.workbench.common.stunner.sw.marshall.json.WorkflowExecTimeoutJsonSerializer;
import org.kie.workbench.common.stunner.sw.marshall.yaml.StateExecTimeoutYamlSerializer;
import org.kie.workbench.common.stunner.sw.marshall.yaml.WorkflowExecTimeoutYamlSerializer;

@JSONMapper
Expand All @@ -42,7 +44,12 @@ public class WorkflowTimeouts {
@YamlTypeSerializer(WorkflowExecTimeoutYamlSerializer.class)
@YamlTypeDeserializer(WorkflowExecTimeoutYamlSerializer.class)
private Object workflowExecTimeout;
private String stateExecTimeout;

@JsonbTypeSerializer(StateExecTimeoutJsonSerializer.class)
@JsonbTypeDeserializer(StateExecTimeoutJsonSerializer.class)
@YamlTypeSerializer(StateExecTimeoutYamlSerializer.class)
@YamlTypeDeserializer(StateExecTimeoutYamlSerializer.class)
private Object stateExecTimeout;
private String actionExecTimeout;
private String branchExecTimeout;
private String eventTimeout;
Expand All @@ -55,11 +62,11 @@ public final void setWorkflowExecTimeout(Object workflowExecTimeout) {
this.workflowExecTimeout = workflowExecTimeout;
}

public final String getStateExecTimeout() {
public final Object getStateExecTimeout() {
return stateExecTimeout;
}

public final void setStateExecTimeout(String stateExecTimeout) {
public final void setStateExecTimeout(Object stateExecTimeout) {
this.stateExecTimeout = stateExecTimeout;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.kie.workbench.common.stunner.sw.marshall.json;

import java.lang.reflect.Type;

import jakarta.json.JsonValue;
import jakarta.json.bind.serializer.DeserializationContext;
import jakarta.json.bind.serializer.JsonbDeserializer;
import jakarta.json.bind.serializer.JsonbSerializer;
import jakarta.json.bind.serializer.SerializationContext;
import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParser;
import org.kie.j2cl.tools.json.mapper.internal.deserializer.StringJsonDeserializer;
import org.kie.j2cl.tools.json.mapper.internal.serializer.StringJsonSerializer;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout_JsonDeserializerImpl;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout_JsonSerializerImpl;

public class StateExecTimeoutJsonSerializer implements JsonbDeserializer<Object>, JsonbSerializer<Object> {

private static final StateExecTimeout_JsonSerializerImpl serializer =
StateExecTimeout_JsonSerializerImpl.INSTANCE;

private static final StateExecTimeout_JsonDeserializerImpl deserializer =
StateExecTimeout_JsonDeserializerImpl.INSTANCE;
private static final StringJsonSerializer stringJsonSerializer = new StringJsonSerializer();

private static final StringJsonDeserializer stringJsonDeserializer = new StringJsonDeserializer();

@Override
public Object deserialize(JsonParser parser, DeserializationContext ctx, Type type) {
JsonValue value = parser.getValue();
if(value != null) {
if (value.getValueType() != JsonValue.ValueType.NULL) {
if (value.getValueType() == JsonValue.ValueType.STRING) {
return stringJsonDeserializer.deserialize(value, ctx);
} else if (value.getValueType() == JsonValue.ValueType.OBJECT) {
return deserializer.deserialize(parser.getValue(), ctx);
}
}
}
return null;
}

@Override
public void serialize(Object stateExecTimeout, JsonGenerator generator, SerializationContext serializationContext) {
if (stateExecTimeout instanceof String) {
stringJsonSerializer.serialize((String) stateExecTimeout, generator, serializationContext);
} else if (stateExecTimeout instanceof StateExecTimeout) {
JsonGenerator jsonGenerator = generator.writeStartObject();
serializer.serialize((StateExecTimeout) stateExecTimeout, jsonGenerator, serializationContext);
jsonGenerator.writeEnd();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.kie.workbench.common.stunner.sw.marshall.yaml;

import org.kie.j2cl.tools.yaml.mapper.api.YAMLDeserializer;
import org.kie.j2cl.tools.yaml.mapper.api.YAMLSerializer;
import org.kie.j2cl.tools.yaml.mapper.api.exception.YAMLDeserializationException;
import org.kie.j2cl.tools.yaml.mapper.api.internal.deser.StringYAMLDeserializer;
import org.kie.j2cl.tools.yaml.mapper.api.internal.deser.YAMLDeserializationContext;
import org.kie.j2cl.tools.yaml.mapper.api.internal.ser.StringYAMLSerializer;
import org.kie.j2cl.tools.yaml.mapper.api.internal.ser.YAMLSerializationContext;
import org.kie.j2cl.tools.yaml.mapper.api.node.NodeType;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlMapping;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlNode;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlSequence;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout_YamlMapperImpl;

public class StateExecTimeoutYamlSerializer implements YAMLDeserializer<Object>, YAMLSerializer<Object> {


private static final StateExecTimeout_YamlMapperImpl mapper =
StateExecTimeout_YamlMapperImpl.INSTANCE;

private static final StringYAMLSerializer stringYAMLSerializer = new StringYAMLSerializer();
private static final StringYAMLDeserializer stringYAMLDeserializer = new StringYAMLDeserializer();

@Override
public Object deserialize(YamlMapping yaml, String key, YAMLDeserializationContext ctx) throws YAMLDeserializationException {
YamlNode value = yaml.getNode(key);
if (value == null) {
return null;
}
return deserialize(value, ctx);
}

@Override
public Object deserialize(YamlNode node, YAMLDeserializationContext ctx) {
if (node == null) {
return null;
}
if(node.type() == NodeType.SCALAR) {
return stringYAMLDeserializer.deserialize(node, ctx);
} else {
return mapper.getDeserializer().deserialize(node, ctx);
}
}

@Override
public void serialize(YamlMapping writer, String propertyName, Object value, YAMLSerializationContext ctx) {
if (value instanceof String) {
stringYAMLSerializer.serialize(writer, propertyName, (String) value, ctx);
} else if (value instanceof StateExecTimeout) {
mapper.getSerializer().serialize(writer, propertyName, (StateExecTimeout) value, ctx);
}
}

@Override
public void serialize(YamlSequence writer, Object value, YAMLSerializationContext ctx) {
if (value instanceof String) {
stringYAMLSerializer.serialize(writer, (String) value, ctx);
} else if (value instanceof StateExecTimeout) {
mapper.getSerializer().serialize(writer, (StateExecTimeout) value, ctx);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.kie.workbench.common.stunner.sw.definition.ActionNode;
import org.kie.workbench.common.stunner.sw.definition.CallbackState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;

import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.CLOCK;
Expand Down Expand Up @@ -66,7 +67,9 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
getView().addChild(new CornerIcon(CLOCK,
CENTER_TOP,
getTranslation(TIMEOUT_EVENT) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getEventTimeout()) + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()) + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout() instanceof String ?
(String) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()
: ((StateExecTimeout) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()).getTotal()) + "\r\n"
+ getTranslation(TIMEOUT_ACTION) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getActionExecTimeout())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.kie.workbench.common.stunner.sw.client.theme.ColorTheme;
import org.kie.workbench.common.stunner.sw.definition.EventState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;

import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.CLOCK;
Expand All @@ -56,7 +57,9 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
getView().addChild(new CornerIcon(CLOCK,
RIGHT_TOP_CORNER,
getTranslation(TIMEOUT_EVENT) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getEventTimeout()) + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()) + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout() instanceof String ?
(String) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()
: ((StateExecTimeout) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()).getTotal()) + "\r\n"
+ getTranslation(TIMEOUT_ACTION) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getActionExecTimeout())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.kie.workbench.common.stunner.sw.client.theme.ColorTheme;
import org.kie.workbench.common.stunner.sw.definition.ForEachState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;

import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.CLOCK;
Expand Down Expand Up @@ -65,7 +66,9 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
if (state.getTimeouts() != null && state.getTimeouts() instanceof WorkflowTimeouts) {
getView().addChild(new CornerIcon(CLOCK,
LEFT_FROM_RIGHT_TOP_CORNER,
getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()) + "\r\n"
getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout() instanceof String ?
(String) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()
: ((StateExecTimeout) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()).getTotal()) + "\r\n"
+ getTranslation(TIMEOUT_ACTION) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getActionExecTimeout())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.kie.workbench.common.stunner.sw.client.theme.ColorTheme;
import org.kie.workbench.common.stunner.sw.definition.OperationState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;

import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.CLOCK;
Expand Down Expand Up @@ -63,7 +64,9 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
if (state.getTimeouts() != null && state.getTimeouts() instanceof WorkflowTimeouts) {
getView().addChild(new CornerIcon(CLOCK,
LEFT_FROM_RIGHT_TOP_CORNER,
getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()) + "\r\n"
getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout() instanceof String ?
(String) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()
: ((StateExecTimeout) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()).getTotal()) + "\r\n"
+ getTranslation(TIMEOUT_ACTION) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getActionExecTimeout())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.kie.workbench.common.stunner.sw.client.theme.ColorTheme;
import org.kie.workbench.common.stunner.sw.definition.ParallelState;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;

import static org.kie.workbench.common.stunner.sw.client.shapes.icons.IconPath.BRANCH;
Expand Down Expand Up @@ -62,7 +63,9 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
getView().addChild(new CornerIcon(CLOCK,
LEFT_FROM_RIGHT_TOP_CORNER,
getTranslation(TIMEOUT_BRANCH) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getBranchExecTimeout()) + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout())));
+ getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout() instanceof String ?
(String) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()
: ((StateExecTimeout) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()).getTotal())));
}

getView().addChild(new CornerIcon(BRANCH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.kie.workbench.common.stunner.sw.client.shapes.icons.CornerIcon;
import org.kie.workbench.common.stunner.sw.client.theme.ColorTheme;
import org.kie.workbench.common.stunner.sw.definition.State;
import org.kie.workbench.common.stunner.sw.definition.StateExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.SwitchState;
import org.kie.workbench.common.stunner.sw.definition.WorkflowTimeouts;

Expand Down Expand Up @@ -57,7 +58,9 @@ public void applyProperties(Node<View<State>, Edge> element, MutationContext mut
getView().addChild(new CornerIcon(CLOCK,
LEFT_FROM_RIGHT_TOP_CORNER,
getTranslation(TIMEOUT_EVENT) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getEventTimeout()) + "\r\n"
+ getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout())));
+ getTranslation(TIMEOUT_STATE) + ": " + truncate(((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout() instanceof String ?
(String) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()
: ((StateExecTimeout) ((WorkflowTimeouts) state.getTimeouts()).getStateExecTimeout()).getTotal())));
}

if (state.getStateDataFilter() != null) {
Expand Down
Loading
Loading