Search in sources :

Example 21 with CliCommand

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

the class FieldCommands method addFieldString.

@CliCommand(value = "field string", help = "Adds a private String field to an existing Java source file.")
public void addFieldString(@CliOption(key = { "", "fieldName" }, mandatory = true, help = "The name of the field to add.") final JavaSymbolName fieldName, @CliOption(key = "class", mandatory = true, unspecifiedDefaultValue = "*", optionContext = UPDATE_PROJECT, help = "The name of the class to generate the field. When working on a mono module project, " + "simply specify the name of the class in which the field will be included. If you " + "consider it necessary, you can also specify the package. Ex.: `--class ~.domain.MyClass`" + " (where `~` is the base package). When working with multiple modules, you should specify" + " the name of the class and the module where it is. Ex.: `--class model:~.domain.MyClass`." + " If the module is not specified, it is assumed that the class is in the module which has" + " the focus. " + "This option is mandatory for this command when the focus is not set to one class. " + "Default if option not present: the class focused by Roo Shell.") final JavaType typeName, @CliOption(key = "column", mandatory = true, help = "The JPA `@Column` name. " + "This option is mandatory if `spring.roo.jpa.require.schema-object-name` configuration " + "setting exists and it's `true`. " + "This option is only available for JPA entities and embeddable classes.") final String column, @CliOption(key = "transient", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates to mark the field as transient, adding JPA `javax.persistence.Transient` " + "annotation. This marks the field as not persistent. " + "This option is only available for JPA entities and embeddable classes. " + "Default if option present:`true`. Default if option not present: `false`") final boolean transientModifier, @CliOption(key = "lob", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates that this field is a Large Object. This option adds `javax.persistence.Lob` " + "annotation to the field. " + "This option is only available for JPA entities and embeddable classes. " + "Default if option present: `true`; default if option not present: `false`.") final boolean lob, @CliOption(key = "unique", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates whether to mark the field with a unique constraint. " + "This option is only available for JPA entities and embeddable classes. " + "Default if option present: `true`; default if option not present: `false`.") final boolean unique, @CliOption(key = "regexp", mandatory = false, help = "The required regular expression pattern. This option adds " + "`javax.validation.constraints.Pattern` with the provided value as `regexp` attribute.") final String regexp, @CliOption(key = "sizeMin", mandatory = false, help = "The minimum string length. This option adds or updates " + "`javax.validation.constraints.Size` with the provided value as `min` attribute value.") final Integer sizeMin, @CliOption(key = "sizeMax", mandatory = false, help = "The maximum string length. This option adds or updates " + "`javax.validation.constraints.Size` with the provided value as `max` attribute value.") final Integer sizeMax, @CliOption(key = "notNull", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether this value cannot be null. Adds `javax.validation.constraints.NotNull` annotation to the field. " + "This option is not available if `--nullRequired` has already been specified. " + "Default if option present: `true`; default if option not present: `false`.") final boolean notNull, @CliOption(key = "nullRequired", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether this value must be null. Adds `javax.validation.constraints.Null` annotation to the field. " + "This option is not available if `--notNull` has already been specified. " + "Default if option present: `true`; default if option not present: `false`.") final boolean nullRequired, @CliOption(key = "value", mandatory = false, help = "Inserts an optional Spring `org.springframework.beans.factory.annotation.Value` " + "annotation with the given content, typically used for expression-driven dependency " + "injection.") final String value, @CliOption(key = "comment", mandatory = false, help = "An optional comment for JavaDocs.") final String comment, @CliOption(key = "permitReservedWords", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates whether reserved words are ignored by Roo. " + "Default if option present: `true`; default if option not present: `false`.") final boolean permitReservedWords, ShellContext shellContext) {
    final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(typeName);
    Validate.notNull(cid, "The type specified, '%s', doesn't exist", typeName);
    checkFieldExists(fieldName, shellContext, cid);
    getFieldCreatorProvider(typeName).createStringField(cid, fieldName, notNull, nullRequired, null, null, sizeMin, sizeMax, regexp, column, comment, unique, value, lob, permitReservedWords, transientModifier);
}
Also used : ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliCommand(org.springframework.roo.shell.CliCommand)

Example 22 with CliCommand

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

the class FieldCommands method addFileUploadField.

