Search in sources :

Example 21 with ClassAttributeValue

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

the class RepositoryJpaOperationsImpl method addRepositoryInterface.

/**
 * Method that generates the repository interface. This method takes in mind
 * if entity is defined as readOnly or not.
 *
 * @param interfaceType
 * @param domainType
 * @param entityDetails
 * @param interfaceIdentifier
 */
private void addRepositoryInterface(JavaType interfaceType, JavaType domainType, ClassOrInterfaceTypeDetails entityDetails, String interfaceIdentifier, JavaType defaultReturnType) {
    // Generates @RooJpaRepository annotation with referenced entity value
    // and repository custom associated to this repository
    final AnnotationMetadataBuilder interfaceAnnotationMetadata = new AnnotationMetadataBuilder(RooJavaType.ROO_REPOSITORY_JPA);
    interfaceAnnotationMetadata.addAttribute(new ClassAttributeValue(new JavaSymbolName("entity"), domainType));
    if (defaultReturnType != null) {
        interfaceAnnotationMetadata.addAttribute(new ClassAttributeValue(new JavaSymbolName("defaultReturnType"), defaultReturnType));
        // Add dependencies between modules
        getProjectOperations().addModuleDependency(interfaceType.getModule(), defaultReturnType.getModule());
    }
    // Generating interface
    final String interfaceMdId = PhysicalTypeIdentifier.createIdentifier(interfaceType, getPathResolver().getPath(interfaceIdentifier));
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(interfaceMdId, Modifier.PUBLIC, interfaceType, PhysicalTypeCategory.INTERFACE);
    // Annotate repository interface
    cidBuilder.addAnnotation(interfaceAnnotationMetadata.build());
    // Save new repository on disk
    getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassAttributeValue(org.springframework.roo.classpath.details.annotations.ClassAttributeValue) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 22 with ClassAttributeValue

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

the class ServiceOperationsImpl method createServiceInterface.

/**
 * Method that creates the service interface
 *
 * @param domainType
 * @param interfaceType
 */
private void createServiceInterface(final JavaType domainType, final JavaType interfaceType) {
    Validate.notNull(interfaceType.getModule(), "JavaType %s does not have a module", domainType);
    // Checks if new service interface already exists.
    final String interfaceIdentifier = pathResolver.getCanonicalPath(interfaceType.getModule(), Path.SRC_MAIN_JAVA, interfaceType);
    if (fileManager.exists(interfaceIdentifier)) {
        // Type already exists - nothing to do
        return;
    }
    // Validate that user provides a valid entity
    Validate.notNull(domainType, "ERROR: Domain type required to generate service");
    ClassOrInterfaceTypeDetails entityDetails = typeLocationService.getTypeDetails(domainType);
    Validate.notNull(entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "ERROR: Provided entity should be annotated with @RooJpaEntity");
    // Generating @RooService annotation
    final AnnotationMetadataBuilder interfaceAnnotationMetadata = new AnnotationMetadataBuilder(ROO_SERVICE);
    interfaceAnnotationMetadata.addAttribute(new ClassAttributeValue(new JavaSymbolName("entity"), domainType));
    // Creating interface builder
    final String interfaceMid = PhysicalTypeIdentifier.createIdentifier(interfaceType, pathResolver.getPath(interfaceIdentifier));
    final ClassOrInterfaceTypeDetailsBuilder interfaceTypeBuilder = new ClassOrInterfaceTypeDetailsBuilder(interfaceMid, PUBLIC, interfaceType, PhysicalTypeCategory.INTERFACE);
    // Adding @RooService annotation to current interface
    interfaceTypeBuilder.addAnnotation(interfaceAnnotationMetadata.build());
    // Write service interface on disk
    typeManagementService.createOrUpdateTypeOnDisk(interfaceTypeBuilder.build());
    // Add dependencies between modules
    projectOperations.addModuleDependency(interfaceType.getModule(), domainType.getModule());
    // Add springlets-data-commons dependency
    projectOperations.addDependency(interfaceType.getModule(), new Dependency("io.springlets", "springlets-data-commons", null));
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassAttributeValue(org.springframework.roo.classpath.details.annotations.ClassAttributeValue) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) Dependency(org.springframework.roo.project.Dependency) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)22 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)16 ArrayList (java.util.ArrayList)13 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)13 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)12 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)10 JavaType (org.springframework.roo.model.JavaType)10 List (java.util.List)9 ArrayAttributeValue (org.springframework.roo.classpath.details.annotations.ArrayAttributeValue)9 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)9 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)7 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)6 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)5 EnumAttributeValue (org.springframework.roo.classpath.details.annotations.EnumAttributeValue)5 RooJavaType (org.springframework.roo.model.RooJavaType)5 BooleanAttributeValue (org.springframework.roo.classpath.details.annotations.BooleanAttributeValue)4 CharAttributeValue (org.springframework.roo.classpath.details.annotations.CharAttributeValue)4 DoubleAttributeValue (org.springframework.roo.classpath.details.annotations.DoubleAttributeValue)4 IntegerAttributeValue (org.springframework.roo.classpath.details.annotations.IntegerAttributeValue)4