class LegacyDetectorRepositoryImpl implements LegacyDetectorRepository {

    @Override
    public UUID createDetector(DetectorDocument document) {
        notNull(document, "document can't be null");
        isNull(document.getUuid(), "Required: document.uuid == null");

        val uuid = UUID.randomUUID();
        document.setUuid(uuid);
        Date nowDate = DateUtil.now();

        // Force setting last update time to current time. Although deprecated, this field is still used to determine what changed for cache loading.
        // In the future this can change to the field within Meta
        document.setLastUpdateTimestamp(nowDate);

        // Set meta fields if none are provided
        if (document.getMeta() == null) {
            DetectorDocument.Meta metaBlock = new DetectorDocument.Meta();
            metaBlock.setDateCreated(nowDate);
            metaBlock.setCreatedBy(document.getCreatedBy());
            document.setMeta(metaBlock);
        } else {
            DetectorDocument.Meta metaBlock = document.getMeta();
            metaBlock.setDateCreated(nowDate);
            if (metaBlock.getCreatedBy() == null) {
                metaBlock.setCreatedBy(document.getCreatedBy());
            }
        }

        // Do this after setting the UUID since validation checks for the UUID.
        RequestValidator.validateDetectorDocument(document);

        val indexRequest = new IndexRequest(DETECTOR_INDEX, DETECTOR_DOC_TYPE, uuid.toString());
        val json = objectMapperUtil.convertToString(getElasticSearchDetector(document));

        // FIXME We should not be returning an implementation-specific ID here. (This is an Elasticsearch document ID.)
//        return elasticsearchUtil.index(indexRequest, json).getId();
        elasticsearchUtil.index(indexRequest, json);
        return uuid;
    }

}