use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class JpaResourceInformationProvider method build.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public ResourceInformation build(final Class<?> resourceClass) {
String resourceType = getResourceType(resourceClass);
MetaDataObject meta = metaProvider.discoverMeta(resourceClass).asDataObject();
DefaultResourceInstanceBuilder instanceBuilder = new DefaultResourceInstanceBuilder(resourceClass);
List<ResourceField> fields = getResourceFields(resourceClass);
Class<?> superclass = resourceClass.getSuperclass();
String superResourceType = superclass != Object.class && superclass.getAnnotation(MappedSuperclass.class) == null ? context.getResourceType(superclass) : null;
TypeParser typeParser = context.getTypeParser();
ResourceInformation info = new ResourceInformation(typeParser, resourceClass, resourceType, superResourceType, instanceBuilder, fields, new OffsetLimitPagingBehavior());
info.setValidator(new JpaOptimisticLockingValidator(meta));
info.setIdStringMapper(new JpaIdMapper(meta));
return info;
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class SecurityModule method toType.
private <T> String toType(Class<T> resourceClass) {
ResourceRegistry resourceRegistry = context.getResourceRegistry();
RegistryEntry entry = resourceRegistry.getEntryForClass(resourceClass);
if (entry == null) {
throw new ResourceNotFoundException("resource type not found: " + resourceClass.getName());
}
ResourceInformation resourceInformation = entry.getResourceInformation();
return resourceInformation.getResourceType();
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class QuerySpecAdapter method getResourceType.
private String getResourceType(QuerySpec spec) {
if (spec.getResourceType() != null) {
return spec.getResourceType();
}
RegistryEntry entry = resourceRegistry.getEntry(spec.getResourceClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
return resourceInformation.getResourceType();
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class PagingSpecUrlBuilder method build.
public String build(QueryAdapter queryAdapter) {
JsonApiUrlBuilder urlBuilder = new JsonApiUrlBuilder(resourceRegistry);
Object relationshipSourceId = requestSpec.getId();
ResourceField relationshipField = requestSpec.getRelationshipField();
ResourceInformation rootInfo;
if (relationshipField == null) {
rootInfo = queryAdapter.getResourceInformation();
} else {
rootInfo = relationshipField.getParentResourceInformation();
}
return urlBuilder.buildUrl(rootInfo, relationshipSourceId, queryAdapter, relationshipField != null ? relationshipField.getJsonName() : null);
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class RelationshipRepositoryBase method setRelation.
@Override
public void setRelation(T source, J targetId, String fieldName) {
RegistryEntry sourceEntry = getSourceEntry();
ResourceRepositoryAdapter<T, I> sourceAdapter = sourceEntry.getResourceRepository();
ResourceInformation sourceInformation = getSourceEntry().getResourceInformation();
ResourceField field = sourceInformation.findFieldByUnderlyingName(fieldName);
if (field.hasIdField()) {
field.getIdAccessor().setValue(source, targetId);
} else {
RegistryEntry targetEntry = getTargetEntry(field);
D target = getTarget(targetEntry, targetId);
field.getAccessor().setValue(source, target);
}
sourceAdapter.update(source, getSaveQueryAdapter(fieldName));
}
Aggregations