Search in sources :

Example 1 with CliOptionVisibilityIndicator

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

the class FinderCommands method isReturnTypeParameterVisible.

/**
 * This indicator says if --returnType parameter should be visible or not.
 *
 * @param context ShellContext
 * @return false if domain entity specified in --entity parameter has no associated Projections.
 */
@CliOptionVisibilityIndicator(params = "returnType", command = "finder add", help = "--returnType parameter is not visible if --entity parameter hasn't " + "been specified before or if there aren't exist any Projection class associated " + "to the current entity.")
public boolean isReturnTypeParameterVisible(ShellContext shellContext) {
    // Get current value of 'entity'
    JavaType entity = getTypeFromEntityParam(shellContext);
    if (entity == null) {
        return false;
    }
    Set<ClassOrInterfaceTypeDetails> projectionsInProject = getTypeLocationService().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)) {
            return true;
        }
    }
    return false;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliOptionVisibilityIndicator(org.springframework.roo.shell.CliOptionVisibilityIndicator)

Example 2 with CliOptionVisibilityIndicator

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

the class RepositoryJpaCommands method isDefaultReturnTypeParameterVisible.

/**
 * This indicator says if --defaultReturnType parameter should be visible or not.
 *
 * @param context ShellContext
 * @return false if domain entity specified in --entity parameter has no associated Projections.
 */
@CliOptionVisibilityIndicator(params = "defaultReturnType", command = "repository jpa", help = "--defaultReturnType parameter is not visible if domain entity specified in --entity parameter has no associated Projections.")
public boolean isDefaultReturnTypeParameterVisible(ShellContext shellContext) {
    // Get current value of 'entity'
    JavaType entity = getTypeFromEntityParam(shellContext);
    if (entity == null) {
        return false;
    }
    Set<ClassOrInterfaceTypeDetails> projectionsInProject = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_ENTITY_PROJECTION);
    boolean visible = false;
    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)) {
            visible = true;
            break;
        }
    }
    return visible;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliOptionVisibilityIndicator(org.springframework.roo.shell.CliOptionVisibilityIndicator)

Example 3 with CliOptionVisibilityIndicator

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

the class FinderCommands method isNameVisible.

@CliOptionVisibilityIndicator(command = "finder add", params = { "name" }, help = "You must define --entity to be able to define --name parameter.")
public boolean isNameVisible(ShellContext shellContext) {
    // Getting all defined parameters on autocompleted command
    Map<String, String> params = shellContext.getParameters();
    // If mandatory parameter entity is not defined, name parameter should not
    // be visible
    String entity = params.get("entity");
    if (StringUtils.isBlank(entity)) {
        return false;
    }
    // Get current entity member details to check if is a valid Spring Roo entity
    MemberDetails entityDetails = getEntityDetails(entity);
    // If not entity details, is not a valid entity, so --name parameter is not visible
    if (entityDetails == null) {
        return false;
    }
    return true;
}
Also used : MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) CliOptionVisibilityIndicator(org.springframework.roo.shell.CliOptionVisibilityIndicator)

Aggregations

CliOptionVisibilityIndicator (org.springframework.roo.shell.CliOptionVisibilityIndicator)3 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)2 JavaType (org.springframework.roo.model.JavaType)2 RooJavaType (org.springframework.roo.model.RooJavaType)2 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)1