@CliCommand(value = "field file", help = "Adds a byte array field for storing uploaded file contents.")
public void addFileUploadField(@CliOption(key = { "", "fieldName" }, mandatory = true, help = "The name of the file upload field to add.") final JavaSymbolName fieldName, @CliOption(key = "contentType", mandatory = true, help = "The content type of the file. " + "Possible values are: `CSS`, `CSV`, `DOC`, `GIF`, `HTML`, `JAVASCRIPT`, `JPG`, " + "`JSON`, `MP3`, `MP4`, `MPEG`, `PDF`, `PNG`, `TXT`, `XLS`, `XML` and `ZIP`.") final UploadedFileContentType contentType, @CliOption(key = "class", mandatory = true, unspecifiedDefaultValue = "*", optionContext = UPDATE_PROJECT, help = "The name of the class to generate the field. When working on a mono module project, " + "simply specify the name of the class in which the field will be included. If you " + "consider it necessary, you can also specify the package. Ex.: `--class ~.domain.MyClass`" + " (where `~` is the base package). When working with multiple modules, you should specify" + " the name of the class and the module where it is. Ex.: `--class model:~.domain.MyClass`." + " If the module is not specified, it is assumed that the class is in the module which has" + " the focus. " + "This option is mandatory for this command when the focus is not set to one class. " + "Default if option not present: the class focused by Roo Shell.") final JavaType typeName, @CliOption(key = "column", mandatory = true, help = "The JPA `@Column` name. " + "This option is mandatory if `spring.roo.jpa.require.schema-object-name` configuration " + "setting exists and it's `true`. " + "This option is only available for JPA entities and embeddable classes.") final String column, @CliOption(key = "autoUpload", mandatory = false, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = "Whether the file is uploaded automatically when selected. " + "Default if option present: `true`; default if option not present: `false`.") final boolean autoUpload, @CliOption(key = "notNull", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether this value cannot be null. Adds `javax.validation.constraints.NotNull` annotation to the field." + "Default if option present: `true`; default if option not present: `false`.") final boolean notNull, @CliOption(key = "permitReservedWords", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates whether reserved words are ignored by Roo." + "Default if option present: `true`; default if option not present: `false`.") final boolean permitReservedWords, ShellContext shellContext) {
    final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(typeName);
    Validate.notNull(cid, "The type specified, '%s', doesn't exist", typeName);
    checkFieldExists(fieldName, shellContext, cid);
    getFieldCreatorProvider(typeName).createFileField(cid, fieldName, contentType, autoUpload, notNull, column, permitReservedWords);
}
Also used : ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliCommand(org.springframework.roo.shell.CliCommand)

Example 23 with CliCommand

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

the class ServiceCommands method service.

