use of io.crnk.meta.model.MetaKey in project crnk-framework by crnk-project.
the class TSMetaDataObjectTransformation method generateResourceFields.
private static void generateResourceFields(TSMetaTransformationContext context, TSInterfaceType interfaceType, MetaDataObject meta) {
TSInterfaceType attributesType = new TSInterfaceType();
attributesType.setName(ATTRIBUTES_CLASS_NAME);
attributesType.setExported(true);
TSInterfaceType relationshipsType = new TSInterfaceType();
relationshipsType.setName(RELATIONSHIPS_CLASS_NAME);
relationshipsType.setExported(true);
TSIndexSignature relationshipsIndexSignature = new TSIndexSignature();
relationshipsIndexSignature.setKeyType(TSPrimitiveType.STRING);
relationshipsIndexSignature.setValueType(NgrxJsonApiLibrary.RESOURCE_RELATIONSHIP);
relationshipsIndexSignature.setParent(relationshipsType);
relationshipsType.setIndexSignature(relationshipsIndexSignature);
// TODO remo: interface support
MetaKey primaryKey = meta.getPrimaryKey();
for (MetaAttribute attr : meta.getDeclaredAttributes()) {
if (primaryKey != null && primaryKey.getUniqueElement().equals(attr)) {
continue;
}
generateResourceField(attr, context, interfaceType, attributesType, relationshipsType);
}
if (!isEmpty(relationshipsType)) {
TSModule module = TypescriptUtils.getNestedTypeContainer(interfaceType, true);
module.getElements().add(relationshipsType);
relationshipsType.setParent(module);
TSField relationshipsField = new TSField();
relationshipsField.setName("relationships");
relationshipsField.setType(relationshipsType);
relationshipsField.setNullable(true);
interfaceType.getDeclaredMembers().add(relationshipsField);
}
if (!isEmpty(attributesType)) {
TSModule module = TypescriptUtils.getNestedTypeContainer(interfaceType, true);
module.getElements().add(attributesType);
attributesType.setParent(module);
TSField attributesField = new TSField();
attributesField.setName("attributes");
attributesField.setType(attributesType);
attributesField.setNullable(true);
interfaceType.getDeclaredMembers().add(attributesField);
}
}
use of io.crnk.meta.model.MetaKey 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.MetaKey in project crnk-framework by crnk-project.
the class MetaRelationshipRepositoryImplTest method findOneTargetReturnsNull.
@Test
public void findOneTargetReturnsNull() {
MetaResource resource = resourceProvider.getMeta(Task.class);
resource.setPrimaryKey(null);
MetaKey key = (MetaKey) repo.findOneTarget(resource.getId(), "primaryKey", new QuerySpec(MetaElement.class));
Assert.assertNull(key);
}
use of io.crnk.meta.model.MetaKey in project crnk-framework by crnk-project.
the class JpaRepositoryUtils method getPrimaryKeyAttr.
/**
* @param meta of the entity
* @return Gets the primary key attribute of the given entity. Assumes a
* primary key is available and no compound primary keys are
* supported.
*/
public static MetaAttribute getPrimaryKeyAttr(MetaDataObject meta) {
MetaKey primaryKey = meta.getPrimaryKey();
PreconditionUtil.assertNotNull("no primary key", primaryKey);
PreconditionUtil.assertEquals("non-compound primary key expected", 1, primaryKey.getElements().size());
return primaryKey.getElements().get(0);
}
use of io.crnk.meta.model.MetaKey in project crnk-framework by crnk-project.
the class QuerydslQueryBackend method getParentIdExpression.
private Expression<Object> getParentIdExpression(MetaDataObject parentMeta, MetaAttribute parentAttr) {
MetaKey primaryKey = parentMeta.getPrimaryKey();
PreconditionUtil.assertNotNull("no primary key specified for parentAttribute " + parentAttr.getId(), parentMeta);
List<MetaAttribute> elements = primaryKey.getElements();
PreconditionUtil.assertEquals("composite primary keys not supported yet", 1, elements.size());
MetaAttribute primaryKeyAttr = elements.get(0);
return QuerydslUtils.get(parentFrom, primaryKeyAttr.getName());
}
Aggregations