use of org.springframework.roo.shell.CliCommand in project spring-roo by spring-projects.
the class FieldCommands method addFieldBoolean.
@CliCommand(value = "field boolean", help = "Adds a private boolean field to an existing Java source file.")
public void addFieldBoolean(@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 only available for JPA entities and " + "embeddable classes. " + "This option is mandatory if `spring.roo.jpa.require.schema-object-name` " + "configuration setting exists and it's `true`.") 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 = "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 = "assertFalse", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether the value of this field must be false. Adds " + "`javax.validation.constraints.AssertFalse` annotation to the field. " + "This option is not available if `--asssertTrue` has already " + "been specified. " + "Default if option present: `true`; default if option not present: `false`.") final boolean assertFalse, @CliOption(key = "assertTrue", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether the value of this field must be true. Adds " + "`javax.validation.constraints.AssertTrue` annotation to the field. " + "This option is not available if `--asssertFalse` has already " + "been specified. " + "Default if option present: `true`; default if option not present: `false`.") final boolean assertTrue, @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 = "primitive", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates to use the primitive type. " + "Default if option present: `true`; default if option not present: `false`.") final boolean primitive, @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 javaTypeDetails = typeLocationService.getTypeDetails(typeName);
Validate.notNull(javaTypeDetails, "The type specified, '%s', doesn't exist", typeName);
checkFieldExists(fieldName, shellContext, javaTypeDetails);
getFieldCreatorProvider(typeName).createBooleanField(javaTypeDetails, primitive, fieldName, notNull, assertFalse, assertTrue, column, comment, value, permitReservedWords, transientModifier);
}
use of org.springframework.roo.shell.CliCommand in project spring-roo by spring-projects.
the class FieldCommands method addFieldDateJpa.
@CliCommand(value = "field date", help = "Adds a private date field to an existing Java source file.")
public void addFieldDateJpa(@CliOption(key = { "", "fieldName" }, mandatory = true, help = "The name of the field to add.") final JavaSymbolName fieldName, @CliOption(key = "type", mandatory = true, optionContext = "java-date", help = "The Java date type of the field. Its value can be `java.util.Date` or `java.util.Calendar`.") final JavaType fieldType, @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 = "persistenceType", mandatory = false, help = "The type of persistent storage to be used. It adds a `javax.persistence.TemporalType` " + "to a `javax.persistence.Temporal` annotation into the field. " + "This option is only available for JPA entities and embeddable classes. " + "Default if option not present: `TemporalType.TIMESTAMP`") final DateFieldPersistenceType persistenceType, @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 visible 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 = "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 = "future", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether this value must be in the future. Adds `field.javax.validation.constraints.Future` " + "annotation to the field. " + "This option is not available if `--past` option has already been specified. " + "Default if option present: `true`; default if option not present: `false`.") final boolean future, @CliOption(key = "past", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether this value must be in the past. Adds `field.javax.validation.constraints.Past` " + "annotation to the field. " + "This option is not available if `--future` option has already been specified. " + "Default if option present: `true`; default if option not present: `false`.") final boolean past, @CliOption(key = "comment", mandatory = false, help = "An optional comment for JavaDocs.") final String comment, @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 = "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, @CliOption(key = "dateFormat", mandatory = false, unspecifiedDefaultValue = "MEDIUM", specifiedDefaultValue = "MEDIUM", help = "Indicates the style of the date format, adding `style` attribute to " + "`org.springframework.format.annotation.DateTimeFormat` annotation " + "into the field, with date style (first character of the code). " + "Possible values are: `MEDIUM` (style='M-'), `NONE` (style='--') and " + "`SHORT` (style='S-'). " + "This option is not available if `--dateTimeFormatPattern` has already " + "been specified." + "Default: `MEDIUM`.") final DateTime dateFormat, @CliOption(key = "timeFormat", mandatory = false, unspecifiedDefaultValue = "NONE", specifiedDefaultValue = "NONE", help = "Indicates the style of the time format, adding `style` attribute to " + "`org.springframework.format.annotation.DateTimeFormat` annotation " + "into the field, with time style (second character of the code). " + "Possible values are: `MEDIUM` (style='-M'), `NONE` (style='--') and " + "`SHORT` (style='-S'). " + "This option is not available if `--dateTimeFormatPattern` has already " + "been specified. " + "Default: `NONE`.") final DateTime timeFormat, @CliOption(key = "dateTimeFormatPattern", mandatory = false, help = "Indicates a 'custom' DateTime format pattern such as yyyy-MM-dd hh:mm:ss, adding " + "`pattern` attribute to `org.springframework.format.annotation.DateTimeFormat` " + "annotation into the field, with the provided value. " + "This option is not available if `--timeFormat` or `--dateFormat` have already " + "been specified.") final String pattern, ShellContext shellContext) {
final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService.getTypeDetails(typeName);
Validate.notNull(javaTypeDetails, "The type specified, '%s', doesn't exist", typeName);
checkFieldExists(fieldName, shellContext, javaTypeDetails);
getFieldCreatorProvider(typeName).createDateField(javaTypeDetails, fieldType, fieldName, notNull, nullRequired, future, past, persistenceType, column, comment, dateFormat, timeFormat, pattern, value, permitReservedWords, transientModifier);
}
use of org.springframework.roo.shell.CliCommand in project spring-roo by spring-projects.
the class FieldCommands method addFieldNumber.
@CliCommand(value = "field number", help = "Adds a private numeric field to an existing Java source file. User can choose the field type between a wide range of numeric types.")
public void addFieldNumber(@CliOption(key = { "", "fieldName" }, mandatory = true, help = "The name of the field to add.") final JavaSymbolName fieldName, @CliOption(key = "type", mandatory = true, optionContext = "java-number", help = "The Java type of the field. Only numeric types allowed. " + "Possible values are: `java.math.BigDecimal`, `java.math.BigInteger`, `byte`, " + "`java.lang.Byte`, `double`, `java.lang.Double`, `float`, `java.lang.Float`, `int`, " + "`java.lang.Integer`, `long`, `java.lang.Long`, `java.lang.Number`, `short` and " + "`java.lang.Short`.") JavaType fieldType, @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 = "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 = "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 = "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` or `--primitive` option have already been specified " + "with value `true` or without value. " + "Default if option present: `true`; default if option not present: `false`.") final boolean nullRequired, @CliOption(key = "decimalMin", mandatory = false, help = "The BigDecimal string-based representation of the minimum value. It adds to the field " + "`javax.validation.constraints.DecimalMin` annotation with provided value.") final String decimalMin, @CliOption(key = "decimalMax", mandatory = false, help = "The BigDecimal string based representation of the maximum value. It adds to the field " + "`javax.validation.constraints.DecimalMax` annotation with provided value.") final String decimalMax, @CliOption(key = "digitsInteger", mandatory = false, help = "Maximum number of integral digits accepted for this number. It creates or updates field " + "`javax.validation.constraints.Digits` annotation, adding `integer` attribute with the " + "provided value.") final Integer digitsInteger, @CliOption(key = "digitsFraction", mandatory = false, help = "Maximum number of fractional digits accepted for this number. It creates or updates field " + "`javax.validation.constraints.Digits` annotation, adding `fraction` attribute with the " + "provided value.") final Integer digitsFraction, @CliOption(key = "min", mandatory = false, help = "The minimum value of the numeric field. It adds " + "`javax.validation.constraints.Min` with provided value to the field.") final Long min, @CliOption(key = "max", mandatory = false, help = "The maximum value of the numeric field. It adds " + "`javax.validation.constraints.Max` with provided value to the field.") final Long max, @CliOption(key = "comment", mandatory = false, help = "An optional comment for JavaDocs.") final String comment, @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 = "primitive", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates to use a primitive type if possible. " + "Default if option present: `true`; default if option not present: `false`.") final boolean primitive, @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 javaTypeDetails = typeLocationService.getTypeDetails(typeName);
Validate.notNull(javaTypeDetails, "The type specified, '%s', doesn't exist", typeName);
checkFieldExists(fieldName, shellContext, javaTypeDetails);
getFieldCreatorProvider(typeName).createNumericField(javaTypeDetails, fieldType, primitive, legalNumericPrimitives, fieldName, notNull, nullRequired, decimalMin, decimalMax, digitsInteger, digitsFraction, min, max, column, comment, unique, value, permitReservedWords, transientModifier);
}
use of org.springframework.roo.shell.CliCommand in project spring-roo by spring-projects.
the class FieldCommands method addFieldEnum.
@CliCommand(value = "field enum", help = "Adds a private enum field to an existing Java source file. The field type must be a Java enum type.")
public void addFieldEnum(@CliOption(key = { "", "fieldName" }, mandatory = true, help = "The name of the field to add.") final JavaSymbolName fieldName, @CliOption(key = "type", mandatory = true, optionContext = ENUMERATION, help = "The Java type of the field. It must be a Java enum type. " + "Possible values are: any enumerated class in the user's project.") final JavaType fieldType, @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 = "enumType", mandatory = false, help = "Defines how the enumerated field should be persisted at a JPA level. Adds the " + "`javax.persistence.Enumerated` annotation to the field, with `javax.persistence.EnumType`" + " attribute. " + "Possible values are: `ORDINAL` (persists as an integer) and `STRING` " + "(persists as a String). " + "This option is only available for JPA entities and embeddable classes. " + "Default if option not present: `ORDINAL` (no `@Enumerated` - default by JPA).") final EnumType enumType, @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 = "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 enumTypeCid = typeLocationService.getTypeDetails(fieldType);
Validate.notNull(enumTypeCid, "The enum type specified, '%s', doesn't exist. Please, specify an existent enum type.", fieldType.getSimpleTypeName());
final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(typeName);
Validate.notNull(cid, "The class specified, '%s', doesn't exist. Please, specify an existent class.", typeName.getSimpleTypeName());
checkFieldExists(fieldName, shellContext, cid);
getFieldCreatorProvider(typeName).createEnumField(cid, fieldType, fieldName, column, notNull, nullRequired, enumType, comment, permitReservedWords, transientModifier);
}
use of org.springframework.roo.shell.CliCommand in project spring-roo by spring-projects.
the class FieldCommands method addFieldEmbeddedJpa.
@CliCommand(value = "field embedded", help = "Adds a private `@Embedded` field to an existing Java source file. " + "This command is only available for entities annotated with `@RooJpaEntity` (Roo JPA " + "entities). Therefore, you should focus the desired entity in the Roo Shell to make " + "this command available.")
public void addFieldEmbeddedJpa(@CliOption(key = { "", "fieldName" }, mandatory = true, help = "The name of the field to add.") final JavaSymbolName fieldName, @CliOption(key = "type", mandatory = true, optionContext = PROJECT, help = "The Java type of an embeddable class, annotated with `@Embeddable`. " + "Possible values are: any class in the project annotated with `@Embeddable`.") final JavaType fieldType, @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 = "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) {
// Check if the field type is a JPA @Embeddable class
final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(fieldType);
Validate.notNull(cid, "The specified target '--type' does not exist or can not be found. Please create this type first.");
Validate.notNull(cid.getAnnotation(EMBEDDABLE), "The field embedded command is only applicable to JPA @Embeddable field types.");
checkFieldExists(fieldName, shellContext, cid);
getFieldCreatorProvider(typeName).createEmbeddedField(typeName, fieldType, fieldName, permitReservedWords);
}
Aggregations