use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class TestCommands method getAllEntities.
@CliOptionAutocompleteIndicator(command = "test integration", param = "class", help = "Option `--class` must " + "be a non-abstract valid type. Please, use auto-complete feature to select it.")
public List<String> getAllEntities(ShellContext shellContext) {
// Get current value of class
String currentText = shellContext.getParameters().get("class");
// Create results to return
List<String> results = new ArrayList<String>();
// Look for all valid types for all available test creators
for (TestCreatorProvider creator : getAllTestCreators()) {
if (creator.isIntegrationTestCreationAvailable()) {
for (JavaType annotationType : creator.getValidTypes()) {
// Look for types with this annotation type
Set<ClassOrInterfaceTypeDetails> types = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(annotationType);
for (ClassOrInterfaceTypeDetails typeCid : types) {
String name = replaceTopLevelPackageString(typeCid.getType(), 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 ControllerCommands method getAllEntities.
/**
* 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 = "web mvc controller", param = "entity", help = "--entity parameter must be an existing class annotated with @RooEntity. Please, assign a valid one.")
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;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class ControllerCommands method getDetailFieldsRelatedToEntity.
@CliOptionAutocompleteIndicator(command = "web mvc detail", param = "field", help = "--field parameter must be an existing @OneToMany or @ManyToMany field of the specified entity in parameter --entity.", includeSpaceOnFinish = false)
public List<String> getDetailFieldsRelatedToEntity(ShellContext shellContext) {
// Get current value of class
String currentEntity = shellContext.getParameters().get("entity");
// Get current fields in --field value
String currentFieldValue = shellContext.getParameters().get("field");
// Check the field value (ex: 'entity.detailentity.')
String[] splittedCurrentField = null;
boolean includeChildren = false;
boolean removedData = false;
if (currentFieldValue.contains(".")) {
if (!currentFieldValue.endsWith(".")) {
currentFieldValue = currentFieldValue.substring(0, currentFieldValue.lastIndexOf("."));
removedData = true;
}
includeChildren = true;
splittedCurrentField = currentFieldValue.split("[.]");
} else {
currentFieldValue = "";
}
// 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 (getClasspathOperations().replaceTopLevelPackageString(entity, entity.getType().getModule()).equals(currentEntity)) {
if (includeChildren) {
// Get the entity where search the fields
entity = getEntityByDetailField(entity, splittedCurrentField, 0);
}
if (removedData) {
currentFieldValue = currentFieldValue.concat(".");
}
results.addAll(getDetailFieldsRelatedToEntity(entity, currentFieldValue));
}
}
return results;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class SecurityCommands method getAllMethodsRelatedWithProvidedClassForAuthorize.
@CliOptionAutocompleteIndicator(command = "security authorize", param = "method", help = "You must select a valid method from the provided class or a regular expression that match with existing methods", validate = false)
public List<String> getAllMethodsRelatedWithProvidedClassForAuthorize(ShellContext context) {
List<String> results = new ArrayList<String>();
String service = context.getParameters().get("class");
JavaType type = null;
if (service != null) {
type = getJavaTypeConverter().convertFromText(service, JavaType.class, PROJECT);
} else {
type = lastUsed.getJavaType();
}
MemberDetails serviceDetails = memberDetailsScanner.getMemberDetails(getClass().getName(), typeLocationService.getTypeDetails(type));
List<MethodMetadata> methods = serviceDetails.getMethods();
for (MethodMetadata method : methods) {
String methodName = method.getMethodName().getSymbolName();
List<AnnotatedJavaType> parameterTypes = method.getParameterTypes();
methodName = methodName.concat("(");
for (int i = 0; i < parameterTypes.size(); i++) {
String paramType = parameterTypes.get(i).getJavaType().getSimpleTypeName();
methodName = methodName.concat(paramType).concat(",");
}
if (!parameterTypes.isEmpty()) {
methodName = methodName.substring(0, methodName.length() - 1).concat(")");
} else {
methodName = methodName.concat(")");
}
results.add(methodName);
}
return results;
}
use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.
the class SecurityCommands method getAllMethodsRelatedWithProvidedClassForFiltering.
@CliOptionAutocompleteIndicator(command = "security filtering", param = "method", help = "You must select a valid method from the provided class or a regular expression that match with existing methods", validate = false)
public List<String> getAllMethodsRelatedWithProvidedClassForFiltering(ShellContext context) {
List<String> results = new ArrayList<String>();
String service = context.getParameters().get("class");
JavaType type = null;
if (service != null) {
type = getJavaTypeConverter().convertFromText(service, JavaType.class, PROJECT);
} else {
type = lastUsed.getJavaType();
}
MemberDetails serviceDetails = memberDetailsScanner.getMemberDetails(getClass().getName(), typeLocationService.getTypeDetails(type));
List<MethodMetadata> methods = serviceDetails.getMethods();
for (MethodMetadata method : methods) {
String methodName = method.getMethodName().getSymbolName();
List<AnnotatedJavaType> parameterTypes = method.getParameterTypes();
methodName = methodName.concat("(");
for (int i = 0; i < parameterTypes.size(); i++) {
String paramType = parameterTypes.get(i).getJavaType().getSimpleTypeName();
methodName = methodName.concat(paramType).concat(",");
}
if (!parameterTypes.isEmpty()) {
methodName = methodName.substring(0, methodName.length() - 1).concat(")");
} else {
methodName = methodName.concat(")");
}
results.add(methodName);
}
return results;
}
Aggregations