Skip to content

Commit

Permalink
Changed required for #37
Browse files Browse the repository at this point in the history
  • Loading branch information
sagIoTPower committed Jul 5, 2023
1 parent e7b7fb9 commit 22ab6fa
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
Expand Up @@ -220,7 +220,7 @@ public ProcessingContext<T> substituteInTargetAndSend(ProcessingContext<T> conte
public void substituteValueInObject(SubstituteValue sub, DocumentContext jsonObject, String keys)
throws JSONException {
boolean subValueEmpty = sub.value == null || sub.value.isEmpty();
if (sub.repairStrategy.equals(RepairStrategy.REMOVE_IF_MISSING) && subValueEmpty) {
if (( sub.repairStrategy.equals(RepairStrategy.REMOVE_IF_MISSING) || sub.repairStrategy.equals(RepairStrategy.REMOVE_IF_NULL)) && subValueEmpty) {
jsonObject.delete(keys);
} else {
jsonObject.set(keys, sub.typedValue());
Expand Down
Expand Up @@ -27,4 +27,5 @@ public enum RepairStrategy {
USE_LAST_VALUE_OF_ARRAY,
IGNORE,
REMOVE_IF_MISSING,
REMOVE_IF_NULL,
}
Expand Up @@ -184,7 +184,7 @@ public ProcessingContext<T> substituteInTargetAndSend(ProcessingContext<T> conte
public void substituteValueInObject(SubstituteValue sub, DocumentContext jsonObject, String keys)
throws JSONException {
boolean subValueEmpty = sub.value == null || sub.value.isEmpty();
if (sub.repairStrategy.equals(RepairStrategy.REMOVE_IF_MISSING) && subValueEmpty) {
if (( sub.repairStrategy.equals(RepairStrategy.REMOVE_IF_MISSING) || sub.repairStrategy.equals(RepairStrategy.REMOVE_IF_NULL)) && subValueEmpty) {
jsonObject.delete(keys);
} else {
jsonObject.set(keys, sub.typedValue());
Expand Down
Expand Up @@ -166,19 +166,19 @@ export abstract class PayloadProcessorInbound {
}
}
if (
substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_MISSING &&
!substituteValue
(substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_MISSING && !substituteValue.value )|| (substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_NULL && substituteValue.value == null)
) {
_.unset(payloadTarget, pathTarget);
} else {
_.set(payloadTarget, pathTarget, getTypedValue(substituteValue));
}
} else if (pathTarget != API[mapping.targetAPI].identifier) {
if (
substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_MISSING &&
!substituteValue
(substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_MISSING && !substituteValue.value )|| (substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_NULL && substituteValue.value == null)
) {
_.unset(payloadTarget, pathTarget);
} else {
Expand Down
Expand Up @@ -154,19 +154,19 @@ export abstract class PayloadProcessorOutbound {
}
}
if (
substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_MISSING &&
!substituteValue
(substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_MISSING && !substituteValue.value )|| (substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_NULL && substituteValue.value == null)
) {
_.unset(payloadTarget, pathTarget);
} else {
_.set(payloadTarget, pathTarget, getTypedValue(substituteValue));
}
} else if (pathTarget != API[mapping.targetAPI].identifier) {
if (
substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_MISSING &&
!substituteValue
(substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_MISSING && !substituteValue.value )|| (substituteValue.repairStrategy ==
RepairStrategy.REMOVE_IF_NULL && substituteValue.value == null)
) {
_.unset(payloadTarget, pathTarget);
} else {
Expand Down
Expand Up @@ -712,8 +712,8 @@ export class MappingStepperComponent implements OnInit, AfterContentChecked {
className: "col-lg-3 pull-right p-t-24",
type: "button",
templateOptions: {
text: "Add new substitution",
description: `Add new substitution. Before target and source property in
text: "Upsert substitution",
description: `Upsert substitution. Before target and source property in
templates
have to be selected.`,
onClick: ($event) => this.onAddSubstitution(),
Expand Down
1 change: 1 addition & 0 deletions mqtt-mapping-ui/mqtt-mapping/src/shared/mapping.model.ts
Expand Up @@ -275,6 +275,7 @@ export enum RepairStrategy {
USE_LAST_VALUE_OF_ARRAY = "USE_LAST_VALUE_OF_ARRAY",
IGNORE = "IGNORE",
REMOVE_IF_MISSING = "REMOVE_IF_MISSING",
REMOVE_IF_NULL = "REMOVE_IF_NULL",
}

export class C8YAPISubscription {
Expand Down

0 comments on commit 22ab6fa

Please sign in to comment.