@Test public void succeedGetBulkIndexNameWithCreateBulkPattern() { Optional<String> result = RequestIdentifier.getBulkIndexName(TestConstants.BULK_CREATE_PAYLOAD); assertTrue(result.isPresent()); assertEquals(TestConstants.INDEX_NAME, result.get()); }
public static Optional<String> getBulkIndexName(@NonNull String payloadLine) { String payloadLineWithoutSpace = payloadLine.replaceAll(" +", ""); Optional<String> indexName = Optional.empty(); try { JSONObject payloadJson = new JSONObject(payloadLineWithoutSpace); if (payloadJson.has(Constants.BULK_INDEX_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_INDEX_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } if (payloadJson.has(Constants.BULK_CREATE_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_CREATE_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } return indexName; } catch (JSONException e) { return indexName; } }
RequestIdentifier { public static Optional<String> getBulkIndexName(@NonNull String payloadLine) { String payloadLineWithoutSpace = payloadLine.replaceAll(" +", ""); Optional<String> indexName = Optional.empty(); try { JSONObject payloadJson = new JSONObject(payloadLineWithoutSpace); if (payloadJson.has(Constants.BULK_INDEX_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_INDEX_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } if (payloadJson.has(Constants.BULK_CREATE_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_CREATE_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } return indexName; } catch (JSONException e) { return indexName; } } }
RequestIdentifier { public static Optional<String> getBulkIndexName(@NonNull String payloadLine) { String payloadLineWithoutSpace = payloadLine.replaceAll(" +", ""); Optional<String> indexName = Optional.empty(); try { JSONObject payloadJson = new JSONObject(payloadLineWithoutSpace); if (payloadJson.has(Constants.BULK_INDEX_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_INDEX_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } if (payloadJson.has(Constants.BULK_CREATE_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_CREATE_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } return indexName; } catch (JSONException e) { return indexName; } }  }
RequestIdentifier { public static Optional<String> getBulkIndexName(@NonNull String payloadLine) { String payloadLineWithoutSpace = payloadLine.replaceAll(" +", ""); Optional<String> indexName = Optional.empty(); try { JSONObject payloadJson = new JSONObject(payloadLineWithoutSpace); if (payloadJson.has(Constants.BULK_INDEX_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_INDEX_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } if (payloadJson.has(Constants.BULK_CREATE_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_CREATE_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } return indexName; } catch (JSONException e) { return indexName; } }  static boolean isConfigRequest(@NonNull Request esRequest); static boolean isConfigUpdateRequest(@NonNull Request esRequest); static boolean isMutationRequest(@NonNull Request esRequest); static boolean isIndexRequest(@NonNull Request esRequest); static boolean isBulkRequest(@NonNull Request esRequest); static String getIndexName(@NonNull Request esRequest); static Optional<String> getBulkIndexName(@NonNull String payloadLine); }
RequestIdentifier { public static Optional<String> getBulkIndexName(@NonNull String payloadLine) { String payloadLineWithoutSpace = payloadLine.replaceAll(" +", ""); Optional<String> indexName = Optional.empty(); try { JSONObject payloadJson = new JSONObject(payloadLineWithoutSpace); if (payloadJson.has(Constants.BULK_INDEX_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_INDEX_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } if (payloadJson.has(Constants.BULK_CREATE_ACTION_KEY)) { return Optional.ofNullable(payloadJson.getJSONObject(Constants.BULK_CREATE_ACTION_KEY) .getString(Constants.BULK_INDEX_ACTION_KEY_NAME)); } return indexName; } catch (JSONException e) { return indexName; } }  static boolean isConfigRequest(@NonNull Request esRequest); static boolean isConfigUpdateRequest(@NonNull Request esRequest); static boolean isMutationRequest(@NonNull Request esRequest); static boolean isIndexRequest(@NonNull Request esRequest); static boolean isBulkRequest(@NonNull Request esRequest); static String getIndexName(@NonNull Request esRequest); static Optional<String> getBulkIndexName(@NonNull String payloadLine);  }