use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class PersistentResourceFetcher method fetchRelationship.
/**
* Fetches a relationship for a top-level entity.
*
* @param parentResource Parent object
* @param relationship constructed relationship object with entityProjection
* @param ids List of ids
* @return persistence resource object(s)
*/
public static ConnectionContainer fetchRelationship(PersistentResource<?> parentResource, @NotNull Relationship relationship, Optional<List<String>> ids) {
EntityDictionary dictionary = parentResource.getRequestScope().getDictionary();
Type relationshipClass = dictionary.getParameterizedType(parentResource.getObject(), relationship.getName());
String relationshipType = dictionary.getJsonAliasFor(relationshipClass);
Set<PersistentResource> relationResources;
if (ids.isPresent()) {
relationResources = parentResource.getRelation(ids.get(), relationship).toList(LinkedHashSet::new).blockingGet();
} else {
relationResources = parentResource.getRelationCheckedFiltered(relationship).toList(LinkedHashSet::new).blockingGet();
}
return new ConnectionContainer(relationResources, Optional.ofNullable(relationship.getProjection().getPagination()), relationshipType);
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class MultiplexManagerTest method partialCommitFailure.
@Test
public void partialCommitFailure() throws IOException {
final EntityDictionary entityDictionary = EntityDictionary.builder().build();
final HashMapDataStore ds1 = new HashMapDataStore(DefaultClassScanner.getInstance(), FirstBean.class.getPackage());
final DataStore ds2 = new TestDataStore(OtherBean.class.getPackage());
final MultiplexManager multiplexManager = new MultiplexManager(ds1, ds2);
multiplexManager.populateEntityDictionary(entityDictionary);
assertEquals(ds1, multiplexManager.getSubManager(ClassType.of(FirstBean.class)));
assertEquals(ds2, multiplexManager.getSubManager(ClassType.of(OtherBean.class)));
try (DataStoreTransaction t = ds1.beginTransaction()) {
assertFalse(t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().hasNext());
FirstBean firstBean = FirstBean.class.newInstance();
firstBean.setName("name");
t.createObject(firstBean, null);
// t.save(firstBean);
assertFalse(t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().hasNext());
t.commit(null);
} catch (InstantiationException | IllegalAccessException e) {
log.error("", e);
}
try (DataStoreTransaction t = multiplexManager.beginTransaction()) {
FirstBean firstBean = (FirstBean) t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().next();
firstBean.setName("update");
t.save(firstBean, null);
OtherBean otherBean = OtherBean.class.newInstance();
t.createObject(otherBean, null);
// t.save(firstBean);
assertThrows(TransactionException.class, () -> t.commit(null));
} catch (InstantiationException | IllegalAccessException e) {
log.error("", e);
}
// verify state
try (DataStoreTransaction t = ds1.beginTransaction()) {
Iterable<Object> beans = t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null);
assertNotNull(beans);
ArrayList<Object> list = Lists.newArrayList(beans.iterator());
assertEquals(list.size(), 1);
assertEquals(((FirstBean) list.get(0)).getName(), "name");
}
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class ResourceIT method testSpecialCharacterLikeQueryHQL.
@ParameterizedTest
@MethodSource("queryProviderHQL")
public void testSpecialCharacterLikeQueryHQL(FilterPredicate filterPredicate, int noOfRecords) throws Exception {
DataStoreTransaction tx = dataStore.beginReadTransaction();
RequestScope scope = mock(RequestScope.class);
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Book.class);
when(scope.getDictionary()).thenReturn(dictionary);
PaginationImpl pagination = mock(PaginationImpl.class);
when(pagination.returnPageTotals()).thenReturn(true);
tx.loadObjects(EntityProjection.builder().type(Book.class).filterExpression(filterPredicate).pagination(pagination).build(), scope);
tx.commit(scope);
tx.close();
verify(pagination).setPageTotals((long) noOfRecords);
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class TableExportIT method tableExportModelAdminReadPermissions.
/**
* Tests Read Permissions on TableExport Model for Admin Role.
* @throws IOException IOException
*/
@Test
public void tableExportModelAdminReadPermissions() throws IOException {
ElideResponse response = null;
String id = "edc4a871-dff2-4054-804e-d80075c08959";
String query = "test-query";
com.yahoo.elide.async.models.TableExport queryObj = new com.yahoo.elide.async.models.TableExport();
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setResultType(ResultType.CSV);
queryObj.setQueryType(QueryType.JSONAPI_V1_0);
queryObj.setPrincipalName("owner-user");
EntityDictionary dictionary = EntityDictionary.builder().checks(AsyncIntegrationTestApplicationResourceConfig.MAPPINGS).build();
dataStore.populateEntityDictionary(dictionary);
DataStoreTransaction tx = dataStore.beginTransaction();
tx.createObject(queryObj, null);
tx.commit(null);
tx.close();
Elide elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(dictionary).withAuditLogger(new TestAuditLogger()).build());
User ownerUser = new User(() -> "owner-user");
SecurityContextUser securityContextAdminUser = new SecurityContextUser(new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return () -> "1";
}
@Override
public boolean isUserInRole(String s) {
return true;
}
@Override
public boolean isSecure() {
return false;
}
@Override
public String getAuthenticationScheme() {
return null;
}
});
SecurityContextUser securityContextNonAdminUser = new SecurityContextUser(new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return () -> "2";
}
@Override
public boolean isUserInRole(String s) {
return false;
}
@Override
public boolean isSecure() {
return false;
}
@Override
public String getAuthenticationScheme() {
return null;
}
});
String baseUrl = "/";
// Principal is Owner
response = elide.get(baseUrl, "/tableExport/" + id, new MultivaluedHashMap<>(), ownerUser, NO_VERSION);
assertEquals(HttpStatus.SC_OK, response.getResponseCode());
// Principal has Admin Role
response = elide.get(baseUrl, "/tableExport/" + id, new MultivaluedHashMap<>(), securityContextAdminUser, NO_VERSION);
assertEquals(HttpStatus.SC_OK, response.getResponseCode());
// Principal without Admin Role
response = elide.get(baseUrl, "/tableExport/" + id, new MultivaluedHashMap<>(), securityContextNonAdminUser, NO_VERSION);
assertEquals(HttpStatus.SC_NOT_FOUND, response.getResponseCode());
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class VerboseErrorResponsesTestBinder method configure.
@Override
protected void configure() {
EntityDictionary dictionary = EntityDictionary.builder().injector(injector::inject).checks(TestCheckMappings.MAPPINGS).build();
bind(dictionary).to(EntityDictionary.class);
// Elide instance
bindFactory(new Factory<Elide>() {
@Override
public Elide provide() {
DefaultFilterDialect defaultFilterStrategy = new DefaultFilterDialect(dictionary);
RSQLFilterDialect rsqlFilterStrategy = RSQLFilterDialect.builder().dictionary(dictionary).build();
MultipleFilterDialect multipleFilterStrategy = new MultipleFilterDialect(Arrays.asList(rsqlFilterStrategy, defaultFilterStrategy), Arrays.asList(rsqlFilterStrategy, defaultFilterStrategy));
Elide elide = new Elide(new ElideSettingsBuilder(getDataStore()).withAuditLogger(auditLogger).withJoinFilterDialect(multipleFilterStrategy).withSubqueryFilterDialect(multipleFilterStrategy).withEntityDictionary(dictionary).withVerboseErrors().build());
elide.doScans();
return elide;
}
@Override
public void dispose(Elide elide) {
// do nothing
}
}).to(Elide.class).named("elide");
bind(new BillingService() {
@Override
public long purchase(Invoice invoice) {
return 0;
}
}).to(BillingService.class);
}
Aggregations