use of io.crnk.meta.model.resource.MetaResource in project crnk-framework by crnk-project.
the class TSMetaDataObjectTransformation method setupParent.
private static void setupParent(TSMetaTransformationContext context, TSInterfaceType interfaceType, MetaDataObject metaDataObject) {
TSContainerElement parent = null;
// move links and meta information to the resource itself
boolean isMeta = TypescriptUtils.isInstance(metaDataObject.getImplementationClass(), "io.crnk.core.resource.meta.MetaInformation");
boolean isLinks = TypescriptUtils.isInstance(metaDataObject.getImplementationClass(), "io.crnk.core.resource.links.LinksInformation");
if ((isMeta || isLinks) && metaDataObject.getImplementationClass().getEnclosingClass() != null) {
MetaElement enclosingMeta = context.getMeta(metaDataObject.getImplementationClass().getEnclosingClass());
if (enclosingMeta instanceof MetaResource) {
TSType enclosingType = (TSType) context.transform(enclosingMeta, TSMetaTransformationOptions.EMPTY);
TSModule module = TypescriptUtils.getNestedTypeContainer(enclosingType, true);
interfaceType.setName(isLinks ? "Links" : "Meta");
parent = module;
}
}
if (parent == null) {
TSSource source = new TSSource();
source.setName(TypescriptUtils.toFileName(metaDataObject.getName()));
source.setNpmPackage(context.getNpmPackage(metaDataObject));
source.setDirectory(context.getDirectory(metaDataObject));
context.addSource(source);
parent = source;
}
parent.getElements().add(interfaceType);
interfaceType.setParent(parent);
}
use of io.crnk.meta.model.resource.MetaResource 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.resource.MetaResource in project crnk-framework by crnk-project.
the class MetaDefaultLimitIntTest method limitShouldNotAffectRelationshipsWithCustomLimit.
@Test
public void limitShouldNotAffectRelationshipsWithCustomLimit() {
QuerySpec querySpec = new QuerySpec(MetaResource.class);
querySpec.includeRelation(Arrays.asList("attributes"));
querySpec.setLimit(3L);
querySpec.addFilter(new FilterSpec(Arrays.asList("resourceType"), FilterOperator.EQ, "tasks"));
ResourceList<MetaResource> list = repository.findAll(querySpec);
Assert.assertEquals(1, list.size());
MetaResource taskMeta = list.get(0);
List<? extends MetaAttribute> attributes = taskMeta.getAttributes();
Assert.assertTrue(attributes.size() > 5);
}
use of io.crnk.meta.model.resource.MetaResource in project crnk-framework by crnk-project.
the class MetaDefaultLimitIntTest method limitShouldNotAffectRelationshipsWithMetaElement.
@Test
public void limitShouldNotAffectRelationshipsWithMetaElement() {
ResourceRepositoryV2<MetaElement, Serializable> elementRepository = client.getRepositoryForType(MetaElement.class);
QuerySpec querySpec = new QuerySpec(MetaElement.class);
querySpec.includeRelation(Arrays.asList("attributes"));
querySpec.addFilter(new FilterSpec(Arrays.asList("id"), FilterOperator.EQ, "resources.tasks"));
ResourceList<MetaElement> list = elementRepository.findAll(querySpec);
Assert.assertEquals(1, list.size());
MetaResource taskMeta = (MetaResource) list.get(0);
List<? extends MetaAttribute> attributes = taskMeta.getAttributes();
Assert.assertTrue(attributes.size() > 5);
}
use of io.crnk.meta.model.resource.MetaResource in project crnk-framework by crnk-project.
the class MetaDefaultLimitIntTest method limitShouldApplyToResults.
@Test
public void limitShouldApplyToResults() {
QuerySpec querySpec = new QuerySpec(MetaResource.class);
querySpec.includeRelation(Arrays.asList("attributes"));
ResourceList<MetaResource> list = repository.findAll(querySpec);
Assert.assertEquals(2, list.size());
}
Aggregations