@CliCommand(value = "service", help = "Creates new service interface and its implementation related to an entity, or for all the " + "entities in generated project, with some basic management methods by using Spring Data repository methods.")
public void service(@CliOption(key = "all", mandatory = false, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = "Indicates if developer wants to generate service interfaces and their implementations " + "for every entity of current project. " + "This option is mandatory if `--entity` is not specified. Otherwise, using `--entity` " + "will cause the parameter `--all` won't be available. " + "Default if option present: `true`; default if option not present: `false`.") boolean all, @CliOption(key = "entity", optionContext = PROJECT, mandatory = false, help = "The domain entity this service should manage. When working on a single module " + "project, simply specify the name of the entity. If you consider it necessary, you can " + "also specify the package. Ex.: `--class ~.domain.MyEntity` (where `~` is the base package). " + "When working with multiple modules, you should specify the name of the entity and the " + "module where it is. Ex.: `--class model:~.domain.MyEntity`. If the module is not specified, " + "it is assumed that the entity is in the module which has the focus. " + "Possible values are: any of the entities in the project. " + "This option is mandatory if `--all` is not specified. Otherwise, using `--all` " + "will cause the parameter `--entity` won't be available.") final JavaType domainType, @CliOption(key = "repository", optionContext = PROJECT, mandatory = true, help = "The repository this service should expose. When working on a single module project, " + "simply specify the name of the class. If you consider it necessary, you can also " + "specify the package. Ex.: `--class ~.repository.MyClass` (where `~` is the base " + "package). When working with multiple modules, you should specify the name of the class " + "and the module where it is. Ex.: `--class repository:~.MyClass`. If the module is not " + "specified, it is assumed that the class is in the module which has the focus. " + "Possible values are: any of the repositories annotated with `@RooJpaRepository` and " + "associated to the entity specified in `--entity`. " + "This option is mandatory if `--entity` has been already specified and the project is " + "multi-module. " + "This option is available only when `--entity` has been specified. " + "Default if option not present: first repository annotated with `@RooJpaRepository` and " + "associated to the entity specified in `--entity`.") final JavaType repositoryType, @CliOption(key = "interface", mandatory = true, help = "The service interface to be generated. When working on a single module project, simply " + "specify the name of the class. If you consider it necessary, you can also specify the " + "package. Ex.: `--class ~.service.api.MyClass` (where `~` is the base package). When " + "working with multiple modules, you should specify the name of the class and the module " + "where it is. Ex.: `--class service-api:~.MyClass`. If the module is not specified, it " + "is assumed that the class is in the module which has the focus. " + "This option is mandatory if `--entity` has been already specified and the project is " + "multi-module. " + "This option is available only when `--entity` has been specified. " + "Default if option not present: concatenation of entity simple name with 'Service' in " + "`~.service.api` package, or 'service-api:~.' if multi-module project.") final JavaType interfaceType, @CliOption(key = "class", mandatory = false, help = "The service implementation to be generated. When working on a single module " + "project, simply specify the name of the class. If you consider it necessary, you can " + "also specify the package. Ex.: `--class ~.service.impl.MyClass` (where `~` is the base " + "package). When working with multiple modules, you should specify the name of the class " + "and the module where it is. Ex.: `--class service-impl:~.MyClass`. If the module is not " + "specified, it is assumed that the class is in the module which has the focus. " + "This option is available only when `--entity` has been specified. " + "Default if option not present: concatenation of entity simple name with 'ServiceImpl' " + "in `~.service.impl` package, or 'service-impl:~.' if multi-module project.") final JavaType implType, @CliOption(key = "apiPackage", mandatory = false, help = "The java interface package. In multi-module project you should specify the module name" + " before the package name. Ex.: `--apiPackage service-api:org.springframework.roo` but, " + "if module name is not present, the Roo Shell focused module will be used. " + "This option is available only when `--all` parameter has been specified. " + "Default value if not present: `~.service.api` package, or 'service-api:~.' if " + "multi-module project.") JavaPackage apiPackage, @CliOption(key = "implPackage", mandatory = false, help = "The java package of the implementation classes for the interfaces. In multi-module " + "project you should specify the module name before the package name. Ex.: `--implPackage " + "service-impl:org.springframework.roo` but, if module name is not present, the Roo Shell " + "focused module will be used. " + "This option is available only when `--all` parameter has been specified. " + "Default value if not present: `~.service.impl` package, or 'service-impl:~.' if " + "multi-module project.") JavaPackage implPackage) {
    if (all) {
        // If user didn't specified some API package, use default API package
        if (apiPackage == null) {
            if (projectOperations.isMultimoduleProject()) {
                // Build default JavaPackage with module
                for (String moduleName : projectOperations.getModuleNames()) {
                    if (moduleName.equals("service-api")) {
                        Pom module = projectOperations.getPomFromModuleName(moduleName);
                        apiPackage = new JavaPackage(typeLocationService.getTopLevelPackageForModule(module), moduleName);
                        break;
                    }
                }
                // Check if repository found
                Validate.notNull(apiPackage, "Couldn't find in project a default service.api " + "package. Please, use 'apiPackage' option to specify it.");
            } else {
                // Build default JavaPackage for single module
                apiPackage = new JavaPackage(projectOperations.getFocusedTopLevelPackage().getFullyQualifiedPackageName().concat(".service.api"), projectOperations.getFocusedModuleName());
            }
        }
        // If user didn't specified some impl package, use default impl package
        if (implPackage == null) {
            if (projectOperations.isMultimoduleProject()) {
                // Build default JavaPackage with module
                for (String moduleName : projectOperations.getModuleNames()) {
                    if (moduleName.equals("service-impl")) {
                        Pom module = projectOperations.getPomFromModuleName(moduleName);
                        implPackage = new JavaPackage(typeLocationService.getTopLevelPackageForModule(module), moduleName);
                        break;
                    }
                }
                // Check if repository found
                Validate.notNull(implPackage, "Couldn't find in project a default service.impl " + "package. Please, use 'implPackage' option to specify it.");
            } else {
                // Build default JavaPackage for single module
                implPackage = new JavaPackage(projectOperations.getFocusedTopLevelPackage().getFullyQualifiedPackageName().concat(".service.impl"), projectOperations.getFocusedModuleName());
            }
        }
        serviceOperations.addAllServices(apiPackage, implPackage);
    } else {
        serviceOperations.addService(domainType, repositoryType, interfaceType, implType);
    }
}
Also used : JavaPackage(org.springframework.roo.model.JavaPackage) Pom(org.springframework.roo.project.maven.Pom) CliCommand(org.springframework.roo.shell.CliCommand)

