Getting activities

To add functionality for the getActivities method of the API handler class, you need to do the following:
  • Create an integration mapping file that maps the API root objects into JSON data that conforms to the JSON schema document for the Activities API.
  • Update the getActivities method to use the JSON mapper to return the required list of activities.

Creating a JSON mapper file

Each integration mapping file can have any number of integration mappers defined in it. Each integration mapper defines a single entry point into the mapping transformation. An integration mapper takes a single input object and transforms it into JSON that matches an output schema. Each integration mapper contains mapping properties that correspond to each property in the output schema.

For the getActivities method, you need to create a mapper file named activityAPI-1.0.mapping.json in the following directory in the Studio Project window:
  • configuration > config > Integration > mappings > mc > activityapi
Your updated mapper file needs to contain code similar to the following example:
{
  "schemaName": "mc.activityapi.activityAPI-1.0",
  "mappers": {
    "ActivitySummary" : {
      "schemaDefinition" : "ActivitySummary",
      "root" : "entity.Activity",
      "properties" : {
        "assignedUser" : {
          "path" : "Activity.AssignedUser",
          "mapper" : "#/mappers/AssignedUser"
        },
        "escalated" : {
          "path" : "Activity.Escalated"
        },
        "escalationDate" : {
          "path" : "Activity.EscalationDate"
        },
        "mandatory" : {
          "path" : "Activity.Mandatory"
        },
        "priority" : {
          "path" : "Activity.Priority"
        },
        "publicId" : {
          "path" : "Activity.PublicID"
        },
        "status" : {
          "path" : "Activity.Status"
        },
        "subject" : {
          "path" : "Activity.Subject"
        },
        "targetDate" : {
          "path" : "Activity.TargetDate"
        }
      }
    },
    "AssignedUser" : {
      "schemaDefinition" : "AssignedUser",
      "root" : "entity.User",
      "properties" : {
        "displayName" : {
          "path" : "User.DisplayName"
        },
        "publicId" : {
          "path" : "User.PublicID"
        },
        "username" : {
          "path" : "User.Credential.UserName"
        }
      }
    }
  }
}

Adding functionality to handler method getActivities

Handler class ExampleActivitiesApiHandler defines the methods that support the Activities API. This class exists in the following directory in the Studio Project window:
  • configuration > gsrc > mc > activityapi
The getActivities handler method uses the ActivitySummary declaration to produce a List<TransformResult> as a result. The code for the getActivities handler method looks similar to the following example.
function getActivities() : List<TransformResult> {
  var query = Query.make(Activity)
  var resultSet = query.select()
  var mapper = JsonConfigAccess.getMapper("mc.activityapi.activityAPI-1.0", "ActivitySummary")

  return mapper.transformObjects(resultSet)
}

Next steps

After adding the mapper file in Studio and updating the API handler file, do the following:
  • Recompile the PolicyCenter application
  • Restart the application server

You need to restart the application server in order for PolicyCenter to recognize the new mapper file. In general, you need to restart the application server once only for PolicyCenter to recognize a newly added file. Thereafter, the server recognizes subsequent changes to the file.