diff options
author | Andrei Barcovschi <andrei.barcovschi@ericsson.com> | 2019-03-26 15:25:44 +0000 |
---|---|---|
committer | Andrei Barcovschi <andrei.barcovschi@ericsson.com> | 2019-03-26 15:25:55 +0000 |
commit | befc44d1b17d92b5417aa121714152a898236a7b (patch) | |
tree | ce4be44f30119ee55c9b36d65a00a12b944ee817 /bpmn/MSOCommonBPMN/src/main/java | |
parent | af46c0d4b30ecb5c8f36992e74adb86d7d5bbe06 (diff) |
Fix serialize DelegateExecutionImpl object bug
Change-Id: I140796717f9e8a365650355d92df60b85bc7a8e2
Issue-ID: SO-1690
Signed-off-by: Andrei Barcovschi <andrei.barcovschi@ericsson.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/java')
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/DelegateExecutionImpl.java | 219 |
1 files changed, 117 insertions, 102 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/DelegateExecutionImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/DelegateExecutionImpl.java index 1c1d6b73fd..39a209efa8 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/DelegateExecutionImpl.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/DelegateExecutionImpl.java @@ -1,22 +1,22 @@ /*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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 - * +* ============LICENSE_START======================================================= +* ONAP - SO +* ================================================================================ +* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +* ================================================================================ +* Licensed 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. - * ============LICENSE_END========================================================= - */ +* 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. +* ============LICENSE_END========================================================= +*/ package org.onap.so.bpmn.common; @@ -31,92 +31,107 @@ import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + public class DelegateExecutionImpl implements BuildingBlockExecution, Serializable { - private final Map<String, Serializable> seedMap; - private transient DelegateExecution execution; - private static final String INVALID_INPUT_MISSING = "Expected variable of \"%s\" not found in execution"; - private static final String INVALID_INPUT_CLASS_CAST = "Expected variable of \"%s\" was the wrong object type in the execution"; - - private static final String MISSING_MSG = "Execution variable \"gBBInput\" cannot be null when executing building blocks"; - private static final String MALFORMED_MSG = "Execution variable \"gBBInput\" must contain an element of type GeneralBuildingBlock"; - - public DelegateExecutionImpl(Map<String, Serializable> seedMap) { - this.seedMap = seedMap; - } - - public DelegateExecutionImpl(DelegateExecution execution) { - this.seedMap = new HashMap<>(); - execution.getVariables().forEach((key, value) -> { - if (value instanceof Serializable) { - seedMap.put(key, (Serializable)value); - } - }); - /* must occur for junit tests to work */ - this.execution = execution; - } - @Override - public GeneralBuildingBlock getGeneralBuildingBlock() { - try { - GeneralBuildingBlock generalBuildingBlock = (GeneralBuildingBlock) execution.getVariable("gBBInput"); - - if (generalBuildingBlock == null) { - throw new MissingBuildingBlockInputException(MISSING_MSG); - } - - return generalBuildingBlock; - } catch (ClassCastException e) { - throw new MalformedBuildingBlockInputException(MALFORMED_MSG, e); - } - } - - @Override - public <T> T getVariable(String key) { - return this.get(key); - } - - @Override - public <T> T getRequiredVariable(String key) throws RequiredExecutionVariableExeception { - final T result; - - result = this.get(key); - if (result == null) { - throw new RequiredExecutionVariableExeception(String.format(INVALID_INPUT_MISSING, key)); - - } - return result; - } - - @Override - public void setVariable(String key, Serializable value) { - this.execution.setVariable(key, value); - } - - @Override - public Map<ResourceKey, String> getLookupMap() { - return this.get("lookupKeyMap"); - } - - @Override - public String getFlowToBeCalled() { - return this.get("flowToBeCalled"); - } - public DelegateExecution getDelegateExecution() { - return this.execution; - } - - public void setDelegateExecution(DelegateExecution execution) { - this.execution = execution; - this.seedMap.forEach((key, value) -> { - if (!execution.hasVariable(key)) { - execution.setVariable(key, value); - } - }); - } - - protected <T> T get(String key) { - final Object value = this.execution.getVariable(key); - - return (T)value; - } + private static final long serialVersionUID = 5559067662634919395L; + + @JsonProperty + private final Map<String, Serializable> seedMap; + + private transient DelegateExecution execution; + private static final String INVALID_INPUT_MISSING = "Expected variable of \"%s\" not found in execution"; + + private static final String MISSING_MSG = + "Execution variable \"gBBInput\" cannot be null when executing building blocks"; + private static final String MALFORMED_MSG = + "Execution variable \"gBBInput\" must contain an element of type GeneralBuildingBlock"; + + public DelegateExecutionImpl(final Map<String, Serializable> seedMap) { + this.seedMap = seedMap; + } + + public DelegateExecutionImpl(final DelegateExecution execution) { + this.seedMap = new HashMap<>(); + execution.getVariables().forEach((key, value) -> { + if (value instanceof Serializable) { + seedMap.put(key, (Serializable) value); + } + }); + /* must occur for junit tests to work */ + this.execution = execution; + } + + @JsonIgnore + @Override + public GeneralBuildingBlock getGeneralBuildingBlock() { + try { + final GeneralBuildingBlock generalBuildingBlock = (GeneralBuildingBlock) execution.getVariable("gBBInput"); + + if (generalBuildingBlock == null) { + throw new MissingBuildingBlockInputException(MISSING_MSG); + } + + return generalBuildingBlock; + } catch (final ClassCastException e) { + throw new MalformedBuildingBlockInputException(MALFORMED_MSG, e); + } + } + + @Override + public <T> T getVariable(final String key) { + return this.get(key); + } + + @Override + public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { + final T result; + + result = this.get(key); + if (result == null) { + throw new RequiredExecutionVariableExeception(String.format(INVALID_INPUT_MISSING, key)); + + } + return result; + } + + @Override + public void setVariable(final String key, final Serializable value) { + this.execution.setVariable(key, value); + } + + @JsonIgnore + @Override + public Map<ResourceKey, String> getLookupMap() { + return this.get("lookupKeyMap"); + } + + @JsonIgnore + @Override + public String getFlowToBeCalled() { + return this.get("flowToBeCalled"); + } + + @JsonIgnore + public DelegateExecution getDelegateExecution() { + return this.execution; + } + + public void setDelegateExecution(final DelegateExecution execution) { + this.execution = execution; + this.seedMap.forEach((key, value) -> { + if (!execution.hasVariable(key)) { + execution.setVariable(key, value); + } + }); + } + + @SuppressWarnings("unchecked") + protected <T> T get(final String key) { + final Object value = this.execution.getVariable(key); + return (T) value; + } + } |