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());
}
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));
}
Aggregations