@Override
  public void handle(Request request, Response response) throws Exception {
    DbSession session = dbClient.openSession(false);
    try {
      String profileKey =
          QProfileIdentificationParamUtils.getProfileKeyFromParameters(
              request, profileFactory, session);
      if (dbClient.qualityProfileDao().getByKey(session, profileKey) == null) {
        throw new NotFoundException(
            String.format("Could not find a profile with key '%s'", profileKey));
      }

      QProfileActivityQuery query = new QProfileActivityQuery().setQprofileKey(profileKey);
      Date since = request.paramAsDateTime(PARAM_SINCE);
      if (since != null) {
        query.setSince(since);
      }
      Date to = request.paramAsDateTime(PARAM_TO);
      if (to != null) {
        query.setTo(to);
      }
      SearchOptions options = new SearchOptions();

      int page = request.mandatoryParamAsInt(Param.PAGE);
      options.setPage(page, request.mandatoryParamAsInt(Param.PAGE_SIZE));

      Result<QProfileActivity> result = searchActivities(query, options);
      writeResponse(
          response.newJsonWriter(),
          result,
          Paging.create(options.getLimit(), page, (int) result.getTotal()));
    } finally {
      session.close();
    }
  }
  @Override
  public void define(NewController context) {
    NewAction changelog =
        context
            .createAction("changelog")
            .setSince("5.2")
            .setDescription(
                "Get the history of changes on a quality profile: rule activation/deactivation, change in parameters/severity. "
                    + "Events are ordered by date in descending order (most recent first).")
            .setHandler(this)
            .setResponseExample(getClass().getResource("example-changelog.json"));

    QProfileIdentificationParamUtils.defineProfileParams(changelog, languages);

    changelog.addPagingParams(50);

    changelog
        .createParam(PARAM_SINCE)
        .setDescription("Start date for the changelog.")
        .setExampleValue("2011-04-25T01:15:42+0100");

    changelog
        .createParam(PARAM_TO)
        .setDescription("End date for the changelog.")
        .setExampleValue("2013-07-25T07:35:42+0200");
  }