@Test public void testCreateDetector_populatedMeta_noUser() { val mom = ObjectMother.instance(); val document = mom.buildDetectorDocument(); DetectorDocument.Meta metaBlock = new DetectorDocument.Meta(); metaBlock.setCreatedBy(null); document.setMeta(metaBlock); repoUnderTest.createDetector(document); }
@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(); document.setLastUpdateTimestamp(nowDate); 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()); } } RequestValidator.validateDetectorDocument(document); val indexRequest = new IndexRequest(DETECTOR_INDEX, DETECTOR_DOC_TYPE, uuid.toString()); val json = objectMapperUtil.convertToString(getElasticSearchDetector(document)); elasticsearchUtil.index(indexRequest, json); return uuid; }
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(); document.setLastUpdateTimestamp(nowDate); 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()); } } RequestValidator.validateDetectorDocument(document); val indexRequest = new IndexRequest(DETECTOR_INDEX, DETECTOR_DOC_TYPE, uuid.toString()); val json = objectMapperUtil.convertToString(getElasticSearchDetector(document)); elasticsearchUtil.index(indexRequest, json); return uuid; } }
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(); document.setLastUpdateTimestamp(nowDate); 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()); } } RequestValidator.validateDetectorDocument(document); val indexRequest = new IndexRequest(DETECTOR_INDEX, DETECTOR_DOC_TYPE, uuid.toString()); val json = objectMapperUtil.convertToString(getElasticSearchDetector(document)); elasticsearchUtil.index(indexRequest, json); return uuid; }  }
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(); document.setLastUpdateTimestamp(nowDate); 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()); } } RequestValidator.validateDetectorDocument(document); val indexRequest = new IndexRequest(DETECTOR_INDEX, DETECTOR_DOC_TYPE, uuid.toString()); val json = objectMapperUtil.convertToString(getElasticSearchDetector(document)); elasticsearchUtil.index(indexRequest, json); return uuid; }  @Override UUID createDetector(DetectorDocument document); @Override void deleteDetector(String uuid); @Override void updateDetector(String uuid, DetectorDocument document); @Override DetectorDocument findByUuid(String uuid); @Override List<DetectorDocument> findByCreatedBy(String user); @Override void toggleDetector(String uuid, Boolean enabled); @Override void trustDetector(String uuid, Boolean trusted); @Override List<DetectorDocument> getLastUpdatedDetectors(long interval); @Override List<DetectorDocument> getLastUpdatedDetectors(String fromDate, String toDate); }
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(); document.setLastUpdateTimestamp(nowDate); 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()); } } RequestValidator.validateDetectorDocument(document); val indexRequest = new IndexRequest(DETECTOR_INDEX, DETECTOR_DOC_TYPE, uuid.toString()); val json = objectMapperUtil.convertToString(getElasticSearchDetector(document)); elasticsearchUtil.index(indexRequest, json); return uuid; }  @Override UUID createDetector(DetectorDocument document); @Override void deleteDetector(String uuid); @Override void updateDetector(String uuid, DetectorDocument document); @Override DetectorDocument findByUuid(String uuid); @Override List<DetectorDocument> findByCreatedBy(String user); @Override void toggleDetector(String uuid, Boolean enabled); @Override void trustDetector(String uuid, Boolean trusted); @Override List<DetectorDocument> getLastUpdatedDetectors(long interval); @Override List<DetectorDocument> getLastUpdatedDetectors(String fromDate, String toDate);  }