Search in sources :

Example 1 with CliOptionAutocompleteIndicator

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;
}
Also used : JavaType(org.springframework.roo.model.JavaType) ArrayList(java.util.ArrayList) TestCreatorProvider(org.springframework.roo.addon.test.providers.TestCreatorProvider) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 2 with CliOptionAutocompleteIndicator

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;
}
Also used : ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 3 with CliOptionAutocompleteIndicator

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;
}
Also used : ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 4 with CliOptionAutocompleteIndicator

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;
}
Also used : AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 5 with CliOptionAutocompleteIndicator

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;
}
Also used : AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Aggregations

ArrayList (java.util.ArrayList)35 CliOptionAutocompleteIndicator (org.springframework.roo.shell.CliOptionAutocompleteIndicator)35 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)24 JavaType (org.springframework.roo.model.JavaType)14 RooJavaType (org.springframework.roo.model.RooJavaType)11 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)4 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)3 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)3 TestCreatorProvider (org.springframework.roo.addon.test.providers.TestCreatorProvider)2 JpaJavaType (org.springframework.roo.model.JpaJavaType)2 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 List (java.util.List)1 PartTree (org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree)1 SecurityProvider (org.springframework.roo.addon.security.addon.security.providers.SecurityProvider)1 SearchAnnotationValues (org.springframework.roo.addon.web.mvc.controller.addon.finder.SearchAnnotationValues)1 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)1 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)1 JavaPackageConverter (org.springframework.roo.converters.JavaPackageConverter)1