Example 24 with CliCommand

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

the class FinderCommands method installFinders.

@CliCommand(value = "finder add", help = "Installs a finder in the given target (must be an entity). This command needs an existing " + "repository for the target entity, you can create it with `repository jpa` command. The " + "finder will be added to targeted entity associated repository and associated service if " + "exists or when it will be created.")
public void installFinders(@CliOption(key = "entity", mandatory = true, unspecifiedDefaultValue = "*", optionContext = PROJECT, help = "The entity for which the finders are generated. When working on a mono module project, " + "simply specify the name of the entity. If you consider it necessary, you can also " + "specify the package. Ex.: `--class ~.domain.MyEntity` (where `~` is the base package). " + "When working with multiple modules, you should specify the name of the class and the " + "module where it is. Ex.: `--class model:~.domain.MyEntity`. If the module is not " + "specified, it is assumed that the entity is in the module which has the focus.") final JavaType entity, @CliOption(key = "name", mandatory = true, help = "The finder string defined as a Spring Data query. Use Spring Data JPA nomenclature. " + "Possible values are: any finder name following Spring Data nomenclature. " + "This option will not be available until `--entity` is specified.") final JavaSymbolName finderName, @CliOption(key = "formBean", mandatory = true, help = "The finder's search parameter. Should be a DTO and it must have at least same fields " + "(name and type) as those included in the finder `--name`, which can be target entity" + " fields or related entity fields. " + "Possible values are: any of the DTO's in the project. " + "This option is mandatory if `--returnType` is specified and its a projection. " + "This option is not available if `--entity` parameter has not been specified before or " + "if it does not exist any DTO in generated project. " + "Default if option not present: the entity specified in `--entity` option.") final JavaType formBean, @CliOption(key = "returnType", mandatory = false, optionContext = PROJECT, help = "The finder's results return type. " + "Possible values are: Projection classes annotated with `@RooEntityProjection` and " + "related to the entity specified in `--entity` option (use `entity projection` command), " + "or the same entity. " + "This option is not available if `--entity` parameter has not been specified before or " + "if it does not exist any Projection class associated to the targeted entity. " + "Default if not present: the default return type of the repository related to the entity, " + "which can be specified with `--defaultReturnType` parameter in `repository jpa` command.") JavaType returnType) {
    // Check if specified finderName follows Spring Data nomenclature
    PartTree partTree = new PartTree(finderName.getSymbolName(), getEntityDetails(entity), this);
    // If generated partTree is not valid, shows an exception
    Validate.isTrue(partTree.isValid(), "--name parameter must follow Spring Data nomenclature. Please, write a valid value using autocomplete feature (TAB or CTRL + Space)");
    // related repository
    if (returnType == null) {
        // Obtain the related repository metadata
        RepositoryJpaMetadata repositoryMetadata = getRepositoryJpaLocator().getFirstRepositoryMetadata(entity);
        Validate.notNull(repositoryMetadata, "ERROR: You must create a repository related with this entity before to generate a finder");
        // Use the repository metadata to obtain the default return type
        returnType = repositoryMetadata.getDefaultReturnType();
    }
    Validate.notNull(returnType, "ERROR: The new finder must define a returnType");
    // Check if the returnType is an entity. If is is not an entity validate
    // that the formBean is not null
    ClassOrInterfaceTypeDetails type = getTypeLocationService().getTypeDetails(returnType);
    if (type.getAnnotation(RooJavaType.ROO_JPA_ENTITY) == null) {
        Validate.notNull(formBean, "--formBean is requied when --returnType parameter is a projection.");
    }
    finderOperations.installFinder(entity, finderName, formBean, returnType);
}
Also used : RepositoryJpaMetadata(org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) PartTree(org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree) CliCommand(org.springframework.roo.shell.CliCommand)

Example 25 with CliCommand

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

the class WebFinderCommands method addController.

/**
 * This method provides the Command definition to be able to add
 * new finder on controllers.
 *
 * @param controller
 * @param all
 * @param finder
 * @param responseType
 */
