Search in sources :

Example 1 with JSONMixinAnnotationValues

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());
}
Also used : AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) JSONMixinAnnotationValues(org.springframework.roo.addon.web.mvc.controller.addon.config.JSONMixinAnnotationValues) ArrayList(java.util.ArrayList) 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)

Aggregations

ArrayList (java.util.ArrayList)1 JSONMixinAnnotationValues (org.springframework.roo.addon.web.mvc.controller.addon.config.JSONMixinAnnotationValues)1 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)1 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)1 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)1 JavaType (org.springframework.roo.model.JavaType)1 JpaJavaType (org.springframework.roo.model.JpaJavaType)1 RooJavaType (org.springframework.roo.model.RooJavaType)1 SpringJavaType (org.springframework.roo.model.SpringJavaType)1 LogicalPath (org.springframework.roo.project.LogicalPath)1