-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#175: add separate 'person2' model to mock-up position/organization a…
…s nested objects
- Loading branch information
Rob Nelson
committed
Jan 30, 2020
1 parent
e767e2a
commit 8fd749a
Showing
8 changed files
with
404 additions
and
3 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/main/java/edu/tamu/scholars/middleware/graphql/inert/model/person/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package edu.tamu.scholars.middleware.graphql.inert.model.person; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY; | ||
|
||
import java.util.List; | ||
|
||
import edu.tamu.scholars.middleware.discovery.model.Common; | ||
import edu.tamu.scholars.middleware.graphql.model.AbstractNestedDocument; | ||
import io.leangen.graphql.annotations.types.GraphQLType; | ||
import org.springframework.data.solr.core.mapping.Indexed; | ||
import org.springframework.data.solr.core.mapping.SolrDocument; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import edu.tamu.scholars.middleware.discovery.annotation.CollectionSource; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedMultiValuedProperty; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedObject; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedObject.Reference; | ||
import edu.tamu.scholars.middleware.discovery.annotation.PropertySource; | ||
|
||
import edu.tamu.scholars.middleware.graphql.inert.model.position.Organization; | ||
import io.leangen.graphql.annotations.GraphQLIgnore; | ||
|
||
// @GraphQLIgnore | ||
@GraphQLType( | ||
name = "CustomPerson" | ||
) | ||
|
||
@JsonInclude(NON_EMPTY) | ||
public class Person extends AbstractNestedDocument { | ||
private String name; | ||
private String[] type; | ||
private PositionStub[] positionStubs; | ||
|
||
public Person() { | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String[] getType() { | ||
return this.type; | ||
} | ||
|
||
public void setType(String[] type) { | ||
this.type = type; | ||
} | ||
|
||
@GraphQLIgnore | ||
public PositionStub[] getPositions() { | ||
return this.positionStubs; | ||
} | ||
|
||
@GraphQLIgnore | ||
public void setPositions(PositionStub[] pos) { | ||
this.positionStubs = pos; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/edu/tamu/scholars/middleware/graphql/inert/model/person/PositionStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package edu.tamu.scholars.middleware.graphql.inert.model.person; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY; | ||
|
||
import java.util.List; | ||
|
||
import edu.tamu.scholars.middleware.discovery.model.Common; | ||
import edu.tamu.scholars.middleware.graphql.model.AbstractNestedDocument; | ||
import io.leangen.graphql.annotations.types.GraphQLType; | ||
import org.springframework.data.solr.core.mapping.Indexed; | ||
import org.springframework.data.solr.core.mapping.SolrDocument; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import edu.tamu.scholars.middleware.discovery.annotation.CollectionSource; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedMultiValuedProperty; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedObject; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedObject.Reference; | ||
import edu.tamu.scholars.middleware.discovery.annotation.PropertySource; | ||
|
||
//import edu.tamu.scholars.middleware.graphql.inert.model.position.Organization; | ||
import edu.tamu.scholars.middleware.graphql.inert.model.position.OrganizationStub; | ||
|
||
import io.leangen.graphql.annotations.GraphQLIgnore; | ||
|
||
@GraphQLIgnore | ||
@JsonInclude(NON_EMPTY) | ||
public class PositionStub extends AbstractNestedDocument { | ||
private String id; | ||
private String label; | ||
private String[] type; | ||
private OrganizationStub[] organizations; | ||
|
||
public PositionStub() { | ||
} | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public void setLabel(String label) { | ||
this.label = label; | ||
} | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String[] getType() { | ||
return this.getType(); | ||
} | ||
|
||
public void setType(String[] type) { | ||
this.type = type; | ||
} | ||
|
||
public OrganizationStub[] getOrganizations() { | ||
return this.organizations; | ||
} | ||
|
||
public void setOrganizations(OrganizationStub[] orgs) { | ||
this.organizations = orgs; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/edu/tamu/scholars/middleware/graphql/inert/model/position/Organization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package edu.tamu.scholars.middleware.graphql.inert.model.position; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY; | ||
|
||
import java.util.List; | ||
|
||
import edu.tamu.scholars.middleware.discovery.model.Common; | ||
import edu.tamu.scholars.middleware.graphql.model.AbstractNestedDocument; | ||
import io.leangen.graphql.annotations.types.GraphQLType; | ||
import org.springframework.data.solr.core.mapping.Indexed; | ||
import org.springframework.data.solr.core.mapping.SolrDocument; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import edu.tamu.scholars.middleware.discovery.annotation.CollectionSource; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedMultiValuedProperty; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedObject; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedObject.Reference; | ||
import edu.tamu.scholars.middleware.discovery.annotation.PropertySource; | ||
// import io.leangen.graphql.annotations.GraphQLIgnore; | ||
|
||
// @GraphQLIgnore | ||
@GraphQLType( | ||
name = "CustomOrganization" | ||
) | ||
|
||
@JsonInclude(NON_EMPTY) | ||
public class Organization extends AbstractNestedDocument { | ||
private String name; | ||
private String[] type; | ||
|
||
public Organization() { | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String[] getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String[] type) { | ||
this.type = type; | ||
} | ||
|
||
// TODO: organizationWithin ... | ||
} |
58 changes: 58 additions & 0 deletions
58
...main/java/edu/tamu/scholars/middleware/graphql/inert/model/position/OrganizationStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package edu.tamu.scholars.middleware.graphql.inert.model.position; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY; | ||
|
||
import java.util.List; | ||
|
||
import edu.tamu.scholars.middleware.discovery.model.Common; | ||
import edu.tamu.scholars.middleware.graphql.model.AbstractNestedDocument; | ||
import io.leangen.graphql.annotations.types.GraphQLType; | ||
import org.springframework.data.solr.core.mapping.Indexed; | ||
import org.springframework.data.solr.core.mapping.SolrDocument; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import edu.tamu.scholars.middleware.discovery.annotation.CollectionSource; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedMultiValuedProperty; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedObject; | ||
import edu.tamu.scholars.middleware.discovery.annotation.NestedObject.Reference; | ||
import edu.tamu.scholars.middleware.discovery.annotation.PropertySource; | ||
|
||
import edu.tamu.scholars.middleware.graphql.inert.model.position.Organization; | ||
import io.leangen.graphql.annotations.GraphQLIgnore; | ||
|
||
@GraphQLIgnore | ||
@JsonInclude(NON_EMPTY) | ||
public class OrganizationStub extends AbstractNestedDocument { | ||
private String id; | ||
private String label; | ||
private String[] type; | ||
|
||
public OrganizationStub() { | ||
} | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getLabel() { | ||
return this.label; | ||
} | ||
|
||
public void setTitle(String label) { | ||
this.label = label; | ||
} | ||
|
||
public String[] getType() { | ||
return this.type; | ||
} | ||
|
||
public void setType(String[] type) { | ||
this.type = type; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/edu/tamu/scholars/middleware/graphql/inert/service/OrganizationResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package edu.tamu.scholars.middleware.graphql.inert.service; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import edu.tamu.scholars.middleware.discovery.model.Individual; | ||
import edu.tamu.scholars.middleware.discovery.model.repo.IndividualRepo; | ||
// import edu.tamu.scholars.middleware.graphql.model.Collection; | ||
import graphql.language.Field; | ||
import io.leangen.graphql.annotations.GraphQLArgument; | ||
import io.leangen.graphql.annotations.GraphQLEnvironment; | ||
import io.leangen.graphql.annotations.GraphQLQuery; | ||
import io.leangen.graphql.annotations.GraphQLContext; | ||
import io.leangen.graphql.spqr.spring.annotations.GraphQLApi; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import edu.tamu.scholars.middleware.graphql.inert.model.position.Organization; | ||
import edu.tamu.scholars.middleware.graphql.inert.model.position.OrganizationStub; | ||
import edu.tamu.scholars.middleware.graphql.inert.model.person.Position; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@GraphQLApi | ||
@Service | ||
public class OrganizationResolver { | ||
@Autowired | ||
private IndividualRepo repo; | ||
|
||
@Autowired | ||
private ObjectMapper mapper; | ||
|
||
@GraphQLQuery(name = "organization") | ||
// @formatter:off | ||
public Organization getById( | ||
@GraphQLArgument(name = "id") String id, | ||
@GraphQLEnvironment List<Field> fields | ||
) { | ||
// @formatter:on | ||
|
||
|
||
Optional<Individual> organization = repo.findById(id); | ||
ObjectNode node = mapper.valueToTree(organization); | ||
System.out.println("**** NODE: " + node); | ||
return mapper.convertValue(node, Organization.class); | ||
} | ||
|
||
|
||
|
||
@GraphQLQuery | ||
public Organization[] organizations(@GraphQLContext Position position) { | ||
OrganizationStub[] organizations = position.getOrganization(); | ||
Organization[] list = new Organization[organizations.length]; | ||
|
||
for (int i = 0; i < organizations.length; i++) { | ||
OrganizationStub orgStub = organizations[i]; | ||
Optional<Individual> org = repo.findById(orgStub.getId()); | ||
ObjectNode node = mapper.valueToTree(org); | ||
System.out.println("**** NODE: " + node); | ||
Organization real = mapper.convertValue(node, Organization.class); | ||
list[i] = real; | ||
} | ||
return list; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.