Search in sources :

Example 1 with LinkFactoryAnnotationValues

use of org.springframework.roo.addon.web.mvc.thymeleaf.addon.link.factory.LinkFactoryAnnotationValues in project spring-roo by spring-projects.

the class ThymeleafMetadataProviderImpl method createMetadataInstance.

@Override
protected ThymeleafMetadata createMetadataInstance(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final ControllerMetadata controllerMetadata, final ServiceMetadata serviceMetadata, final JpaEntityMetadata entityMetadata, final String entityPlural, final String entityIdentifierPlural, final List<Pair<RelationInfo, JpaEntityMetadata>> compositionRelationOneToOne, final JavaType itemController, final JavaType collectionController, final List<FieldMetadata> dateTimeFields, final List<FieldMetadata> enumFields, final Map<String, MethodMetadata> findersToAdd, final Map<JavaType, List<FieldMetadata>> formBeansDateTimeFields, final Map<JavaType, List<FieldMetadata>> formBeansEnumFields, final JavaType detailsItemController, final JavaType detailsCollectionController) {
    final ThymeleafAnnotationValues annotationValues = new ThymeleafAnnotationValues(governorPhysicalTypeMetadata);
    // Get related controller for select2 request
    JavaType relatedCollectionController = null;
    JavaType relatedItemController = null;
    RelationInfoExtended info = controllerMetadata.getLastDetailsInfo();
    if (controllerMetadata.getType() == ControllerType.DETAIL && info.type == JpaRelationType.AGGREGATION) {
        Collection<ClassOrInterfaceTypeDetails> controllers = getControllerLocator().getControllers(info.childType, ControllerType.COLLECTION, RooJavaType.ROO_THYMELEAF);
        final String prefix = controllerMetadata.getAnnotationValues().getPathPrefix();
        for (ClassOrInterfaceTypeDetails controller : controllers) {
            // use annotation values to avoid cyclic dependencies
            ControllerAnnotationValues valuesToCheck = new ControllerAnnotationValues(controller);
            if (StringUtils.equals(prefix, valuesToCheck.getPathPrefix())) {
                relatedCollectionController = controller.getType();
                break;
            }
        }
        Validate.notNull(relatedCollectionController, "Can't found Collection-type controller of entity '%s' and pathPrefix '%s' required by '%s' controller", info.childType, prefix, controllerMetadata.getDestination());
        controllers = getControllerLocator().getControllers(info.childType, ControllerType.ITEM, RooJavaType.ROO_THYMELEAF);
        for (ClassOrInterfaceTypeDetails controller : controllers) {
            // use annotation values to avoid cyclic dependencies
            ControllerAnnotationValues valuesToCheck = new ControllerAnnotationValues(controller);
            if (StringUtils.equals(prefix, valuesToCheck.getPathPrefix())) {
                relatedItemController = controller.getType();
                break;
            }
        }
        Validate.notNull(relatedItemController, "Can't found Item-type controller of entity '%s' and pathPrefix '%s' required by '%s' controller", info.childType, prefix, controllerMetadata.getDestination());
    }
    Validate.notNull(getJasperReportsMap(), "Couldn't find class `JasperReportsExporter` in project.");
    // Get valid entity fields (those suitable for reports)
    JavaType defaultReturnType = serviceMetadata.getCurrentFindAllWithGlobalSearchMethod().getReturnType().getParameters().get(0);
    List<FieldMetadata> entityFields = getReturnTypeValidFields(getMemberDetailsScanner().getMemberDetails(this.getClass().getName(), getTypeLocationService().getTypeDetails(defaultReturnType)).getFields());
    // Getting the related linkFactory for this controller
    Set<ClassOrInterfaceTypeDetails> linkFactories = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_LINK_FACTORY);
    JavaType relatedCollectionLinkFactory = null;
    JavaType relatedItemLinkFactory = null;
    JavaType collectionControllerToCheck = collectionController;
    if (collectionControllerToCheck == null) {
        collectionControllerToCheck = governorPhysicalTypeMetadata.getType();
    }
    JavaType itemControllerToCheck = itemController;
    if (itemControllerToCheck == null) {
        itemControllerToCheck = governorPhysicalTypeMetadata.getType();
    }
    for (ClassOrInterfaceTypeDetails linkFactory : linkFactories) {
        LinkFactoryAnnotationValues linkAnnotationValues = new LinkFactoryAnnotationValues(linkFactory);
        // Getting link factory of the collection controller
        if (linkAnnotationValues.getController().equals(collectionControllerToCheck)) {
            relatedCollectionLinkFactory = linkFactory.getType();
        } else if (linkAnnotationValues.getController().equals(itemControllerToCheck)) {
            relatedItemLinkFactory = linkFactory.getType();
        }
    }
    final ThymeleafMetadata metadata = new ThymeleafMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, controllerMetadata, serviceMetadata, entityMetadata, entityPlural, entityIdentifierPlural, compositionRelationOneToOne, itemController, collectionController, dateTimeFields, enumFields, findersToAdd, formBeansDateTimeFields, formBeansEnumFields, detailsItemController, detailsCollectionController, relatedCollectionController, relatedItemController, entityFields, getJasperReportsMap(), relatedCollectionLinkFactory, relatedItemLinkFactory);
    return metadata;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ControllerAnnotationValues(org.springframework.roo.addon.web.mvc.controller.addon.ControllerAnnotationValues) RelationInfoExtended(org.springframework.roo.addon.web.mvc.controller.addon.RelationInfoExtended) LinkFactoryAnnotationValues(org.springframework.roo.addon.web.mvc.thymeleaf.addon.link.factory.LinkFactoryAnnotationValues) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Aggregations

ControllerAnnotationValues (org.springframework.roo.addon.web.mvc.controller.addon.ControllerAnnotationValues)1 RelationInfoExtended (org.springframework.roo.addon.web.mvc.controller.addon.RelationInfoExtended)1 LinkFactoryAnnotationValues (org.springframework.roo.addon.web.mvc.thymeleaf.addon.link.factory.LinkFactoryAnnotationValues)1 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)1 JavaType (org.springframework.roo.model.JavaType)1 JpaJavaType (org.springframework.roo.model.JpaJavaType)1 RooJavaType (org.springframework.roo.model.RooJavaType)1