Skip to content

Commit

Permalink
partial implementation of changes for #175
Browse files Browse the repository at this point in the history
  • Loading branch information
bluedevelz committed Jan 8, 2020
1 parent 9994bf6 commit 8f52539
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 io.leangen.graphql.annotations.GraphQLIgnore;

// @GraphQLIgnore
@GraphQLType(
name = "CustomPosition"
)

@JsonInclude(NON_EMPTY)
public class Position extends AbstractNestedDocument {
private String title;
private String[] type;

public Position() {
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}
public String[] getType() {
return type;
}

public void setType(String[] type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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.spqr.spring.annotations.GraphQLApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import edu.tamu.scholars.middleware.graphql.inert.model.person.Position;

import java.util.List;
import java.util.Optional;

@GraphQLApi
@Service
public class PositionResolver {
@Autowired
private IndividualRepo repo;

@Autowired
private ObjectMapper mapper;

@GraphQLQuery(name = "position")
// @formatter:off
public Position getById(
@GraphQLArgument(name = "id") String id,
@GraphQLEnvironment List<Field> fields
) {
// @formatter:on


Optional<Individual> position = repo.findById(id);
ObjectNode node = mapper.valueToTree(position);
System.out.println("**** NODE: " + node);
return mapper.convertValue(node, Position.class);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package edu.tamu.scholars.middleware.graphql.model;

import edu.tamu.scholars.middleware.graphql.model.Relationship;
import edu.tamu.scholars.middleware.graphql.model.person.Position;
import edu.tamu.scholars.middleware.graphql.model.person.ResearchArea;
import edu.tamu.scholars.middleware.graphql.model.person.GeographicFocus;
import edu.tamu.scholars.middleware.graphql.model.person.HeadOf;
Expand Down Expand Up @@ -55,7 +55,7 @@
public class Person extends AbstractNestedDocument {
private static final long serialVersionUID = -3444805L;

private List<Relationship> positions;
private List<Position> positions;

private List<ResearchArea> researchAreas;

Expand Down Expand Up @@ -214,11 +214,11 @@ public Person() {
super();
}

public List<Relationship> getPositions() {
public List<Position> getPositions() {
return positions;
}

public void setPositions(List<Relationship> positions) {
public void setPositions(List<Position> positions) {
this.positions = positions;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package edu.tamu.scholars.middleware.graphql.model.person;

import edu.tamu.scholars.middleware.graphql.model.person.PositionOrganization;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;

import com.fasterxml.jackson.annotation.JsonInclude;
import edu.tamu.scholars.middleware.graphql.model.AbstractNestedDocument;
import io.leangen.graphql.annotations.types.GraphQLType;
import java.lang.String;
import java.util.List;

/**
* This file is automatically generated on compile.
*
* Do not modify this file -- YOUR CHANGES WILL BE ERASED!
*/
@GraphQLType(
name = "PersonPosition"
)
@JsonInclude(NON_EMPTY)
public class Position extends AbstractNestedDocument {
private static final long serialVersionUID = -294827460L;

private String label;

private String type;

private List<PositionOrganization> organizations;

public Position() {
super();
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public List<PositionOrganization> getOrganizations() {
return organizations;
}

public void setOrganizations(List<PositionOrganization> organizations) {
this.organizations = organizations;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package edu.tamu.scholars.middleware.graphql.model.person;

import edu.tamu.scholars.middleware.graphql.model.person.PositionOrganizationParent;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;

import com.fasterxml.jackson.annotation.JsonInclude;
import edu.tamu.scholars.middleware.graphql.model.AbstractNestedDocument;
import io.leangen.graphql.annotations.types.GraphQLType;
import java.lang.String;
import java.util.List;

/**
* This file is automatically generated on compile.
*
* Do not modify this file -- YOUR CHANGES WILL BE ERASED!
*/
@GraphQLType(
name = "PersonPositionOrganization"
)
@JsonInclude(NON_EMPTY)
public class PositionOrganization extends AbstractNestedDocument {
private static final long serialVersionUID = -913043057L;

private String label;

private List<PositionOrganizationParent> parent;

public PositionOrganization() {
super();
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public List<PositionOrganizationParent> getParent() {
return parent;
}

public void setParent(List<PositionOrganizationParent> parent) {
this.parent = parent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.tamu.scholars.middleware.graphql.model.person;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;

import com.fasterxml.jackson.annotation.JsonInclude;
import edu.tamu.scholars.middleware.graphql.model.AbstractNestedDocument;
import io.leangen.graphql.annotations.types.GraphQLType;
import java.lang.String;

/**
* This file is automatically generated on compile.
*
* Do not modify this file -- YOUR CHANGES WILL BE ERASED!
*/
@GraphQLType(
name = "PersonPositionOrganizationParent"
)
@JsonInclude(NON_EMPTY)
public class PositionOrganizationParent extends AbstractNestedDocument {
private static final long serialVersionUID = -1355915495L;

private String label;

public PositionOrganizationParent() {
super();
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/graphql/composites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

- type: Person
references:
- name: positions
type: Relationship
# - name: positions
# type: Relationship
- name: publications
type: Document

Expand Down

0 comments on commit 8f52539

Please sign in to comment.