use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.
the class TSMetaDataObjectTransformation method setRelationshipsSuperType.
private void setRelationshipsSuperType(TSInterfaceType interfaceType, MetaDataObject metaDataObject, TSMetaTransformationContext context) {
// iterate over super types till (non-empty) one is found with a relationship interface definition
MetaDataObject current = metaDataObject;
while (current.getSuperType() != null && generateAsResource(current.getSuperType())) {
MetaDataObject superType = current.getSuperType();
TSInterfaceType superInterface = (TSInterfaceType) context.transform(superType, TSMetaTransformationOptions.EMPTY);
TSInterfaceType relationshipsType = TypescriptUtils.getNestedInterface(interfaceType, RELATIONSHIPS_CLASS_NAME, false);
if (relationshipsType != null) {
TSInterfaceType superRelationshipType = TypescriptUtils.getNestedInterface(superInterface, RELATIONSHIPS_CLASS_NAME, false);
if (superRelationshipType != null) {
relationshipsType.getImplementedInterfaces().add(superRelationshipType);
break;
}
}
current = superType;
}
}
use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.
the class JpaResourceInformationProvider method build.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public ResourceInformation build(final Class<?> resourceClass) {
String resourceType = getResourceType(resourceClass);
MetaDataObject meta = metaProvider.discoverMeta(resourceClass).asDataObject();
DefaultResourceInstanceBuilder instanceBuilder = new DefaultResourceInstanceBuilder(resourceClass);
List<ResourceField> fields = getResourceFields(resourceClass);
Class<?> superclass = resourceClass.getSuperclass();
String superResourceType = superclass != Object.class && superclass.getAnnotation(MappedSuperclass.class) == null ? context.getResourceType(superclass) : null;
TypeParser typeParser = context.getTypeParser();
ResourceInformation info = new ResourceInformation(typeParser, resourceClass, resourceType, superResourceType, instanceBuilder, fields, new OffsetLimitPagingBehavior());
info.setValidator(new JpaOptimisticLockingValidator(meta));
info.setIdStringMapper(new JpaIdMapper(meta));
return info;
}
use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.
the class TSMetaResourceRepositoryTransformation method transform.
@Override
public TSElement transform(MetaElement element, TSMetaTransformationContext context, TSMetaTransformationOptions options) {
MetaResourceRepository metaRepository = (MetaResourceRepository) element;
MetaResource metaResource = metaRepository.getResourceType();
TSType resourceType = context.transform(metaResource, TSMetaTransformationOptions.EMPTY).asType();
TSContainerElement parent = (TSContainerElement) resourceType.getParent();
MetaDataObject metaListLinks = metaRepository.getListLinksType();
MetaDataObject metaListMeta = metaRepository.getListMetaType();
TSInterfaceType oneResultType = new TSInterfaceType();
oneResultType.setName(metaResource.getName() + "Result");
oneResultType.setExported(true);
oneResultType.getImplementedInterfaces().add(NgrxJsonApiLibrary.ONE_QUERY_RESULT);
oneResultType.addDeclaredMember(newDataField(context, resourceType, false));
parent.addElement(oneResultType);
TSInterfaceType manyResultType = new TSInterfaceType();
manyResultType.setName(metaResource.getName() + "ListResult");
manyResultType.setExported(true);
manyResultType.getImplementedInterfaces().add(NgrxJsonApiLibrary.MANY_QUERY_RESULT);
manyResultType.addDeclaredMember(newDataField(context, resourceType, true));
parent.addElement(manyResultType);
if (metaListLinks != null) {
TSMetaTransformationOptions listOptions = new TSMetaTransformationOptions();
listOptions.setParent(TypescriptUtils.getNestedTypeContainer(manyResultType, true));
TSType linksType = context.transform(metaListLinks, listOptions).asType();
TSField field = new TSField();
field.setName("links");
field.setNullable(true);
field.setType(linksType);
manyResultType.addDeclaredMember(field);
}
if (metaListMeta != null) {
TSMetaTransformationOptions listOptions = new TSMetaTransformationOptions();
listOptions.setParent(TypescriptUtils.getNestedTypeContainer(manyResultType, true));
TSType metaType = context.transform(metaListMeta, listOptions).asType();
TSField field = new TSField();
field.setName("meta");
field.setNullable(true);
field.setType(metaType);
manyResultType.addDeclaredMember(field);
}
return null;
}
use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.
the class JoinRegistry method getEntityAttribute.
public E getEntityAttribute(MetaAttributePath attrPath) {
MetaAttributePath associationPath = extractAssociationPath(attrPath);
MetaAttributePath primitivePath = attrPath.subPath(associationPath.length());
@SuppressWarnings("unchecked") E from = (E) getOrCreateJoin(associationPath);
if (primitivePath.length() == 0) {
return from;
}
MetaAttributePath currentPath = associationPath;
E criteriaPath = null;
for (MetaAttribute pathElement : primitivePath) {
currentPath = currentPath.concat(pathElement);
E currentCriteriaPath = criteriaPath != null ? criteriaPath : from;
if (pathElement instanceof MetaMapAttribute) {
if (criteriaPath != null)
throw new IllegalStateException("Cannot join to map");
criteriaPath = joinMap(currentCriteriaPath, pathElement);
} else {
// we may need to downcast if attribute is defined on a subtype
MetaDataObject parent = pathElement.getParent().asDataObject();
Class<?> pathType = parent.getImplementationClass();
Class<?> currentType = backend.getJavaElementType(currentCriteriaPath);
boolean isSubType = !pathType.isAssignableFrom(currentType);
if (isSubType) {
currentCriteriaPath = backend.joinSubType(currentCriteriaPath, pathType);
}
criteriaPath = backend.getAttribute(currentCriteriaPath, pathElement);
}
}
return criteriaPath;
}
use of io.crnk.meta.model.MetaDataObject in project crnk-framework by crnk-project.
the class MetaDataObjectProvider method onInitialized.
@Override
public void onInitialized(MetaElement element) {
if (element instanceof MetaAttribute && element.getParent().getClass() == getMetaClass()) {
MetaAttribute attr = (MetaAttribute) element;
MetaDataObject parent = attr.getParent();
Type implementationType = PropertyUtils.getPropertyType(parent.getImplementationClass(), attr.getName());
MetaElement metaType = context.allocate(implementationType);
attr.setType(metaType.asType());
}
}
Aggregations