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;
}
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;
}
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;
}
Aggregations