Search in sources :

Example 16 with CliOptionAutocompleteIndicator

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

Example 17 with CliOptionAutocompleteIndicator

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

Example 18 with CliOptionAutocompleteIndicator

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

Example 19 with CliOptionAutocompleteIndicator

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

Example 20 with CliOptionAutocompleteIndicator

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