Search in sources :

Example 26 with CliOptionAutocompleteIndicator

use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.

the class ControllerCommands method getAllServiceForOperationCommandValues.

@CliOptionAutocompleteIndicator(param = "service", command = "web mvc operation", help = "--service parameter should be completed with an service generated previously.")
public List<String> getAllServiceForOperationCommandValues(ShellContext context) {
    // Get the actual service selected
    String currentText = context.getParameters().get("service");
    // Create results to return
    List<String> results = new ArrayList<String>();
    // Get controllers full qualified names
    Set<ClassOrInterfaceTypeDetails> services = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_SERVICE);
    for (ClassOrInterfaceTypeDetails service : services) {
        String name = getClasspathOperations().replaceTopLevelPackageString(service, 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 27 with CliOptionAutocompleteIndicator

use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.

the class WsCommands method getAllWsdlFiles.

/**
 * This method is an autocomplete indicator of 'ws client' command.
 *
 * It provides all existing .wsdl files inside /src/main/resources of
 * each existing module.
 *
 * @param context
 * @return
 */
@CliOptionAutocompleteIndicator(command = "ws client", param = "wsdl", help = "By default, Spring Roo searches .wsdl files " + "in the 'src/main/resources/' folder of the existing modules. " + "Include your .wsdl file in 'src/main/resources' to be able to generate" + " a client.")
public List<String> getAllWsdlFiles(ShellContext context) {
    List<String> existingWsdlFiles = new ArrayList<String>();
    Collection<String> existingModules = getProjectOperations().getModuleNames();
    String rootPath = getPathResolver().getRoot();
    for (String moduleName : existingModules) {
        String moduleResourcesFolder = rootPath.concat("/").concat(moduleName).concat("/src/main/resources");
        // To prevent errors, check if src main resources folder exists in current module
        if (getFileManager().exists(moduleResourcesFolder)) {
            File folder = new File(moduleResourcesFolder);
            for (final File fileEntry : folder.listFiles()) {
                if (fileEntry.isFile() && fileEntry.getName().endsWith(".wsdl")) {
                    String fileName = fileEntry.getName();
                    if (StringUtils.isNotEmpty(moduleName)) {
                        fileName = moduleName.concat(":").concat(fileName);
                    }
                    existingWsdlFiles.add(fileName);
                }
            }
        }
    }
    return existingWsdlFiles;
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 28 with CliOptionAutocompleteIndicator

use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.

the class MavenCommands method returnPomModules.

@CliOptionAutocompleteIndicator(command = MODULE_CREATE_COMMAND, param = "packaging", help = "--packaging select one of the available Maven packaging values")
public List<String> returnPomModules(ShellContext shellContext) {
    List<String> allPossibleValues = new ArrayList<String>();
    Collection<PackagingProvider> allPackagingProviders = packagingProviderRegistry.getAllPackagingProviders();
    for (final PackagingProvider packagingProvider : allPackagingProviders) {
        // ROO-3801 Can't create POM children
        if (!"pom".equals(packagingProvider.getId())) {
            allPossibleValues.add(packagingProvider.getId().toUpperCase());
        }
    }
    return allPossibleValues;
}
Also used : ArrayList(java.util.ArrayList) PackagingProvider(org.springframework.roo.project.packaging.PackagingProvider) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 29 with CliOptionAutocompleteIndicator

use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.

the class FieldCommands method getReferenceTypePossibleValues.

@CliOptionAutocompleteIndicator(command = "field reference", param = "type", help = "--type option should be an entity.")
public List<String> getReferenceTypePossibleValues(ShellContext shellContext) {
    // Get current value of class
    String currentText = shellContext.getParameters().get("type");
    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 30 with CliOptionAutocompleteIndicator

use of org.springframework.roo.shell.CliOptionAutocompleteIndicator in project spring-roo by spring-projects.

the class DtoCommands method returnFieldValues.

/**
 * Attempts to obtain entity specified in 'entity' option and returns an
 * auto-complete list with the entity fields, separated by comma's.
 *
 * @param shellContext
 * @return a List<String> with the possible values.
 */
@CliOptionAutocompleteIndicator(command = "entity projection", param = "fields", help = "Option fields must have a comma-separated list of valid fields. Please, assign it a " + "correct value. Transient, static and entity collection fields are not valid for " + "projections.", includeSpaceOnFinish = false)
public List<String> returnFieldValues(ShellContext shellContext) {
    List<String> fieldValuesToReturn = new ArrayList<String>();
    // Get entity JavaType
    JavaType entity = getTypeFromEntityParam(shellContext);
    // Get current fields in --field value
    String currentFieldValue = shellContext.getParameters().get("fields");
    String[] fields = StringUtils.split(currentFieldValue, ",");
    // Check for bad written separators and return no options
    if (currentFieldValue.contains(",.") || currentFieldValue.contains(".,")) {
        return fieldValuesToReturn;
    }
    // Check if it is first field
    if (currentFieldValue.equals("")) {
        for (FieldMetadata field : getEntityFieldList(entity)) {
            fieldValuesToReturn.add(field.getFieldName().getSymbolName());
        }
        return fieldValuesToReturn;
    }
    // VALIDATION OF CURRENT SPECIFIED VALUES UNTIL LAST MEMBER
    JavaType lastRelatedEntity = null;
    String completedValue = "";
    List<FieldMetadata> entityFields = null;
    boolean fieldFound = false;
    boolean lastFieldIsEntity = false;
    boolean isMainEntityField = true;
    for (int i = 0; i < fields.length; i++) {
        JavaType lastFieldType = entity;
        // Split field by ".", in case it was a relation field
        String[] splittedByPeriod = StringUtils.split(fields[i], ".");
        // Build auto-complete values
        for (int t = 0; t < splittedByPeriod.length; t++) {
            fieldFound = false;
            // Find the field in entity fields
            if (typeLocationService.getTypeDetails(lastFieldType) != null && typeLocationService.getTypeDetails(lastFieldType).getAnnotation(RooJavaType.ROO_JPA_ENTITY) != null) {
                entityFields = getEntityFieldList(lastFieldType);
            }
            for (FieldMetadata entityField : entityFields) {
                lastFieldIsEntity = false;
                if (splittedByPeriod[t].equals(entityField.getFieldName().getSymbolName())) {
                    // Add auto-complete value
                    if (completedValue.equals("")) {
                        completedValue = entityField.getFieldName().getSymbolName();
                    } else {
                        if (splittedByPeriod.length > 1 && t > 0) {
                            // Field is from a relation
                            completedValue = completedValue.concat(".").concat(entityField.getFieldName().getSymbolName());
                        } else {
                            // Field is a simple field
                            completedValue = completedValue.concat(",").concat(entityField.getFieldName().getSymbolName());
                        }
                    }
                    // Record last field JavaType for auto-completing last value
                    lastFieldType = entityField.getFieldType();
                    // Check if field is an entity different from original entity
                    if (typeLocationService.getTypeDetails(lastFieldType) != null && typeLocationService.getTypeDetails(lastFieldType).getAnnotation(RooJavaType.ROO_JPA_ENTITY) != null && !entityField.getFieldType().equals(entity)) {
                        lastFieldIsEntity = true;
                        lastRelatedEntity = lastFieldType;
                    }
                    fieldFound = true;
                    break;
                }
            }
            // Checks if field to autocomplete is from main entity
            if (currentFieldValue.endsWith(".") || (splittedByPeriod.length > 1 && !fieldFound)) {
                isMainEntityField = false;
            }
        }
    }
    // Add field separator if needed
    if (fieldFound) {
        // Always add current value for validation only
        fieldValuesToReturn.add(completedValue);
        // If field is entity, append , and . and return values
        if (lastFieldIsEntity) {
            fieldValuesToReturn.add(completedValue.concat(","));
            fieldValuesToReturn.add(completedValue.concat("."));
            if (!currentFieldValue.endsWith(",") && !currentFieldValue.endsWith(".")) {
                return fieldValuesToReturn;
            }
        }
    }
    // Build auto-complete values for last member
    String autocompleteValue = "";
    if (isMainEntityField) {
        // Complete simple fields. Add entity fields as auto-complete values
        List<FieldMetadata> mainEntityFields = getEntityFieldList(entity);
        for (FieldMetadata mainEntityField : mainEntityFields) {
            if (completedValue.equals("")) {
                // Is first field to complete
                fieldValuesToReturn.add(mainEntityField.getFieldName().getSymbolName());
            } else if (!completedValue.equals("")) {
                // Check if field is specified and add it if not
                boolean alreadySpecified = false;
                // boolean relationField = false;
                for (int i = 0; i < fields.length; i++) {
                    if (mainEntityField.getFieldName().getSymbolName().equals(fields[i])) {
                        alreadySpecified = true;
                    }
                }
                if (!alreadySpecified) {
                    // Add completion
                    autocompleteValue = completedValue.concat(",").concat(mainEntityField.getFieldName().getSymbolName());
                } else if (alreadySpecified && typeIsEntity(mainEntityField.getFieldType())) {
                    // Add completion as relation field
                    autocompleteValue = completedValue.concat(",").concat(mainEntityField.getFieldName().getSymbolName()).concat(".");
                }
                // Add completion
                fieldValuesToReturn.add(autocompleteValue);
            }
        }
    } else if (lastRelatedEntity != null) {
        // Complete with fields of current relation field
        List<FieldMetadata> relatedEntityFields = getEntityFieldList(lastRelatedEntity);
        for (FieldMetadata relatedEntityField : relatedEntityFields) {
            autocompleteValue = completedValue.concat(".").concat(relatedEntityField.getFieldName().getSymbolName());
            // Check if value already exists
            String additionalValueToAdd = StringUtils.substringAfterLast(autocompleteValue, ",");
            if (!fieldValuesToReturn.contains(autocompleteValue) && !currentFieldValue.contains(additionalValueToAdd)) {
                fieldValuesToReturn.add(autocompleteValue);
            } else if (!fieldValuesToReturn.contains(autocompleteValue) && typeIsEntity(relatedEntityField.getFieldType())) {
                fieldValuesToReturn.add(autocompleteValue);
            } else if (additionalValueToAdd.equals("")) {
                fieldValuesToReturn.add(autocompleteValue);
            }
        }
    }
    return fieldValuesToReturn;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) 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