use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JpaAuditCommands method auditAdd.
@CliCommand(value = "jpa audit add", help = "Adds support for auditing a JPA entity. This will add JPA " + "and Spring listeners to this entity to record the entity changes.")
public void auditAdd(@CliOption(key = "entity", mandatory = true, help = "The entity which should be audited. 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 = "createdDateColumn", mandatory = true, help = "The DB column used for storing the date when each record is created." + "This option is mandatory if `spring.roo.jpa.require.schema-object-name` " + "configuration setting exists and it's `true`.") final String createdDateColumn, @CliOption(key = "modifiedDateColumn", mandatory = true, help = "The DB column used for storing the date when each record is modified." + "This option is mandatory if `spring.roo.jpa.require.schema-object-name` " + "configuration setting exists and it's `true`.") final String modifiedDateColumn, @CliOption(key = "createdByColumn", mandatory = true, help = "The DB column used for storing information about who creates each record." + "This option is mandatory if `spring.roo.jpa.require.schema-object-name` configuration " + "setting exists and it's `true`.") final String createdByColumn, @CliOption(key = "modifiedByColumn", mandatory = true, help = "The DB column used for storing information about who modifies each record." + "This option is mandatory if `spring.roo.jpa.require.schema-object-name` configuration " + "setting exists and it's `true`.") final String modifiedByColumn) {
// Check if entity exists
final ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
Validate.notNull(entityDetails, "ERROR: The type specified, '%s', doesn't exist", entity);
// Check if entity is a valid entity
Validate.notNull(entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "'%s' is not a valid entity. It should be annotated with @RooEntity", entity);
getAuditOperations().addJpaAuditToEntity(entity, createdDateColumn, modifiedDateColumn, createdByColumn, modifiedByColumn);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class EqualsOperationsImpl method addEqualsAndHashCodeMethods.
public void addEqualsAndHashCodeMethods(final JavaType javaType, final boolean appendSuper, final Set<String> excludeFields) {
// Add @RooEquals annotation to class if not yet present
final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(javaType);
if (cid == null || cid.getTypeAnnotation(ROO_EQUALS) != null) {
return;
}
final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(ROO_EQUALS);
if (appendSuper) {
annotationBuilder.addBooleanAttribute("appendSuper", appendSuper);
}
if (!CollectionUtils.isEmpty(excludeFields)) {
final List<StringAttributeValue> attributes = new ArrayList<StringAttributeValue>();
for (final String excludeField : excludeFields) {
attributes.add(new StringAttributeValue(new JavaSymbolName("value"), excludeField));
}
annotationBuilder.addAttribute(new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("excludeFields"), attributes));
}
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(cid);
cidBuilder.addAnnotation(annotationBuilder.build());
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ToStringMetadataProviderImpl method getToStringFields.
/* (non-Javadoc)
* @see org.springframework.roo.addon.javabean.addon.ToStringMetadataProvider#getToStringFields(org.springframework.roo.classpath.PhysicalTypeMetadata, java.util.List)
*/
public List<FieldMetadata> getToStringFields(final PhysicalTypeMetadata governorPhysicalTypeMetadata, final List<FieldMetadata> declaredFields) {
ClassOrInterfaceTypeDetails superclass = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getSuperclass();
List<FieldMetadata> toStringFields = new ArrayList<FieldMetadata>();
if (superclass != null && superclass != JavaType.OBJECT) {
List<FieldMetadata> superclassFields = getMemberDetailsScanner().getMemberDetails(this.getClass().getName(), superclass).getFields();
for (FieldMetadata field : declaredFields) {
boolean alreadyInSuperclass = false;
for (FieldMetadata superclassField : superclassFields) {
if (superclassField.getDeclaredByMetadataId().equals(field.getDeclaredByMetadataId()) && superclassField.getFieldName().equals(field.getFieldName())) {
alreadyInSuperclass = true;
break;
}
}
if (!alreadyInSuperclass) {
toStringFields.add(field);
}
}
} else {
toStringFields.addAll(declaredFields);
}
return toStringFields;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JavaParserTypeParsingServiceTest method testGetTypeFromStringWhenFileContainsNoSuchType.
@Test
public void testGetTypeFromStringWhenFileContainsNoSuchType() {
// Set up
final JavaType mockTargetType = mock(JavaType.class);
when(mockTargetType.getSimpleTypeName()).thenReturn("NoSuchType");
// Invoke
final ClassOrInterfaceTypeDetails locatedType = typeParsingService.getTypeFromString(SOURCE_FILE, DECLARED_BY_MID, mockTargetType);
// Check
assertNull(locatedType);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JavaParserTypeParsingServiceTest method testGetTypeFromStringWhenFileContainsNoTypes.
@Test
public void testGetTypeFromStringWhenFileContainsNoTypes() {
// Set up
final JavaType mockTargetType = mock(JavaType.class);
// Invoke
final ClassOrInterfaceTypeDetails locatedType = typeParsingService.getTypeFromString(EMPTY_FILE, DECLARED_BY_MID, mockTargetType);
// Check
assertNull(locatedType);
}
Aggregations