use of io.crnk.meta.model.MetaType in project crnk-framework by crnk-project.
the class JpaMetaFilter method onInitialized.
@Override
public void onInitialized(MetaElement element) {
if (element.getParent() instanceof MetaJpaDataObject && element instanceof MetaAttribute) {
MetaAttribute attr = (MetaAttribute) element;
MetaDataObject parent = attr.getParent();
Type implementationType = PropertyUtils.getPropertyType(parent.getImplementationClass(), attr.getName());
MetaType metaType = (MetaType) partition.allocateMetaElement(implementationType).get();
attr.setType(metaType);
}
if (element.getParent() instanceof MetaJpaDataObject && element instanceof MetaAttribute && ((MetaAttribute) element).getOppositeAttribute() == null) {
MetaAttribute attr = (MetaAttribute) element;
String mappedBy = getMappedBy(attr);
if (mappedBy != null) {
MetaType attrType = attr.getType();
MetaDataObject oppositeType = attrType.getElementType().asDataObject();
if (!mappedBy.contains(".")) {
MetaAttribute oppositeAttr = oppositeType.getAttribute(mappedBy);
attr.setOppositeAttribute(oppositeAttr);
} else {
// references within embeddables not yet supported
}
}
}
}
use of io.crnk.meta.model.MetaType in project crnk-framework by crnk-project.
the class QueryFilterBuilder method enhanceAttributePath.
public MetaAttributePath enhanceAttributePath(MetaAttributePath attrPath, Object value) {
MetaAttribute attr = attrPath.getLast();
MetaType valueType = attr.getType();
if (valueType instanceof MetaMapType) {
valueType = valueType.getElementType();
}
boolean anyType = AnyTypeObject.class.isAssignableFrom(valueType.getImplementationClass());
if (anyType) {
// we have and AnyType and do need to select the proper attribute of
// the embeddable
MetaAttribute anyAttr = AnyUtils.findAttribute((MetaDataObject) valueType, value);
return attrPath.concat(anyAttr);
} else {
return attrPath;
}
}
use of io.crnk.meta.model.MetaType in project crnk-framework by crnk-project.
the class MetaLookupTest method testObjectArrayMeta.
@Test
public void testObjectArrayMeta() {
MetaArrayType meta = metaProvider.discoverMeta(TestEntity[].class);
MetaType elementType = meta.getElementType();
Assert.assertTrue(elementType instanceof MetaDataObject);
}
use of io.crnk.meta.model.MetaType in project crnk-framework by crnk-project.
the class TSMetaDataObjectTransformation method generateResourceField.
private static void generateResourceField(MetaAttribute attr, TSMetaTransformationContext context, TSInterfaceType interfaceType, TSInterfaceType attributesType, TSInterfaceType relationshipsType) {
MetaType metaElementType = attr.getType().getElementType();
TSType elementType = (TSType) context.transform(metaElementType, TSMetaTransformationOptions.EMPTY);
TSField field = new TSField();
field.setName(attr.getName());
field.setType(elementType);
field.setNullable(true);
if (attr.isAssociation()) {
TSType relationshipType = attr.getType().isCollection() ? NgrxJsonApiLibrary.TYPED_MANY_RESOURCE_RELATIONSHIP : NgrxJsonApiLibrary.TYPED_ONE_RESOURCE_RELATIONSHIP;
field.setType(new TSParameterizedType(relationshipType, elementType));
relationshipsType.getDeclaredMembers().add(field);
field.setParent(relationshipsType);
} else if (attr instanceof MetaResourceField && ((MetaResourceField) attr).isMeta()) {
field.setName("meta");
interfaceType.getDeclaredMembers().add(field);
field.setParent(interfaceType);
} else if (attr instanceof MetaResourceField && ((MetaResourceField) attr).isLinks()) {
field.setName("links");
interfaceType.getDeclaredMembers().add(field);
field.setParent(interfaceType);
} else {
attributesType.getDeclaredMembers().add(field);
field.setParent(attributesType);
}
}
use of io.crnk.meta.model.MetaType in project crnk-framework by crnk-project.
the class ResourceMetaParitition method computeId.
private String computeId(MetaType element) {
Type implementationType = element.getImplementationType();
Class<?> rawType = ClassUtils.getRawType(implementationType);
Class<?> enclosingClass = rawType.getEnclosingClass();
boolean isLinks = LinksInformation.class.isAssignableFrom(rawType);
boolean isMeta = MetaInformation.class.isAssignableFrom(rawType);
ResourceRegistry resourceRegistry = context.getModuleContext().getResourceRegistry();
if (enclosingClass != null && (isLinks || isMeta)) {
RegistryEntry entry = resourceRegistry.getEntry(enclosingClass);
if (entry != null) {
String id = getId(entry.getResourceInformation().getResourceType());
if (isMeta) {
return id + "$meta";
} else {
return id + "$links";
}
}
}
if (!element.hasId()) {
PreconditionUtil.assertNotNull("must have package", rawType.getPackage());
String packageName = rawType.getPackage().getName();
String closedPackageName = null;
String closedResourceType = null;
for (RegistryEntry entry : resourceRegistry.getResources()) {
ResourceInformation resourceInformation = entry.getResourceInformation();
Class<?> resourceClass = resourceInformation.getResourceClass();
String resourcePackageName = resourceClass.getPackage().getName();
if (packageName.startsWith(resourcePackageName) && (closedPackageName == null || closedPackageName.length() < resourcePackageName.length())) {
closedPackageName = resourcePackageName;
closedResourceType = resourceInformation.getResourceType();
}
Object resourceRepository = entry.getResourceRepository().getResourceRepository();
resourcePackageName = resourceRepository.getClass().getPackage().getName();
if (packageName.startsWith(resourcePackageName) && (closedPackageName == null || closedPackageName.length() < resourcePackageName.length())) {
closedPackageName = resourcePackageName;
closedResourceType = resourceInformation.getResourceType();
}
}
if (closedResourceType != null) {
String resourceId = getId(closedResourceType);
String basePath = resourceId.substring(0, resourceId.lastIndexOf('.'));
String relativePath = packageName.substring(closedPackageName.length());
return basePath + relativePath + "." + element.getName().toLowerCase();
}
}
return idProvider.computeIdPrefixFromPackage(rawType, element) + element.getName().toLowerCase();
}
Aggregations