-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added event mock objects and some new data model object and services
- Loading branch information
1 parent
85a8196
commit 32a2419
Showing
7 changed files
with
404 additions
and
7 deletions.
There are no files selected for viewing
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
119 changes: 113 additions & 6 deletions
119
...phql-impl/src/main/java/org/oasis_open/contextserver/graphql/CXSEventGraphQLProvider.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 |
---|---|---|
@@ -1,53 +1,160 @@ | ||
package org.oasis_open.contextserver.graphql; | ||
|
||
import graphql.Scalars; | ||
import graphql.schema.*; | ||
import graphql.servlet.GraphQLQueryProvider; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static graphql.Scalars.GraphQLID; | ||
import static graphql.Scalars.GraphQLLong; | ||
import static graphql.Scalars.GraphQLString; | ||
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; | ||
import static graphql.schema.GraphQLObjectType.newObject; | ||
import static graphql.schema.GraphQLArgument.newArgument; | ||
|
||
/** | ||
* Created by loom on 20.04.17. | ||
*/ | ||
@Component( | ||
name="CXSEventGraphQLProvider", | ||
immediate=true | ||
name = "CXSEventGraphQLProvider", | ||
immediate = true | ||
) | ||
public class CXSEventGraphQLProvider implements GraphQLQueryProvider { | ||
|
||
private EventService eventService; | ||
|
||
private static GraphQLObjectType CXSProperties = newObject() | ||
.name("Properties") | ||
.description("Generic key-value (string,string) properties") | ||
.field(newFieldDefinition() | ||
.type(GraphQLID) | ||
.name("key") | ||
.description("A unique identifier for the property") | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
Map.Entry<Object,Object> propertyEntry = environment.getSource(); | ||
return propertyEntry.getKey(); | ||
} | ||
}) | ||
) | ||
.field(newFieldDefinition() | ||
.type(GraphQLID) | ||
.name("value") | ||
.description("A value for the property") | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
Map.Entry<Object,Object> propertyEntry = environment.getSource(); | ||
return propertyEntry.getValue(); | ||
} | ||
}) | ||
) | ||
.build(); | ||
|
||
private static GraphQLObjectType CXSGraphQLEvent = newObject() | ||
.name("Event") | ||
.description("An event is generated by user interacting with the Context Server") | ||
.field(newFieldDefinition() | ||
.type(GraphQLID) | ||
.name("id") | ||
.staticValue("eventId") | ||
.description("A unique identifier for the event") | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
Event event = environment.getSource(); | ||
return event.getId(); | ||
} | ||
}) | ||
) | ||
.field(newFieldDefinition() | ||
.type(GraphQLString) | ||
.name("eventType") | ||
.staticValue("pageView") | ||
).build(); | ||
.description("An identifier for the event type") | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
Event event = environment.getSource(); | ||
return event.getEventType(); | ||
} | ||
}) | ||
) | ||
.field(newFieldDefinition() | ||
.type(GraphQLLong) | ||
.name("timestamp") | ||
.description("The difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.") | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
Event event = environment.getSource(); | ||
return event.getTimestamp(); | ||
} | ||
})) | ||
.field(newFieldDefinition() | ||
.type(GraphQLString) | ||
.name("subject") | ||
.description("The entity that has fired the event (using the profile)") | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
Event event = environment.getSource(); | ||
return event.getSubject(); | ||
} | ||
})) | ||
.field(newFieldDefinition() | ||
.type(GraphQLString) | ||
.name("object") | ||
.description("The object on which the event was fired.") | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
Event event = environment.getSource(); | ||
return event.getObject(); | ||
} | ||
}) | ||
) | ||
.field(newFieldDefinition() | ||
.type(new GraphQLList(CXSProperties)) | ||
.name("properties") | ||
.description("Generic properties for the event") | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
Event event = environment.getSource(); | ||
return new ArrayList<Map.Entry<Object,Object>>(event.getProperties().entrySet()); | ||
} | ||
}) | ||
) | ||
.build(); | ||
|
||
@Reference | ||
public void setEventService(EventService eventService) { | ||
this.eventService = eventService; | ||
} | ||
|
||
public Collection<GraphQLFieldDefinition> getQueries() { | ||
List<GraphQLFieldDefinition> fieldDefinitions = new ArrayList<GraphQLFieldDefinition>(); | ||
fieldDefinitions.add( | ||
newFieldDefinition() | ||
.name("events") | ||
.type(new GraphQLList(CXSGraphQLEvent)) | ||
.argument(newArgument().name("offset").type(Scalars.GraphQLLong).build()) | ||
.argument(newArgument().name("pageSize").type(Scalars.GraphQLLong).build()) | ||
.dataFetcher(new DataFetcher() { | ||
public Object get(DataFetchingEnvironment environment) { | ||
return null; | ||
Long offset = environment.getArgument("offset"); | ||
if (offset == null) { | ||
offset = 0L; | ||
} | ||
; | ||
Long pageSize = environment.getArgument("pageSize"); | ||
if (pageSize == null) { | ||
pageSize = 50L; | ||
} | ||
return eventService.getEvents(offset, pageSize); | ||
} | ||
}) | ||
.build()); | ||
return fieldDefinitions; | ||
} | ||
|
||
|
||
} |
77 changes: 77 additions & 0 deletions
77
java/bundles/graphql-impl/src/main/java/org/oasis_open/contextserver/graphql/Event.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,77 @@ | ||
package org.oasis_open.contextserver.graphql; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* Created by loom on 04.05.17. | ||
*/ | ||
public class Event { | ||
private String id; | ||
private Long timestamp; | ||
private String eventType; | ||
|
||
private String subject; // e.g. profileId | ||
private String object; // e.g. page | ||
|
||
private Properties properties; | ||
|
||
public Event() { | ||
} | ||
|
||
public Event(String id, Long timestamp, String eventType, String subject, String object, Properties properties) { | ||
this.id = id; | ||
this.timestamp = timestamp; | ||
this.eventType = eventType; | ||
this.subject = subject; | ||
this.object = object; | ||
this.properties = properties; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public void setTimestamp(Long timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
public String getEventType() { | ||
return eventType; | ||
} | ||
|
||
public void setEventType(String eventType) { | ||
this.eventType = eventType; | ||
} | ||
|
||
public String getSubject() { | ||
return subject; | ||
} | ||
|
||
public void setSubject(String subject) { | ||
this.subject = subject; | ||
} | ||
|
||
public String getObject() { | ||
return object; | ||
} | ||
|
||
public void setObject(String object) { | ||
this.object = object; | ||
} | ||
|
||
public Properties getProperties() { | ||
return properties; | ||
} | ||
|
||
public void setProperties(Properties properties) { | ||
this.properties = properties; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...bundles/graphql-impl/src/main/java/org/oasis_open/contextserver/graphql/EventService.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,10 @@ | ||
package org.oasis_open.contextserver.graphql; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by loom on 04.05.17. | ||
*/ | ||
public interface EventService { | ||
public List<Event> getEvents(long offset, long pageSize); | ||
} |
Oops, something went wrong.