Search in sources :

Example 46 with LogicalPath

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

the class JpaAuditMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = JpaAuditMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = JpaAuditMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) RooJavaType(org.springframework.roo.model.RooJavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 47 with LogicalPath

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

the class JpaDataOnDemandCreator method createEntityFactory.

@Override
public JavaType createEntityFactory(JavaType currentEntity) {
    Validate.notNull(currentEntity, "Entity to produce a data on demand provider for is required");
    // Verify the requested entity actually exists as a class and is not
    // abstract
    final ClassOrInterfaceTypeDetails cid = getEntityDetails(currentEntity);
    Validate.isTrue(cid.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS, "Type %s is not a class", currentEntity.getFullyQualifiedTypeName());
    Validate.isTrue(!Modifier.isAbstract(cid.getModifier()), "Type %s is abstract", currentEntity.getFullyQualifiedTypeName());
    // Check if the requested entity is a JPA @Entity
    final MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(JpaDataOnDemandCreator.class.getName(), cid);
    final AnnotationMetadata entityAnnotation = memberDetails.getAnnotation(ENTITY);
    Validate.isTrue(entityAnnotation != null, "Type %s must be a JPA entity type", currentEntity.getFullyQualifiedTypeName());
    // Get related entities
    List<JavaType> entities = getEntityAndRelatedEntitiesList(currentEntity);
    // Get test Path for module
    final LogicalPath path = LogicalPath.getInstance(Path.SRC_TEST_JAVA, currentEntity.getModule());
    JavaType currentEntityFactory = null;
    for (JavaType entity : entities) {
        // Create the JavaType for the configuration class
        JavaType factoryClass = new JavaType(String.format("%s.dod.%sFactory", entity.getPackage().getFullyQualifiedPackageName(), entity.getSimpleTypeName()), entity.getModule());
        final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(factoryClass, path);
        if (metadataService.get(declaredByMetadataId) != null) {
            // The file already exists
            continue;
        }
        // Create the CID builder
        ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, factoryClass, PhysicalTypeCategory.CLASS);
        // Add @RooEntityFactory annotation
        AnnotationMetadataBuilder entityFactoryAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_ENTITY_FACTORY);
        entityFactoryAnnotation.addClassAttribute("entity", entity);
        cidBuilder.addAnnotation(entityFactoryAnnotation);
        // Write changes to disk
        typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
        // First entity is current entity
        if (currentEntityFactory == null) {
            currentEntityFactory = cidBuilder.getName();
        }
    }
    return currentEntityFactory;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 48 with LogicalPath

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

the class JpaDataOnDemandMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = JpaDataOnDemandMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = JpaDataOnDemandMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 49 with LogicalPath

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

the class JpaDataOnDemandConfigurationMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = JpaDataOnDemandConfigurationMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = JpaDataOnDemandConfigurationMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : JavaType(org.springframework.roo.model.JavaType) RooJavaType(org.springframework.roo.model.RooJavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 50 with LogicalPath

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

the class JpaEntityFactoryMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = JpaEntityFactoryMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = JpaEntityFactoryMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Aggregations

LogicalPath (org.springframework.roo.project.LogicalPath)85 JavaType (org.springframework.roo.model.JavaType)62 RooJavaType (org.springframework.roo.model.RooJavaType)55 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)13 JpaJavaType (org.springframework.roo.model.JpaJavaType)12 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)9 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)9 SpringJavaType (org.springframework.roo.model.SpringJavaType)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)6 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)5 BufferedInputStream (java.io.BufferedInputStream)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 I18n (org.springframework.roo.addon.web.mvc.i18n.components.I18n)4 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)3 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)3