@CliCommand(value = "web mvc finder", help = "Publishes existing finders to web layer, generating controllers and additional views for " + "them. It adds `@RooWebFinder` annotation to MVC controller type.")
public void addController(@CliOption(key = "entity", mandatory = false, help = "The entity owning the finders that should be published. When working on a single module " + "project, simply specify the name of the entity. If you consider it necessary, you can " + "also specify the package. Ex.: `--class ~.domain.MyEntity` (where `~` is the base " + "package). When working with multiple modules, you should specify the name of the entity " + "and the module where it is. Ex.: `--class model:~.domain.MyEntity`. If the module is not " + "specified, it is assumed that the entity is in the module which has the focus. " + "Possible values are: any of the entities in the project. " + "This option is mandatory if `--all` is not specified. Otherwise, using `--all` " + "will cause the parameter `--entity` won't be available.") JavaType entity, @CliOption(key = "all", mandatory = false, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = "Indicates if developer wants to publish in web layer all finders from all entities in " + "project. " + "This option is mandatory if `--entity` is not specified. Otherwise, using `--entity` " + "will cause the parameter `--all` won't be available. " + "Default if option present: `true`; default if option not present: `false`.") boolean all, @CliOption(key = "queryMethod", mandatory = false, help = "Indicates the name of the finder to add to web layer. " + "Possible values are: any of the finder names created for the entity, included in " + "`@RooJpaRepository` of the `--entity` associated repository. " + "This option is available only when `--entity` has been specified.") String queryMethod, @CliOption(key = "responseType", mandatory = false, help = "Indicates the responseType to be used by generated finder controllers. Depending on " + "the selected responseType, generated methods and views will vary. " + "Possible values are: `JSON` plus any response type installed with `web mvc view setup` " + "command. " + "This option is only available if `--all` or `--entity` parameters have been specified. " + "Default: `JSON`.") String responseType, @CliOption(key = "package", mandatory = true, unspecifiedDefaultValue = "~.web", help = "Indicates the Java package where the finder controllers should be generated. In" + " multi-module project you should specify the module name before the package name. " + "Ex.: `--package application:org.springframework.roo.web` but, if module name is not " + "present, the Roo Shell focused module will be used. " + "This option is available only if `--all` or `--entity` option has been specified. " + "Default value if not present: `~.web` package, or 'application:~.web' if multi-module " + "project.") JavaPackage controllerPackage, @CliOption(key = "pathPrefix", mandatory = false, unspecifiedDefaultValue = "", specifiedDefaultValue = "", help = "Indicates the default path value for accesing finder resources in controller, used for " + "this controller `@RequestMapping` excluding first '/'. " + "This option is available only if `--all` or `--entity` option has been specified.") String pathPrefix) {
    // Getting --responseType service
    Map<String, ControllerMVCResponseService> responseTypeServices = getInstalledControllerMVCResponseTypes();
    // Validate that provided responseType is a valid provided
    ControllerMVCResponseService controllerResponseType = null;
    if (responseType != null) {
        if (!responseTypeServices.containsKey(responseType)) {
            LOGGER.log(Level.SEVERE, "ERROR: Provided responseType is not valid. Use autocomplete feature " + "to obtain valid responseTypes.");
            return;
        } else {
            controllerResponseType = responseTypeServices.get(responseType);
        }
    } else {
        controllerResponseType = responseTypeServices.get("JSON");
    }
    // Execute finder operation
    if (!all) {
        // Create queryMethods list
        List<String> queryMethods = new ArrayList<String>();
        if (queryMethod != null) {
            queryMethods.add(queryMethod);
        } else {
            queryMethods = getFinders(entity, controllerResponseType);
        }
        webFinderOperations.createOrUpdateSearchControllerForEntity(entity, queryMethods, controllerResponseType, controllerPackage, pathPrefix);
    } else {
        webFinderOperations.createOrUpdateSearchControllerForAllEntities(controllerResponseType, controllerPackage, pathPrefix);
    }
}
Also used : ControllerMVCResponseService(org.springframework.roo.addon.web.mvc.controller.addon.responses.ControllerMVCResponseService) ArrayList(java.util.ArrayList) CliCommand(org.springframework.roo.shell.CliCommand)

Aggregations

CliCommand (org.springframework.roo.shell.CliCommand)26 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)12 ArrayList (java.util.ArrayList)4 PGPPublicKeyRing (org.bouncycastle.openpgp.PGPPublicKeyRing)4 IOException (java.io.IOException)3 Pom (org.springframework.roo.project.maven.Pom)3 TemplateException (freemarker.template.TemplateException)2 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ServiceReference (org.osgi.framework.ServiceReference)2 JavaPackage (org.springframework.roo.model.JavaPackage)2 CliOption (org.springframework.roo.shell.CliOption)2 CommandMarker (org.springframework.roo.shell.CommandMarker)2 MethodTarget (org.springframework.roo.shell.MethodTarget)2 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1