Search in sources :

Example 16 with ClassOrInterfaceTypeDetails

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.

the class EmbeddableFieldCreatorProvider method isValid.

@Override
public boolean isValid(JavaType javaType) {
    ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(javaType);
    MemberDetails details = memberDetailsScanner.getMemberDetails(this.getClass().getName(), cid);
    if (cid.getAnnotation(JpaJavaType.EMBEDDABLE) != null || details.getAnnotation(JpaJavaType.EMBEDDABLE) != null) {
        return true;
    }
    return false;
}
Also used : ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails)

Example 17 with ClassOrInterfaceTypeDetails

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.

the class JpaFieldCreatorProvider method getFieldListTypeAllPossibleValues.

@Override
public List<String> getFieldListTypeAllPossibleValues(ShellContext shellContext) {
    // Get current value of class
    String currentText = shellContext.getParameters().get("type");
    List<String> allPossibleValues = new ArrayList<String>();
    // Getting all existing entities
    Set<ClassOrInterfaceTypeDetails> entitiesInProject = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY);
    for (ClassOrInterfaceTypeDetails entity : entitiesInProject) {
        String name = replaceTopLevelPackageString(entity, currentText);
        if (!allPossibleValues.contains(name)) {
            allPossibleValues.add(name);
        }
    }
    // Getting all existing dtos
    Set<ClassOrInterfaceTypeDetails> dtosInProject = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_DTO);
    for (ClassOrInterfaceTypeDetails dto : dtosInProject) {
        String name = replaceTopLevelPackageString(dto, currentText);
        if (!allPossibleValues.contains(name)) {
            allPossibleValues.add(name);
        }
    }
    // Getting all existing embeddable classes
    Set<ClassOrInterfaceTypeDetails> embeddableClassesInProject = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(JpaJavaType.EMBEDDABLE);
    for (ClassOrInterfaceTypeDetails embeddableClass : embeddableClassesInProject) {
        String name = replaceTopLevelPackageString(embeddableClass, currentText);
        if (!allPossibleValues.contains(name)) {
            allPossibleValues.add(name);
        }
    }
    return allPossibleValues;
}
Also used : ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Example 18 with ClassOrInterfaceTypeDetails

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.

the class JpaFieldCreatorProvider method createChildEntityFactory.

/**
 * Creates the Factory class of the child entity of relationship, only if parent entity has JPA unit tests.
 *
 * @param childType
 * @param parentType
 */
private void createChildEntityFactory(JavaType childType, JavaType parentType) {
    // Find current JPA unit tests
    Set<JavaType> unitTestTypes = typeLocationService.findTypesWithAnnotation(RooJavaType.ROO_JPA_UNIT_TEST);
    for (JavaType unitTestType : unitTestTypes) {
        // Get the annotation @RooJpaUnitTest
        ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(unitTestType);
        AnnotationMetadata rooUnitTestAnnotation = cid.getAnnotation(RooJavaType.ROO_JPA_UNIT_TEST);
        // Check if parent entity has JPA unit test class
        AnnotationAttributeValue<Object> targetClass = rooUnitTestAnnotation.getAttribute("targetClass");
        Validate.notNull(targetClass, String.format("'targetClass' attribute can't be found for annotation @RooJpaUnitTest in class %s", unitTestType.getSimpleTypeName()));
        if (parentType.equals(targetClass.getValue())) {
            if (jpaEntityFactoryLocator.getFirstJpaEntityFactoryForEntity(childType) == null) {
                // Create factory class for child entity if doesn't exist
                dataOnDemandCreatorProvider.createEntityFactory(childType);
            }
            break;
        }
    }
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata)

Example 19 with ClassOrInterfaceTypeDetails

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.

the class JpaTestCreator method createUnitTest.

@Override
public void createUnitTest(final JavaType entity) {
    Validate.notNull(entity, "Class to produce an unit test class for is required");
    // Check if provided JavaType is a Repository
    ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(entity);
    Validate.notNull(cid.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "Type must be a Roo JPA Entity type.");
    // Create JPA DataOnDemand artifacts
    List<DataOnDemandCreatorProvider> dodCreators = getValidDataOnDemandCreatorsForType(entity);
    for (DataOnDemandCreatorProvider dodCreator : dodCreators) {
        dodCreator.createDataOnDemand(entity);
    }
    final JavaType name = new JavaType(entity + "Test", entity.getModule());
    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, Path.SRC_TEST_JAVA.getModulePathId(entity.getModule()));
    if (metadataService.get(declaredByMetadataId) != null) {
        // The file already exists
        return;
    }
    // Add @RooUnitTest to source file
    AnnotationMetadataBuilder rooUnitTestAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_UNIT_TEST);
    rooUnitTestAnnotation.addClassAttribute("targetClass", entity);
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS);
    cidBuilder.addAnnotation(rooUnitTestAnnotation);
    typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) DataOnDemandCreatorProvider(org.springframework.roo.addon.test.providers.DataOnDemandCreatorProvider) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 20 with ClassOrInterfaceTypeDetails

use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.

the class JpaDataOnDemandCreator method createDataOnDemandConfiguration.

@Override
public JavaType createDataOnDemandConfiguration(String moduleName) {
    // Check if alreafy exists
    JavaType dodConfig = getDataOnDemandConfiguration();
    if (dodConfig != null) {
        return dodConfig;
    }
    // Add spring-boot-test dependency with test scope
    projectOperations.addDependency(moduleName, SPRING_BOOT_TEST_DEPENDENCY);
    // Get Pom
    final Pom module = projectOperations.getPomFromModuleName(moduleName);
    // Get test Path for module
    final LogicalPath path = LogicalPath.getInstance(Path.SRC_TEST_JAVA, moduleName);
    // Create the JavaType for the configuration class
    JavaType dodConfigurationClass = new JavaType(String.format("%s.dod.DataOnDemandConfiguration", typeLocationService.getTopLevelPackageForModule(module), moduleName));
    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(dodConfigurationClass, path);
    if (metadataService.get(declaredByMetadataId) != null) {
        // The file already exists
        return new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId).getName();
    }
    // Create the CID builder
    ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, dodConfigurationClass, PhysicalTypeCategory.CLASS);
    cidBuilder.addAnnotation(new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_DATA_ON_DEMAND_CONFIGURATION));
    // Write changes to disk
    final ClassOrInterfaceTypeDetails configDodCid = cidBuilder.build();
    typeManagementService.createOrUpdateTypeOnDisk(configDodCid);
    return configDodCid.getName();
}
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) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) Pom(org.springframework.roo.project.maven.Pom)

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