Search in sources :

Example 11 with CliOptionAutocompleteIndicator

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;
}
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) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 12 with CliOptionAutocompleteIndicator

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

Example 13 with CliOptionAutocompleteIndicator

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;
}
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 14 with CliOptionAutocompleteIndicator

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;
}
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 15 with CliOptionAutocompleteIndicator

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;
    }
}
Also used : ArrayList(java.util.ArrayList) PartTree(org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree) 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