use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class NotifyTopicLifeCycleHookTest method testManagedModelNotification.
@Test
public void testManagedModelNotification() {
NotifyTopicLifeCycleHook<Book> bookHook = new NotifyTopicLifeCycleHook<Book>(connectionFactory, JMSContext::createProducer, new GsonBuilder().create());
Book book = new Book();
PersistentResource<Book> resource = new PersistentResource<>(book, "123", scope);
bookHook.execute(LifeCycleHookBinding.Operation.CREATE, LifeCycleHookBinding.TransactionPhase.PRECOMMIT, new CRUDEvent(LifeCycleHookBinding.Operation.CREATE, resource, "", Optional.empty()));
ArgumentCaptor<String> topicCaptor = ArgumentCaptor.forClass(String.class);
verify(context).createTopic(topicCaptor.capture());
assertEquals("bookAdded", topicCaptor.getValue());
verify(producer, times(1)).send(isA(Destination.class), isA(String.class));
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class LogMessageImplTest method init.
@BeforeAll
public static void init() {
final EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Child.class);
dictionary.bindEntity(Parent.class);
final Child child = new Child();
child.setId(5);
final Parent parent = new Parent();
parent.setId(7);
final Child friend = new Child();
friend.setId(9);
child.setFriends(Sets.newHashSet(friend));
final RequestScope requestScope = new RequestScope(null, null, NO_VERSION, null, null, new TestUser("aaron"), null, null, UUID.randomUUID(), new ElideSettingsBuilder(null).withAuditLogger(new TestAuditLogger()).withEntityDictionary(dictionary).build());
final PersistentResource<Parent> parentRecord = new PersistentResource<>(parent, requestScope.getUUIDFor(parent), requestScope);
childRecord = new PersistentResource<>(child, parentRecord, "children", requestScope.getUUIDFor(child), requestScope);
friendRecord = new PersistentResource<>(friend, childRecord, "friends", requestScope.getUUIDFor(friend), requestScope);
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class TableExportOperation method call.
@Override
public AsyncAPIResult call() {
log.debug("TableExport Object from request: {}", exportObj);
Elide elide = service.getElide();
TableExportResult exportResult = new TableExportResult();
UUID requestId = UUID.fromString(exportObj.getRequestId());
try (DataStoreTransaction tx = elide.getDataStore().beginTransaction()) {
// Do Not Cache Export Results
Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>();
requestHeaders.put("bypasscache", new ArrayList<String>(Arrays.asList("true")));
RequestScope requestScope = getRequestScope(exportObj, scope, tx, requestHeaders);
Collection<EntityProjection> projections = getProjections(exportObj, requestScope);
validateProjections(projections);
EntityProjection projection = projections.iterator().next();
Observable<PersistentResource> observableResults = Observable.empty();
elide.getTransactionRegistry().addRunningTransaction(requestId, tx);
// TODO - we need to add the baseUrlEndpoint to the queryObject.
// TODO - Can we have projectionInfo as null?
requestScope.setEntityProjection(projection);
if (projection != null) {
projection.setPagination(null);
observableResults = PersistentResource.loadRecords(projection, Collections.emptyList(), requestScope);
}
Observable<String> results = Observable.empty();
String preResult = formatter.preFormat(projection, exportObj);
results = observableResults.map(resource -> {
this.recordNumber++;
return formatter.format(resource, recordNumber);
});
String postResult = formatter.postFormat(projection, exportObj);
// Stitch together Pre-Formatted, Formatted, Post-Formatted results of Formatter in single observable.
Observable<String> interimResults = concatStringWithObservable(preResult, results, true);
Observable<String> finalResults = concatStringWithObservable(postResult, interimResults, false);
TableExportResult result = storeResults(exportObj, engine, finalResults);
if (result != null && result.getMessage() != null) {
throw new IllegalStateException(result.getMessage());
}
exportResult.setUrl(new URL(generateDownloadURL(exportObj, scope)));
exportResult.setRecordCount(recordNumber);
tx.flush(requestScope);
elide.getAuditLogger().commit();
tx.commit(requestScope);
} catch (BadRequestException e) {
exportResult.setMessage(e.getMessage());
} catch (MalformedURLException e) {
exportResult.setMessage("Download url generation failure.");
} catch (IOException e) {
log.error("IOException during TableExport", e);
exportResult.setMessage(e.getMessage());
} catch (Exception e) {
exportResult.setMessage(e.getMessage());
} finally {
// Follows same flow as GraphQL. The query may result in failure but request was successfully processed.
exportResult.setHttpStatus(200);
exportResult.setCompletedOn(new Date());
elide.getTransactionRegistry().removeRunningTransaction(requestId);
elide.getAuditLogger().clear();
}
return exportResult;
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class JSONExportFormatter method resourceToJSON.
public static String resourceToJSON(ObjectMapper mapper, PersistentResource resource) {
if (resource == null || resource.getObject() == null) {
return null;
}
StringBuilder str = new StringBuilder();
try {
Resource jsonResource = resource.toResource(getRelationships(resource), getAttributes(resource));
str.append(mapper.writeValueAsString(jsonResource.getAttributes()));
} catch (JsonProcessingException e) {
log.error("Exception when converting to JSON {}", e.getMessage());
throw new IllegalStateException(e);
}
return str.toString();
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class BaseState method getResponseBody.
protected static JsonNode getResponseBody(PersistentResource resource, RequestScope requestScope) {
MultivaluedMap<String, String> queryParams = requestScope.getQueryParams();
JsonApiDocument jsonApiDocument = new JsonApiDocument();
// TODO Make this a document processor
Data<Resource> data = resource == null ? null : new Data<>(resource.toResource());
jsonApiDocument.setData(data);
// TODO Iterate over set of document processors
DocumentProcessor includedProcessor = new IncludedProcessor();
includedProcessor.execute(jsonApiDocument, resource, queryParams);
return requestScope.getMapper().toJsonObject(jsonApiDocument);
}
Aggregations