@Override public void put(Value value, Object object, CoderContext context) { Measure<?> m = (Measure) object; value.putUTF(m.getMetricKey()); value.put(m.getValue()); putUTFOrNull(value, m.getData()); putUTFOrNull(value, m.getDescription()); value.putString(m.getAlertStatus() != null ? m.getAlertStatus().name() : null); putUTFOrNull(value, m.getAlertText()); value.putDate(m.getDate()); value.put(m.getVariation1()); value.put(m.getVariation2()); value.put(m.getVariation3()); value.put(m.getVariation4()); value.put(m.getVariation5()); putUTFOrNull(value, m.getUrl()); Integer personId = m.getPersonId(); value.put(personId != null ? personId.intValue() : null); PersistenceMode persistenceMode = m.getPersistenceMode(); value.putString(persistenceMode != null ? persistenceMode.name() : null); }
@Override public Object get(Value value, Class clazz, CoderContext context) { Measure<?> m = new Measure(); String metricKey = value.getString(); org.sonar.api.batch.measure.Metric metric = metricFinder.findByKey(metricKey); if (metric == null) { throw new IllegalStateException("Unknow metric with key " + metricKey); } m.setMetric((org.sonar.api.measures.Metric) metric); m.setRawValue(value.isNull(true) ? null : value.getDouble()); m.setData(value.getString()); m.setDescription(value.getString()); m.setAlertStatus(value.isNull(true) ? null : Metric.Level.valueOf(value.getString())); m.setAlertText(value.getString()); m.setDate(value.getDate()); m.setVariation1(value.isNull(true) ? null : value.getDouble()); m.setVariation2(value.isNull(true) ? null : value.getDouble()); m.setVariation3(value.isNull(true) ? null : value.getDouble()); m.setVariation4(value.isNull(true) ? null : value.getDouble()); m.setVariation5(value.isNull(true) ? null : value.getDouble()); m.setUrl(value.getString()); m.setPersonId(value.isNull(true) ? null : value.getInt()); m.setPersistenceMode(value.isNull(true) ? null : PersistenceMode.valueOf(value.getString())); return m; } }
@VisibleForTesting static boolean shouldPersistMeasure(@Nullable Resource resource, @Nullable Measure measure) { if (resource == null || measure == null) { return false; } return measure.getPersistenceMode().useDatabase() && !(ResourceUtils.isEntity(resource) && measure.isBestValue()) && isMeasureNotEmpty(measure); }
@Override public void put(Value value, Object object, CoderContext context) { Measure<?> m = (Measure) object; value.putUTF(m.getMetricKey()); value.put(m.getValue()); putUTFOrNull(value, m.getData()); putUTFOrNull(value, m.getDescription()); value.putString(m.getAlertStatus() != null ? m.getAlertStatus().name() : null); putUTFOrNull(value, m.getAlertText()); value.put(m.getTendency()); value.putDate(m.getDate()); value.put(m.getVariation1()); value.put(m.getVariation2()); value.put(m.getVariation3()); value.put(m.getVariation4()); value.put(m.getVariation5()); putUTFOrNull(value, m.getUrl()); Characteristic characteristic = m.getCharacteristic(); value.put(characteristic != null ? characteristic.id() : null); Requirement requirement = m.getRequirement(); value.put(requirement != null ? requirement.id() : null); Integer personId = m.getPersonId(); value.put(personId != null ? personId.intValue() : null); PersistenceMode persistenceMode = m.getPersistenceMode(); value.putString(persistenceMode != null ? persistenceMode.name() : null); }
@Override public Object get(Value value, Class clazz, CoderContext context) { Measure<?> m = new Measure(); String metricKey = value.getString(); org.sonar.api.batch.measure.Metric metric = metricFinder.findByKey(metricKey); if (metric == null) { throw new IllegalStateException("Unknow metric with key " + metricKey); } m.setMetric((org.sonar.api.measures.Metric) metric); m.setRawValue(value.isNull(true) ? null : value.getDouble()); m.setData(value.getString()); m.setDescription(value.getString()); m.setAlertStatus(value.isNull(true) ? null : Metric.Level.valueOf(value.getString())); m.setAlertText(value.getString()); m.setTendency(value.isNull(true) ? null : value.getInt()); m.setDate(value.getDate()); m.setVariation1(value.isNull(true) ? null : value.getDouble()); m.setVariation2(value.isNull(true) ? null : value.getDouble()); m.setVariation3(value.isNull(true) ? null : value.getDouble()); m.setVariation4(value.isNull(true) ? null : value.getDouble()); m.setVariation5(value.isNull(true) ? null : value.getDouble()); m.setUrl(value.getString()); m.setCharacteristic(value.isNull(true) ? null : techDebtModel.characteristicById(value.getInt())); m.setRequirement(value.isNull(true) ? null : techDebtModel.requirementsById(value.getInt())); m.setPersonId(value.isNull(true) ? null : value.getInt()); m.setPersistenceMode(value.isNull(true) ? null : PersistenceMode.valueOf(value.getString())); return m; } }