private static MetricDto newMetricTemplate(Request request) { int id = request.mandatoryParamAsInt(PARAM_ID); String key = request.param(PARAM_KEY); if (key != null) { MetricKeyValidator.checkMetricKeyFormat(key); } String type = request.param(PARAM_TYPE); String name = request.param(PARAM_NAME); String domain = request.param(PARAM_DOMAIN); String description = request.param(PARAM_DESCRIPTION); MetricDto metricTemplate = new MetricDto().setId(id); if (key != null) { metricTemplate.setKey(key); } if (type != null) { metricTemplate.setValueType(type); } if (name != null) { metricTemplate.setShortName(name); } if (domain != null) { metricTemplate.setDomain(domain); } if (description != null) { metricTemplate.setDescription(description); } return metricTemplate; }