Java Code Examples for org.elasticsearch.common.Strings#isEmpty()
The following examples show how to use
org.elasticsearch.common.Strings#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockAmazonS3.java From crate with Apache License 2.0 | 6 votes |
@Override public ObjectListing listObjects(final ListObjectsRequest request) throws AmazonClientException { assertThat(request.getBucketName(), equalTo(bucket)); final ObjectListing listing = new ObjectListing(); listing.setBucketName(request.getBucketName()); listing.setPrefix(request.getPrefix()); for (Map.Entry<String, byte[]> blob : blobs.entrySet()) { if (Strings.isEmpty(request.getPrefix()) || blob.getKey().startsWith(request.getPrefix())) { S3ObjectSummary summary = new S3ObjectSummary(); summary.setBucketName(request.getBucketName()); summary.setKey(blob.getKey()); summary.setSize(blob.getValue().length); listing.getObjectSummaries().add(summary); } } return listing; }
Example 2
Source File: DocumentParser.java From crate with Apache License 2.0 | 6 votes |
private static String[] splitAndValidatePath(String fullFieldPath) { if (fullFieldPath.contains(".")) { String[] parts = fullFieldPath.split("\\."); for (String part : parts) { if (Strings.hasText(part) == false) { // check if the field name contains only whitespace if (Strings.isEmpty(part) == false) { throw new IllegalArgumentException( "object field cannot contain only whitespace: ['" + fullFieldPath + "']"); } throw new IllegalArgumentException( "object field starting or ending with a [.] makes object resolution ambiguous: [" + fullFieldPath + "]"); } } return parts; } else { if (Strings.isEmpty(fullFieldPath)) { throw new IllegalArgumentException("field name cannot be an empty string"); } return new String[] {fullFieldPath}; } }
Example 3
Source File: RestGetAnomalyDetectorAction.java From anomaly-detection with Apache License 2.0 | 6 votes |
@Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { if (!EnabledSetting.isADPluginEnabled()) { throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG); } String detectorId = request.param(DETECTOR_ID); String typesStr = request.param(TYPE); String rawPath = request.rawPath(); if (!Strings.isEmpty(typesStr) || rawPath.endsWith(PROFILE) || rawPath.endsWith(PROFILE + "/")) { boolean all = request.paramAsBoolean("_all", false); return channel -> profileRunner .profile(detectorId, getProfileActionListener(channel, detectorId), getProfilesToCollect(typesStr, all)); } else { boolean returnJob = request.paramAsBoolean("job", false); MultiGetRequest.Item adItem = new MultiGetRequest.Item(ANOMALY_DETECTORS_INDEX, detectorId) .version(RestActions.parseVersion(request)); MultiGetRequest multiGetRequest = new MultiGetRequest().add(adItem); if (returnJob) { MultiGetRequest.Item adJobItem = new MultiGetRequest.Item(ANOMALY_DETECTOR_JOB_INDEX, detectorId) .version(RestActions.parseVersion(request)); multiGetRequest.add(adJobItem); } return channel -> client.multiGet(multiGetRequest, onMultiGetResponse(channel, returnJob, detectorId)); } }
Example 4
Source File: LangDetectProcessor.java From elasticsearch-ingest-langdetect with Apache License 2.0 | 6 votes |
@Override public IngestDocument execute(IngestDocument ingestDocument) throws Exception { Detector detector = DetectorFactory.create(); detector.setMaxTextLength(maxLength.bytesAsInt()); String content; try { content = ingestDocument.getFieldValue(field, String.class); } catch (IllegalArgumentException e) { if (ignoreMissing) { return ingestDocument; } throw e; } if (Strings.isEmpty(content)) { return ingestDocument; } detector.append(content); String language = detector.detect(); ingestDocument.setFieldValue(targetField, language); return ingestDocument; }
Example 5
Source File: CsvProcessor.java From elasticsearch-ingest-csv with Apache License 2.0 | 6 votes |
@Override public CsvProcessor create(Map<String, Processor.Factory> factories, String tag, Map<String, Object> config) throws Exception { String field = readStringProperty(TYPE, tag, config, "field"); List<String> columns = readList(TYPE, tag, config, "columns"); // FIXME should test duplicate name if (columns.size() == 0) { throw new IllegalArgumentException("columns is missing"); } String quoteChar = readStringProperty(TYPE, tag, config, "quote_char", "\""); if (Strings.isEmpty(quoteChar) || quoteChar.length() != 1) { throw new IllegalArgumentException("quote_char must be a character, like \" or \'"); } String separator = readStringProperty(TYPE, tag, config, "separator", ","); if (Strings.isEmpty(separator) || separator.length() != 1) { throw new IllegalArgumentException("separator must be a character, like , or TAB"); } int maxCharsPerColumn = readIntProperty(TYPE, tag, config, "max_chars_per_column", 4096); if (maxCharsPerColumn < 1 || maxCharsPerColumn > 64000) { throw new IllegalArgumentException("maxCharsPerColumn must be between 1 and 64000 (default 4096)"); } return new CsvProcessor(tag, field, columns, quoteChar.charAt(0), separator.charAt(0),maxCharsPerColumn); }
Example 6
Source File: UserDictionaryLoader.java From elasticsearch-analysis-openkoreantext with Apache License 2.0 | 5 votes |
private static void addUserDictionary(BufferedReader bufferedReader) throws IOException { List<String> words = new ArrayList<>(); String word; while ((word = bufferedReader.readLine()) != null) { if(Strings.isEmpty(word)) continue; words.add(word); } addUserDictionary(words); }
Example 7
Source File: NodeTestHelper.java From elasticsearch-graphite-plugin with Do What The F*ck You Want To Public License | 5 votes |
public static Node createNode(String clusterName, int graphitePort, String refreshInterval, String includeRegex, String excludeRegex, String prefix) throws IOException { ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder(); settingsBuilder.put("path.conf", NodeTestHelper.class.getResource("/").getFile()); settingsBuilder.put("gateway.type", "none"); settingsBuilder.put("cluster.name", clusterName); settingsBuilder.put("index.number_of_shards", 1); settingsBuilder.put("index.number_of_replicas", 1); settingsBuilder.put("metrics.graphite.host", "localhost"); settingsBuilder.put("metrics.graphite.port", graphitePort); settingsBuilder.put("metrics.graphite.every", refreshInterval); if (!Strings.isEmpty(prefix)) { settingsBuilder.put("metrics.graphite.prefix", prefix); } if (Strings.hasLength(includeRegex)) { settingsBuilder.put("metrics.graphite.include", includeRegex); } if (Strings.hasLength(excludeRegex)) { settingsBuilder.put("metrics.graphite.exclude", excludeRegex); } LogConfigurator.configure(settingsBuilder.build()); return NodeBuilder.nodeBuilder().settings(settingsBuilder.build()).node(); }
Example 8
Source File: PhraseCountQueryBuilder.java From pyramid with Apache License 2.0 | 5 votes |
public PhraseCountQueryBuilder(String fieldName, int slop, boolean inOrder, boolean weightedCount, String... terms) { if (Strings.isEmpty(fieldName)) { throw new IllegalArgumentException("[" + NAME + "] requires fieldName"); } if (terms == null) { throw new IllegalArgumentException("[" + NAME + "] requires terms"); } this.fieldName = fieldName; this.value = String.join(" ", terms); this.inOrder = inOrder; this.weightedCount = weightedCount; this.slop = slop; }
Example 9
Source File: PhraseCountQueryBuilder.java From pyramid with Apache License 2.0 | 5 votes |
public PhraseCountQueryBuilder(String fieldName, Object value) { if (Strings.isEmpty(fieldName)) { throw new IllegalArgumentException("[" + NAME + "] requires fieldName"); } if (value == null) { throw new IllegalArgumentException("[" + NAME + "] requires query value"); } this.fieldName = fieldName; this.value = value.toString(); }
Example 10
Source File: CustomRealm.java From shield-custom-realm-example with Apache License 2.0 | 5 votes |
/** * Utility method to extract a user from the realm's settings * @param settings the settings of the realm. This is not the node's settings * @return a {@link Map} of the usernames to the information about the user */ private static Map<String, InfoHolder> parseUsersMap(Settings settings) { Map<String, Settings> usersSerttings = settings.getGroups("users"); Map<String, InfoHolder> usersMap = new HashMap<>(usersSerttings.size()); for (Entry<String, Settings> entry : usersSerttings.entrySet()) { Settings userSettings = entry.getValue(); String username = entry.getKey(); String password = userSettings.get("password"); if (Strings.isEmpty(password)) { throw new IllegalArgumentException("password must be specified for user [" + username + "]"); } usersMap.put(username, new InfoHolder(password, userSettings.getAsList("roles").toArray(new String[] {}))); } return Collections.unmodifiableMap(usersMap); }
Example 11
Source File: ReNounRelationshipAnnotator.java From baleen with Apache License 2.0 | 5 votes |
@Override public void doInitialize(UimaContext aContext) throws ResourceInitializationException { super.doInitialize(aContext); type = "ReNoun"; if (!Strings.isEmpty(factCollection)) { MongoDatabase db = mongoResource.getDB(); factsColl = db.getCollection(factCollection); } }
Example 12
Source File: StopDetectorRequest.java From anomaly-detection with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (Strings.isEmpty(adID)) { validationException = addValidationError(CommonErrorMessages.AD_ID_MISSING_MSG, validationException); } return validationException; }
Example 13
Source File: AnomalyResultRequest.java From anomaly-detection with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (Strings.isEmpty(adID)) { validationException = addValidationError(CommonErrorMessages.AD_ID_MISSING_MSG, validationException); } if (start <= 0 || end <= 0 || start > end) { validationException = addValidationError( String.format(Locale.ROOT, "%s: start %d, end %d", INVALID_TIMESTAMP_ERR_MSG, start, end), validationException ); } return validationException; }
Example 14
Source File: ThresholdResultRequest.java From anomaly-detection with Apache License 2.0 | 5 votes |
/** * Verify request parameter corresponds to our understanding of the data. * We don't verify whether rcfScore is less than 0 or not because this cannot happen. */ @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (Strings.isEmpty(adID)) { validationException = addValidationError(CommonErrorMessages.AD_ID_MISSING_MSG, validationException); } if (Strings.isEmpty(modelID)) { validationException = addValidationError(CommonErrorMessages.MODEL_ID_MISSING_MSG, validationException); } return validationException; }
Example 15
Source File: RCFResultRequest.java From anomaly-detection with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (features == null || features.length == 0) { validationException = addValidationError(RCFResultRequest.INVALID_FEATURE_MSG, validationException); } if (Strings.isEmpty(adID)) { validationException = addValidationError(CommonErrorMessages.AD_ID_MISSING_MSG, validationException); } if (Strings.isEmpty(modelID)) { validationException = addValidationError(CommonErrorMessages.MODEL_ID_MISSING_MSG, validationException); } return validationException; }
Example 16
Source File: DeleteModelRequest.java From anomaly-detection with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (Strings.isEmpty(adID)) { validationException = addValidationError(CommonErrorMessages.AD_ID_MISSING_MSG, validationException); } return validationException; }
Example 17
Source File: RestGetAnomalyDetectorAction.java From anomaly-detection with Apache License 2.0 | 5 votes |
private Set<ProfileName> getProfilesToCollect(String typesStr, boolean all) { if (all) { return this.allProfileTypes; } else if (Strings.isEmpty(typesStr)) { return this.defaultProfileTypes; } else { Set<String> typesInRequest = new HashSet<>(Arrays.asList(typesStr.split(","))); return ProfileName.getNames(Sets.intersection(this.allProfileTypeStrs, typesInRequest)); } }
Example 18
Source File: AuditMessage.java From deprecated-security-advanced-modules with Apache License 2.0 | 5 votes |
protected static void addIfNonEmpty(StringBuilder builder, String key, String value) { if (!Strings.isEmpty(value)) { if (builder.length() > 0) { builder.append("\n"); } builder.append(key).append(": ").append(value); } }
Example 19
Source File: WebhookSink.java From deprecated-security-advanced-modules with Apache License 2.0 | 4 votes |
@Override public boolean doStore(AuditMessage msg) { if (Strings.isEmpty(webhookUrl)) { log.debug("Webhook URL is null"); return false; } if (msg == null) { log.debug("Message is null"); return true; } return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { boolean success = false; try { switch (webhookFormat.method) { case POST: success = post(msg); break; case GET: success =get(msg); break; default: log.error("Http Method '{}' defined in WebhookFormat '{}' not implemented yet", webhookFormat.method.name(), webhookFormat.name()); } // log something in case endpoint is not reachable or did not return 200 if (!success) { log.error(msg.toString()); } return success; } catch(Throwable t) { log.error("Uncaught exception while trying to log message.", t); log.error(msg.toString()); return false; } } }); }
Example 20
Source File: RestStatsAnomalyDetectorAction.java From anomaly-detection with Apache License 2.0 | 4 votes |
/** * Creates a ADStatsRequest from a RestRequest * * @param request RestRequest * @return ADStatsRequest Request containing stats to be retrieved */ private ADStatsRequest getRequest(RestRequest request) { // parse the nodes the user wants to query the stats for String nodesIdsStr = request.param("nodeId"); Set<String> validStats = adStats.getStats().keySet(); ADStatsRequest adStatsRequest = null; if (!Strings.isEmpty(nodesIdsStr)) { String[] nodeIdsArr = nodesIdsStr.split(","); adStatsRequest = new ADStatsRequest(nodeIdsArr); } else { DiscoveryNode[] dataNodes = nodeFilter.getEligibleDataNodes(); adStatsRequest = new ADStatsRequest(dataNodes); } adStatsRequest.timeout(request.param("timeout")); // parse the stats the user wants to see HashSet<String> statsSet = null; String statsStr = request.param("stat"); if (!Strings.isEmpty(statsStr)) { statsSet = new HashSet<>(Arrays.asList(statsStr.split(","))); } if (statsSet == null) { adStatsRequest.addAll(validStats); // retrieve all stats if none are specified } else if (statsSet.size() == 1 && statsSet.contains(ADStatsRequest.ALL_STATS_KEY)) { adStatsRequest.addAll(validStats); } else if (statsSet.contains(ADStatsRequest.ALL_STATS_KEY)) { throw new IllegalArgumentException( "Request " + request.path() + " contains " + ADStatsRequest.ALL_STATS_KEY + " and individual stats" ); } else { Set<String> invalidStats = new TreeSet<>(); for (String stat : statsSet) { if (validStats.contains(stat)) { adStatsRequest.addStat(stat); } else { invalidStats.add(stat); } } if (!invalidStats.isEmpty()) { throw new IllegalArgumentException(unrecognized(request, invalidStats, adStatsRequest.getStatsToBeRetrieved(), "stat")); } } return adStatsRequest; }