@Test(expected=Exception.class) public void testEnsureIndexAndTypeForAnnotationWithNoEsURL() throws Exception{ Annotation annotation = new Annotation(); annotation.put(PacmanSdkConstants.DATA_SOURCE_KEY, "test"); annotation.put(PacmanSdkConstants.TARGET_TYPE, "test"); annotation.put(PacmanSdkConstants.TYPE, "test"); PowerMockito.mockStatic(CommonUtils.class); PowerMockito.when(CommonUtils.isValidResource(anyString())).thenReturn(Boolean.TRUE); ESUtils.ensureIndexAndTypeForAnnotation(annotation, Boolean.FALSE); }
public static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound) throws Exception { String esUrl = getEsUrl(); if(Strings.isNullOrEmpty(esUrl)){ throw new Exception("ES host cannot be null"); } String indexName = buildIndexNameFromAnnotation(annotation); if (!Strings.isNullOrEmpty(indexName)) { indexName = indexName.toLowerCase(); } else throw new Exception("Index/datasource/pac_ds name cannot be null or blank"); if (!isValidIndex(esUrl, indexName)) { throw new Exception("Index is not yet ready to publish the data"); } String parentType, type; if (!Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TARGET_TYPE)) && !Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TYPE))) { parentType = annotation.get(PacmanSdkConstants.TARGET_TYPE); type = getIssueTypeFromAnnotation(annotation); } else throw new Exception("targetType name cannot be null or blank"); if (!isValidType(esUrl, indexName, type)) { throw new Exception("Index exists but unable to find type to publish the data"); } }
ESUtils { public static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound) throws Exception { String esUrl = getEsUrl(); if(Strings.isNullOrEmpty(esUrl)){ throw new Exception("ES host cannot be null"); } String indexName = buildIndexNameFromAnnotation(annotation); if (!Strings.isNullOrEmpty(indexName)) { indexName = indexName.toLowerCase(); } else throw new Exception("Index/datasource/pac_ds name cannot be null or blank"); if (!isValidIndex(esUrl, indexName)) { throw new Exception("Index is not yet ready to publish the data"); } String parentType, type; if (!Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TARGET_TYPE)) && !Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TYPE))) { parentType = annotation.get(PacmanSdkConstants.TARGET_TYPE); type = getIssueTypeFromAnnotation(annotation); } else throw new Exception("targetType name cannot be null or blank"); if (!isValidType(esUrl, indexName, type)) { throw new Exception("Index exists but unable to find type to publish the data"); } } }
ESUtils { public static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound) throws Exception { String esUrl = getEsUrl(); if(Strings.isNullOrEmpty(esUrl)){ throw new Exception("ES host cannot be null"); } String indexName = buildIndexNameFromAnnotation(annotation); if (!Strings.isNullOrEmpty(indexName)) { indexName = indexName.toLowerCase(); } else throw new Exception("Index/datasource/pac_ds name cannot be null or blank"); if (!isValidIndex(esUrl, indexName)) { throw new Exception("Index is not yet ready to publish the data"); } String parentType, type; if (!Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TARGET_TYPE)) && !Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TYPE))) { parentType = annotation.get(PacmanSdkConstants.TARGET_TYPE); type = getIssueTypeFromAnnotation(annotation); } else throw new Exception("targetType name cannot be null or blank"); if (!isValidType(esUrl, indexName, type)) { throw new Exception("Index exists but unable to find type to publish the data"); } }  }
ESUtils { public static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound) throws Exception { String esUrl = getEsUrl(); if(Strings.isNullOrEmpty(esUrl)){ throw new Exception("ES host cannot be null"); } String indexName = buildIndexNameFromAnnotation(annotation); if (!Strings.isNullOrEmpty(indexName)) { indexName = indexName.toLowerCase(); } else throw new Exception("Index/datasource/pac_ds name cannot be null or blank"); if (!isValidIndex(esUrl, indexName)) { throw new Exception("Index is not yet ready to publish the data"); } String parentType, type; if (!Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TARGET_TYPE)) && !Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TYPE))) { parentType = annotation.get(PacmanSdkConstants.TARGET_TYPE); type = getIssueTypeFromAnnotation(annotation); } else throw new Exception("targetType name cannot be null or blank"); if (!isValidType(esUrl, indexName, type)) { throw new Exception("Index exists but unable to find type to publish the data"); } }  static List<Map<String, String>> getResourcesFromEs(String index, String targetType,
            Map<String, String> filter, List<String> fields); @SuppressWarnings("unchecked") static long getTotalDocumentCountForIndexAndType(String url, String index, String type,
            Map<String, Object> filter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter); static boolean isValidIndex(final String url, final String index); static boolean isValidType(final String url, final String index, final String type); static String getEsUrl(); static String createMapping(String esUrl, String index, String type); static String createMappingWithParent(String esUrl, String index, String type, String parentType); static void createIndex(String url, String indexName); static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound); static String buildIndexNameFromAnnotation(final Annotation annotation); static String getIssueTypeFromAnnotation(Annotation annotation); @SuppressWarnings("unchecked") static List<Map<String, String>> getDataFromES(final String url, String dataSource, String entityType,
            Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
            final HashMultimap<String, Object> shouldFilter, List<String> fields, long from, long size); static String convertAttributetoKeyword(String attributeName); static Map<String, String> getDocumentForId(String index, String targetType, String _id); static Boolean publishMetrics(Map<String, Object> evalResults,String type); static int getESPort(); static String getESHost(); static Boolean doESPublish(Map<String, Object> evalResults, String indexName, String type); static Boolean doESUpdate(String docId,Map<String, Object> evalResults, String indexName, String type); static String createKeyword(final String key); }
