All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.geode.management.internal.cli.CommandRequest Maven / Gradle / Ivy

Go to download

Apache Geode provides a database-like consistency model, reliable transaction processing and a shared-nothing architecture to maintain very low latency performance with high concurrency processing

There is a newer version: 1.15.1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.apache.geode.management.internal.cli;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.geode.internal.lang.StringUtils;

/**
 * The CommandRequest class encapsulates information pertaining to the command the user entered in
 * Gfsh.
 * 

* * @see org.apache.geode.management.internal.cli.GfshParseResult * @since GemFire 8.0 */ @SuppressWarnings("unused") public class CommandRequest { protected static final String OPTION_SPECIFIER = "--"; private final byte[][] fileData; private final GfshParseResult parseResult; private final Map customParameters = new HashMap(); private final Map env; private String customInput; public CommandRequest(final Map env) { this.env = env; this.fileData = null; this.parseResult = null; } public CommandRequest(final Map env, final byte[][] fileData) { this.env = env; this.fileData = fileData; this.parseResult = null; } public CommandRequest(final GfshParseResult parseResult, final Map env) { this(parseResult, env, null); } public CommandRequest(final GfshParseResult parseResult, final Map env, final byte[][] fileData) { assert parseResult != null : "The Gfsh ParseResult cannot be null!"; assert env != null : "The reference to the Gfsh CLI environment cannot be null!"; this.env = env; this.fileData = fileData; this.parseResult = parseResult; } public String getName() { if (getUserInput() != null) { final String[] userInputTokenized = getUserInput().split("\\s"); final StringBuilder buffer = new StringBuilder(); for (final String token : userInputTokenized) { if (!token.startsWith(OPTION_SPECIFIER)) { buffer.append(token).append(StringUtils.SPACE); } } return buffer.toString().trim(); } else { return "unknown"; } } public String getCustomInput() { return customInput; } public void setCustomInput(final String input) { this.customInput = input; } public Map getCustomParameters() { return customParameters; } public Map getEnvironment() { return Collections.unmodifiableMap(env); } public byte[][] getFileData() { return fileData; } public boolean hasFileData() { return (getFileData() != null); } public String getInput() { return StringUtils.defaultIfBlank(getCustomInput(), getUserInput()); } public Map getParameters() { final Map parameters = new HashMap<>(); for (Map.Entry mapEntry : getUserParameters().entrySet()) { String key = mapEntry.getKey(); String value = mapEntry.getValue(); if (hasQuotesAroundNegativeNumber(value)) { String trimmed = value.substring(1, value.length() - 1); parameters.put(key, trimmed); } else { parameters.put(key, value); } } parameters.putAll(getCustomParameters()); return Collections.unmodifiableMap(parameters); } protected GfshParseResult getParseResult() { return parseResult; } public String getUserInput() { return getParseResult().getUserInput(); } public Map getUserParameters() { return getParseResult().getParamValueStrings(); } private boolean hasQuotesAroundNegativeNumber(String value) { if (value == null) { return false; } else { return value.startsWith("\"") && value.endsWith("\"") && value.matches("\"-[0-9]+\""); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy