SolrMetaAlertDao implements MetaAlertDao { @Override public void init(IndexDao indexDao, Optional<String> threatSort) { if (indexDao instanceof MultiIndexDao) { this.indexDao = indexDao; MultiIndexDao multiIndexDao = (MultiIndexDao) indexDao; for (IndexDao childDao : multiIndexDao.getIndices()) { if (childDao instanceof SolrDao) { this.solrDao = (SolrDao) childDao; } } } else if (indexDao instanceof SolrDao) { this.indexDao = indexDao; this.solrDao = (SolrDao) indexDao; } else { throw new IllegalArgumentException( "Need a SolrDao when using SolrMetaAlertDao" ); } Supplier<Map<String, Object>> globalConfigSupplier = () -> new HashMap<>(); if(metaAlertSearchDao != null && metaAlertSearchDao.solrSearchDao != null && metaAlertSearchDao.solrSearchDao.getAccessConfig() != null) { globalConfigSupplier = metaAlertSearchDao.solrSearchDao.getAccessConfig().getGlobalConfigSupplier(); } MetaAlertConfig config = new MetaAlertConfig( metaAlertsCollection, this.threatSort, globalConfigSupplier ) { @Override protected String getDefaultThreatTriageField() { return MetaAlertConstants.THREAT_FIELD_DEFAULT.replace(':', '.'); } @Override protected String getDefaultSourceTypeField() { return Constants.SENSOR_TYPE; } }; SolrClient solrClient = SolrClientFactory.create(globalConfigSupplier.get()); this.metaAlertSearchDao = new SolrMetaAlertSearchDao(solrClient, solrDao.getSolrSearchDao(), config); this.metaAlertRetrieveLatestDao = new SolrMetaAlertRetrieveLatestDao(solrClient, solrDao); this.metaAlertUpdateDao = new SolrMetaAlertUpdateDao( solrClient, solrDao, metaAlertSearchDao, metaAlertRetrieveLatestDao, config); if (threatSort.isPresent()) { this.threatSort = threatSort.get(); } } SolrMetaAlertDao(IndexDao indexDao, SolrMetaAlertSearchDao metaAlertSearchDao,
      SolrMetaAlertUpdateDao metaAlertUpdateDao,
      SolrMetaAlertRetrieveLatestDao metaAlertRetrieveLatestDao);  SolrMetaAlertDao(IndexDao indexDao, SolrMetaAlertSearchDao metaAlertSearchDao,
      SolrMetaAlertUpdateDao metaAlertUpdateDao,
      SolrMetaAlertRetrieveLatestDao metaAlertRetrieveLatestDao,
      String metaAlertsCollection,
      String threatSort);  SolrMetaAlertDao(); @Override void init(IndexDao indexDao, Optional<String> threatSort); @Override void init(AccessConfig config); @Override Map<String, FieldType> getColumnMetadata(List<String> indices); @Override Document getLatest(String guid, String sensorType); @Override Iterable<Document> getAllLatest(List<GetRequest> getRequests); @Override SearchResponse search(SearchRequest searchRequest); @Override GroupResponse group(GroupRequest groupRequest); @Override Document update(Document update, Optional<String> index); @Override Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>> updates); @Override Document patch(RetrieveLatestDao retrieveLatestDao, PatchRequest request,
      Optional<Long> timestamp); @Override SearchResponse getAllMetaAlertsForAlert(String guid); @Override Document createMetaAlert(MetaAlertCreateRequest request); @Override Document addAlertsToMetaAlert(String metaAlertGuid, List<GetRequest> alertRequests); @Override Document removeAlertsFromMetaAlert(String metaAlertGuid, List<GetRequest> alertRequests); @Override Document updateMetaAlertStatus(String metaAlertGuid, MetaAlertStatus status); @Override Document addCommentToAlert(CommentAddRemoveRequest request); @Override Document removeCommentFromAlert(CommentAddRemoveRequest request); @Override Document addCommentToAlert(CommentAddRemoveRequest request, Document latest); @Override Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest); static final String METAALERTS_COLLECTION; }
@Test public void testInvalidInit() { IndexDao dao = new IndexDao() { @Override public SearchResponse search(SearchRequest searchRequest) { return null; } @Override public GroupResponse group(GroupRequest groupRequest) { return null; } @Override public void init(AccessConfig config) { } @Override public Document getLatest(String guid, String sensorType) { return null; } @Override public Iterable<Document> getAllLatest( List<GetRequest> getRequests) { return null; } @Override public Document update(Document update, Optional<String> index) { return null; } @Override public Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>> updates) { return null; } @Override public Document addCommentToAlert(CommentAddRemoveRequest request) { return null; } @Override public Document removeCommentFromAlert(CommentAddRemoveRequest request) { return null; } @Override public Document addCommentToAlert(CommentAddRemoveRequest request, Document latest) { return null; } @Override public Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest) { return null; } @Override public Document patch(RetrieveLatestDao dao, PatchRequest request, Optional<Long> timestamp) { return null; } @Override public Map<String, FieldType> getColumnMetadata(List<String> indices) { return null; } }; SolrMetaAlertDao metaAlertDao = new SolrMetaAlertDao(); assertThrows(IllegalArgumentException.class, () -> metaAlertDao.init(dao)); }
@Test public void testInitInvalidDao() { HBaseDao dao = new HBaseDao(); SolrMetaAlertDao solrDao = new SolrMetaAlertDao(); assertThrows(IllegalArgumentException.class, () -> solrDao.init(dao, Optional.empty())); }