use of org.springframework.roo.addon.web.mvc.controller.annotations.ControllerType in project spring-roo by spring-projects.
the class ThymeleafViewGeneratorServiceImpl method createDetailEntityItem.
@Override
protected DetailEntityItem createDetailEntityItem(ThymeleafMetadata detailController, MemberDetails entityMembers, JpaEntityMetadata entityMetadata, String entityName, ViewContext<ThymeleafMetadata> ctx, String detailSuffix, EntityItem rootEntity) {
JavaType detailItemController;
JavaType detailCollectionController;
final ControllerType type = detailController.getControllerMetadata().getType();
if (type == ControllerType.DETAIL) {
detailCollectionController = detailController.getDestination();
detailItemController = detailController.getDetailItemController();
} else {
detailCollectionController = detailController.getDetailCollectionController();
detailItemController = detailController.getDestination();
}
JavaType itemController = detailController.getItemController();
JavaType relatedCollectionController = detailController.getRelatedCollectionController();
JavaType relatedItemController = detailController.getRelatedItemController();
DetailEntityItem item = super.createDetailEntityItem(detailController, entityMembers, entityMetadata, entityName, ctx, detailSuffix, rootEntity);
item.addConfigurationElement("mvcDetailControllerName", detailController.getMvcControllerName());
item.addConfigurationElement("mvcDetailItemControllerName", detailItemController.getSimpleTypeName());
item.addConfigurationElement("mvcDetailCollectionControllerName", detailCollectionController.getSimpleTypeName());
if (relatedItemController != null) {
item.addConfigurationElement("select2MethodName", ThymeleafMetadata.SELECT2_METHOD_NAME);
item.addConfigurationElement("select2ControllerName", relatedCollectionController.getSimpleTypeName());
}
return item;
}
use of org.springframework.roo.addon.web.mvc.controller.annotations.ControllerType in project spring-roo by spring-projects.
the class ControllerMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
ControllerAnnotationValues controllerValues = new ControllerAnnotationValues(governorPhysicalTypeMetadata);
// Getting entity
final JavaType entity = controllerValues.getEntity();
ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
// Get entity metadata
final String entityMetadataId = JpaEntityMetadata.createIdentifier(entityDetails);
registerDependency(entityMetadataId, metadataIdentificationString);
final JpaEntityMetadata entityMetadata = getMetadataService().get(entityMetadataId);
// This metadata is not available yet.
if (entityMetadata == null) {
return null;
}
// Getting type
ControllerType type = controllerValues.getType();
// Getting related service
ClassOrInterfaceTypeDetails serviceDetails = getServiceLocator().getService(entity);
JavaType service = serviceDetails.getType();
final String serviceMetadataId = ServiceMetadata.createIdentifier(serviceDetails);
registerDependency(serviceMetadataId, metadataIdentificationString);
final ServiceMetadata serviceMetadata = getMetadataService().get(serviceMetadataId);
// This metadata is not available yet.
if (serviceMetadata == null) {
return null;
}
// Generate path
final String path = getControllerOperations().getBasePathForController(governorPhysicalTypeMetadata.getMemberHoldingTypeDetails());
final String baseUrl = getControllerOperations().getBaseUrlForController(governorPhysicalTypeMetadata.getMemberHoldingTypeDetails());
List<RelationInfoExtended> detailsFieldInfo = null;
String detailAnnotaionFieldValue = null;
Map<JavaType, ServiceMetadata> detailsServiceMetadata = null;
if (type == ControllerType.DETAIL || type == ControllerType.DETAIL_ITEM) {
final JavaType controller = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getName();
// Getting the relationField from @RooDetail entity
final AnnotationAttributeValue<Object> relationFieldAttr = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getAnnotation(RooJavaType.ROO_DETAIL).getAttribute("relationField");
Validate.notNull(relationFieldAttr, "ERROR: In %s controller, @RooDetail annotation must have relationField value", controller);
detailAnnotaionFieldValue = (String) relationFieldAttr.getValue();
Validate.isTrue(StringUtils.isNotBlank(detailAnnotaionFieldValue), "ERROR: In %s controller, @RooDetail annotation must have relationField value", controller);
// generate detail info object
detailsFieldInfo = getControllerOperations().getRelationInfoFor(entityMetadata, detailAnnotaionFieldValue);
detailsServiceMetadata = new TreeMap<JavaType, ServiceMetadata>();
for (RelationInfoExtended info : detailsFieldInfo) {
if (detailsServiceMetadata.containsKey(info.childType)) {
continue;
}
// Getting related service
ClassOrInterfaceTypeDetails detailsServiceDetails = getServiceLocator().getService(info.childType);
String detailServiceMetadataId = ServiceMetadata.createIdentifier(detailsServiceDetails);
registerDependency(detailServiceMetadataId, metadataIdentificationString);
ServiceMetadata curMetadata = getMetadataService().get(detailServiceMetadataId);
if (curMetadata == null) {
// Not ready for this metadata yet
return null;
}
detailsServiceMetadata.put(info.childType, curMetadata);
// Register dependency with related entity
registerDependency(info.childEntityMetadata.getId(), metadataIdentificationString);
}
}
Map<String, RelationInfoExtended> relationInfos = new HashMap<String, RelationInfoExtended>();
for (String fieldName : entityMetadata.getRelationInfos().keySet()) {
RelationInfoExtended info = getControllerOperations().getRelationInfoFor(entityMetadata, fieldName).get(0);
if (info.childEntityMetadata == null) {
// Not ready for this metadata yet
return null;
}
relationInfos.put(fieldName, info);
}
return new ControllerMetadata(metadataIdentificationString, aspectName, controllerValues, governorPhysicalTypeMetadata, entity, entityMetadata, service, path, baseUrl, type, serviceMetadata, detailAnnotaionFieldValue, detailsServiceMetadata, detailsFieldInfo, relationInfos);
}
Aggregations