Search in sources :

Example 1 with CliOptionMandatoryIndicator

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

the class FinderCommands method isFormBeanMandatory.

@CliOptionMandatoryIndicator(command = "finder add", params = { "formBean" })
public boolean isFormBeanMandatory(ShellContext shellContext) {
    // Get current value of 'entity'
    JavaType entity = getTypeFromEntityParam(shellContext);
    if (entity == null) {
        return false;
    }
    // Get current value of returnType
    String returnType = shellContext.getParameters().get("returnType");
    // This parameter is not mandatory if returnType has not been specified
    if (StringUtils.isBlank(returnType)) {
        return false;
    }
    // If returnType has been specified, but it's an entity, this parameter is not
    // mandatory
    JavaTypeConverter converter = (JavaTypeConverter) getJavaTypeConverter().get(0);
    JavaType type = converter.convertFromText(returnType, JavaType.class, PROJECT);
    if (type == null) {
        return false;
    }
    ClassOrInterfaceTypeDetails details = getTypeLocationService().getTypeDetails(type);
    if (details == null) {
        return false;
    }
    AnnotationMetadata entityAnnotation = details.getAnnotation(RooJavaType.ROO_JPA_ENTITY);
    if (entityAnnotation != null) {
        return false;
    }
    return true;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) JavaTypeConverter(org.springframework.roo.converters.JavaTypeConverter) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) CliOptionMandatoryIndicator(org.springframework.roo.shell.CliOptionMandatoryIndicator)

Aggregations

ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)1 JavaTypeConverter (org.springframework.roo.converters.JavaTypeConverter)1 JavaType (org.springframework.roo.model.JavaType)1 RooJavaType (org.springframework.roo.model.RooJavaType)1 CliOptionMandatoryIndicator (org.springframework.roo.shell.CliOptionMandatoryIndicator)1