org.springframework.shell.core.MethodTarget Java Examples

The following examples show how to use org.springframework.shell.core.MethodTarget. 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: DiskStoreNameConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.DISKSTORE_ALL.equals(optionContext)) {
    Set<String> diskStoreNames = getDiskStoreNames();
    
    for (String diskStoreName : diskStoreNames) {
      if (existingData != null) {
        if (diskStoreName.startsWith(existingData)) {
          completions.add(new Completion(diskStoreName));
        }
      } else {
        completions.add(new Completion(diskStoreName));
      }
    }
  }
  
  return !completions.isEmpty();
}
 
Example #2
Source File: DiskStoreNameConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.DISKSTORE_ALL.equals(optionContext)) {
    Set<String> diskStoreNames = getDiskStoreNames();
    
    for (String diskStoreName : diskStoreNames) {
      if (existingData != null) {
        if (diskStoreName.startsWith(existingData)) {
          completions.add(new Completion(diskStoreName));
        }
      } else {
        completions.add(new Completion(diskStoreName));
      }
    }
  }
  
  return !completions.isEmpty();
}
 
Example #3
Source File: EnumConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public boolean getAllPossibleValues(final List<Completion> completions, 
    final Class<?> requiredType, final String existingData, 
    final String optionContext, final MethodTarget target) {
	Class<Enum> enumClass = (Class<Enum>) requiredType;
	for (Enum enumValue : enumClass.getEnumConstants()) {
		String candidate = enumValue.name();
     // GemFire/gfsh addition - check 'existingData == null'. GfshParser can 
		// pass existingData as null  
     if ("".equals(existingData) || existingData == null
         || candidate.startsWith(existingData)
         || existingData.startsWith(candidate)
         || candidate.toUpperCase().startsWith(existingData.toUpperCase())
         || existingData.toUpperCase().startsWith(candidate.toUpperCase())) {
			completions.add(new Completion(candidate));
		}
	}
	return true;
}
 
Example #4
Source File: DirConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String[] existingData, String context,
    MethodTarget target) {
  String adjustedUserInput = convertUserInputIntoAFullyQualifiedPath((existingData != null) ? existingData[existingData.length - 1]
      : "");

  String directoryData = adjustedUserInput.substring(0,
      adjustedUserInput.lastIndexOf(File.separator) + 1);
  adjustedUserInput = adjustedUserInput.substring(adjustedUserInput
      .lastIndexOf(File.separator) + 1);

  populate(completions, adjustedUserInput,
      ((existingData != null) ? existingData[existingData.length - 1] : ""),
      directoryData);

  return true;
}
 
Example #5
Source File: StreamConverter.java    From Decision with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData,
        String optionContext, MethodTarget target) {
    log.info("Listing possible values. TargetType: {}, Existing data: {}, Option context: {}, Target {}",
            targetType, existingData, optionContext, target);
    boolean completedValues = false;
    try {
        List<StratioStream> streams = cachedStreamsDAO.listStreams();
        log.info("Listed {} streams", streams.size());
        for (int i = 0; i < streams.size(); i++) {
            if (existingData.equals("") || streams.get(i).getStreamName().startsWith(existingData)) {
                log.info("Stream {} start with {}", streams.get(i).getStreamName(), existingData);
                completions.add(new Completion(streams.get(i).getStreamName()));
                if (existingData.equals(streams.get(i).getStreamName())) {
                    log.info("Stream match! {} ", streams.get(i).getStreamName());
                    break;
                }
            }
        }
        return completedValues;
    } catch (Exception e) {
        log.error("Error reading streams", e);
        return false;
    }
}
 
Example #6
Source File: EnumConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public boolean getAllPossibleValues(final List<Completion> completions, 
    final Class<?> requiredType, final String existingData, 
    final String optionContext, final MethodTarget target) {
	Class<Enum> enumClass = (Class<Enum>) requiredType;
	for (Enum enumValue : enumClass.getEnumConstants()) {
		String candidate = enumValue.name();
     // GemFire/gfsh addition - check 'existingData == null'. GfshParser can 
		// pass existingData as null  
     if ("".equals(existingData) || existingData == null
         || candidate.startsWith(existingData)
         || existingData.startsWith(candidate)
         || candidate.toUpperCase().startsWith(existingData.toUpperCase())
         || existingData.toUpperCase().startsWith(candidate.toUpperCase())) {
			completions.add(new Completion(candidate));
		}
	}
	return true;
}
 
Example #7
Source File: DirConverter.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String[] existingData, String context,
    MethodTarget target) {
  String adjustedUserInput = convertUserInputIntoAFullyQualifiedPath((existingData != null) ? existingData[existingData.length - 1]
      : "");

  String directoryData = adjustedUserInput.substring(0,
      adjustedUserInput.lastIndexOf(File.separator) + 1);
  adjustedUserInput = adjustedUserInput.substring(adjustedUserInput
      .lastIndexOf(File.separator) + 1);

  populate(completions, adjustedUserInput,
      ((existingData != null) ? existingData[existingData.length - 1] : ""),
      directoryData);

  return true;
}
 
