<commit_before>package com.wikia.mobileconfig.resources;

import com.codahale.metrics.annotation.Timed;
import com.theoryinpractise.halbuilder.api.Representation;
import com.theoryinpractise.halbuilder.api.RepresentationFactory;
import com.wikia.mobileconfig.MobileConfigApplication;
import com.wikia.mobileconfig.core.EmptyMobileConfiguration;
import com.wikia.mobileconfig.core.MobileConfiguration;
import com.wikia.mobileconfig.exceptions.ConfigurationNotFoundException;
import com.wikia.mobileconfig.exceptions.InvalidApplicationTagException;
import com.wikia.mobileconfig.exceptions.MobileConfigException;
import com.wikia.mobileconfig.gateway.AppsListService;
import com.wikia.mobileconfig.service.ConfigurationService;

import java.io.IOException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

@Path("/configurations/{platform}/apps/{app-tag}")
@Produces(RepresentationFactory.HAL_JSON)
public class MobileConfigResource {

  private final static String APP_TAG_VALIDATION_EXCEPTION_MESSAGE =
      "An exception occurred while validating application tag";

  private final static String GET_CONFIGURATION_EXCEPTION_MESSAGE =
      "An exception occurred while getting configuration";

  private final ConfigurationService appConfiguration;
  private final AppsListService appsList;

  public MobileConfigResource(ConfigurationService configuration, AppsListService list) {
    this.appConfiguration = configuration;
    this.appsList = list;
  }

  /**
   * GET /configurations/{platform}/apps/{app-tag}
   *
   * @return Representation
   */
  @GET
  @Timed
  public Representation getMobileApplicationConfig(
      @PathParam("platform") String platform,
      @PathParam("app-tag") String appTag,
      @QueryParam("ui-lang") String uiLang,
      @QueryParam("content-lang") String contentLang
  ) throws MobileConfigException {
    Boolean isValidAppTag = isValidAppTag(platform, appTag);

    if (!isValidAppTag) {
      throw new InvalidApplicationTagException(appTag);
    }

    MobileConfiguration configuration = getConfiguration(platform, appTag, uiLang, contentLang);

    if (configuration.getModules().isEmpty()) {
      throw new ConfigurationNotFoundException(platform, appTag);
    }
<commit_msg>Add a 5 minute maxage to CacheControl for configs<commit_after>package com.wikia.mobileconfig.resources;

import com.codahale.metrics.annotation.Timed;
import com.theoryinpractise.halbuilder.api.Representation;
import com.theoryinpractise.halbuilder.api.RepresentationFactory;
import com.wikia.mobileconfig.MobileConfigApplication;
import com.wikia.mobileconfig.core.EmptyMobileConfiguration;
import com.wikia.mobileconfig.core.MobileConfiguration;
import com.wikia.mobileconfig.exceptions.ConfigurationNotFoundException;
import com.wikia.mobileconfig.exceptions.InvalidApplicationTagException;
import com.wikia.mobileconfig.exceptions.MobileConfigException;
import com.wikia.mobileconfig.gateway.AppsListService;
import com.wikia.mobileconfig.service.ConfigurationService;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import io.dropwizard.jersey.caching.CacheControl;

@Path("/configurations/{platform}/apps/{app-tag}")
@Produces(RepresentationFactory.HAL_JSON)
public class MobileConfigResource {

  private final static String APP_TAG_VALIDATION_EXCEPTION_MESSAGE =
      "An exception occurred while validating application tag";

  private final static String GET_CONFIGURATION_EXCEPTION_MESSAGE =
      "An exception occurred while getting configuration";

  private final ConfigurationService appConfiguration;
  private final AppsListService appsList;

  public MobileConfigResource(ConfigurationService configuration, AppsListService list) {
    this.appConfiguration = configuration;
    this.appsList = list;
  }

  /**
   * GET /configurations/{platform}/apps/{app-tag}
   *
   * @return Representation
   */
  @GET
  @Timed
  @CacheControl(maxAge = 5, maxAgeUnit = TimeUnit.MINUTES)
  public Representation getMobileApplicationConfig(
      @PathParam("platform") String platform,
      @PathParam("app-tag") String appTag,
      @QueryParam("ui-lang") String uiLang,
      @QueryParam("content-lang") String contentLang
  ) throws MobileConfigException {
    Boolean isValidAppTag = isValidAppTag(platform, appTag);

    if (!isValidAppTag) {
      throw new InvalidApplicationTagException(appTag);
    }

    MobileConfiguration configuration = getConfiguration(platform, appTag, uiLang, contentLang);

    if (configuration.getModules().isEmpty()) {
      throw new ConfigurationNotFoundException(platform, appTag);
    }

{'fraction_non_alphanumeric': 0.08928571428571429, 'fraction_numerical': 0.0004152823920265781, 'mean_word_length': 5.52710027100271, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6082697', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1306, 'n_words': 266}