Home > Software design >  Write same two logic for same field
Write same two logic for same field

Time:11-27

I am trying to write two logic for same field. In first logic I am mapping it's value and in the second I am trying to apply if loop. But while writing if loop I am getting "Duplicate object key" error. So how do I use both the logic in JOLT?

Any idea on how I can make it work successfully?

enter image description here

Input-

{
  "PURCHASE_ORDER_DISPATCH": {
    "MsgData": {
      "Transaction": {
        "PO_POD_HDR_EVW1": {
          "WG_ADDR_SEQ_NUM": 1,
          "WG_PO_CNTCT_EMAIL": "[email protected]",
          "WG_REQUESTOR_EMAIL": "[email protected]",
          "WG_REQ_FIRST_NAME": "Zachary",
          "WG_REQ_LAST_NAME": "Engels",
          "WG_DELIVER_TO": "[email protected]",
          "BUSINESS_UNIT": "OFIC",
          "PO_ID": 25052,
          "VENDOR_SETID": "WCOS",
          "VENDOR_ID": 35958,
          "VNDR_LOC": 1,
          "PO_DT": "2020-01-24",
          "DB_NUMBER_BU": "",
          "DESCR_BU": "OhioFarmersInsuranceCo",
          "ADDRESS1_BU": "WESTFIELDCOMPANIES",
          "ADDRESS2_BU": "HOMEOFFICE",
          "ADDRESS3_BU": "1PARKCIRCLE",
          "ADDRESS4_BU": "",
          "CITY_BU": "WESTFIELDCENTER",
          "STATE_BU": "OH",
          "POSTAL_BU": "44251-5001",
          "COUNTRY_BU": "USA",
          "ADDRESS1_BILL": "",
          "ADDRESS2_BILL": "",
          "ADDRESS3_BILL": "",
          "ADDRESS4_BILL": "",
          "CITY_BILL": "",
          "STATE_BILL": "",
          "POSTAL_BILL": "",
          "COUNTRY_BILL": "",
          "CURRENCY_CD": "USD",
          "TAX_EXEMPT_ID": "",
          "STD_ID_NUM_VNDR": "",
          "NAME1_VNDR": "AMAZONCAPITALSERVICESINC",
          "ADDRESS1_VNDR": "410TERRYAVEN",
          "ADDRESS2_VNDR": "",
          "ADDRESS3_VNDR": "",
          "ADDRESS4_VNDR": "",
          "CITY_VNDR": "SEATTLE",
          "STATE_VNDR": "WA",
          "POSTAL_VNDR": 98109,
          "COUNTRY_VNDR": "USA",
          "PYMNT_TERMS_CD": "NET30",
          "DESCR50_PAY": "Net30",
          "BUYER_ID": 1083,
          "PO_AMT_TTL": 14.99,
          "TEXT254_CC1": "",
          "TEXT254_CC2": "",
          "VNDR_UPN_FLG": "N",
          "STD_ID_NUM_VNDRGLN": "",
          "STD_ID_NUM_BILLTO": "",
          "ATTN_TO": "ZacharyEngels",
          "PO_POD_LN_EVW1": {
            "WG_REQ_ID": 25694,
            "WG_CATEGORY_CD": "FSSUP",
            "WG_ITEM_TYPE": 0,
            "WG_ACCOUNT": 641100,
            "WG_DEPT_ID": 30400,
            "WG_PRODUCT": "",
            "BUSINESS_UNIT": "OFIC",
            "PO_ID": 25052,
            "WG_ASSET_GROUP": "",
            "WG_CAPITALIZE": "NO",
            "WG_PROFILE_ID": "",
            "WG_SPLIT_TYPE": 1,
            "WG_ASSET_LOC": "HOME",
            "WG_PROJECT": "",
            "VENDOR_SETID": "WCOS",
            "VENDOR_ID": 35958,
            "VNDR_LOC": 1,
            "LINE_NBR": 1,
            "INV_ITEM_ID": "",
            "DESCR254_MIXED": "147-1518156-3620845,1GreenMountainCoffeeRoastersCaramelVanillaCreamKeurigSingle-ServeK-CupPods,LightRoastCoffee,32Count",
            "UNIT_OF_MEASURE": "EA",
            "ITM_ID_VNDR": "B0798CX2Q9",
            "INV_ITEM_WEIGHT": 0,
            "INV_ITEM_HEIGHT": 0,
            "INV_ITEM_VOLUME": 0,
            "INV_ITEM_LENGTH": 0,
            "INV_ITEM_WIDTH": 0,
            "VNDR_CATALOG_ID": "",
            "MFG_ID": "",
            "MFG_ITM_ID": 5000196305,
            "CNTRCT_ID": "",
            "VERSION_NBR": 0,
            "CNTRCT_LINE_NBR": 0,
            "CAT_LINE_NBR": 0,
            "RELEASE_NBR": 0,
            "CANCEL_STATUS": "A",
            "UPN_ID": "",
            "PO_POD_SHP_EVW1": {
              "WG_SHIP_ADDR_TYPE": 0,
              "WG_CUST_ADDR_CODE": "OFIC",
              "BUSINESS_UNIT": "OFIC",
              "PO_ID": 25052,
              "VENDOR_SETID": "WCOS",
              "VENDOR_ID": 35958,
              "VNDR_LOC": 1,
              "LINE_NBR": 1,
              "SCHED_NBR": 1,
              "DUE_DT": "2020-01-29",
              "SHIPTO_ID": "OFIC",
              "DESCR_SHIPTO": "OHIOFARMERSINSURANCECOMPANY",
              "ADDRESS1_SHIPTO": "OHIOFARMERSINSURANCECOMPANY",
              "ADDRESS2_SHIPTO": "1PARKCIRCLE",
              "ADDRESS3_SHIPTO": "POBOX5001",
              "ADDRESS4_SHIPTO": "",
              "CITY_SHIPTO": "WESTFIELDCENTER",
              "STATE_SHIPTO": "OH",
              "POSTAL_SHIPTO": "44251-5001",
              "COUNTRY_SHIPTO": "USA",
              "PRICE_PO": 14.99,
              "FREIGHT_TERMS": "FOBDEST",
              "QTY_PO": 1,
              "SHIP_TYPE_ID": "BEST_WAY",
              "CANCEL_STATUS": "A",
              "ATTN_TO": "",
              "STD_ID_NUM_SHIPTO": ""
            },
            "PSCAMA": {
              "AUDIT_ACTN": "A"
            }
          },
          "PSCAMA": {
            "AUDIT_ACTN": "A"
          }
        },
        "PSCAMA": {
          "LANGUAGE_CD": "ENG",
          "AUDIT_ACTN": "A",
          "BASE_LANGUAGE_CD": "ENG",
          "MSG_SEQ_FLG": "",
          "PROCESS_INSTANCE": 1199010,
          "PUBLISH_RULE_ID": "WG_MAIN_RULE",
          "MSGNODENAME": ""
        }
      }
    }
  }
}

