Getting activity detail

To add functionality for the getActivity method of the API handler class, you need to do the following:
  • Update the integration mapping file with a mapper for the ActivityDetail schema and related pieces.
  • Update the getActivity handler method to load the activity with the specified activityId from the database and return it as a TransformResult object.

Adding objects to the JSON mapper file

Mapping file activityAPI-1.0.mapping.json exists in the following directory in the Studio Project window:
  • configuration > config > Integration > mappings > mc > activityapi
Update your mapper file and add code similar to the following example in an appropriate place:
"ActivityDetail" : {
  "schemaDefinition" : "ActivityDetail",
  "root" : "entity.Activity",
  "properties" : {
    "approvalRationale" : {
      "path" : "Activity.ApprovalRationale"
    },
    "assignedUser" : {
      "path" : "Activity.AssignedUser",
      "mapper" : "#/mappers/AssignedUser"
    },
    "description" : {
      "path" : "Activity.Description"
    },
    "escalationDate" : {
      "path" : "Activity.EscalationDate"
    },
    "mandatory" : {
      "path" : "Activity.Mandatory"
    },
    "priority" : {
      "path" : "Activity.Priority"
    },
    "publicId" : {
      "path" : "Activity.PublicID"
    },
    "relatedAccount" : {
      "path" : "Activity.Account",
      "mapper" : "#/mappers/RelatedAccount"
    },
    "relatedContact" : {
      "path" : "Activity.Contact",
      "mapper" : "#/mappers/RelatedContact"
    },
    "relatedJob" : {
      "path" : "Activity.Job",
      "mapper" : "#/mappers/RelatedJob"
    },
    "relatedPolicy" : {
      "path" : "Activity.Policy",
      "mapper" : "#/mappers/RelatedPolicy"
    },
    "relatedPolicyPeriod" : {
      "path" : "Activity.PolicyPeriod",
      "mapper" : "#/mappers/RelatedPolicyPeriod"
    },
    "status" : {
      "path" : "Activity.Status"
    },
    "subject" : {
      "path" : "Activity.Subject"
    },
    "targetDate" : {
      "path" : "Activity.TargetDate"
    }
  }
},
"RelatedAccount" : {
  "schemaDefinition" : "RelatedAccount",
  "root" : "entity.Account",
  "properties" : {
    "accountNumber" : {
      "path" : "Account.AccountNumber"
    },
    "displayName" : {
      "path" : "Account.DisplayName"
    },
    "publicId" : {
      "path" : "Account.PublicID"
    }
  }
},
"RelatedContact" : {
  "schemaDefinition" : "RelatedContact",
  "root" : "entity.Contact",
  "properties" : {
    "displayName" : {
      "path" : "Contact.DisplayName"
    },
    "publicId" : {
      "path" : "Contact.PublicID"
    }
  }
},
"RelatedJob" : {
  "schemaDefinition" : "RelatedJob",
  "root" : "entity.Job",
  "properties" : {
    "displayName" : {
      "path" : "Job.DisplayName"
    },
    "jobNumber" : {
      "path" : "Job.JobNumber"
    },
    "jobType" : {
      "path" : "Job.Subtype"
    },
    "publicId" : {
      "path" : "Job.PublicID"
    }
  }
},
"RelatedPolicy" : {
  "schemaDefinition" : "RelatedPolicy",
  "root" : "entity.Policy",
  "properties" : {
    "displayName" : {
      "path" : "Policy.DisplayName"
    },
    "publicId" : {
      "path" : "Policy.PublicID"
    }
  }
},
"RelatedPolicyPeriod" : {
  "schemaDefinition" : "RelatedPolicyPeriod",
  "root" : "entity.PolicyPeriod",
  "properties" : {
    "displayName" : {
      "path" : "PolicyPeriod.DisplayName"
    },
    "policyNumber" : {
      "path" : "PolicyPeriod.PolicyNumber"
    },
    "publicId" : {
      "path" : "PolicyPeriod.PublicID"
    }
  }
}

Adding functionality to handler method getActivity

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 getActivty handler method uses a private method to retrieve the specified activity from the database using the activity ID. The method then uses the mapper declaration in generating the object that the method returns.

function getActivity(activityId : String) : TransformResult {
 var activity = loadActivityById(activityId)
  var mapper = JsonConfigAccess.getMapper("mc.activityapi.activityAPI-1.0", "ActivityDetail")
  return mapper.transformObject(activity)
}

private function loadActivityById(activityId : String) : Activity {
  var activity = Query.make(Activity).compare(Activity#PublicID, Relop.Equals, activityId).select().AtMostOneRow
  if (activity == null) {
    throw new NotFoundException("No activity was found with id " + activityId)
  }
  return activity
}

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