use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class WebFinderCommands method getEntityValues.
@CliOptionAutocompleteIndicator(param = "entity", command = "web mvc finder", help = "--entity parameter should be completed with classes annotated with @RooJpaEntity.")
public List<String> getEntityValues(ShellContext context) {
// Get current value of class
String currentText = context.getParameters().get("entity");
// Create results to return
List<String> results = new ArrayList<String>();
for (JavaType entity : getTypeLocationService().findTypesWithAnnotation(RooJavaType.ROO_JPA_ENTITY)) {
ClassOrInterfaceTypeDetails repository = repositoryJpaLocator.getFirstRepository(entity);
if (repository == null) {
continue;
}
AnnotationMetadata repositoryAnnotation = repository.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA);
if (repositoryAnnotation.getAttribute("finders") == null) {
continue;
}
String name = replaceTopLevelPackageString(entity, currentText);
if (!results.contains(name)) {
results.add(name);
}
}
if (results.isEmpty()) {
results.add("");
}
return results;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class ServiceCommands method getEntityPossibleResults.
@CliOptionAutocompleteIndicator(command = "service", param = "entity", help = "--entity option should be an entity.")
public List<String> getEntityPossibleResults(ShellContext shellContext) {
// Get current value of class
String currentText = shellContext.getParameters().get("entity");
List<String> allPossibleValues = new ArrayList<String>();
// Getting all existing entities
Set<ClassOrInterfaceTypeDetails> entitiesInProject = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY);
for (ClassOrInterfaceTypeDetails entity : entitiesInProject) {
String name = replaceTopLevelPackageString(entity, currentText);
if (!allPossibleValues.contains(name)) {
allPossibleValues.add(name);
}
}
return allPossibleValues;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class ServiceCommands method returnRepositories.
@CliOptionAutocompleteIndicator(command = "service", param = "repository", help = "--repository parameter must be the repository associated to the entity specified in --entity parameter. Please, write a valid value using autocomplete feature (TAB or CTRL + Space)")
public List<String> returnRepositories(ShellContext shellContext) {
// Get current value of class
String currentText = shellContext.getParameters().get("repository");
List<String> allPossibleValues = new ArrayList<String>();
// Get all defined parameters
Map<String, String> contextParameters = shellContext.getParameters();
// Getting entity
String entity = contextParameters.get("entity");
if (StringUtils.isNotBlank(entity)) {
JavaType domainEntity = getJavaTypeConverter().convertFromText(entity, JavaType.class, PROJECT);
// Check if current entity has valid repository
Collection<ClassOrInterfaceTypeDetails> repositories = repositoryJpaLocator.getRepositories(domainEntity);
for (ClassOrInterfaceTypeDetails repository : repositories) {
String replacedValue = replaceTopLevelPackageString(repository, currentText);
allPossibleValues.add(replacedValue);
}
if (allPossibleValues.isEmpty()) {
LOGGER.log(Level.INFO, String.format("ERROR: Entity '%s' does not have any repository generated. Use 'repository' commands to generate a valid repository and then try again.", entity));
allPossibleValues.add("");
}
}
return allPossibleValues;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class FinderCommands method getReturnTypePossibleResults.
@CliOptionAutocompleteIndicator(command = "finder add", includeSpaceOnFinish = false, param = "returnType", help = "--returnType option could be a Projection class related with the specified entity or the same entity. " + "By default, uses the value of the 'defaultReturnType' parameter specified during the Jpa Repository creation.")
public List<String> getReturnTypePossibleResults(ShellContext shellContext) {
// Get current value of returnType
String currentText = shellContext.getParameters().get("returnType");
List<String> allPossibleValues = new ArrayList<String>();
// Get current value of 'entity'
JavaType entity = getTypeFromEntityParam(shellContext);
Set<ClassOrInterfaceTypeDetails> entityProjections = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_ENTITY_PROJECTION);
for (ClassOrInterfaceTypeDetails projection : entityProjections) {
if (entity != null && projection.getAnnotation(RooJavaType.ROO_ENTITY_PROJECTION).getAttribute("entity").getValue().equals(entity)) {
String name = replaceTopLevelPackageString(projection, currentText);
if (!allPossibleValues.contains(name)) {
allPossibleValues.add(name);
}
}
}
// Always include the entity name, because if the defaultReturnType of the repository
// is a projection, the developer should be able to specify an entity as return type.
String entityName = replaceTopLevelPackageString(getTypeLocationService().getTypeDetails(entity), currentText);
if (!allPossibleValues.contains(entityName)) {
allPossibleValues.add(entityName);
}
return allPossibleValues;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class FinderCommands method returnOptions.
@CliOptionAutocompleteIndicator(command = "finder add", includeSpaceOnFinish = false, param = "name", help = "--name parameter must follow Spring Data nomenclature. Please, write a " + "valid value using autocomplete feature (TAB or CTRL + Space)")
public List<String> returnOptions(ShellContext shellContext) {
List<String> allPossibleValues = new ArrayList<String>();
// Getting all defined parameters on autocompleted command
Map<String, String> contextParameters = shellContext.getParameters();
// Getting current name value
String name = contextParameters.get("name");
try {
// Use PartTree class to obtain all possible values
PartTree part = new PartTree(name, getEntityDetails(contextParameters.get("entity")), this);
// Check if part has value
if (part != null) {
allPossibleValues = part.getOptions();
}
return allPossibleValues;
} catch (Exception e) {
LOGGER.warning(e.getLocalizedMessage());
return allPossibleValues;
}
}
Aggregations