use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class ApprovalManager method requestApproval.
public <T> T requestApproval(T entity, HttpMethod method) {
RegistryEntry entry = moduleRegistry.getResourceRegistry().getEntry(entity.getClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
Object id = resourceInformation.getId(entity);
ApprovalProcessInstance resource = newApprovalProcessInstance(entity.getClass());
resource.setResourceType(resourceInformation.getResourceType());
resource.setResourceId(id.toString());
resource.setNewValues(approvalMapper.mapValues(entity));
T currentEntity = entity;
if (method != HttpMethod.POST) {
// you may need additional logic here, like detaching entities from an entity manager
// in case of entities, like detaching from entity manager
currentEntity = (T) get(entry, id.toString());
PreconditionUtil.assertFalse("posted resource must not be managed", currentEntity == entity);
if (currentEntity != null) {
resource.setPreviousValues(approvalMapper.mapValues(currentEntity));
}
}
Map<String, Object> processVariables = resourceMapper.mapToVariables(resource);
runtimeService.startProcessInstanceByKey("scheduleChange", processVariables);
return currentEntity;
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class ApprovalManager method get.
private Object get(RegistryEntry entry, String idString) {
ResourceInformation resourceInformation = entry.getResourceInformation();
Object id = resourceInformation.parseIdString(idString);
ResourceRepositoryV2 resourceRepository = entry.getResourceRepositoryFacade();
QuerySpec querySpec = new QuerySpec(resourceInformation.getResourceType());
return resourceRepository.findOne((Serializable) id, querySpec);
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class CrnkClient method setProxyFactory.
public void setProxyFactory(ClientProxyFactory proxyFactory) {
proxyFactory.init(new ClientProxyFactoryContext() {
@Override
public ModuleRegistry getModuleRegistry() {
return moduleRegistry;
}
@Override
public <T> DefaultResourceList<T> getCollection(Class<T> resourceClass, String url) {
RegistryEntry entry = resourceRegistry.findEntry(resourceClass);
ResourceInformation resourceInformation = entry.getResourceInformation();
final ResourceRepositoryStubImpl<T, ?> repositoryStub = new ResourceRepositoryStubImpl<>(CrnkClient.this, resourceClass, resourceInformation, urlBuilder);
return repositoryStub.findAll(url);
}
});
documentMapper.setProxyFactory(proxyFactory);
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class CrnkClient method allocateRepository.
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T, I extends Serializable> RegistryEntry allocateRepository(Class<T> resourceClass) {
ResourceInformationProvider resourceInformationProvider = moduleRegistry.getResourceInformationBuilder();
ResourceInformation resourceInformation = resourceInformationProvider.build(resourceClass);
final ResourceRepositoryStub<T, I> repositoryStub = new ResourceRepositoryStubImpl<>(this, resourceClass, resourceInformation, urlBuilder);
// create interface for it!
RepositoryInstanceBuilder repositoryInstanceBuilder = new RepositoryInstanceBuilder(null, null) {
@Override
public Object buildRepository() {
return repositoryStub;
}
};
ResourceRepositoryInformation repositoryInformation = new ResourceRepositoryInformationImpl(resourceInformation.getResourceType(), resourceInformation, RepositoryMethodAccess.ALL);
ResourceEntry resourceEntry = new DirectResponseResourceEntry(repositoryInstanceBuilder, repositoryInformation);
Map<ResourceField, ResponseRelationshipEntry> relationshipEntries = new HashMap<>();
RegistryEntry registryEntry = new RegistryEntry(resourceEntry, relationshipEntries);
registryEntry.initialize(moduleRegistry);
resourceRegistry.addEntry(resourceClass, registryEntry);
allocateRepositoryRelations(registryEntry);
return registryEntry;
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class ClientResourceUpsert method setRelationsField.
@Override
protected void setRelationsField(Object newResource, RegistryEntry registryEntry, Map.Entry<String, Relationship> property, QueryAdapter queryAdapter, RepositoryMethodParameterProvider parameterProvider) {
Relationship relationship = property.getValue();
if (!relationship.getData().isPresent()) {
ObjectNode links = relationship.getLinks();
if (links != null) {
// create proxy to lazy load relations
String fieldName = property.getKey();
ResourceInformation resourceInformation = registryEntry.getResourceInformation();
ResourceField field = resourceInformation.findRelationshipFieldByName(fieldName);
Class elementType = field.getElementType();
Class collectionClass = field.getType();
JsonNode relatedNode = links.get("related");
if (relatedNode != null) {
String url = null;
if (relatedNode.has(SerializerUtil.HREF)) {
JsonNode hrefNode = relatedNode.get(SerializerUtil.HREF);
if (hrefNode != null) {
url = hrefNode.asText().trim();
}
} else {
url = relatedNode.asText().trim();
}
Object proxy = proxyFactory.createCollectionProxy(elementType, collectionClass, url);
field.getAccessor().setValue(newResource, proxy);
}
}
} else {
// set elements
super.setRelationsField(newResource, registryEntry, property, queryAdapter, parameterProvider);
}
}
Aggregations