Search in sources :

Example 26 with ClassOrInterfaceTypeDetails

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);
}
Also used : ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliCommand(org.springframework.roo.shell.CliCommand)

Example 27 with ClassOrInterfaceTypeDetails

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());
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 28 with ClassOrInterfaceTypeDetails

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;
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Example 29 with ClassOrInterfaceTypeDetails

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);
}
Also used : JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 30 with ClassOrInterfaceTypeDetails

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);
}
Also used : JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)232 JavaType (org.springframework.roo.model.JavaType)114 ArrayList (java.util.ArrayList)87 RooJavaType (org.springframework.roo.model.RooJavaType)86 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)52 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)43 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)42 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)40 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)39 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)36 JpaJavaType (org.springframework.roo.model.JpaJavaType)34 SpringJavaType (org.springframework.roo.model.SpringJavaType)28 CliOptionAutocompleteIndicator (org.springframework.roo.shell.CliOptionAutocompleteIndicator)24 JpaEntityMetadata (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)23 JdkJavaType (org.springframework.roo.model.JdkJavaType)22 Test (org.junit.Test)20 File (java.io.File)19 List (java.util.List)19 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)19 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)17