use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class ErrorMapperTest method testElideCreateWithErrorMapperUnmapped.
@Test
public void testElideCreateWithErrorMapperUnmapped() throws Exception {
DataStore store = mock(DataStore.class);
DataStoreTransaction tx = mock(DataStoreTransaction.class);
FieldTestModel mockModel = mock(FieldTestModel.class);
Elide elide = getElide(store, dictionary, MOCK_ERROR_MAPPER);
String body = "{\"data\": {\"type\":\"testModel\",\"id\":\"1\",\"attributes\": {\"field\":\"Foo\"}}}";
when(store.beginTransaction()).thenReturn(tx);
when(tx.createNewObject(eq(ClassType.of(FieldTestModel.class)), any())).thenReturn(mockModel);
doThrow(EXPECTED_EXCEPTION).when(tx).preCommit(any());
RuntimeException result = assertThrows(RuntimeException.class, () -> elide.post(baseUrl, "/testModel", body, null, NO_VERSION));
assertEquals(EXPECTED_EXCEPTION, result.getCause());
verify(tx).close();
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction 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.datastore.DataStoreTransaction in project elide by yahoo.
the class ResourceIT method setup.
@BeforeEach
public void setup() throws IOException {
dataStore.populateEntityDictionary(EntityDictionary.builder().build());
DataStoreTransaction tx = dataStore.beginTransaction();
final Company company = new Company();
company.setId("abc");
company.setDescription("ABC");
Address address = new Address();
address.setStreet1("foo");
address.setProperties(Map.of("boo", "baz"));
company.setAddress(address);
tx.createObject(company, null);
// id 1
Parent parent = new Parent();
// id 1
Child child = new Child();
parent.setChildren(Sets.newHashSet(child));
parent.setSpouses(Sets.newHashSet());
child.setParents(Sets.newHashSet(parent));
tx.createObject(parent, null);
tx.createObject(child, null);
// Single tests
// id 2
Parent p1 = new Parent();
p1.setFirstName("John");
p1.setSpouses(Sets.newHashSet());
// id 2
Child c1 = new Child();
c1.setName("Child-ID2");
c1.setParents(Sets.newHashSet(p1));
// id 3
Child c2 = new Child();
c2.setName("Child-ID3");
c2.setParents(Sets.newHashSet(p1));
Set<Child> friendSet = new HashSet<>();
friendSet.add(c2);
c1.setFriends(friendSet);
Set<Child> childrenSet1 = new HashSet<>();
childrenSet1.add(c1);
childrenSet1.add(c2);
p1.setChildren(childrenSet1);
// List tests
// id 3
Parent p2 = new Parent();
// id 4
Parent p3 = new Parent();
// id 4
Child c3 = new Child();
c3.setParents(Sets.newHashSet(p2));
// id 5
Child c4 = new Child();
c4.setParents(Sets.newHashSet(p2));
Set<Child> childrenSet2 = new HashSet<>();
childrenSet2.add(c3);
childrenSet2.add(c4);
p2.setChildren(childrenSet2);
p2.setFirstName("Link");
p3.setFirstName("Unknown");
p2.setSpouses(Sets.newHashSet());
p3.setSpouses(Sets.newHashSet(p2));
p3.setChildren(Sets.newHashSet());
tx.createObject(c1, null);
tx.createObject(c2, null);
tx.createObject(c3, null);
tx.createObject(c4, null);
tx.createObject(p1, null);
tx.createObject(p2, null);
tx.createObject(p3, null);
Book bookWithPercentage = new Book();
bookWithPercentage.setTitle("titlewith%percentage");
Book bookWithoutPercentage = new Book();
bookWithoutPercentage.setTitle("titlewithoutpercentage");
tx.createObject(bookWithPercentage, null);
tx.createObject(bookWithoutPercentage, null);
FunWithPermissions fun = new FunWithPermissions();
tx.createObject(fun, null);
// ID 1
User user = new User();
user.setPassword("god");
tx.createObject(user, null);
Invoice invoice = new Invoice();
invoice.setId(1);
LineItem item = new LineItem();
invoice.setItems(Sets.newHashSet(item));
item.setInvoice(invoice);
tx.createObject(invoice, null);
tx.createObject(item, null);
ExceptionThrowingBean etb = new ExceptionThrowingBean();
etb.setId(1L);
tx.createObject(etb, null);
tx.commit(null);
tx.close();
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class TransferableIT method setUp.
@BeforeEach
public void setUp() throws Exception {
dataStore.populateEntityDictionary(EntityDictionary.builder().build());
DataStoreTransaction tx = dataStore.beginTransaction();
Left left = new Left();
tx.createObject(left, null);
tx.commit(null);
tx.close();
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class AccessIT method accessParentBean.
@Test
public void accessParentBean() throws IOException {
DataStoreTransaction tx = dataStore.beginTransaction();
Parent parent = new Parent();
parent.setChildren(new HashSet<>());
parent.setSpouses(new HashSet<>());
tx.createObject(parent, null);
tx.commit(null);
tx.close();
}
Aggregations