class LegacyDetectorRepositoryImpl implements LegacyDetectorRepository {

    @Override
    public void updateDetector(String uuid, DetectorDocument document) {
        notNull(document, "document can't be null");
        MDC.put("DetectorUuid", uuid);
        RequestValidator.validateDetectorDocument(document);

        val updateRequest = new UpdateRequest(DETECTOR_INDEX, DETECTOR_DOC_TYPE, uuid);
        Map<String, Object> jsonMap = new HashMap<>();

        for (Field field : document.getClass().getDeclaredFields()) {
            //SAST SCAN. Access Specifier Manipulation. Using reflection utils to make the field accessible.
            ReflectionUtils.makeAccessible(field);
            String name = field.getName();
            if (!name.isEmpty()) {
                Object value;
                Date nowDate = DateUtil.now();
                try {
                    value = field.get(document);
                } catch (IllegalAccessException e) {
                    log.error("Updating elastic search failed", e);
                    throw new RuntimeException(e);
                }
                if ("lastUpdateTimestamp".equals(name)) {
                    value = DateUtil.toDateString(nowDate.toInstant());
                }
                if ("meta".equals(name)) {
                    // Set meta fields if none are provided
                    if (document.getMeta() == null) {
                        DetectorDocument.Meta metaBlock = new DetectorDocument.Meta();
                        metaBlock.setDateUpdated(nowDate);
                        document.setMeta(metaBlock);
                    } else {
                        DetectorDocument.Meta metaBlock = document.getMeta();
                        metaBlock.setDateUpdated(nowDate);
                        metaBlock.setUpdatedBy(document.getMeta().getUpdatedBy());
                    }
                }
                // Remap the JSON property name for any DetectorDocument properties with a defined JsonProperty name
                if (field.isAnnotationPresent(JsonProperty.class)) {
                    name = field.getAnnotation(JsonProperty.class).value();
                }
                if (value != null) {
                    jsonMap.put(name, value);
                }
            }
        }
        val json = objectMapperUtil.convertToString(jsonMap);   // Convert hashmap to JSON for elasticsearch
        updateRequest.doc(json, XContentType.JSON);
        try {
            val updateResponse = legacyElasticSearchClient.update(updateRequest, RequestOptions.DEFAULT);
            if (elasticsearchUtil.checkNullResponse(updateResponse.getResult())) {
                throw new RecordNotFoundException("Invalid request: " + uuid);
            }
        } catch (IOException e) {
            log.error("Updating elastic search failed", e);
            throw new RuntimeException(e);
        } finally {
            MDC.remove("DetectorUuid");
        }
    }

}