use of io.crnk.meta.model.MetaElement 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.MetaElement in project crnk-framework by crnk-project.
the class JpaResourceInformationProvider method accept.
@Override
public boolean accept(Class<?> resourceClass) {
// needs to be configured for being exposed
if (resourceClass.getAnnotation(JpaResource.class) != null) {
return true;
}
if (JpaMetaUtils.isJpaType(resourceClass)) {
// needs to be an entity
MetaElement meta = metaProvider.discoverMeta(resourceClass);
if (meta instanceof MetaEntity) {
MetaEntity metaEntity = (MetaEntity) meta;
MetaKey primaryKey = metaEntity.getPrimaryKey();
return primaryKey != null && primaryKey.getElements().size() == 1;
} else {
// note that DTOs cannot be handled here
return meta instanceof MetaJpaDataObject;
}
}
return false;
}
use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class TSGeneratorTest method throwExceptionWhenMetaElementNotMappedToNpmPackage.
@Test(expected = UnsupportedOperationException.class)
public void throwExceptionWhenMetaElementNotMappedToNpmPackage() {
TSMetaTransformationContext transformationContext = generator.createMetaTransformationContext();
MetaElement metaElement = Mockito.mock(MetaElement.class);
metaElement.setId("does.not.exist");
transformationContext.getNpmPackage(metaElement);
}
use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class TSGeneratorTest method throwExceptionWhenTransformingUnknownMetaElement.
@Test(expected = IllegalStateException.class)
public void throwExceptionWhenTransformingUnknownMetaElement() {
MetaElement metaElement = Mockito.mock(MetaElement.class);
metaElement.setId("does.not.exist");
TSMetaTransformationOptions options = Mockito.mock(TSMetaTransformationOptions.class);
generator.transform(metaElement, options);
}
use of io.crnk.meta.model.MetaElement in project crnk-framework by crnk-project.
the class TSGeneratorTest method throwExceptionWhenMetaElementNotMappedToDirectory.
@Test(expected = UnsupportedOperationException.class)
public void throwExceptionWhenMetaElementNotMappedToDirectory() {
TSMetaTransformationContext transformationContext = generator.createMetaTransformationContext();
MetaElement metaElement = Mockito.mock(MetaElement.class);
metaElement.setId("does.not.exist");
transformationContext.getDirectory(metaElement);
}
Aggregations