use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class AbstractEntityMetaFactory method create.
@Override
public MetaElement create(Type type) {
Class<?> rawClazz = ClassUtils.getRawType(type);
Class<?> superClazz = rawClazz.getSuperclass();
MetaElement superMeta = getSuperMeta(superClazz);
T meta = newDataObject();
meta.setElementType(meta);
meta.setName(rawClazz.getSimpleName());
meta.setImplementationType(type);
meta.setSuperType((MetaDataObject) superMeta);
if (superMeta != null) {
((MetaDataObject) superMeta).addSubType(meta);
}
createAttributes(meta);
setKey(meta);
return meta;
}
use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class EmbeddableMetaFactory method create.
@Override
public MetaEmbeddable create(Type type) {
Class<?> rawClazz = ClassUtils.getRawType(type);
Class<?> superClazz = rawClazz.getSuperclass();
MetaElement superMeta = null;
if (superClazz != Object.class) {
superMeta = context.allocate(superClazz);
}
MetaEmbeddable meta = new MetaEmbeddable();
meta.setElementType(meta);
meta.setName(rawClazz.getSimpleName());
meta.setImplementationType(type);
meta.setSuperType((MetaDataObject) superMeta);
if (superMeta != null) {
((MetaDataObject) superMeta).addSubType(meta);
}
createAttributes(meta);
return meta;
}
use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class TSGenerator method transformMetaToTypescript.
public void transformMetaToTypescript() {
Collection<MetaElement> elements = lookup.getMetaById().values();
LOGGER.debug("transforming {} elements", elements.size());
for (MetaElement element : elements) {
boolean isRoot = isRoot(element);
boolean isGenerated = isGenerated(element);
if (isRoot && isGenerated) {
LOGGER.debug("transforming {}", element.getId());
transform(element, TSMetaTransformationOptions.EMPTY);
} else {
LOGGER.debug("ignoring {}, root={}, generated={}", element.getId(), isRoot, isGenerated);
}
}
try {
postProcessing = true;
for (TSElement transformedElement : new ArrayList<>(transformedElements)) {
for (TSMetaTransformation transformation : transformations) {
transformation.postTransform(transformedElement, createMetaTransformationContext());
}
}
} finally {
postProcessing = false;
}
}
use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class MetaModule method registerRepositories.
protected void registerRepositories(DefaultResourceInformationProvider informationBuilder, Set<Class<? extends MetaElement>> metaClasses) {
Supplier<MetaLookup> lookupSupplier = new Supplier<MetaLookup>() {
@Override
public MetaLookup get() {
return getLookup();
}
};
for (Class<? extends MetaElement> metaClass : metaClasses) {
context.addRepository(new MetaResourceRepositoryImpl<>(lookupSupplier, metaClass));
HashSet<Class<? extends MetaElement>> targetResourceClasses = new HashSet<>();
ResourceInformation information = informationBuilder.build(metaClass);
for (ResourceField relationshipField : information.getRelationshipFields()) {
if (!MetaElement.class.isAssignableFrom(relationshipField.getElementType())) {
throw new IllegalStateException("only MetaElement relations supported, got " + relationshipField);
}
targetResourceClasses.add((Class<? extends MetaElement>) relationshipField.getElementType());
}
for (Class<? extends MetaElement> targetResourceClass : targetResourceClasses) {
context.addRepository(new MetaRelationshipRepositoryImpl(lookupSupplier, metaClass, targetResourceClass));
}
}
}
use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class TSMetaDataObjectTransformation method postTransform.
@Override
public void postTransform(TSElement element, TSMetaTransformationContext context) {
if (element instanceof TSInterfaceType) {
TSInterfaceType interfaceType = (TSInterfaceType) element;
String metaId = interfaceType.getPrivateData(TSMetaDataObjectTransformation.PRIVATE_DATA_META_ELEMENT_ID, String.class);
MetaElement metaElement = context.getMeta(metaId);
if (metaElement instanceof MetaDataObject) {
MetaDataObject metaDataObject = (MetaDataObject) metaElement;
if (generateAsResource(metaDataObject)) {
// link to super type, only available once all fields are initialized
MetaDataObject superType = metaDataObject.getSuperType();
if (superType != null) {
setAttributeSuperType(interfaceType, metaDataObject, context);
setRelationshipsSuperType(interfaceType, metaDataObject, context);
}
}
}
}
}
Aggregations