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