Search in sources :

Example 1 with JavaTypeConverter

use of org.springframework.roo.converters.JavaTypeConverter in project spring-roo by spring-projects.

the class FinderCommands method getTypeFromEntityParam.

/**
 * Tries to obtain JavaType indicated in command or which has the focus
 * in the Shell
 *
 * @param shellContext the Roo Shell context
 * @return JavaType or null if no class has the focus or no class is
 * specified in the command
 */
private JavaType getTypeFromEntityParam(ShellContext shellContext) {
    // Try to get 'entity' from ShellContext
    String typeString = shellContext.getParameters().get("entity");
    JavaType type = null;
    if (typeString != null) {
        JavaTypeConverter converter = (JavaTypeConverter) getJavaTypeConverter().get(0);
        type = converter.convertFromText(typeString, JavaType.class, PROJECT);
    } else {
        type = lastUsed.getJavaType();
    }
    return type;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) JavaTypeConverter(org.springframework.roo.converters.JavaTypeConverter)

Example 2 with JavaTypeConverter

use of org.springframework.roo.converters.JavaTypeConverter in project spring-roo by spring-projects.

the class ControllerCommands method getTypeFromEntityParam.

/**
 * This method provides the Command definition to be able to publish service
 * operations in controllers.
 *
 * @param controller
 * @param service
 * @param operation
 * @param all
 */
/* TODO: TO BE IMPLEMENTED
     @CliCommand(value = "web mvc operation",
      help = "Update or generates @RooController with service operations")
  public void addOperationInController(

      @CliOption(key = "controller", mandatory = true,
          help = "Indicates the controller where should be published the service methods") JavaType controller,
      @CliOption(
          key = "service",
          mandatory = false,
          help = "This param will be visible if --controller parameter doesn't exists in the application. Indicates the service on which methods should be published in the controller") JavaType service,
      @CliOption(
          key = "operation",
          mandatory = false,
          help = "This param will be visible if --all parameter hasn't been specified. Indicates the operation of the service that should be published in the controller") String operation,
      @CliOption(
          key = "all",
          mandatory = false,
          specifiedDefaultValue = "true",
          unspecifiedDefaultValue = "false",
          help = "This param will be visible if --operation parameter hasn't been specified. Indicates if every method of the service should be published in the controller") boolean all) {

    List<String> operations = new ArrayList<String>();

    // Check --all parameter
    if (all) {

      // Getting the service
      String currentService = null;
      String serviceName = "";
      if (service != null) {
        currentService = service.getFullyQualifiedTypeName();

        // Get service name to concatenate it on each method name
        serviceName =
            getControllerOperations().replaceTopLevelPackage(
                getTypeLocationService().getTypeDetails(service));
      }

      // Getting the controller
      String currentController = null;
      if (controller != null) {
        currentController = controller.getFullyQualifiedTypeName();
      }

      List<String> allMethodsToPublish =
          getControllerOperations().getAllMethodsToPublish(currentService, currentController);


      for (String methodToPublish : allMethodsToPublish) {
        if (service != null) {
          methodToPublish = serviceName.concat(".").concat(methodToPublish);
        }
        operations.add(methodToPublish);
      }

      // Get all the methods related with controller or service

    } else {
      if (service != null) {
        // Add service name to operation
        String serviceName =
            getControllerOperations().replaceTopLevelPackage(
                getTypeLocationService().getTypeDetails(service));
        operation = serviceName.concat(".").concat(operation);
      }

      operations.add(operation);
    }

    getControllerOperations().exportOperation(controller, operations);
  }*/
/**
 * Tries to obtain JavaType indicated in command or which has the focus in the
 * Shell
 *
 * @param shellContext the Roo Shell context
 * @return JavaType or null if no class has the focus or no class is specified
 *         in the command
 */
private JavaType getTypeFromEntityParam(ShellContext shellContext) {
    // Try to get 'class' from ShellContext
    String typeString = shellContext.getParameters().get("entity");
    JavaType type = null;
    if (typeString != null) {
        JavaTypeConverter converter = (JavaTypeConverter) getJavaTypeConverter().get(0);
        type = converter.convertFromText(typeString, JavaType.class, PROJECT);
    }
    return type;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) JavaTypeConverter(org.springframework.roo.converters.JavaTypeConverter)

Example 3 with JavaTypeConverter

use of org.springframework.roo.converters.JavaTypeConverter 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

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