use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class RepositoryJpaCommands method getEntityPossibleResults.
@CliOptionAutocompleteIndicator(command = "repository jpa", 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 RepositoryJpaCommands method getAssociatedProjectionResults.
/**
* This indicator return all Projection classes associated to an entity specified
* in the 'entity' parameter.
*
* @param shellContext the Roo ShellContext.
* @return List<String> with fullyQualifiedNames of each associated Projection.
*/
@CliOptionAutocompleteIndicator(command = "repository jpa", param = "defaultReturnType", help = "--defaultReturnType option should be a Projection class associated to the entity specified in --entity.")
public List<String> getAssociatedProjectionResults(ShellContext shellContext) {
List<String> allPossibleValues = new ArrayList<String>();
// Get current value of 'defaultReturnType'
String currentText = shellContext.getParameters().get("defaultReturnType");
// Get current value of 'entity'
JavaType entity = getTypeFromEntityParam(shellContext);
Set<ClassOrInterfaceTypeDetails> projectionsInProject = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_ENTITY_PROJECTION);
for (ClassOrInterfaceTypeDetails projection : projectionsInProject) {
// Add only projections associated to the entity specified in the command
if (projection.getAnnotation(RooJavaType.ROO_ENTITY_PROJECTION).getAttribute("entity").getValue().equals(entity)) {
String name = replaceTopLevelPackageString(projection, 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 DtoCommands method returnEntityValues.
/**
* Find entities in project and returns a list with their fully qualified
* names.
*
* @param shellContext
* @return List<String> with available entity full qualified names.
*/
@CliOptionAutocompleteIndicator(command = "entity projection", param = "entity", help = "Option 'entity' must have an existing entity value. Please, assign it a right value.")
public List<String> returnEntityValues(ShellContext shellContext) {
// Get current value of class
String currentText = shellContext.getParameters().get("entity");
// Create results to return
List<String> results = new ArrayList<String>();
// Get entity fully qualified names
Set<ClassOrInterfaceTypeDetails> entities = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY, JpaJavaType.ENTITY);
for (ClassOrInterfaceTypeDetails entity : entities) {
String name = replaceTopLevelPackageString(entity, currentText);
if (!results.contains(name)) {
results.add(name);
}
}
return results;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class JpaCommands method getClassPossibleValues.
/**
* Indicator that provides all possible values for --class parameter The
* provided results will not be validate. It will not include space on finish.
*
* @param shellContext
* @return List with all possible values for --class parameter
*/
@CliOptionAutocompleteIndicator(command = "entity jpa", param = "class", help = "Provided --class option should be a class annotated with @RooJpaEntity.", validate = false, includeSpaceOnFinish = false)
public List<String> getClassPossibleValues(ShellContext shellContext) {
List<String> allPossibleValues = new ArrayList<String>();
// Add all modules to completions list
if (projectOperations.isMultimoduleProject()) {
Collection<String> modules = projectOperations.getModuleNames();
for (String module : modules) {
// Ignore root module
if (StringUtils.isBlank(module)) {
continue;
}
// Ignore module name if it is the focused module
if (module.equals(projectOperations.getFocusedModule().getModuleName())) {
List<JavaPackage> modulePackages = typeLocationService.getPackagesForModule(module);
// Always add module top level package and project top level package
modulePackages.add(projectOperations.getTopLevelPackage(module));
for (JavaPackage javaPackage : modulePackages) {
// Check if package name contains top level package to shorten it
String currentPackageName = getPackageStringValue(module, javaPackage.getFullyQualifiedPackageName());
// Add package to possible values
if (!allPossibleValues.contains(currentPackageName.concat("."))) {
allPossibleValues.add(currentPackageName.concat("."));
}
}
} else {
// It is not the focused module
List<JavaPackage> modulePackages = typeLocationService.getPackagesForModule(module);
// Always add module top level package and project top level package
modulePackages.add(projectOperations.getTopLevelPackage(module));
for (JavaPackage javaPackage : modulePackages) {
// Check if package name contains top level package to shorten it
String currentPackageName = getPackageStringValue(module, javaPackage.getFullyQualifiedPackageName());
// Add package to possible values
String valueToAdd = String.format("%s%s%s.", module, LogicalPath.MODULE_PATH_SEPARATOR, currentPackageName);
if (!allPossibleValues.contains(valueToAdd)) {
allPossibleValues.add(valueToAdd);
}
}
}
}
} else {
// Check all JavaPackages in single module project
for (JavaPackage javaPackage : typeLocationService.getPackagesForModule("")) {
// Check if package name contains top level package to shorten it
String currentPackageName = getPackageStringValue("", javaPackage.getFullyQualifiedPackageName());
// Add package to possible values
if (!allPossibleValues.contains(currentPackageName.concat("."))) {
allPossibleValues.add(currentPackageName.concat("."));
}
}
}
return allPossibleValues;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class JpaAuditCommands method getAllEntities.
@CliOptionAutocompleteIndicator(command = "jpa audit add", param = "entity", help = "You must specify an entity")
public List<String> getAllEntities(ShellContext shellContext) {
// Get current value of class
String currentText = shellContext.getParameters().get("entity");
// Create results to return
List<String> results = new ArrayList<String>();
// Get entity full qualified names
Set<ClassOrInterfaceTypeDetails> entities = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY);
for (ClassOrInterfaceTypeDetails entity : entities) {
if (!entity.isAbstract()) {
String name = getClasspathOperations().replaceTopLevelPackageString(entity, currentText);
if (!results.contains(name)) {
results.add(name);
}
}
}
return results;
}
Aggregations