Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GraphQLEntityProjectionMaker #986

Merged
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c0a942e
AggregationDataStore: Schema (#846)
QubitPi Jul 13, 2019
5828227
Initial sketch
Jul 19, 2019
8083eec
Fixed build issues after rebase
Sep 3, 2019
325d1af
Removed duplicated Schema class from rebase
Sep 3, 2019
f48ddcb
GraphQL projection maker using document
Aug 29, 2019
1eca1e0
Argument handling and fragment check
Aug 29, 2019
a81a285
Add comments
Aug 29, 2019
2e34e25
Add fragment resolver
Aug 30, 2019
eac6cbc
fix typo
Aug 30, 2019
e823aaa
break code into more methods
Aug 30, 2019
54f171a
remove pagination and sorting
Aug 30, 2019
66c772a
re-arrange keywords
Sep 4, 2019
5a97cb6
Address comment
Sep 5, 2019
00d7ffd
Add arguments for attribute fields
Sep 6, 2019
3e40da8
Handle arguments
Sep 6, 2019
04e13ed
support partial query, update edges/node logic
Sep 9, 2019
a790cda
Entity projection with aliases
hellohanchen Sep 11, 2019
c007793
Entity projection with aliases (#963)
aklish Sep 11, 2019
e103312
fix create relationship object using entity
Sep 12, 2019
4b7c3bb
Add tests passed
Sep 12, 2019
44b2f8a
code clean up
Sep 12, 2019
1026f13
refactor fatcher, fix test cases
Sep 12, 2019
f8e7af8
rename keywords
Sep 12, 2019
332d30f
rebase branch (#12)
hellohanchen Sep 13, 2019
3c193a8
rebased
Sep 13, 2019
3a7f2d8
Graphql projection refactor (#13)
hellohanchen Sep 20, 2019
eb45070
fix fragment resolver
Sep 20, 2019
dfe47b6
Fix variable resolver
Sep 20, 2019
3466f0f
Wire in entity projection4 json api (#964)
aklish Sep 12, 2019
8f1596b
Wire in entity projection4 json api (#965)
aklish Sep 13, 2019
b6a8072
Pre-inspection cleanup
Sep 13, 2019
61199a2
minor inspection fixup
Sep 19, 2019
cbe37dd
rebase
Sep 20, 2019
d3076b5
Rebased on AggregationDataStore
Sep 23, 2019
1e7ef34
clean up extra new lines
Sep 23, 2019
2d6b045
address comments
Sep 24, 2019
9933201
Builder pattern
Sep 24, 2019
1c0f8ae
update comments
Sep 24, 2019
54cf3ab
remove projection in entity
Sep 25, 2019
7d5a9f8
fix jackson
Sep 27, 2019
6c04150
Hydrate Relationship (#987) (#15)
hellohanchen Sep 30, 2019
fddd88b
Address some codecy comments
Sep 30, 2019
6633840
Add comment for partial query
Sep 30, 2019
56a7c8a
Reenable tests
Sep 30, 2019
e502da9
Address comments, refactor alias
Oct 1, 2019
76c36b6
Add test for alias
Oct 1, 2019
f4a6dab
swapped test case
Oct 1, 2019
c1ce579
Merge branch 'AggregationDataStore' into entityProjectionMakerRebased-02
hellohanchen Oct 1, 2019
ec58f24
fix get type
Oct 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ public ParseTree getPermissionsForClass(Class<?> resourceClass, Class<? extends
* or {@code null} if the permission is not specified on that field
*/
public ParseTree getPermissionsForField(Class<?> resourceClass,
String field,
Class<? extends Annotation> annotationClass) {
String field,
Class<? extends Annotation> annotationClass) {
EntityBinding binding = getEntityBinding(resourceClass);
return binding.entityPermissions.getFieldChecksForPermission(field, annotationClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;

import org.apache.commons.collections4.CollectionUtils;

import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
Expand Down Expand Up @@ -129,7 +127,7 @@ public static <T> PersistentResource<T> createObject(
RequestScope requestScope,
Optional<String> uuid) {

//instead of calling transcation.createObject, create the new object here.
//instead of calling transaction.createObject, create the new object here.
T obj = requestScope.getTransaction().createNewObject(entityClass);

String id = uuid.orElse(null);
Expand Down Expand Up @@ -169,8 +167,12 @@ public static <T> PersistentResource<T> createObject(
* @param id the id
* @param scope the request scope
*/
public PersistentResource(@NonNull T obj, PersistentResource parent,
String id, @NonNull RequestScope scope) {
public PersistentResource(
@NonNull T obj,
PersistentResource parent,
String id,
@NonNull RequestScope scope
) {
this.obj = obj;
this.uuid = Optional.ofNullable(id);
this.lineage = parent != null ? new ResourceLineage(parent.lineage, parent) : new ResourceLineage();
Expand Down Expand Up @@ -212,8 +214,10 @@ public boolean matchesId(String checkId) {
*/
@SuppressWarnings("resource")
@NonNull public static <T> PersistentResource<T> loadRecord(
EntityProjection projection, String id, RequestScope requestScope)
throws InvalidObjectIdentifierException {
EntityProjection projection,
String id,
RequestScope requestScope
) throws InvalidObjectIdentifierException {
Preconditions.checkNotNull(projection);
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(requestScope);
Expand Down Expand Up @@ -241,7 +245,12 @@ public boolean matchesId(String checkId) {
}
}

PersistentResource<T> resource = new PersistentResource(obj, null, requestScope.getUUIDFor(obj), requestScope);
PersistentResource<T> resource = new PersistentResource<>(
(T) obj,
null,
requestScope.getUUIDFor(obj),
requestScope);

// No need to have read access for a newly created object
if (!requestScope.getNewResources().contains(resource)) {
resource.checkFieldAwarePermissions(ReadPermission.class);
Expand Down Expand Up @@ -1261,11 +1270,10 @@ protected Map<String, Relationship> getRelationships() {
* @return Relationship mapping
*/
private Map<String, Relationship> getRelationships(EntityProjection projection) {
return getRelationshipsWithRelationshipFunction((relationName) -> {
return getRelationCheckedFiltered(projection.getRelationship(relationName)
.orElseThrow(IllegalStateException::new)
);
});
return getRelationshipsWithRelationshipFunction(
(relationName) -> getRelationCheckedFiltered(projection.getRelationship(relationName)
.orElseThrow(IllegalStateException::new)
));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ private Pagination(Map<PaginationKey, Integer> pageData, int defaultMaxPageSize,
this.defaultPageSize = defaultPageSize;
}

/**
* Set limit.
*
* @param perPage page size.
*/
public void setLimit(Integer perPage) {
this.limit = perPage;
pageData.put(PaginationKey.limit, perPage);
}

public void setOffset(Integer offset) {
this.offset = offset;
pageData.put(PaginationKey.offset, offset);
}

/**
* TODO - Refactor Pagination.
* IMPORTANT - This method should only be used for testing until Pagination is refactored. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ private Map<String, EntityProjection> getSparseRelationships(Class<?> entityClas
.collect(Collectors.toMap(
Function.identity(),
(relationshipName) -> {

FilterExpression filter = scope.getExpressionForRelation(entityClass, relationshipName)
.orElse(null);

Expand Down Expand Up @@ -367,21 +366,18 @@ private Set<Path> getIncludePaths(Class<?> entityClass) {
.flatMap(param -> Arrays.stream(param.split(",")))
.map(pathString -> new Path(entityClass, dictionary, pathString))
.collect(Collectors.toSet());

}

return new HashSet<>();
}

private Set<Relationship> toRelationshipSet(Map<String, EntityProjection> relationships) {
return relationships.entrySet().stream()
.map(entry -> {
return Relationship.builder()
.name(entry.getKey())
.alias(entry.getKey())
.projection(entry.getValue())
.build();
})
.map(entry -> Relationship.builder()
.name(entry.getKey())
.alias(entry.getKey())
.projection(entry.getValue())
.build())
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void handle(StateContext state, SubCollectionReadCollectionContext ctx) {
} else {
entityName = dictionary.getJsonAliasFor(paramType);
entityClass = dictionary.getEntityClass(entityName);

}
if (entityClass == null) {
throw new IllegalArgumentException("Unknown type " + entityName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NonNull;

import java.util.LinkedHashSet;
Expand Down Expand Up @@ -122,9 +123,22 @@ public EntityProjection merge(EntityProjection toMerge) {
* Customizes the lombok builder to our needs.
*/
public static class EntityProjectionBuilder {
@Getter
private Class<?> type;

private Set<Relationship> relationships = new LinkedHashSet<>();

private Set<Attribute> attributes = new LinkedHashSet<>();

@Getter
private FilterExpression filterExpression;

@Getter
private Sorting sorting;

@Getter
private Pagination pagination;

public EntityProjectionBuilder relationships(Set<Relationship> relationships) {
this.relationships = relationships;
return this;
Expand Down Expand Up @@ -166,5 +180,18 @@ public EntityProjectionBuilder attribute(Attribute attribute) {
this.attributes.add(attribute);
return this;
}

/**
* Get an attribute by alias.
*
* @param attributeAlias alias to refer to an attribute field
* @return found attribute or null
*/
public Attribute getAttributeByAlias(String attributeAlias) {
return attributes.stream()
.filter(attribute -> attribute.getAlias().equals(attributeAlias))
.findAny()
.orElse(null);
}
}
}
Loading