Riyafa Abdul Hameed
Riyafa Abdul Hameed

Reputation: 7973

Storing key value pair for reference in a WSO2 ESB proxy service

I get json data using the peopleHr connector in the following format with about 500 employee details:

{
  "Result": [
    {
      "EmployeeId": {
        "DisplayValue": "UK20900"
      },
      "Title": {
        "DisplayValue": "",
        "FieldHistory": []
      },
      "FirstName": {
        "DisplayValue": "Riyafa",
        "FieldHistory": []
      },
      "LastName": {
        "DisplayValue": "Abdul Hameed",
        "FieldHistory": []
      },
      "OtherName": {
        "DisplayValue": "",
        "FieldHistory": []
      },
      "KnownAs": {
        "DisplayValue": "",
        "FieldHistory": []
      },
      "EmailId": {
        "DisplayValue": "[email protected]",
        "FieldHistory": []
      },
      "StartDate": {
        "DisplayValue": "2015-11-18",
        "FieldHistory": []
      },
      "DateOfBirth": {
        "DisplayValue": "",
        "FieldHistory": []
      },
      "JobRole": {
        "DisplayValue": "",
        "FieldHistoryForJobRole": [
          {
            "JobRole": null,
            "EffectiveDate": "2015-11-18",
            "ChangedOn": "2015-11-18",
            "ReasonForChange": "New Starter"
          }
        ]
      }
    },
    {
      "EmployeeId": {
        "DisplayValue": "LK500200",
        "FieldHistory": [
          {
            "OldValue": "LK",
            "NewValue": "LK500200",
            "ChangedOn": "2015-11-18",
            "ReasonForChange": "We choose our own employee ids"
          },
          {
            "OldValue": "PW2",
            "NewValue": "LK",
            "ChangedOn": "2015-11-18",
            "ReasonForChange": "Because we have a specific format for our employee ids"
          }
        ]
      },
      "Title": {
        "DisplayValue": "",
        "FieldHistory": []
      },
      "FirstName": {
        "DisplayValue": "Kalani",
        "FieldHistory": []
      },
      "LastName": {
        "DisplayValue": "Gayathri",
        "FieldHistory": []
      },
      "OtherName": {
        "DisplayValue": "",
        "FieldHistory": []
      },
      "KnownAs": {
        "DisplayValue": "",
        "FieldHistory": []
      },
      "EmailId": {
        "DisplayValue": "[email protected]",
        "FieldHistory": []
      },
      "StartDate": {
        "DisplayValue": "2015-11-17",
        "FieldHistory": []
      },
      "DateOfBirth": {
        "DisplayValue": "1992-05-08",
        "FieldHistory": []
      },
      "JobRole": {
        "DisplayValue": "IT",
        "FieldHistoryForJobRole": [
          {
            "JobRole": "IT",
            "EffectiveDate": "2015-11-17",
            "ChangedOn": "2015-11-18",
            "ReasonForChange": "New Starter"
          }
        ]
      }
    }
  ]
}

I would like to store the EmailId and the EmployeeId as a key value pair to be used in future reference in a WSO2 ESB proxy service where I would need to reference the EmployeeId using the EmailId. I thought of using a property mediator with the name as the EmailId and the value as EmployeeId, but an expression cannot be used as the name in property mediator. How can I extract these values and store them for future reference in an ESB proxy service?

Upvotes: 1

Views: 344

Answers (1)

Rajeev Sampath
Rajeev Sampath

Reputation: 2747

You can use the 'expression' attribute in property mediator to extract values (using xpath or jsonpath).

But using a property mediator won't work for this case since those properties are local to a message. That is, when you receive a new message, you'll get a separate fresh copy of the property and not the previously set values.

Hence you can try one of the following approaches:
- User DBReport and DBLookup mediators to store and retrieve values. This will involve setting up a database.
- Use a custom mediator that'll hold the values across incoming messages. There's a sample code here that holds a value (from a property) and compares it to a new one. You can modify this to just hold the value and set it to a new property which you can use when a new message arrives.

Upvotes: 2

Related Questions