JOLT Spec-

[
    {
      "operation": "shift",
      "spec": {
        "#UPSERT": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityHeader.action",
        "*": {
          "*": {
            "*": {
              "*": {
                "PO_ID": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.externalId",
                "#APPROVED": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.status",
                "PO_AMT_TTL": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.grossTotalAmount",
                "FREIGHT_TERMS": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.deliveryTermCode",
                "WG_REQUESTOR_EMAIL": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.items.item.requesterDetails.userEmailId",
                "WG_DELIVER_TO": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.items.item.deliverToUser.userEmailId",
                "*": {
                  "WG_REQ_ID": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.poDescription",
                  "#STANDARD": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.poType",
                  "*": {
                    "WG_SHIP_ADDR_TYPE":"integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddressType",
                    "WG_SHIP_ADDR_TYPE": {
                        "2": {
                            
                            "@(2,DESCR_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressName",
                            "@(2,ADDRESS1_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressLine1",
                            "@(2,ADDRESS2_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressLine2",
                            "@(2,ADDRESS3_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressLine3",
                            "@(2,ADDRESS4_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressLine4",
                            "@(2,CITY_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.city",
                            "@(2,POSTAL_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.zip",
                            "@(2,STATE_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.state",
                            "@(2,COUNTRY_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.country"
                        }
                    },

                    "WG_CUST_ADDR_CODE":"integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressCode",
                    "FREIGHT_TERMS": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.deliveryTermCode"
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "operation": "shift",
      "spec": {
        "*": {
          "*": {
            "*": {
              "integrationEntityHeader": "&3.&2.&1.&",
              "integrationEntityDetails": {
                "*": {
                  "externalId": "&5.&4.&3.&2.&1.&",
                  "status": "&5.&4.&3.&2.&1.&",
                  "poHeader": {
                    "poDescription": "&6.&5.&4.&3.&2.&1.&",
                    "poType": "&6.&5.&4.&3.&2.&1.&",
                    "grossTotalAmount": "&6.&5.&4.&3.&2.&1.&",
                    "deliveryTermCode": "&6.&5.&4.&3.&2.&1.&",
                    "shipToAddressType":"&6.&5.&4.&3.&2.&1.&",
                    "shipToAddress":"&6.&5.&4.&3.&2.&1.&"
                  },
                  "items": "&5.&4.&3.&2.&1.&"
                }
              }
            }
          }
        }
      }
    },
    {
      "operation": "cardinality",
      "spec": {
        "*": {
          "*": {
            "*": {
              "*": {
                "*": {
                  "status": "ONE",
                  "poHeader": {
                    "*": "ONE"
                  }
                }
              }
            }
          }
        }
      }
    }
  ]

Output-

{
  "integration-inbound:IntegrationDetails": {
    "integrationEntities": {
      "integrationEntity": {
        "integrationEntityHeader": {
          "action": "UPSERT"
        },
        "integrationEntityDetails": {
          "poDetails": {
            "externalId": 25052,
            "status": "APPROVED",
            "poHeader": {
              "poDescription": 25694,
              "poType": "STANDARD",
              "grossTotalAmount": 14.99,
              "deliveryTermCode": "FOBDEST",
              "shipToAddress": {
                "addressCode": "OFIC"
              }
            },
            "items": {
              "item": {
                "requesterDetails": {
                  "userEmailId": "[email protected]"
                },
                "deliverToUser": {
                  "userEmailId": "[email protected]"
                }
              }
            }
          }
        }
      }
    }
  }
}

CodePudding user response:

Convert one of them to

"@(0,WG_SHIP_ADDR_TYPE)"

since zero represents the value for the current level(with no level difference), and as the tags of the attributes/objects/arrays should be different

CodePudding user response:

You writing WG_SHIP_ADDR_TYPE 2 times in your spec, If you want to map WG_SHIP_ADDR_TYPE with all value you can add

"@": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddressType"

and if the value was 2 you want to add new object with shipToAddress.

For this you can using my below spec, otherwise you can use the previous answer of Barbaros Özhan.

[
  {
    "operation": "shift",
    "spec": {
      "#UPSERT": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityHeader.action",
      "*": {
        "*": {
          "*": {
            "*": {
              "PO_ID": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.externalId",
              "#APPROVED": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.status",
              "PO_AMT_TTL": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.grossTotalAmount",
              "FREIGHT_TERMS": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.deliveryTermCode",
              "WG_REQUESTOR_EMAIL": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.items.item.requesterDetails.userEmailId",
              "WG_DELIVER_TO": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.items.item.deliverToUser.userEmailId",
              "*": {
                "WG_REQ_ID": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.poDescription",
                "#STANDARD": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.poType",
                "*": {
                  "WG_SHIP_ADDR_TYPE": {
                    "@": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddressType",
                    "2": {
                      "@(2,DESCR_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressName",
                      "@(2,ADDRESS1_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressLine1",
                      "@(2,ADDRESS2_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressLine2",
                      "@(2,ADDRESS3_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressLine3",
                      "@(2,ADDRESS4_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressLine4",
                      "@(2,CITY_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.city",
                      "@(2,POSTAL_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.zip",
                      "@(2,STATE_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.state",
                      "@(2,COUNTRY_SHIPTO)": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.country"
                    }
                  },
                  "WG_CUST_ADDR_CODE": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.shipToAddress.addressCode",
                  "FREIGHT_TERMS": "integration-inbound:IntegrationDetails.integrationEntities.integrationEntity.integrationEntityDetails.poDetails.poHeader.deliveryTermCode"
                }
              }
            }
          }
        }
      }
    }
  }
]
  • Related