Example #8
Source File: EntityNameConverter.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData, String optionContext, MethodTarget target) {
	try {
		String kind = determineKind(optionContext).get();
		switch (kind) {
			case "stream":
				streamOperations().list().forEach(sdr -> completions.add(new Completion(sdr.getName())));
				break;
			case "task":
				taskOperations().list().forEach(tdf -> completions.add(new Completion(tdf.getName())));
				break;
			case "job":
				jobOperations().executionList().forEach(jer -> {if (!"?".equals(jer.getName())) {
					completions.add(new Completion(jer.getName()));
				}});
				break;
			default:
				throw new AssertionError("Unsupported entity kind: " + kind);
		}
	} // Protect from exceptions in non-command code, as it would crash the whole shell
	catch (Exception e) {
	}
	return false;
}
 
Example #9
Source File: LocatorIdNameConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.LOCATOR_MEMBER_IDNAME.equals(optionContext)) {
    Set<String> locatorIdsAndNames = getLocatorIdAndNames();

    for (String string : locatorIdsAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #10
Source File: CompletionConverter.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData,
		String optionContext, MethodTarget target) {
	String start = (existingData.startsWith("'") || existingData.startsWith("\"")) ? existingData.substring(1)
			: existingData;

	try {
		int successiveInvocations = determineNumberOfInvocations(optionContext);
		String kind = completionKind(optionContext);
		CompletionProposalsResource candidates;
		switch (kind) {
		case "stream":
			candidates = completionOperations().streamCompletions(start, successiveInvocations);
			break;
		case "task":
			candidates = completionOperations().taskCompletions(start, successiveInvocations);
			break;
		default:
			throw new IllegalArgumentException("Unsupported completion kind: " + kind);
		}
		for (CompletionProposalsResource.Proposal candidate : candidates.getProposals()) {
			completions.add(new Completion(candidate.getText()));
		}
		return false;
	}
	// Protect from exception in non-command code
	catch (Exception e) {
		return false;
	}
}
 
Example #11
Source File: QualifiedApplicationNameConverter.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData,
		String optionContext, MethodTarget target) {
	for (AppRegistrationResource app : dataFlowShell.getDataFlowOperations().appRegistryOperations().list()) {
		String value = app.getType() + ":" + app.getName();
		completions.add(new Completion(value, app.getName(), pretty(app.getType()), 0));
	}
	return true;

}
 
Example #12
Source File: LocatorIdNameConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.LOCATOR_MEMBER_IDNAME.equals(optionContext)) {
    Set<String> locatorIdsAndNames = getLocatorIdAndNames();

    for (String string : locatorIdsAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #13
Source File: RegionPathConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.REGIONPATH.equals(optionContext)) {
    Set<String> regionPathSet = getAllRegionPaths();
    Gfsh gfsh = Gfsh.getCurrentInstance();
    String currentContextPath = "";
    if (gfsh != null) {
      currentContextPath = gfsh.getEnvProperty(Gfsh.ENV_APP_CONTEXT_PATH);
      if (currentContextPath != null && !com.gemstone.gemfire.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH.equals(currentContextPath)) {
        regionPathSet.remove(currentContextPath);
        regionPathSet.add(com.gemstone.gemfire.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH);
      }
    }

    for (String regionPath : regionPathSet) {
      if (existingData != null) {
        if (regionPath.startsWith(existingData)) {
          completions.add(new Completion(regionPath));
        }
      } else {
        completions.add(new Completion(regionPath));
      }
    }
  }

  return !completions.isEmpty();
}
 
Example #14
Source File: GatewayReceiverIdsConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.GATEWAY_RECEIVER_ID.equals(optionContext)) {
    Set<String> gatewaySenderIds = getGatewayRecieverIds();

    for (String gatewaySenderId : gatewaySenderIds) {
      completions.add(new Completion(gatewaySenderId));
    }
  }

  return !completions.isEmpty();
}
 
Example #15
Source File: MemberIdNameConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.MEMBERIDNAME.equals(optionContext)) {
    Set<String> memberIdAndNames = getMemberIdAndNames();

    for (String string : memberIdAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #16
Source File: LogLevelConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  completions.addAll(logLevels);
  return !completions.isEmpty();
}
 
Example #17
Source File: ConnectionEndpointConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (ConnectionEndpoint.JMXMANAGER_OPTION_CONTEXT.equals(optionContext)) {
    completions.add(new Completion(DEFAULT_JMX_ENDPOINTS));
  } else if (ConnectionEndpoint.LOCATOR_OPTION_CONTEXT.equals(optionContext)) {
    completions.add(new Completion(DEFAULT_LOCATOR_ENDPOINTS));
  }
  
  return completions.size() > 0;
}
 
