use of org.springframework.roo.addon.web.mvc.controller.addon.config.JSONMixinAnnotationValues in project spring-roo by spring-projects.
the class ControllerOperationsImpl method createJsonMixinIfDontExists.
/**
* Create the Json Mixin utility class (annotated with @RooJsonMixin) for
* target Entity if it isn't created yet.
*
* @param entity
* @param entityMetadata
* @param requiresDeserializer
* @param module
* @param controllerPackage
*/
private void createJsonMixinIfDontExists(JavaType entity, JpaEntityMetadata entityMetadata, String module, JavaPackage controllerPackage) {
Set<ClassOrInterfaceTypeDetails> allJsonMixin = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JSON_MIXIN);
JSONMixinAnnotationValues values;
for (ClassOrInterfaceTypeDetails mixin : allJsonMixin) {
values = new JSONMixinAnnotationValues(mixin);
if (entity.equals(values.getEntity())) {
// Found mixing. Nothing to do.
return;
}
}
// Not found. Create class
List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations = new ArrayList<AnnotationMetadataBuilder>();
AnnotationMetadataBuilder mixinAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_JSON_MIXIN);
mixinAnnotation.addClassAttribute("entity", entity);
annotations.add(mixinAnnotation);
JavaType mixinClass = new JavaType(String.format("%s.%sJsonMixin", controllerPackage.getFullyQualifiedPackageName(), entity.getSimpleTypeName()), module);
final LogicalPath mixinPath = getPathResolver().getPath(module, Path.SRC_MAIN_JAVA);
final String resourceIdentifierItem = getTypeLocationService().getPhysicalTypeCanonicalPath(mixinClass, mixinPath);
final String declaredByMetadataIdItem = PhysicalTypeIdentifier.createIdentifier(mixinClass, getPathResolver().getPath(resourceIdentifierItem));
ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataIdItem, Modifier.PUBLIC + Modifier.ABSTRACT, mixinClass, PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
Aggregations