ESUtils { public static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound) throws Exception { String esUrl = getEsUrl(); if(Strings.isNullOrEmpty(esUrl)){ throw new Exception("ES host cannot be null"); } String indexName = buildIndexNameFromAnnotation(annotation); if (!Strings.isNullOrEmpty(indexName)) { indexName = indexName.toLowerCase(); } else throw new Exception("Index/datasource/pac_ds name cannot be null or blank"); if (!isValidIndex(esUrl, indexName)) { throw new Exception("Index is not yet ready to publish the data"); } String parentType, type; if (!Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TARGET_TYPE)) && !Strings.isNullOrEmpty(annotation.get(PacmanSdkConstants.TYPE))) { parentType = annotation.get(PacmanSdkConstants.TARGET_TYPE); type = getIssueTypeFromAnnotation(annotation); } else throw new Exception("targetType name cannot be null or blank"); if (!isValidType(esUrl, indexName, type)) { throw new Exception("Index exists but unable to find type to publish the data"); } }  static List<Map<String, String>> getResourcesFromEs(String index, String targetType,
            Map<String, String> filter, List<String> fields); @SuppressWarnings("unchecked") static long getTotalDocumentCountForIndexAndType(String url, String index, String type,
            Map<String, Object> filter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter); static boolean isValidIndex(final String url, final String index); static boolean isValidType(final String url, final String index, final String type); static String getEsUrl(); static String createMapping(String esUrl, String index, String type); static String createMappingWithParent(String esUrl, String index, String type, String parentType); static void createIndex(String url, String indexName); static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound); static String buildIndexNameFromAnnotation(final Annotation annotation); static String getIssueTypeFromAnnotation(Annotation annotation); @SuppressWarnings("unchecked") static List<Map<String, String>> getDataFromES(final String url, String dataSource, String entityType,
            Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
            final HashMultimap<String, Object> shouldFilter, List<String> fields, long from, long size); static String convertAttributetoKeyword(String attributeName); static Map<String, String> getDocumentForId(String index, String targetType, String _id); static Boolean publishMetrics(Map<String, Object> evalResults,String type); static int getESPort(); static String getESHost(); static Boolean doESPublish(Map<String, Object> evalResults, String indexName, String type); static Boolean doESUpdate(String docId,Map<String, Object> evalResults, String indexName, String type); static String createKeyword(final String key);  }