Example #18
Source File: LocatorDiscoveryConfigConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.LOCATOR_DISCOVERY_CONFIG.equals(optionContext)) {
    Set<String> locatorIdsAndNames = getLocatorIdAndNames();

    for (String string : locatorIdsAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #19
Source File: HintTopicConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.HINTTOPIC.equals(optionContext)) {
    CommandManager commandManager = CommandManager.getExisting();
    if (commandManager != null) {
      Set<String> topicNames = commandManager.getTopicNames();
      
      for (String topicName : topicNames) {
        if (existingData != null && !existingData.isEmpty()) {
          if (topicName.startsWith(existingData)) { // match exact case
            completions.add(new Completion(topicName));
          } else if (topicName.toLowerCase().startsWith(existingData.toLowerCase())) {  // match case insensitive
            String completionStr = existingData + topicName.substring(existingData.length());
            
            completions.add(new Completion(completionStr));
          }
        } else {
          completions.add(new Completion(topicName));
        }
      }
    }
  }

  return !completions.isEmpty();
}
 
Example #20
Source File: HelpConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completionCandidates,
    Class<?> dataType, String existingData, String optionContext,
    MethodTarget arg4) {

  List<String> commandNames = Gfsh.getCurrentInstance().obtainHelpCommandNames(existingData);
  
  for (String string : commandNames) {
    completionCandidates.add(new Completion(string));
  }
  if (completionCandidates.size() > 0) {
    return true;
  }
  return false;
}
 
Example #21
Source File: HintTopicConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.HINTTOPIC.equals(optionContext)) {
    CommandManager commandManager = CommandManager.getExisting();
    if (commandManager != null) {
      Set<String> topicNames = commandManager.getTopicNames();
      
      for (String topicName : topicNames) {
        if (existingData != null && !existingData.isEmpty()) {
          if (topicName.startsWith(existingData)) { // match exact case
            completions.add(new Completion(topicName));
          } else if (topicName.toLowerCase().startsWith(existingData.toLowerCase())) {  // match case insensitive
            String completionStr = existingData + topicName.substring(existingData.length());
            
            completions.add(new Completion(completionStr));
          }
        } else {
          completions.add(new Completion(topicName));
        }
      }
    }
  }

  return !completions.isEmpty();
}
 
Example #22
Source File: IndexTypeConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  
  if (String.class.equals(targetType) && ConverterHint.INDEX_TYPE.equals(optionContext)) {
    completions.add(new Completion("range"));
    completions.add(new Completion("key"));
    completions.add(new Completion("hash"));
  }
  return !completions.isEmpty();
}
 
Example #23
Source File: MemberGroupConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
  public boolean getAllPossibleValues(List<Completion> completions,
      Class<?> targetType, String existingData, String optionContext,
      MethodTarget target) {
//    System.out.println("MemberGroupConverter.getAllPossibleValues("+existingData+","+targetType+","+optionContext+")");
    if (String.class.equals(targetType) && ConverterHint.MEMBERGROUP.equals(optionContext)) {
      String[] memberGroupNames = getMemberGroupNames();
      
      for (String memberGroupName : memberGroupNames) {
        completions.add(new Completion(memberGroupName));
      }
    }
    return !completions.isEmpty();
  }
 
Example #24
Source File: ClusterMemberIdNameConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.ALL_MEMBER_IDNAME.equals(optionContext)) {
    Set<String> memberIdAndNames = getMemberIdAndNames();

    for (String string : memberIdAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #25
Source File: ConnectionEndpointConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (ConnectionEndpoint.JMXMANAGER_OPTION_CONTEXT.equals(optionContext)) {
    completions.add(new Completion(DEFAULT_JMX_ENDPOINTS));
  } else if (ConnectionEndpoint.LOCATOR_OPTION_CONTEXT.equals(optionContext)) {
    completions.add(new Completion(DEFAULT_LOCATOR_ENDPOINTS));
  }
  
  return completions.size() > 0;
}
 
Example #26
Source File: MemberIdNameConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.MEMBERIDNAME.equals(optionContext)) {
    Set<String> memberIdAndNames = getMemberIdAndNames();

    for (String string : memberIdAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #27
Source File: LogLevelConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  completions.addAll(logLevels);
  return !completions.isEmpty();
}
 
Example #28
Source File: LocatorDiscoveryConfigConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.LOCATOR_DISCOVERY_CONFIG.equals(optionContext)) {
    Set<String> locatorIdsAndNames = getLocatorIdAndNames();

    for (String string : locatorIdsAndNames) {
      completions.add(new Completion(string));
    }
  }

  return !completions.isEmpty();
}
 
Example #29
Source File: GatewaySenderIdConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.GATEWAY_SENDER_ID.equals(optionContext)) {
    Set<String> gatewaySenderIds = getGatewaySenderIds();
    
    for (String gatewaySenderId : gatewaySenderIds) {
      completions.add(new Completion(gatewaySenderId));
    }
  }
  
  return !completions.isEmpty();
}
 
Example #30
Source File: GatewayReceiverIdsConverter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getAllPossibleValues(List<Completion> completions,
    Class<?> targetType, String existingData, String optionContext,
    MethodTarget target) {
  if (String.class.equals(targetType) && ConverterHint.GATEWAY_RECEIVER_ID.equals(optionContext)) {
    Set<String> gatewaySenderIds = getGatewayRecieverIds();

    for (String gatewaySenderId : gatewaySenderIds) {
      completions.add(new Completion(gatewaySenderId));
    }
  }

  return !completions.isEmpty();
}