├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── graph-client-impl-provider-dse
├── .gitignore
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── intuit
│ │ └── ugc
│ │ └── impl
│ │ └── persistence
│ │ └── dse
│ │ ├── DSEConnectionManager.java
│ │ ├── DSEGraphSession.java
│ │ ├── DSEGraphVisitor.java
│ │ ├── DSEMetadata.java
│ │ ├── DSEPersistence.java
│ │ ├── DSEPersistenceConfiguration.java
│ │ ├── DSEPersistenceConfigurationProperties.java
│ │ ├── DSEPersistenceModule.java
│ │ ├── DSEPersistenceRepositoryProvider.java
│ │ ├── GraphCallBack.java
│ │ ├── GraphEntityOperations.java
│ │ ├── GraphOperations.java
│ │ └── GraphRelationshipOperations.java
│ └── test
│ ├── java
│ └── com
│ │ └── intuit
│ │ └── ugc
│ │ └── impl
│ │ └── persistence
│ │ ├── DSEGraphTestConstants.java
│ │ ├── DSETestQueries.java
│ │ ├── UGCDSETestBase.java
│ │ └── dse
│ │ ├── DSEConnectionManagerTest.java
│ │ ├── DSEGraphSessionTest.java
│ │ ├── DSEGraphTest.java
│ │ ├── DSEGraphVisitorTest.java
│ │ ├── DSEMetadataTest.java
│ │ ├── DSEPersistenceConfigurationTest.java
│ │ ├── DSEPersistenceRepositoryProviderTest.java
│ │ ├── DSEPersistenceTest.java
│ │ ├── DSETestModule.java
│ │ ├── GraphCallbackTest.java
│ │ ├── GraphEntityOperationsTest.java
│ │ └── helper
│ │ ├── DSEConfigurationMock.java
│ │ └── DSEConnectionManagerMock.java
│ └── resource
│ ├── graph_client_dse_test.properties
│ └── logback.xml
├── pom.xml
├── universal-graph-client-api
├── .gitignore
├── Jenkinsfile
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── intuit
│ │ └── ugc
│ │ └── api
│ │ ├── AbstractQualifiedName.java
│ │ ├── AbstractValueSpecifier.java
│ │ ├── AccessControlException.java
│ │ ├── AccessToken.java
│ │ ├── Attribute.java
│ │ ├── BatchMutation.java
│ │ ├── Entity.java
│ │ ├── InvalidAttributeException.java
│ │ ├── InvalidFormatException.java
│ │ ├── NewEntity.java
│ │ ├── NewRelationship.java
│ │ ├── OperationResult.java
│ │ ├── Persistence.java
│ │ ├── PersistenceException.java
│ │ ├── Predicate.java
│ │ ├── Queries.java
│ │ ├── Query.java
│ │ ├── Relationship.java
│ │ ├── ValueSpecifier.java
│ │ └── mogwai
│ │ ├── Gizmo.java
│ │ ├── GizmoPipeline.java
│ │ ├── GizmoPredicate.java
│ │ └── GizmoQuery.java
│ └── test
│ └── java
│ └── com
│ └── intuit
│ └── ugc
│ └── api
│ ├── AbstractQualifiedNameTest.java
│ ├── AbstractValueSpecifierTest.java
│ ├── AccessControlExceptionTest.java
│ ├── AccessTokenTest.java
│ ├── AttributeTest.java
│ ├── GraphTraversalTest.java
│ ├── InvalidAttributeExceptionTest.java
│ ├── InvalidFormatExceptionTest.java
│ ├── NewEntityTest.java
│ ├── NewRelationshipTest.java
│ ├── PersistenceExceptionTest.java
│ ├── PersistenceImpl.java
│ ├── ValueBuilder.java
│ ├── helper
│ ├── MockAccessToken.java
│ ├── MockEntity.java
│ └── QualifiedName.java
│ └── mogwai
│ └── GizmoTest.java
└── universal-graph-client-impl-core
├── .gitignore
├── Jenkinsfile
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── intuit
│ │ └── ugc
│ │ └── impl
│ │ └── core
│ │ ├── AbstractGraphPersistence.java
│ │ ├── GraphAttribute.java
│ │ ├── GraphAttributeOperations.java
│ │ ├── GraphEntity.java
│ │ ├── GraphEntityMutation.java
│ │ ├── GraphLookUpQuery.java
│ │ ├── GraphMutation.java
│ │ ├── GraphMutationResult.java
│ │ ├── GraphPredicate.java
│ │ ├── GraphProjection.java
│ │ ├── GraphQueryImpl.java
│ │ ├── GraphQueryResult.java
│ │ ├── GraphRelationship.java
│ │ ├── GraphRelationshipMutation.java
│ │ ├── InstantTypeConversion.java
│ │ ├── UUIDTypeConversion.java
│ │ ├── VisitOperationResult.java
│ │ ├── predicate
│ │ ├── AndPredicate.java
│ │ ├── CompoundPredicate.java
│ │ ├── EqualToPredicate.java
│ │ ├── OrPredicate.java
│ │ ├── StreamComparison.java
│ │ ├── StreamPredicate.java
│ │ ├── StreamPredicateBuilder.java
│ │ └── StreamPredicates.java
│ │ ├── queryplan
│ │ ├── ContextOperation.java
│ │ ├── MutationExecutorFactory.java
│ │ ├── Operation.java
│ │ ├── OperationFeeder.java
│ │ ├── OperationFeederImpl.java
│ │ ├── OperationIterator.java
│ │ ├── OperationList.java
│ │ ├── OperationPipeline.java
│ │ ├── TerminalOperation.java
│ │ └── operations
│ │ │ ├── CreateEntity.java
│ │ │ ├── CreateRelationship.java
│ │ │ ├── DeleteEntity.java
│ │ │ ├── DeleteRelationship.java
│ │ │ ├── GetBatchEntityByID.java
│ │ │ ├── GetEntityByID.java
│ │ │ ├── GetEntityByProperty.java
│ │ │ ├── GraphTerminalOperation.java
│ │ │ ├── SelectEntities.java
│ │ │ ├── SelectRelationships.java
│ │ │ ├── UpdateEntity.java
│ │ │ └── UpdateRelationship.java
│ │ └── spi
│ │ ├── GraphVisitor.java
│ │ ├── QueryResult.java
│ │ ├── QueryResultImpl.java
│ │ └── RepositoryException.java
└── resources
│ └── logback.xml
└── test
├── java
└── com
│ └── intuit
│ └── ugc
│ └── impl
│ └── core
│ ├── AbstractGraphPersistenceTest.java
│ ├── GraphAttributeOperationsTest.java
│ ├── GraphAttributeTest.java
│ ├── GraphEntityMutationTest.java
│ ├── GraphEntityTest.java
│ ├── GraphLookupQueryTest.java
│ ├── GraphMutationResultTest.java
│ ├── GraphMutationTest.java
│ ├── GraphPredicateTest.java
│ ├── GraphProjectionTest.java
│ ├── GraphQueryImplTest.java
│ ├── GraphRelationshipMutationTest.java
│ ├── GraphRelationshipTest.java
│ ├── InstantTypeConversionTest.java
│ ├── TestGraphQueryResult.java
│ ├── UUIDTypeConversionTest.java
│ ├── helper
│ ├── MockBatchMutation.java
│ ├── MockGraphPersistence.java
│ ├── MockGraphVisitor.java
│ ├── MockMetadata.java
│ ├── MockMutationExecuterFactory.java
│ ├── TartanImplTestConstants.java
│ └── TartanImplTestUtil.java
│ ├── predicate
│ ├── AndPredicateTest.java
│ ├── EqualToPredicateTest.java
│ ├── OrPredicateTest.java
│ ├── StreamComparisonTest.java
│ ├── StreamPredicateBuilderTest.java
│ └── StreamPredicatesTest.java
│ ├── queryplan
│ ├── OperationFeederImplTest.java
│ ├── OperationPipelineTest.java
│ └── operations
│ │ ├── CreateEntityTest.java
│ │ ├── CreateRelationshipTest.java
│ │ ├── DeleteEntityTest.java
│ │ ├── DeleteRelationshipTest.java
│ │ ├── GetBatchEntityByIdTest.java
│ │ ├── GetEntityByIdTest.java
│ │ ├── GetEntityByPropertyTest.java
│ │ ├── GraphTerminalOperationTest.java
│ │ ├── SelectEntitiesTest.java
│ │ ├── SelectRelationshipTest.java
│ │ ├── UpdateEntityTest.java
│ │ └── UpdateRelationshipTest.java
│ └── spi
│ ├── QueryResultImplUnitTest.java
│ └── RepositoryExceptionTest.java
└── resources
├── logback.xml
└── testng.xml
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to coding
2 |
3 | If you're reading this, you're awesome! Thank you for helping us make this project great and being a part of the coding community. Here are a few guidelines that will help you along the way.
4 | Code of Conduct
5 |
6 | Steps to contribute:
7 |
8 | 1. Fork this repository into your account on Github
9 | 2. Clone your forked repository (not our original one) to your hard drive with git clone https://github.com/YOURUSERNAME/universal-graph-client.git
10 | 3. Design and develop your changes
11 | 4. Add/update unit tests
12 | 5. Add/update integration tests
13 | 6. Add/update documentation on gh-pages branch
14 | 7. Create a pull request for review to request merge
15 |
16 | THANK YOU!
17 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/README.md:
--------------------------------------------------------------------------------
1 | # Graph Client DSE Provider
2 |
3 | This is a specific provider for DSE Graph. Look at the `com.intuit.ugc.impl.persistence.dse.DSEGraphVisitor` class to understand how the implementation for all the different graph operations are done. Each of the API here is specific to one operation that can be done over the underlying DSE Graph database. Currently, create, select, update and delete operations are supported for both vertices and edges.
4 |
5 | ### Initializing Graph Client DSE Provider
6 | To see how to inject your specific dependencies and initialize the Graph Client DSE Provider, check the details in the class `com.intuit.ugc.impl.persistence.UGCDSETestBase`. The connection specific properties for connecting with DSE persistence store can be found at `/src/test/resource/graph_client_dse_test.properties`. Similarly, the user can have their own properties file placed in their project as applicable. Reference `com.intuit.ugc.impl.persistence.dse.DSETestModule` to see how this file is read and the configs loaded. The user should have an equivalent of this class in their project.
7 |
8 | ### Using Graph Client DSE Provider
9 | For details on how to use the Graph Client DSE Provider, look at the tests in `com.intuit.ugc.impl.persistence.dse.DSEGraphTest`. The tests here create a simple `author` Vertex and a `book` Vertex with their own specific properties and then create an `authored` relationship between these two vertices, all using the `com.intuit.ugc.impl.persistence.dse.DSEGraphVisitor` APIs. The user can have one or more equivalent of the implementation in this test class to run operations over underlying DSE persistence store.
10 |
11 | ### Integration
12 | Universal Graph Client DSE provider is readily embeddable via the following maven dependency:
13 | ```xml
14 |
15 | com.intuit.graph.client.impl
16 | graph-client-impl-provider-dse
17 | 1.0-SNAPSHOT
18 | ```
19 |
20 | However, to get working with this provider, you need to modify it's pom.xml file, and include the following data stax dependency in the pom.xml file and then compile the module once.
21 | ```xml
22 |
23 | com.datastax.cassandra
24 | dse-driver
25 | 1.1.0
26 |
27 | ````
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/main/java/com/intuit/ugc/impl/persistence/dse/DSEConnectionManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import javax.inject.Inject;
15 |
16 | import com.datastax.driver.dse.graph.SimpleGraphStatement;
17 |
18 | /**
19 | * A connection manager that wraps up the underlying DSE connection. Also
20 | * contains API to create and return a
21 | * {@link com.datastax.driver.dse.graph.SimpleGraphStatement} to the caller and
22 | * one to create and return a
23 | * {@link com.intuit.ugc.impl.persistence.dse.DSEGraphSession} instance
24 | *
25 | * @author nverma1
26 | *
27 | */
28 | public class DSEConnectionManager {
29 | private DSEPersistenceConfiguration config;
30 |
31 | @Inject
32 | public DSEConnectionManager(DSEPersistenceConfiguration config) {
33 | this.config = config;
34 | }
35 |
36 | /**
37 | * From the string passed, a
38 | * {@link com.datastax.driver.dse.graph.SimpleGraphStatement} is created and
39 | * returned to the caller for execution
40 | *
41 | * @param cmd
42 | * a String representing a valid gremlin query.
43 | * @return A {@link com.datastax.driver.dse.graph.SimpleGraphStatement}
44 | */
45 | public SimpleGraphStatement getStatement(String cmd) {
46 | SimpleGraphStatement sVertexStatement = new SimpleGraphStatement(cmd);
47 | sVertexStatement.setGraphName(config.getGraph());
48 | return sVertexStatement;
49 | }
50 |
51 | /**
52 | * returns a {@link com.intuit.ugc.impl.persistence.dse.DSEGraphSession}
53 | * object. This session is required to run all DSE graph queries over it.
54 | *
55 | * @return {@link com.intuit.ugc.impl.persistence.dse.DSEGraphSession}
56 | */
57 | public DSEGraphSession getDSEGraphSession() {
58 | return new DSEGraphSession(config);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/main/java/com/intuit/ugc/impl/persistence/dse/DSEGraphSession.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import com.datastax.driver.dse.DseCluster;
15 | import com.datastax.driver.dse.DseSession;
16 |
17 | /**
18 | * This class provides functionality to connect DSE Graph
19 | *
20 | * @author nverma1
21 | *
22 | */
23 | public class DSEGraphSession {
24 | private DseCluster dseCluster = null;
25 | private DseSession dseSession = null;
26 |
27 | /**
28 | * Constructor
29 | *
30 | * @param config
31 | */
32 | public DSEGraphSession(DSEPersistenceConfiguration config) {
33 | init(config);
34 | }
35 |
36 | /**
37 | * Initilizes the dse cluster and session.
38 | * Scope is protected to enable mocking this during testing.
39 | * @param config
40 | */
41 | protected void init(DSEPersistenceConfiguration config){
42 | dseCluster = DseCluster.builder().addContactPoint(config.getHost()).withPort(config.getPort()).build();
43 | dseSession = dseCluster.connect();
44 | }
45 |
46 | /**
47 | * Get DSESession
48 | *
49 | * @return
50 | */
51 | public DseSession getSession() {
52 | return dseSession;
53 | }
54 |
55 | /**
56 | * Close connection
57 | */
58 | public void closeConnections() {
59 | if (dseSession != null) {
60 | dseSession.close();
61 | dseSession = null;
62 | }
63 | if (dseCluster != null) {
64 | dseCluster.close();
65 | dseCluster = null;
66 | }
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/main/java/com/intuit/ugc/impl/persistence/dse/DSEMetadata.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import com.intuit.ugc.api.Attribute.Metadata;
15 |
16 | /**
17 | * Represents Metadata stored specific to data stored in DSE graph persistence store.
18 | *
19 | * @author nverma1
20 | *
21 | * @param
22 | */
23 | public class DSEMetadata implements Metadata {
24 | public DSEMetadata(Class type) {
25 | super();
26 | this.type = type;
27 | }
28 |
29 | public Class getType() {
30 | return this.type;
31 | }
32 |
33 | private final Class type;
34 | }
35 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/main/java/com/intuit/ugc/impl/persistence/dse/DSEPersistence.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import com.google.inject.Inject;
15 | import com.intuit.ugc.impl.core.AbstractGraphPersistence;
16 | import com.intuit.ugc.impl.core.queryplan.MutationExecutorFactory;
17 | import com.intuit.ugc.impl.core.spi.GraphVisitor;
18 |
19 | /**
20 | * represents a DSE Graph Persistence
21 | *
22 | * is initialized with a {@link com.intuit.ugc.impl.core.spi.GraphVisitor}
23 | * instance specific to DSE and a
24 | * {@link com.intuit.ugc.impl.core.queryplan.MutationExecutorFactory}
25 | *
26 | * @author nverma1
27 | *
28 | */
29 | public class DSEPersistence extends AbstractGraphPersistence {
30 |
31 | @Inject
32 | public DSEPersistence(GraphVisitor repository, MutationExecutorFactory factory) {
33 | super(repository, factory);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/main/java/com/intuit/ugc/impl/persistence/dse/DSEPersistenceConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import com.intuit.ugc.api.Persistence;
15 |
16 | /**
17 | * Represents the configurations specific to the DSE persistence store to which
18 | * this library will connect
19 | *
20 | * @author nverma1
21 | *
22 | */
23 | public interface DSEPersistenceConfiguration extends Persistence.Configuration {
24 |
25 | public String getPersistenceRepository();
26 |
27 | public String getHost();
28 |
29 | public int getPort();
30 |
31 | public String getGraph();
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/main/java/com/intuit/ugc/impl/persistence/dse/DSEPersistenceModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import static java.util.Objects.nonNull;
15 |
16 | import javax.inject.Singleton;
17 |
18 | import com.google.inject.AbstractModule;
19 | import com.google.inject.assistedinject.FactoryModuleBuilder;
20 | import com.intuit.ugc.api.Persistence;
21 | import com.intuit.ugc.impl.core.queryplan.MutationExecutorFactory;
22 | import com.intuit.ugc.impl.core.spi.GraphVisitor;
23 |
24 | /**
25 | * The module responsible for initializing with the DSE store specific configs
26 | * and bootstrapping the system.
27 | *
28 | * @author nverma1
29 | *
30 | */
31 | public class DSEPersistenceModule extends AbstractModule {
32 | private DSEPersistenceConfiguration configuration;
33 |
34 | public DSEPersistenceModule() {
35 | super();
36 | }
37 |
38 | public DSEPersistenceModule(DSEPersistenceConfiguration config) {
39 | this();
40 | this.configuration = config;
41 | }
42 |
43 | @Override
44 | protected void configure() {
45 | if ( nonNull(configuration) ) {
46 | bind(Persistence.Configuration.class).toInstance(configuration);
47 | bind(DSEPersistenceConfiguration.class).toInstance(configuration);
48 | }
49 |
50 | requireBinding(Persistence.Configuration.class);
51 | install(new FactoryModuleBuilder().build(MutationExecutorFactory.class));
52 | bind(GraphVisitor.class).toProvider(DSEPersistenceRepositoryProvider.class).in(Singleton.class);
53 | bind(Persistence.class).to(DSEPersistence.class);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/main/java/com/intuit/ugc/impl/persistence/dse/DSEPersistenceRepositoryProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import com.google.inject.Inject;
15 | import com.google.inject.Provider;
16 |
17 | /**
18 | * Repository provider that is initialized with repository specific connection manager
19 | *
20 | * @author nverma1
21 | *
22 | */
23 | public class DSEPersistenceRepositoryProvider implements Provider {
24 |
25 | DSEConnectionManager manager;
26 |
27 | @Inject
28 | public DSEPersistenceRepositoryProvider(DSEConnectionManager manager) {
29 | this.manager = manager;
30 | }
31 |
32 | @Override
33 | public DSEGraphVisitor get() {
34 | return new DSEGraphVisitor(this.manager);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/main/java/com/intuit/ugc/impl/persistence/dse/GraphCallBack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import com.datastax.driver.dse.graph.GraphResultSet;
15 | import com.google.common.util.concurrent.FutureCallback;
16 |
17 | /**
18 | * Graph Callback object used for the graph query executed in async mode. Since
19 | * execution over DSE graph is much faster in async mode.
20 | *
21 | * @author nverma1
22 | *
23 | */
24 | public class GraphCallBack implements FutureCallback {
25 | private GraphResultSet result = null;
26 | private Throwable th = null;
27 |
28 | public void onSuccess(GraphResultSet result) {
29 | this.result = result;
30 | }
31 |
32 | public void onFailure(Throwable t) {
33 | this.th = t;
34 | }
35 |
36 | public GraphResultSet getResult() {
37 | return result;
38 | }
39 |
40 | public Throwable getTh() {
41 | return th;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/DSEGraphTestConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence;
13 |
14 | import com.intuit.ugc.api.Attribute;
15 |
16 | /**
17 | *
18 | * @author nverma1
19 | *
20 | */
21 | public class DSEGraphTestConstants {
22 | public static final Attribute.Name ATTR_DUMMY_ENTITY_KEY = Attribute.Name.valueOf("dse.dummy.entity.ID");
23 | public static final Attribute.Name ATTR_COMPANY_ID = Attribute.Name.valueOf("company.Id");
24 | public static final Attribute.Name ATTR_CUSTOMER_ID = Attribute.Name.valueOf("customer.Id");
25 | public static final Attribute.Name ATTR_COMPANY_NAME = Attribute.Name.valueOf("person.DisplayName");
26 | public static final Attribute.Name ATTR_COMPANY_CREATE_DATE = Attribute.Name.valueOf("company.Createdate");
27 | public static final Attribute.Name ATTR_PERSON_EMAIL = Attribute.Name.valueOf("person.Email");
28 | public static final Attribute.Name ATTR_PERSON_FULL_NAME = Attribute.Name.valueOf("person.FullName");
29 | public static final Attribute.Name ATTR_CUSTOMER_SINCE = Attribute.Name.valueOf("customer.CustomerSince");
30 | }
31 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/DSETestQueries.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence;
13 |
14 | import java.util.Map;
15 | import java.util.UUID;
16 |
17 | import com.intuit.ugc.api.Attribute;
18 | import com.intuit.ugc.api.Entity;
19 | import com.intuit.ugc.api.NewEntity;
20 | import com.intuit.ugc.api.NewRelationship;
21 | import com.intuit.ugc.api.Relationship;
22 | import com.intuit.ugc.api.NewEntity.Builder;
23 |
24 | /**
25 | *
26 | * @author nverma1
27 | *
28 | */
29 | public class DSETestQueries {
30 |
31 | public static NewEntity createNewEntity(String entityName, Mapattributes) {
32 | Attribute.Name entityKey = Attribute.Name.valueOf(entityName);
33 | Entity.ID newEntityID = Entity.ID
34 | .valueOf(entityKey.getName() + "/" + UUID.randomUUID());
35 |
36 | Builder entityBuilder = NewEntity.newInstance(newEntityID);
37 | if(attributes != null && !attributes.isEmpty()){
38 | for(String attributeKey : attributes.keySet()){
39 | Attribute.Name attrName = Attribute.Name.valueOf(attributeKey);
40 | entityBuilder = entityBuilder.withAttribute(attrName).value(attributes.get(attributeKey));
41 | }
42 | }
43 |
44 | NewEntity newEntity = entityBuilder.build();
45 | return newEntity;
46 | }
47 |
48 | public static NewRelationship createNewRelationship(String relationshipName,
49 | Map edgeAttributesMap, Entity.ID sourceEntityId, Entity.ID targetEntityId) {
50 | Relationship.Name relationshipLabel = Relationship.Name.valueOf(relationshipName);
51 | com.intuit.ugc.api.NewRelationship.Builder builder = NewRelationship.between(sourceEntityId, targetEntityId);
52 | for(String attrStr : edgeAttributesMap.keySet()){
53 | Attribute.Name attrName = Attribute.Name.valueOf(attrStr);
54 | builder = builder.withAttribute(attrName).value(edgeAttributesMap.get(attrStr));
55 | }
56 | NewRelationship newRelationship = builder.withLabel(relationshipLabel).build();
57 |
58 | return newRelationship;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/UGCDSETestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence;
13 |
14 | import com.google.inject.Guice;
15 | import com.google.inject.Injector;
16 | import com.intuit.ugc.api.Persistence;
17 | import com.intuit.ugc.impl.core.spi.GraphVisitor;
18 | import com.intuit.ugc.impl.persistence.dse.DSEPersistenceModule;
19 | import com.intuit.ugc.impl.persistence.dse.DSETestModule;
20 |
21 | /**
22 | *
23 | * @author nverma1
24 | *
25 | */
26 | public class UGCDSETestBase {
27 |
28 | public static Persistence persistence = null;
29 | public static GraphVisitor repository = null;
30 |
31 | static {
32 | try {
33 | Injector injector = Guice.createInjector(new DSETestModule(), new DSEPersistenceModule());
34 | repository = injector.getInstance(GraphVisitor.class);
35 | persistence = injector.getInstance(Persistence.class);
36 | }
37 | catch (Exception e) {
38 | e.printStackTrace();
39 | throw e;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/DSEConnectionManagerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import static org.testng.Assert.assertNotNull;
15 |
16 | import org.testng.AssertJUnit;
17 | import org.testng.annotations.Test;
18 |
19 | import com.datastax.driver.dse.graph.SimpleGraphStatement;
20 | import com.intuit.ugc.impl.persistence.dse.helper.DSEConfigurationMock;
21 |
22 | import mockit.Mocked;
23 |
24 | /**
25 | *
26 | * @author nverma1
27 | *
28 | */
29 | public class DSEConnectionManagerTest {
30 | @Mocked DSEGraphSession dseGraphSession;
31 |
32 | @Test
33 | public void testGetStatement(){
34 | DSEConfigurationMock config = new DSEConfigurationMock();
35 | DSEConnectionManager dseConnectionManager = new DSEConnectionManager(config);
36 | SimpleGraphStatement statement = dseConnectionManager.getStatement("mock-command");
37 |
38 | AssertJUnit.assertNotNull(statement);
39 | AssertJUnit.assertEquals(statement.getGraphName(), config.getGraph());
40 | assertNotNull(dseConnectionManager.getDSEGraphSession());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/DSEGraphSessionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import static org.testng.Assert.assertEquals;
15 | import static org.testng.Assert.assertNotNull;
16 | import static org.testng.Assert.fail;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import com.datastax.driver.dse.DseCluster;
21 | import com.datastax.driver.dse.DseCluster.Builder;
22 | import com.datastax.driver.dse.DseSession;
23 | import com.intuit.ugc.impl.persistence.dse.helper.DSEConfigurationMock;
24 |
25 | import mockit.Expectations;
26 | import mockit.Mocked;
27 |
28 | /**
29 | *
30 | * @author nverma1
31 | *
32 | */
33 | public class DSEGraphSessionTest {
34 | @Mocked DseCluster dseCluster;
35 | @Mocked DseSession dseSession;
36 | @Mocked Builder builder;
37 |
38 | @Test
39 | public void testCreateDSESession(){
40 | DSEConfigurationMock config = new DSEConfigurationMock();
41 |
42 | new Expectations() {{
43 | dseCluster.builder();result = builder;
44 | builder.addContactPoint(config.getHost());result=builder;
45 | builder.withPort(config.getPort()); result = builder;
46 | builder.build();result=dseCluster;
47 | dseCluster.connect();result = dseSession;
48 | dseSession.close();
49 | dseCluster.close();
50 | }};
51 |
52 | DSEGraphSession dseGraphSession = new DSEGraphSession(config);
53 | assertNotNull(dseGraphSession);
54 | assertEquals(dseGraphSession.getSession(), dseSession);
55 | try{
56 | dseGraphSession.closeConnections();
57 | }catch(Exception e){
58 | fail("shouldn't have thrown exception");
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/DSEMetadataTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import static org.testng.Assert.assertEquals;
15 |
16 | import org.testng.annotations.Test;
17 |
18 | /**
19 | *
20 | * @author nverma1
21 | *
22 | */
23 | public class DSEMetadataTest {
24 | @Test
25 | public void testCreateDSEMetadata(){
26 | DSEMetadata metadata = new DSEMetadata<>(String.class);
27 | assertEquals(metadata.getType(), String.class);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/DSEPersistenceConfigurationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import static org.testng.Assert.assertTrue;
15 | import static org.testng.Assert.fail;
16 |
17 | import java.util.Properties;
18 |
19 | import org.testng.annotations.Test;
20 |
21 | /**
22 | *
23 | * @author nverma1
24 | *
25 | */
26 | public class DSEPersistenceConfigurationTest {
27 | @Test
28 | public void testDSEPersistenceConfigurationWithoutArgument(){
29 | try{
30 | DSEPersistenceConfigurationProperties props = new DSEPersistenceConfigurationProperties();
31 | props.load(null, null);
32 | }catch(Exception e){
33 | assertTrue(e instanceof IllegalArgumentException);
34 | }
35 | }
36 |
37 | @Test
38 | public void testPersistenceConfigurationWithDefaultProperties(){
39 | try{
40 | Properties defaults = new Properties();
41 | DSEPersistenceConfigurationProperties props = new DSEPersistenceConfigurationProperties(defaults );
42 | }catch(Exception e){
43 | fail("shouldn't throw an exception");
44 | }
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/DSEPersistenceRepositoryProviderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import static org.testng.Assert.assertNotNull;
15 | import static org.testng.Assert.fail;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.impl.persistence.dse.helper.DSEConfigurationMock;
20 | import com.intuit.ugc.impl.persistence.dse.helper.DSEConnectionManagerMock;
21 |
22 | /**
23 | *
24 | * @author nverma1
25 | *
26 | */
27 | public class DSEPersistenceRepositoryProviderTest {
28 |
29 | @Test
30 | public void testInit() {
31 | try {
32 | DSEPersistenceRepositoryProvider provider = new DSEPersistenceRepositoryProvider(
33 | new DSEConnectionManagerMock(new DSEConfigurationMock()));
34 | DSEGraphVisitor dseGraphVisitor = provider.get();
35 | assertNotNull(dseGraphVisitor);
36 | } catch (Exception e) {
37 | fail("shouldn't have thrown");
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/DSEPersistenceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import static org.testng.Assert.fail;
15 |
16 | import org.testng.annotations.Test;
17 |
18 | import com.intuit.ugc.impl.core.queryplan.MutationExecutorFactory;
19 | import com.intuit.ugc.impl.core.queryplan.OperationFeederImpl;
20 | import com.intuit.ugc.impl.core.queryplan.OperationPipeline;
21 | import com.intuit.ugc.impl.core.spi.GraphVisitor;
22 | import com.intuit.ugc.impl.persistence.dse.helper.DSEConfigurationMock;
23 | import com.intuit.ugc.impl.persistence.dse.helper.DSEConnectionManagerMock;
24 |
25 | /**
26 | *
27 | * @author nverma1
28 | *
29 | */
30 | public class DSEPersistenceTest {
31 | @Test
32 | public void testInitializeDSEPersistence() {
33 | GraphVisitor repository = new DSEGraphVisitor(new DSEConnectionManagerMock(new DSEConfigurationMock()));
34 | MutationExecutorFactory factory = new MutationExecutorFactory() {
35 |
36 | @Override
37 | public OperationFeederImpl create(OperationPipeline pipeline) {
38 | return null;
39 | }
40 | };
41 |
42 | try{
43 | DSEPersistence dsePersistence = new DSEPersistence(repository , factory);
44 | }catch(Exception e){
45 | fail("initialization shouldn't throw an error");
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/DSETestModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import java.io.IOException;
15 |
16 | import com.google.inject.AbstractModule;
17 | import com.intuit.ugc.api.Persistence;
18 | import com.intuit.ugc.api.PersistenceException;
19 |
20 | /**
21 | *
22 | * @author nverma1
23 | *
24 | */
25 | public class DSETestModule extends AbstractModule {
26 | @Override
27 | protected void configure() {
28 | DSEPersistenceConfigurationProperties instance = new DSEPersistenceConfigurationProperties();
29 | try {
30 | instance.load("graph_client_dse_test.properties",null);
31 | }
32 | catch (IOException e) {
33 | throw new PersistenceException(e);
34 | }
35 |
36 | bind(Persistence.Configuration.class).toInstance(instance);
37 | bind(DSEPersistenceConfiguration.class).toInstance(instance);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/GraphCallbackTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import static org.testng.Assert.assertEquals;
15 |
16 | import org.testng.annotations.Test;
17 |
18 | import com.datastax.driver.dse.graph.GraphResultSet;
19 |
20 | /**
21 | *
22 | * @author nverma1
23 | *
24 | */
25 | public class GraphCallbackTest {
26 |
27 | @Test
28 | public void testGraphCallback(){
29 | GraphCallBack graphCallback = new GraphCallBack();
30 | GraphResultSet result = new GraphResultSet(null);
31 | graphCallback.onSuccess(result);
32 | Exception th = new Exception("testException");
33 | graphCallback.onFailure(th);
34 | assertEquals(graphCallback.getResult(), result);
35 | assertEquals(graphCallback.getTh(), th);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/GraphEntityOperationsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse;
13 |
14 | import org.testng.annotations.BeforeClass;
15 | import org.testng.annotations.Test;
16 |
17 | import com.intuit.ugc.impl.persistence.dse.helper.DSEConfigurationMock;
18 | import com.intuit.ugc.impl.persistence.dse.helper.DSEConnectionManagerMock;
19 |
20 | import mockit.Mocked;
21 |
22 | /**
23 | *
24 | * @author nverma1
25 | *
26 | */
27 | public class GraphEntityOperationsTest {
28 |
29 | @Mocked GraphRelationshipOperations graphRelationshipOperations;
30 |
31 | private GraphEntityOperations graphEntityOperations = null;
32 |
33 | @BeforeClass
34 | public void setup(){
35 | DSEPersistenceConfiguration config = new DSEConfigurationMock();
36 | DSEConnectionManager connectionManager = new DSEConnectionManagerMock(config );
37 | graphEntityOperations = new GraphEntityOperations(connectionManager , graphRelationshipOperations);
38 | }
39 |
40 | @Test
41 | public void testCreateEntity(){
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/helper/DSEConfigurationMock.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse.helper;
13 |
14 | import com.intuit.ugc.impl.persistence.dse.DSEPersistenceConfigurationProperties;
15 |
16 | /**
17 | *
18 | * @author nverma1
19 | *
20 | */
21 | public class DSEConfigurationMock extends DSEPersistenceConfigurationProperties{
22 |
23 | /**
24 | * Default serial version id
25 | */
26 | private static final long serialVersionUID = 1L;
27 |
28 | @Override
29 | public String getGraph() {
30 | return "mock-graph";
31 | }
32 |
33 | @Override
34 | public String getHost() {
35 | return "127.0.01";
36 | }
37 |
38 | @Override
39 | public int getPort() {
40 | return 1234;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/java/com/intuit/ugc/impl/persistence/dse/helper/DSEConnectionManagerMock.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 & nverma1 - API , implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.persistence.dse.helper;
13 |
14 | import com.intuit.ugc.impl.persistence.dse.DSEConnectionManager;
15 | import com.intuit.ugc.impl.persistence.dse.DSEPersistenceConfiguration;
16 |
17 | /**
18 | *
19 | * @author nverma1
20 | *
21 | */
22 | public class DSEConnectionManagerMock extends DSEConnectionManager {
23 |
24 | public DSEConnectionManagerMock(DSEPersistenceConfiguration config) {
25 | super(config);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/resource/graph_client_dse_test.properties:
--------------------------------------------------------------------------------
1 | host=127.0.0.1
2 | port=9042
3 | graph=test
4 |
--------------------------------------------------------------------------------
/graph-client-impl-provider-dse/src/test/resource/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 | %-4relative [%thread] %-5level %logger{35} - %msg %n
8 |
9 |
10 |
11 |
12 |
14 | universal_graph_client.log
15 |
16 |
17 | universal_graph_client.%d{yyyy-MM-dd}.%i.log
18 |
19 |
21 |
22 | 50MB
23 |
24 |
25 | 3
26 |
27 |
28 | %d{dd MMM yyyy;HH:mm:ss.SSS} %-5level [%thread][%logger{0}]
29 | %m%n
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/universal-graph-client-api/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/universal-graph-client-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | com.intuit.graph.client
5 | graph-client-core
6 | 1.0-SNAPSHOT
7 |
8 |
9 | 4.0.0
10 | com.intuit.graph.client
11 | universal-graph-client-api
12 | 0.5-SNAPSHOT
13 | jar
14 |
15 |
16 | com.toddfast.typeconverter
17 | typeconverter
18 | 1.0
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | org.apache.maven.plugins
27 | maven-compiler-plugin
28 | ${maven.compiler.plugin}
29 |
30 | ${maven.compiler.source}
31 | ${maven.compiler.target}
32 |
33 |
34 |
35 | org.codehaus.mojo
36 | versions-maven-plugin
37 | ${maven.release.plugin}
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/AbstractQualifiedName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | import java.util.Objects;
16 |
17 | /**
18 | * Base class for all types of names. For now, it only wraps a simple name
19 | * represented by a string datatype. But the capabilities can be extended to
20 | * include a namespace, if required, in future.
21 | *
22 | * @author ajain17
23 | */
24 | public abstract class AbstractQualifiedName {
25 |
26 | private String name;
27 |
28 | protected AbstractQualifiedName(String name) {
29 | super();
30 | this.name = name;
31 | }
32 |
33 | /**
34 | * Return the name wrapped inside this class
35 | *
36 | * @return The name, or null if there is no name
37 | */
38 | public final String getName() {
39 | return name;
40 | }
41 |
42 | /**
43 | * Returns the name
44 | *
45 | * @return
46 | */
47 | @Override
48 | public String toString() {
49 | return name;
50 | }
51 |
52 | @Override
53 | public int hashCode() {
54 | int hash = 5;
55 | hash = 71 * hash + Objects.hashCode(getName());
56 | return hash;
57 | }
58 |
59 | @Override
60 | public boolean equals(Object object) {
61 |
62 | if (this == object) {
63 | return true;
64 | }
65 |
66 | if (object == null) {
67 | return false;
68 | }
69 |
70 | if (getClass() != object.getClass()) {
71 | return false;
72 | }
73 |
74 | final AbstractQualifiedName other = (AbstractQualifiedName)object;
75 | if (!Objects.equals(this.getName(), other.getName())) {
76 | return false;
77 | }
78 |
79 | return true;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/AbstractValueSpecifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | import java.time.Instant;
16 |
17 | import com.toddfast.util.convert.TypeConverter;
18 |
19 | /**
20 | * Base class supporting value-specification implementation in the builders
21 | *
22 | * @author ajain17
23 | */
24 | abstract class AbstractValueSpecifier implements ValueSpecifier {
25 |
26 | private B builder;
27 | private final Attribute.Name name;
28 |
29 | protected AbstractValueSpecifier(B builder, Attribute.Name name) {
30 | super();
31 | this.builder = builder;
32 | this.name = name;
33 | }
34 |
35 | @Override
36 | public final B value(String value) {
37 | setValue(value);
38 | return builder;
39 | }
40 |
41 | @Override
42 | public final B value(Integer value) {
43 | setValue(value);
44 | return builder;
45 | }
46 |
47 | @Override
48 | public final B value(Double value) {
49 | setValue(value);
50 | return builder;
51 | }
52 |
53 | @Override
54 | public final B value(Boolean value) {
55 | setValue(value);
56 | return builder;
57 | }
58 |
59 | @Override
60 | public final B value(Instant value) {
61 | setValue(value);
62 | return builder;
63 | }
64 |
65 | @Override
66 | public B value(Object value, TypeConverter.Conversion converter) {
67 | setValue(converter.convert(value));
68 | return builder;
69 | }
70 |
71 | /** SPI method */
72 | protected abstract void setValue(Object value);
73 | }
74 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/AccessControlException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | *
17 | * @author tfast
18 | */
19 | @SuppressWarnings("serial")
20 | public class AccessControlException extends RuntimeException {
21 |
22 | public AccessControlException() {
23 | super();
24 | }
25 |
26 | public AccessControlException(String message) {
27 | super(message);
28 | }
29 |
30 | public AccessControlException(String message, Throwable cause) {
31 | super(message,cause);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/AccessToken.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | * The access token required to access the service. This is modeled off of
17 | * a typical OAuth2-style approach for illustration purposes.
18 | *
19 | * @author ajain17
20 | */
21 | public interface AccessToken {
22 |
23 | public String getToken();
24 |
25 | public AccessToken.Type getType();
26 |
27 | public Long getExpires();
28 |
29 |
30 | /**
31 | * The type of the access token
32 | *
33 | */
34 | public enum Type {
35 | DEFAULT;
36 | }
37 | }
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/BatchMutation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | * A single batch of changes to the persistence store
17 | *
18 | * @author ajain17
19 | */
20 | public interface BatchMutation {
21 |
22 | /**
23 | * create an entity for batch mutation
24 | * @param newEntity
25 | * @return @see {@link com.intuit.ugc.api.OperationResult}
26 | */
27 | public com.intuit.ugc.api.BatchMutation createEntity(NewEntity newEntity);
28 |
29 | /**
30 | * create a relationship for batch mutation
31 | * @param newRelationship
32 | * @return @see {@link com.intuit.ugc.api.OperationResult}
33 | */
34 | public com.intuit.ugc.api.BatchMutation createRelationship(
35 | NewRelationship newRelationship);
36 |
37 | /**
38 | * Facilitate a mutation on a given entity (update)
39 | * @param entity
40 | * @return @see {@link com.intuit.ugc.api.OperationResult}
41 | */
42 | public Entity.Mutation withEntity(Entity entity);
43 |
44 | /**
45 | * Facilitate a mutation on a given relationship (update)
46 | * @param relationship
47 | * @return @see {@link com.intuit.ugc.api.OperationResult}
48 | */
49 | public Relationship.Mutation withRelationship(Relationship relationship);
50 |
51 | /**
52 | * execute the batch mutation
53 | * @return result of the batch mutation @see {@link com.intuit.ugc.api.OperationResult}
54 | * @throws InvalidAttributeException
55 | * @throws AccessControlException
56 | */
57 | public OperationResult execute()
58 | throws InvalidAttributeException, AccessControlException;
59 |
60 | public static interface Result {
61 | // ...
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/Entity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | import java.util.Objects;
16 |
17 | /**
18 | * An entity in the persistence store
19 | *
20 | * @author ajain17
21 | */
22 | public interface Entity {
23 |
24 | /**
25 | * return unique id of this entity
26 | * @return {@link com.intuit.ugc.api.Entity.ID}
27 | */
28 | public Entity.ID getID();
29 |
30 | public Attribute getAttribute(Attribute.Name name)
31 | throws AccessControlException;
32 |
33 | /**
34 | * Represents a change to the persistent state of the entity
35 | *
36 | */
37 | public static interface Mutation {
38 |
39 | public ValueSpecifier withAttribute(Attribute.Name name);
40 |
41 | public Entity.Mutation deleteAttribute(Attribute.Name name);
42 |
43 | public Entity.Mutation deleteAttributes(Attribute.Family family);
44 |
45 | public com.intuit.ugc.api.BatchMutation ready();
46 |
47 | public Entity.Mutation delete();
48 | }
49 |
50 | /**
51 | * An ID for an entity
52 | *
53 | */
54 | public static class ID {
55 |
56 | private ID(String id) {
57 | super();
58 | this.id=id;
59 | }
60 |
61 | /**
62 | * Returns the raw, unqualified ID
63 | *
64 | */
65 | public String getRawID() {
66 | return id;
67 | }
68 |
69 | @Override
70 | public int hashCode() {
71 | int hash=3;
72 | hash=HASH_SEED*hash+Objects.hashCode(this.id);
73 | return hash;
74 | }
75 |
76 | @Override
77 | public boolean equals(Object obj) {
78 | if (obj==null) {
79 | return false;
80 | }
81 | if (getClass()!=obj.getClass()) {
82 | return false;
83 | }
84 | final ID other=(ID)obj;
85 | if (!Objects.equals(this.id,other.id)) {
86 | return false;
87 | }
88 | return true;
89 | }
90 |
91 | @Override
92 | public String toString() {
93 | return this.id;
94 | }
95 |
96 | public static ID valueOf(String id) {
97 | return new ID(id);
98 | }
99 |
100 | private String id;
101 |
102 | /** A large prime number that must be unique to this class to
103 | preserve identity semantics */
104 | private static final int HASH_SEED=59;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/InvalidAttributeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | * @author ajain17
17 | *
18 | */
19 | @SuppressWarnings("serial")
20 | public class InvalidAttributeException extends RuntimeException {
21 |
22 | public InvalidAttributeException() {
23 | super();
24 | }
25 |
26 | public InvalidAttributeException(String message) {
27 | super(message);
28 | }
29 |
30 | public InvalidAttributeException(String message, Throwable cause) {
31 | super(message,cause);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/InvalidFormatException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | * @author ajain17
17 | *
18 | */
19 | @SuppressWarnings("serial")
20 | public class InvalidFormatException extends RuntimeException {
21 |
22 | public InvalidFormatException() {
23 | super();
24 | }
25 |
26 | public InvalidFormatException(String message) {
27 | super(message);
28 | }
29 |
30 | public InvalidFormatException(String message, Throwable cause) {
31 | super(message,cause);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/NewEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | import java.util.Collections;
16 | import java.util.HashMap;
17 | import java.util.Map;
18 |
19 | /**
20 | * Represents a new entity before it has been persisted
21 | *
22 | * @author ajain17
23 | */
24 | public class NewEntity {
25 |
26 | /**
27 | * Can't instantiate
28 | *
29 | */
30 | private NewEntity(Entity.ID entityID) {
31 | super();
32 | this.entityID = entityID;
33 | }
34 |
35 | /**
36 | * Returns a new builder instance
37 | *
38 | */
39 | public static Builder newInstance(Entity.ID entityID) {
40 | return new Builder(entityID);
41 | }
42 |
43 | /**
44 | * Get entity attributes
45 | *
46 | * @return An unmodifiable map of attributes
47 | */
48 | public Map getAttributes() {
49 | return attributes;
50 | }
51 |
52 | /**
53 | * Return the entity ID
54 | *
55 | * @return
56 | */
57 | public Entity.ID getEntityID() {
58 | return entityID;
59 | }
60 |
61 | /**
62 | * Builder for a new instance
63 | *
64 | */
65 | public static class Builder {
66 |
67 | private Builder(Entity.ID entityID) {
68 | instance = new NewEntity(entityID);
69 | }
70 |
71 | public ValueSpecifier withAttribute(Attribute.Name name) {
72 | ensure(name,"name");
73 |
74 | return new AbstractValueSpecifier(this,name) {
75 | protected void setValue(Object value) {
76 | ensure(value,"value");
77 | instance.attributes.put(name,value);
78 | }
79 | };
80 | }
81 |
82 | private void ensure(Object value, String field) {
83 | if (value==null) {
84 | throw new IllegalArgumentException(
85 | "\""+field+"\" cannot be null");
86 | }
87 | }
88 |
89 | public NewEntity build() {
90 | instance.attributes =
91 | Collections.unmodifiableMap(instance.attributes);
92 | NewEntity result=instance;
93 | instance=null;
94 | return result;
95 | }
96 |
97 | private NewEntity instance;
98 | }
99 |
100 | private Entity.ID entityID;
101 | private Map attributes = new HashMap<>();
102 | }
103 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/OperationResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | * Wrapper over the result of a persistence operation.
17 | *
18 | * @author ajain17
19 | */
20 | public interface OperationResult {
21 |
22 | /**
23 | * Always return
24 | *
25 | * @return
26 | */
27 | public R getResult();
28 | }
29 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/Persistence.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | * The primary interface for interacting with persistence services
17 | *
18 | * @author ajain17
19 | */
20 | public interface Persistence {
21 |
22 | /**
23 | * Allocate a new entity ID
24 | *
25 | * @return
26 | */
27 | public Entity.ID allocateID();
28 |
29 | /**
30 | *
31 | *
32 | * @return
33 | */
34 | public Queries.LookupQuery lookup();
35 |
36 | /**
37 | *
38 | *
39 | * @return
40 | */
41 | public Queries.GraphQuery queryGraph();
42 |
43 | /**
44 | * Begin a new mutation
45 | *
46 | * @return
47 | */
48 | public com.intuit.ugc.api.BatchMutation prepareBatchMutation();
49 |
50 | /**
51 | * Returns a new entity mutation in the context of an implicit BatchMutation
52 | *
53 | * @return An entity mutation
54 | */
55 | public Entity.Mutation prepareMutation(Entity entity);
56 |
57 | /**
58 | * Returns a new relationship mutation in the context of an implicit BatchMutation
59 | *
60 | * @return A relationship mutation
61 | */
62 | public Relationship.Mutation prepareMutation(Relationship relationship);
63 |
64 | /**
65 | *
66 | *
67 | */
68 | public Predicate predicates();
69 |
70 |
71 | /**
72 | * Provisions a new instance of Persistence
73 | *
74 | */
75 | public interface Factory {
76 |
77 | public Persistence newInstance(Configuration config);
78 | }
79 |
80 |
81 | /**
82 | * Provides configuration parameters required to obtain a valid instance
83 | * of Persistence
84 | *
85 | */
86 | public interface Configuration {
87 |
88 | /**
89 | * Get the identifier for the endpoint. This must have meaning to the
90 | * the implementation.
91 | *
92 | * @return
93 | */
94 | public String getEndpoint();
95 |
96 | /**
97 | * The access token required to access the endpoint
98 | *
99 | * @return
100 | */
101 | public AccessToken getAccessToken();
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/PersistenceException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | *
17 | * @author ajain17
18 | */
19 | @SuppressWarnings("serial")
20 | public class PersistenceException extends RuntimeException {
21 |
22 | public PersistenceException() {
23 | super();
24 | }
25 |
26 | public PersistenceException(String message) {
27 | super(message);
28 | }
29 |
30 | public PersistenceException(Throwable cause) {
31 | super(cause);
32 | }
33 |
34 | public PersistenceException(String message, Throwable cause) {
35 | super(message,cause);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/Predicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | /**
16 | * A compound predicate builder using attribute values
17 | *
18 | * @author ajain17
19 | */
20 | public interface Predicate {
21 |
22 | public static interface Comparison {
23 |
24 | public Predicate equalTo(Object value);
25 |
26 | public Predicate notEqualTo(Object value);
27 |
28 | public Predicate greaterThan(Object value);
29 |
30 | public Predicate lessThan(Object value);
31 | }
32 |
33 | public Predicate.Comparison attribute(Attribute.Name name);
34 |
35 | public Predicate and(Predicate... predicate);
36 |
37 | public Predicate or(Predicate... predicate);
38 | }
39 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/Query.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * A query that can be performed against the persistence store
19 | *
20 | * @author ajain17
21 | */
22 | public interface Query {
23 |
24 | /**
25 | * Performs the query
26 | *
27 | * @return
28 | * @throws AccessControlException
29 | */
30 | public OperationResult execute()
31 | throws AccessControlException;
32 |
33 |
34 | /**
35 | * The results of query execution
36 | *
37 | */
38 | public static interface Result {
39 |
40 | /**
41 | * Returns the root entity requested in the query
42 | *
43 | * @return If more than a single entity in the result, returns the
44 | * first. Returns null if no root entity in result
45 | */
46 | public Entity getEntity();
47 |
48 | /**
49 | * Returns the list of root entities requested in the query
50 | *
51 | * @return an empty list if no entities in result
52 | */
53 | public List getEntities();
54 |
55 | /**
56 | * Returns the root relationship requested in the query
57 | *
58 | * @return If more than a single relationships in the result, returns
59 | * the first. Returns null if no root relationship in result.
60 | */
61 | public Relationship getRelationship();
62 |
63 | /**
64 | * Returns the list of root relationships requested in the query
65 | *
66 | * @return Returns an empty list if no relationships in result
67 | */
68 | public List getRelationships();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/Relationship.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | import com.intuit.ugc.api.Queries.Projection;
16 |
17 | /**
18 | * Represents a relationship between any two entities in the persistence store.
19 | * A relationship is from a source entity to a target entity.
20 | *
21 | * @author ajain17
22 | */
23 | public interface Relationship {
24 |
25 | /**
26 | * fetches the relationship name
27 | *
28 | * @return the name of this relationship
29 | */
30 | public Name getName();
31 |
32 | /**
33 | * get the source entity id
34 | *
35 | * @return the entity id of the source entity of this relationship
36 | */
37 | public Entity.ID getSourceID();
38 |
39 | /**
40 | * get the target entity id
41 | *
42 | * @return the entity id of the target entity of this relationship
43 | */
44 | public Entity.ID getTargetID();
45 |
46 | public Attribute getAttribute(Attribute.Name name)
47 | throws AccessControlException;
48 |
49 | /**
50 | * Represents a change to the persistent state of the relationship
51 | *
52 | * @author ajain17
53 | */
54 | public static interface Mutation {
55 |
56 | /**
57 | * select an attribute of a relationship
58 | * @param name name of the attribute
59 | * @param value value of the attribute
60 | * @return the corresponding Mutation
61 | */
62 | public Relationship.Mutation setAttribute(Attribute.Name name,
63 | Object value);
64 |
65 | /**
66 | * delete an attribute of a relationship
67 | * @param name name of the attribute
68 | * @return the corresponding Mutation
69 | */
70 | public Relationship.Mutation deleteAttribute(Attribute.Name name);
71 |
72 | public com.intuit.ugc.api.BatchMutation ready();
73 |
74 | public Relationship.Mutation delete();
75 | }
76 |
77 | /**
78 | * Represents the name of the relationship
79 | *
80 | * @author ajain17
81 | */
82 | public static final class Name extends AbstractQualifiedName {
83 |
84 | private Name(String name) {
85 | super(name);
86 | }
87 |
88 | public static Name valueOf(String name) {
89 | return new Name(name);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/ValueSpecifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | import java.time.Instant;
16 |
17 | import com.toddfast.util.convert.TypeConverter;
18 |
19 | /**
20 | * A common interface for specifying the value of something
21 | *
22 | * @author ajain17
23 | */
24 | public interface ValueSpecifier {
25 |
26 | public B value(String value);
27 |
28 | public B value(Integer value);
29 |
30 | public B value(Double value);
31 |
32 | public B value(Boolean value);
33 |
34 | public B value(Instant value);
35 |
36 | /**
37 | * Support conversion to an arbitrary type
38 | *
39 | * @param
40 | * @param value
41 | * @param converter
42 | * @return
43 | */
44 | public B value(Object value, TypeConverter.Conversion converter);
45 | }
46 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/main/java/com/intuit/ugc/api/mogwai/GizmoPredicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api.mogwai;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import com.intuit.ugc.api.Attribute;
19 | import com.intuit.ugc.api.Predicate;
20 |
21 | /**
22 | * A predicate of Gizmo
23 | * @see com.intuit.ugc.api.mogwai.Gizmo
24 | * @author ajain17
25 | */
26 | /*pkg*/ class GizmoPredicate implements Gizmo.Predicate {
27 |
28 | public GizmoPredicate(Predicate predicate) {
29 | super();
30 | this.predicate = predicate;
31 | }
32 |
33 | @Override
34 | public Gizmo.Predicate eq(String name, Object value) {
35 | return new GizmoPredicate(
36 | getPredicate().attribute(Attribute.Name.valueOf(name))
37 | .equalTo(value));
38 | }
39 |
40 | @Override
41 | public Gizmo.Predicate neq(String name, Object value) {
42 | return new GizmoPredicate(
43 | getPredicate().attribute(Attribute.Name.valueOf(name))
44 | .notEqualTo(value));
45 | }
46 |
47 | @Override
48 | public Gizmo.Predicate gt(String name, Object value) {
49 | return new GizmoPredicate(
50 | getPredicate().attribute(Attribute.Name.valueOf(name))
51 | .greaterThan(value));
52 | }
53 |
54 | @Override
55 | public Gizmo.Predicate lt(String name, Object value) {
56 | return new GizmoPredicate(
57 | getPredicate().attribute(Attribute.Name.valueOf(name))
58 | .lessThan(value));
59 | }
60 |
61 | @Override
62 | public Gizmo.Predicate and(Gizmo.Predicate... values) {
63 | return new GizmoPredicate(
64 | getPredicate().and(unwrap(values)));
65 | }
66 |
67 | @Override
68 | public Gizmo.Predicate or(Gizmo.Predicate... values) {
69 | return new GizmoPredicate(
70 | getPredicate().or(unwrap(values)));
71 | }
72 |
73 | /**
74 | * TODO: This is buggy; inoperable with other impls of Gizmo.Predicate.
75 | * One fix might be to just make Gizmo.Predicate concrete and avoid the
76 | * problem altogether, since the abstraction of the Predicate interface
77 | * remains underneath.
78 | *
79 | */
80 | private Predicate[] unwrap(Gizmo.Predicate... values) {
81 | List predicateList = new ArrayList<>();
82 | for (Gizmo.Predicate p: values) {
83 | predicateList.add(((GizmoPredicate)p).getPredicate());
84 | }
85 |
86 | return predicateList.toArray(new Predicate[0]);
87 | }
88 |
89 | /*pkg*/ Predicate getPredicate() {
90 | return predicate;
91 | }
92 |
93 | private Predicate predicate;
94 | }
95 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/AbstractQualifiedNameTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertEquals;
4 | import static org.testng.Assert.assertFalse;
5 | import static org.testng.Assert.assertNotNull;
6 | import static org.testng.Assert.assertTrue;
7 |
8 | import org.testng.annotations.Test;
9 |
10 | import com.intuit.ugc.api.helper.QualifiedName;
11 |
12 | public class AbstractQualifiedNameTest {
13 |
14 | @Test
15 | public void testAbstractQualifiedNameInit(){
16 | String name = "test-name";
17 | AbstractQualifiedName aqn = new QualifiedName(name);
18 | assertEquals(aqn.getName(), name);
19 | assertEquals(aqn.toString(), name);
20 | assertNotNull(aqn.hashCode());
21 | }
22 |
23 | @Test
24 | public void testAbstractQualifiedNameEquality(){
25 | String name1 = "test-name-1";
26 | AbstractQualifiedName aqn1 = new QualifiedName(name1);
27 | AbstractQualifiedName aqn2 = new QualifiedName(name1);
28 | String name2 = "test-name-2";
29 | AbstractQualifiedName aqn3 = new QualifiedName(name2);
30 | assertTrue(aqn1.equals(aqn1));
31 | assertTrue(aqn1.equals(aqn2));
32 | assertFalse(aqn1.equals(aqn3));
33 | assertFalse(aqn1.equals(null));
34 | assertFalse(aqn1.equals(name1));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/AbstractValueSpecifierTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertNotNull;
4 |
5 | import java.time.Instant;
6 |
7 | import org.testng.annotations.Test;
8 |
9 | import com.toddfast.util.convert.TypeConverter.Conversion;
10 | import com.toddfast.util.convert.conversion.StringTypeConversion;
11 |
12 | public class AbstractValueSpecifierTest {
13 |
14 | @Test
15 | public void testAbstractValueSpecifierWithBoolean(){
16 | ValueBuilder valueBuilder = new ValueBuilder();
17 | String name = "attr-name";
18 | ValueBuilder builder = valueBuilder.withAttribute(Attribute.Name.valueOf(name)).value(true);
19 | assertNotNull(builder);
20 | }
21 |
22 | @Test
23 | public void testAbstractValueSpecifierWithString(){
24 | ValueBuilder valueBuilder = new ValueBuilder();
25 | String name = "attr-name";
26 | ValueBuilder builder = valueBuilder.withAttribute(Attribute.Name.valueOf(name)).value("test-value");
27 | assertNotNull(builder);
28 | }
29 |
30 | @Test
31 | public void testAbstractValueSpecifierWithInteger(){
32 | ValueBuilder valueBuilder = new ValueBuilder();
33 | String name = "attr-name";
34 | ValueBuilder builder = valueBuilder.withAttribute(Attribute.Name.valueOf(name)).value(1);
35 | assertNotNull(builder);
36 | }
37 |
38 | @Test
39 | public void testAbstractValueSpecifierWithDouble(){
40 | ValueBuilder valueBuilder = new ValueBuilder();
41 | String name = "attr-name";
42 | Double dbl = 1.5;
43 | ValueBuilder builder = valueBuilder.withAttribute(Attribute.Name.valueOf(name)).value(dbl);
44 | assertNotNull(builder);
45 | }
46 |
47 | @Test
48 | public void testAbstractValueSpecifierWithInstant(){
49 | ValueBuilder valueBuilder = new ValueBuilder();
50 | String name = "attr-name";
51 | ValueBuilder builder = valueBuilder.withAttribute(Attribute.Name.valueOf(name)).value(Instant.EPOCH);
52 | assertNotNull(builder);
53 | }
54 |
55 | @Test
56 | public void testAbstractValueSpecifierWithObjectTypeConversion(){
57 | ValueBuilder valueBuilder = new ValueBuilder();
58 | String name = "attr-name";
59 | Object value = "attr-value";
60 | @SuppressWarnings("unchecked")
61 | Conversion converter = new StringTypeConversion();
62 | ValueBuilder builder = valueBuilder.withAttribute(Attribute.Name.valueOf(name)).value(value, converter);
63 | assertNotNull(builder);
64 | }
65 |
66 | @Test
67 | public void testAbstractValueSpecifierWithObject(){
68 | ValueBuilder valueBuilder = new ValueBuilder();
69 | String name = "attr-name";
70 | Object value = "attr-value";
71 | valueBuilder.withAttribute(Attribute.Name.valueOf(name)).setValue(value);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/AccessControlExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertNotNull;
4 | import static org.testng.Assert.assertTrue;
5 |
6 | import org.testng.annotations.Test;
7 |
8 | public class AccessControlExceptionTest {
9 | @Test
10 | public void initDefault(){
11 | Exception ex = new AccessControlException();
12 | assertNotNull(ex);
13 | assertTrue(ex instanceof AccessControlException);
14 | }
15 |
16 | @Test
17 | public void initWithStringArg(){
18 | Exception ex = new AccessControlException("test-exception");
19 | assertNotNull(ex);
20 | assertTrue(ex instanceof AccessControlException);
21 | }
22 |
23 | @Test
24 | public void initWithStringAndThrowableArg(){
25 | Exception ex = new AccessControlException("test-exception", new Exception());
26 | assertNotNull(ex);
27 | assertTrue(ex instanceof AccessControlException);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/AccessTokenTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertEquals;
4 |
5 | import org.testng.annotations.Test;
6 |
7 | import com.intuit.ugc.api.AccessToken.Type;
8 | import com.intuit.ugc.api.helper.MockAccessToken;
9 |
10 | public class AccessTokenTest {
11 | @Test
12 | public void testAccessTokenType() {
13 | MockAccessToken mockToken = new MockAccessToken();
14 | mockToken.setType(Type.DEFAULT);
15 | assertEquals(Type.DEFAULT, mockToken.getType());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/GraphTraversalTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertEquals;
4 |
5 | import org.testng.annotations.Test;
6 |
7 | import com.intuit.ugc.api.Queries.GraphTraversal;
8 |
9 | public class GraphTraversalTest {
10 | @Test
11 | public void testGraphTraversalDirection(){
12 | GraphTraversal.Direction direction = GraphTraversal.Direction.IN;
13 | assertEquals(direction, GraphTraversal.Direction.IN);
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/InvalidAttributeExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertNotNull;
4 | import static org.testng.Assert.assertTrue;
5 |
6 | import org.testng.annotations.Test;
7 |
8 | public class InvalidAttributeExceptionTest {
9 |
10 | @Test
11 | public void testInit(){
12 | Exception ex = new InvalidAttributeException();
13 | assertNotNull(ex);
14 | assertTrue(ex instanceof InvalidAttributeException);
15 | }
16 |
17 | @Test
18 | public void testInitWithStringArg(){
19 | Exception ex = new InvalidAttributeException("test-exception");
20 | assertNotNull(ex);
21 | assertTrue(ex instanceof InvalidAttributeException);
22 | }
23 |
24 | @Test
25 | public void testInitWithStringAndThrowableArg(){
26 | Exception ex = new InvalidAttributeException("test-exception", new Exception());
27 | assertNotNull(ex);
28 | assertTrue(ex instanceof InvalidAttributeException);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/InvalidFormatExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertNotNull;
4 | import static org.testng.Assert.assertTrue;
5 |
6 | import org.testng.annotations.Test;
7 |
8 | public class InvalidFormatExceptionTest {
9 |
10 | @Test
11 | public void testInit(){
12 | Exception ex = new InvalidFormatException();
13 | assertNotNull(ex);
14 | assertTrue(ex instanceof InvalidFormatException);
15 | }
16 |
17 | @Test
18 | public void testInitWithStringArg(){
19 | Exception ex = new InvalidFormatException("test-exception");
20 | assertNotNull(ex);
21 | assertTrue(ex instanceof InvalidFormatException);
22 | }
23 |
24 | @Test
25 | public void testInitWithStringArgAndThrowable(){
26 | Exception ex = new InvalidFormatException("test-exception", new Exception());
27 | assertNotNull(ex);
28 | assertTrue(ex instanceof InvalidFormatException);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/NewEntityTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertEquals;
4 | import static org.testng.Assert.assertFalse;
5 | import static org.testng.Assert.assertNotNull;
6 | import static org.testng.Assert.assertTrue;
7 | import static org.testng.Assert.fail;
8 |
9 | import org.testng.annotations.Test;
10 |
11 | import com.intuit.ugc.api.Attribute.Name;
12 | import com.intuit.ugc.api.Entity.ID;
13 |
14 | public class NewEntityTest {
15 |
16 | @Test
17 | public void testInit(){
18 | ID entityID = Entity.ID.valueOf("test-entity-id");
19 | Name attribute = Attribute.Name.valueOf("test-attribute");
20 | NewEntity newEntity = NewEntity.newInstance(entityID)
21 | .withAttribute(attribute).value(true).build();
22 | assertTrue(newEntity instanceof NewEntity);
23 | assertEquals(newEntity.getAttributes().get(attribute), true);
24 | assertEquals(newEntity.getEntityID(), entityID);
25 | }
26 |
27 | @Test
28 | public void testInitWithNullAttributeThrowsException(){
29 | ID entityID = Entity.ID.valueOf("test-entity-id");
30 | try{
31 | NewEntity newEntity = NewEntity.newInstance(entityID)
32 | .withAttribute(null).value(true).build();
33 | fail("Should throw an exception");
34 | }catch(Exception ex){
35 | assertTrue(ex instanceof IllegalArgumentException);
36 | }
37 | }
38 |
39 | @Test
40 | public void testEntityID(){
41 | String idStr = "test-entity-id";
42 | Entity.ID entityId = Entity.ID.valueOf(idStr);
43 | assertEquals(entityId.getRawID(), idStr);
44 | assertNotNull(entityId.hashCode());
45 | assertEquals(entityId.toString(), idStr);
46 | }
47 |
48 | @Test
49 | public void testEntityIDEquality(){
50 | String idStr = "test-entity-id";
51 | Entity.ID entityId1 = Entity.ID.valueOf(idStr+"1");
52 | Entity.ID entityId2 = Entity.ID.valueOf(idStr+"2");
53 | Entity.ID entityId3 = Entity.ID.valueOf(idStr+"1");
54 | assertTrue(entityId1.equals(entityId3));
55 | assertTrue(entityId1.equals(entityId1));
56 | assertFalse(entityId1.equals(entityId2));
57 | assertFalse(entityId1.equals(idStr));
58 | assertFalse(entityId1.equals(null));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/PersistenceExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import static org.testng.Assert.assertNotNull;
4 | import static org.testng.Assert.assertTrue;
5 |
6 | import org.testng.annotations.Test;
7 |
8 | public class PersistenceExceptionTest {
9 |
10 | @Test
11 | public void testInit(){
12 | Exception ex = new PersistenceException();
13 | assertNotNull(ex);
14 | assertTrue(ex instanceof PersistenceException);
15 | }
16 |
17 | @Test
18 | public void testInitWithString(){
19 | Exception ex = new PersistenceException("test-exception");
20 | assertNotNull(ex);
21 | assertTrue(ex instanceof PersistenceException);
22 | }
23 |
24 | @Test
25 | public void testInitWithStringAndThrowable(){
26 | Exception ex = new PersistenceException("test-exception", new Exception());
27 | assertNotNull(ex);
28 | assertTrue(ex instanceof PersistenceException);
29 | }
30 |
31 | @Test
32 | public void testInitWithThrowable(){
33 | Exception ex = new PersistenceException(new Exception());
34 | assertNotNull(ex);
35 | assertTrue(ex instanceof PersistenceException);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/PersistenceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api;
14 |
15 | import com.intuit.ugc.api.BatchMutation;
16 | import com.intuit.ugc.api.Entity;
17 | import com.intuit.ugc.api.NewEntity;
18 | import com.intuit.ugc.api.Persistence;
19 | import com.intuit.ugc.api.Predicate;
20 | import com.intuit.ugc.api.Queries;
21 | import com.intuit.ugc.api.Relationship;
22 |
23 | /**
24 | *
25 | *
26 | *
27 | */
28 | public class PersistenceImpl implements Persistence {
29 |
30 | @Override
31 | public Entity.ID allocateID() {
32 | throw new UnsupportedOperationException("Not implemented yet");
33 | }
34 |
35 | public Entity createEntity(NewEntity newEntity) {
36 | return null;
37 | }
38 |
39 | @Override
40 | public BatchMutation prepareBatchMutation() {
41 | return null;
42 | }
43 |
44 | @Override
45 | public Queries.LookupQuery lookup() {
46 | return null;
47 | }
48 |
49 | @Override
50 | public Queries.GraphQuery queryGraph() {
51 | return null;
52 | }
53 |
54 | @Override
55 | public Entity.Mutation prepareMutation(Entity entity) {
56 | return null;
57 | }
58 |
59 | @Override
60 | public Relationship.Mutation prepareMutation(Relationship relationship) {
61 | return null;
62 | }
63 |
64 | @Override
65 | public Predicate predicates() {
66 | return null;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/ValueBuilder.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api;
2 |
3 | import com.intuit.ugc.api.AbstractValueSpecifier;
4 | import com.intuit.ugc.api.Attribute;
5 | import com.intuit.ugc.api.ValueSpecifier;
6 |
7 | public class ValueBuilder {
8 | public AbstractValueSpecifier withAttribute(Attribute.Name name) {
9 | return new AbstractValueSpecifier(this,name) {
10 |
11 | @Override
12 | public void setValue(Object value) {
13 | //Mock implementation
14 | }
15 |
16 | };
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/helper/MockAccessToken.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api.helper;
2 |
3 | import com.intuit.ugc.api.AccessToken;
4 |
5 | public class MockAccessToken implements AccessToken {
6 | private Type type;
7 |
8 | @Override
9 | public String getToken() {
10 | // TODO Auto-generated method stub
11 | return null;
12 | }
13 |
14 | @Override
15 | public Type getType() {
16 | return this.type;
17 | }
18 |
19 | @Override
20 | public Long getExpires() {
21 | // TODO Auto-generated method stub
22 | return null;
23 | }
24 |
25 | public void setType(Type type) {
26 | this.type = type;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/helper/MockEntity.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api.helper;
2 |
3 | import com.intuit.ugc.api.AccessControlException;
4 | import com.intuit.ugc.api.Attribute;
5 | import com.intuit.ugc.api.Attribute.Name;
6 | import com.intuit.ugc.api.Entity;
7 |
8 | public class MockEntity implements Entity {
9 | private Entity.ID id;
10 |
11 | @Override
12 | public ID getID() {
13 | // TODO Auto-generated method stub
14 | return this.id;
15 | }
16 |
17 | @Override
18 | public Attribute getAttribute(Name name) throws AccessControlException {
19 | // TODO Auto-generated method stub
20 | return null;
21 | }
22 |
23 | public void setID(Entity.ID id){
24 | this.id = id;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/helper/QualifiedName.java:
--------------------------------------------------------------------------------
1 | package com.intuit.ugc.api.helper;
2 |
3 | import com.intuit.ugc.api.AbstractQualifiedName;
4 |
5 | public class QualifiedName extends AbstractQualifiedName {
6 |
7 | public QualifiedName(String name) {
8 | super(name);
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/universal-graph-client-api/src/test/java/com/intuit/ugc/api/mogwai/GizmoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * tfast - initial API and implementation and/or initial documentation
10 | * ajain17 & nverma1 - API implementation, enhancements and extension
11 | */
12 |
13 | package com.intuit.ugc.api.mogwai;
14 |
15 | import java.util.List;
16 |
17 | import org.junit.Test;
18 |
19 | import com.intuit.ugc.api.Entity;
20 | import com.intuit.ugc.api.OperationResult;
21 | import com.intuit.ugc.api.Persistence;
22 | import com.intuit.ugc.api.PersistenceImpl;
23 | import com.intuit.ugc.api.Query;
24 | import com.intuit.ugc.api.mogwai.Gizmo;
25 |
26 | /**
27 | *
28 | *
29 | */
30 | public class GizmoTest {
31 |
32 | public GizmoTest() {
33 | }
34 |
35 | @Test
36 | public void testGetEntity() {
37 |
38 | Persistence.Configuration configuration = null; // ...
39 | Persistence.Factory factory = new PersistenceFactoryImpl();
40 | Persistence persistence = factory.newInstance(configuration);
41 |
42 | Gizmo gizmo = Gizmo.newInstance(persistence);
43 |
44 | OperationResult opResult =
45 | gizmo.g()
46 | .v("test.Foo/00000000-0000-0000-0000-000000000001")
47 | .select("test.One","test.Two")
48 | .execute();
49 |
50 | Query.Result result = opResult.getResult();
51 |
52 | List entities = result.getEntities();
53 | }
54 |
55 | @Test
56 | public void testIdiomaticQuery() {
57 |
58 | Persistence.Configuration configuration = null; // ...
59 | Persistence.Factory factory = new PersistenceFactoryImpl();
60 | Persistence persistence = factory.newInstance(configuration);
61 |
62 | Gizmo gizmo = Gizmo.newInstance(persistence);
63 | Gizmo.Predicate _ = gizmo._();
64 |
65 | OperationResult opResult =
66 | gizmo.g()
67 | // Pick a root entity
68 | .v("test.Foo/00000000-0000-0000-0000-000000000001")
69 | // Select all entities connected via REL_TEST_CHILD
70 | .out("test.Child")
71 | // Filter the selected set of entities
72 | .filter(_.and(
73 | _.eq("test.One", "5"),
74 | _.eq("test.Two", "red")))
75 | .select("test.Comment")
76 | .execute();
77 |
78 | Query.Result result = opResult.getResult();
79 |
80 | List entities = result.getEntities();
81 | }
82 |
83 |
84 | public class PersistenceFactoryImpl implements Persistence.Factory {
85 | @Override
86 | public Persistence newInstance(Persistence.Configuration config) {
87 | return new PersistenceImpl();
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/README.md:
--------------------------------------------------------------------------------
1 | # Universal Graph Client SDK Core Implementation
2 |
3 | Partial implementation of the Universal Graph Client API, requiring a persistence provider as specified by the Service-Provider Interface (SPI) contained in the `com.intuit.ugc.impl.core.spi` package.
4 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/GraphAttribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import java.time.Instant;
16 | import java.util.UUID;
17 |
18 | import com.intuit.ugc.api.Attribute;
19 | import com.toddfast.util.convert.TypeConverter;
20 | import com.toddfast.util.preconditions.Preconditions;
21 |
22 | /**
23 | * A representation of Graph specific attribute
24 | *
25 | * @see com.intuit.ugc.api.Attribute
26 | * @author ajain17
27 | */
28 | public class GraphAttribute implements Attribute {
29 |
30 | private final Object attributeValue;
31 | private final Name name;
32 | private final Metadata metadata;
33 |
34 | public GraphAttribute(Name name, Object attributeValue,
35 | Attribute.Metadata metadata) {
36 | super();
37 | this.name = Preconditions.argumentNotNull(name,"name");
38 | this.attributeValue =
39 | Preconditions.argumentNotNull(attributeValue,"attributeValue");
40 | this.metadata = Preconditions.argumentNotNull(metadata,"metadata");
41 | }
42 |
43 | @Override
44 | public Metadata getMetadata() {
45 | return metadata;
46 | }
47 |
48 | @Override
49 | public Name getName() {
50 | return name;
51 | }
52 |
53 | @Override
54 | public V getValue(Class clazz) {
55 | return TypeConverter.convert(
56 | Preconditions.argumentNotNull(clazz,"clazz"),
57 | attributeValue);
58 | }
59 |
60 | @Override
61 | public Integer getInteger() {
62 | return TypeConverter.asInt(attributeValue);
63 | }
64 |
65 | @Override
66 | public Double getDouble() {
67 | return TypeConverter.asDouble(attributeValue);
68 | }
69 |
70 | @Override
71 | public Boolean getBoolean() {
72 | return TypeConverter.asBoolean(attributeValue);
73 | }
74 |
75 | @Override
76 | public String getString() {
77 | return TypeConverter.asString(attributeValue);
78 | }
79 |
80 | @Override
81 | public Instant getInstant() {
82 | return TypeConverter.convert(Instant.class,attributeValue);
83 | }
84 |
85 | @Override
86 | public UUID getUUID() {
87 | return TypeConverter.convert(UUID.class,attributeValue);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/GraphAttributeOperations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import java.util.ArrayList;
16 | import java.util.Collections;
17 | import java.util.HashMap;
18 | import java.util.List;
19 | import java.util.Map;
20 |
21 | import com.intuit.ugc.api.Attribute.Name;
22 | import com.toddfast.util.preconditions.Preconditions;
23 |
24 | /**
25 | * A representation of the operations possible on graph attribute.
26 | *
27 | * @ajain17
28 | */
29 | public class GraphAttributeOperations {
30 |
31 | private Map setOperations;
32 | private List unsetOperations;
33 |
34 | public GraphAttributeOperations() {
35 | setOperations = new HashMap<>();
36 | unsetOperations = new ArrayList<>();
37 | }
38 |
39 | /**
40 | *
41 | * @param value
42 | * The boxed scalar value, or null (which will unset the value)
43 | */
44 | public void setAttributeValue(Name name, Object value) {
45 | if (value == null) {
46 | unsetAttributeValue(name);
47 | }
48 | else {
49 | Preconditions.argumentNotNull(name,"name::Atribute.Name");
50 | setOperations.put(name, value);
51 | }
52 | }
53 |
54 | /**
55 | *
56 | *
57 | */
58 | public void unsetAttributeValue(Name name) {
59 | Preconditions.argumentNotNull(name,"name::Atribute.Name");
60 | unsetOperations.add(name);
61 | }
62 |
63 | /**
64 | *
65 | *
66 | */
67 | public Map getSetValueOperations() {
68 | return Collections.unmodifiableMap(setOperations);
69 | }
70 |
71 | /**
72 | *
73 | *
74 | */
75 | public List getUnsetValueOperations() {
76 | return Collections.unmodifiableList(unsetOperations);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/GraphMutation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import com.google.inject.Inject;
16 | import com.intuit.ugc.api.BatchMutation;
17 | import com.intuit.ugc.api.Entity;
18 | import com.intuit.ugc.api.NewEntity;
19 | import com.intuit.ugc.api.NewRelationship;
20 | import com.intuit.ugc.api.OperationResult;
21 | import com.intuit.ugc.api.Relationship;
22 | import com.intuit.ugc.impl.core.queryplan.MutationExecutorFactory;
23 | import com.intuit.ugc.impl.core.queryplan.OperationFeederImpl;
24 | import com.intuit.ugc.impl.core.queryplan.OperationPipeline;
25 | import com.intuit.ugc.impl.core.queryplan.operations.CreateEntity;
26 | import com.intuit.ugc.impl.core.queryplan.operations.CreateRelationship;
27 | import com.toddfast.util.preconditions.Preconditions;
28 |
29 | /**
30 | * A representation of batch mutation in graph persistence store
31 | *
32 | * @see com.intuit.ugc.api.BatchMutation
33 | * @author ajain17
34 | *
35 | */
36 | public class GraphMutation implements BatchMutation {
37 |
38 | private OperationPipeline pipeline;
39 | private OperationFeederImpl graphOperation;
40 |
41 | @Inject
42 | public GraphMutation(MutationExecutorFactory factory) {
43 | this.pipeline = new OperationPipeline();
44 | this.graphOperation = factory.create(this.pipeline);
45 | }
46 |
47 | @Override
48 | public BatchMutation createEntity(NewEntity newEntity) {
49 | Preconditions.argumentNotNull(newEntity, "newEntity");
50 | CreateEntity createEntity = new CreateEntity(newEntity);
51 | pipeline.add(createEntity);
52 | return this;
53 | }
54 |
55 | @Override
56 | public BatchMutation createRelationship(NewRelationship newRelationship) {
57 | Preconditions.argumentNotNull(newRelationship, "newRelationship");
58 | CreateRelationship createRelationships = new CreateRelationship(
59 | newRelationship);
60 | pipeline.add(createRelationships);
61 | return this;
62 | }
63 |
64 | @Override
65 | public OperationResult execute() {
66 | return () -> (GraphMutationResult) graphOperation.operationResult();
67 | }
68 |
69 | @Override
70 | public Entity.Mutation withEntity(Entity entity) {
71 | Preconditions.argumentNotNull(entity, "entity");
72 | return new GraphEntityMutation(entity, pipeline, this);
73 | }
74 |
75 | @Override
76 | public Relationship.Mutation withRelationship(Relationship relationship) {
77 | Preconditions.argumentNotNull(relationship, "relationship");
78 | return new GraphRelationshipMutation(relationship, pipeline, this);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/GraphMutationResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import java.util.Collections;
16 | import java.util.List;
17 |
18 | import com.intuit.ugc.api.BatchMutation;
19 |
20 | /**
21 | * A representation of Graph persistence specific mutation result
22 | *
23 | * @see com.intuit.ugc.api.BatchMutation.Result
24 | * @see com.intuit.ugc.impl.core.VisitOperationResult
25 | * @author ajain17
26 | */
27 | public class GraphMutationResult implements BatchMutation.Result, VisitOperationResult {
28 |
29 | private List entityKeys = Collections.emptyList();
30 |
31 | public GraphMutationResult() {
32 | super();
33 | }
34 |
35 | public GraphMutationResult(List entityKeys) {
36 | super();
37 | this.entityKeys = Collections.unmodifiableList(entityKeys);
38 | }
39 |
40 | public List getEntityKeys() {
41 | return entityKeys;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/GraphProjection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import com.google.inject.Inject;
16 | import com.intuit.ugc.api.AccessControlException;
17 | import com.intuit.ugc.api.Attribute;
18 | import com.intuit.ugc.api.OperationResult;
19 | import com.intuit.ugc.api.Queries;
20 | import com.intuit.ugc.api.Query;
21 | import com.intuit.ugc.impl.core.queryplan.Operation;
22 | import com.intuit.ugc.impl.core.queryplan.OperationFeederImpl;
23 | import com.intuit.ugc.impl.core.queryplan.OperationPipeline;
24 | import com.intuit.ugc.impl.core.queryplan.TerminalOperation;
25 | import com.intuit.ugc.impl.core.queryplan.operations.GraphTerminalOperation;
26 | import com.intuit.ugc.impl.core.spi.GraphVisitor;
27 | import com.intuit.ugc.impl.core.spi.QueryResultImpl;
28 |
29 | /**
30 | * Represents a projection in a graph persistence store
31 | *
32 | * implements {@link com.intuit.ugc.api.Queries.Projection}
33 | *
34 | * @author ajain17
35 | */
36 | public class GraphProjection implements Queries.Projection {
37 |
38 | private GraphVisitor repository;
39 | private final OperationPipeline pipeline;
40 |
41 | @Inject
42 | public GraphProjection(GraphVisitor repository,
43 | OperationPipeline aPipeline) {
44 | this.pipeline = aPipeline;
45 | this.repository = repository;
46 | this.pipeline.add(new GraphTerminalOperation());
47 | }
48 |
49 | private TerminalOperation getTerminal() {
50 | Operation currentOperation = pipeline.getTailOperation();
51 | if (currentOperation instanceof TerminalOperation) {
52 | TerminalOperation graphOps = (TerminalOperation) currentOperation;
53 | return graphOps;
54 | } else {
55 | return null;
56 | // Throw Exception for Invalid include operation
57 | }
58 | }
59 |
60 | @Override
61 | public Queries.Projection includeAttribute(Attribute.Name name) {
62 | getTerminal().include(name);
63 | return this;
64 | }
65 |
66 | @Override
67 | public Queries.Projection includeAttributes(Attribute.Family namespace) {
68 | getTerminal().include(namespace);
69 | return this;
70 | }
71 |
72 | @Override
73 | public Query ready() {
74 | return new QueryImpl(repository, pipeline);
75 | }
76 |
77 | private class QueryImpl implements Query {
78 | private OperationFeederImpl graphOperation;
79 |
80 | QueryImpl (GraphVisitor persistenceRepository, OperationPipeline operationsPipeline){
81 | this.graphOperation = new OperationFeederImpl(persistenceRepository, operationsPipeline);
82 | }
83 |
84 | @Override
85 | public OperationResult execute() throws AccessControlException {
86 | return () -> new GraphQueryResult((QueryResultImpl) graphOperation.operationResult());
87 | }
88 |
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/GraphQueryResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import java.util.List;
16 |
17 | import com.intuit.ugc.api.Entity;
18 | import com.intuit.ugc.api.Query;
19 | import com.intuit.ugc.api.Relationship;
20 | import com.intuit.ugc.impl.core.spi.QueryResult;
21 |
22 | /**
23 | * A representation of a query result after the query is executed on a graph persistence store
24 | *
25 | * implements {@link com.intuit.ugc.api.Query.Result}
26 | * @author ajain17
27 | */
28 | public class GraphQueryResult implements Query.Result {
29 |
30 | private final QueryResult queryResult;
31 |
32 | public GraphQueryResult(
33 | final QueryResult queryResult) {
34 | this.queryResult = queryResult;
35 | }
36 |
37 | @Override
38 | public Entity getEntity() {
39 | return queryResult.getEntityResponse().size() > 0
40 | ? queryResult.getEntityResponse().get(0)
41 | : null;
42 | }
43 |
44 | @Override
45 | public List getEntities() {
46 | return queryResult.getEntityResponse();
47 | }
48 |
49 | @Override
50 | public Relationship getRelationship() {
51 | return queryResult.getRelationshipResponse().size() > 0
52 | ? queryResult.getRelationshipResponse().get(0)
53 | : null;
54 | }
55 |
56 | @Override
57 | public List getRelationships() {
58 | return queryResult.getRelationshipResponse();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/GraphRelationshipMutation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import com.intuit.ugc.api.BatchMutation;
16 | import com.intuit.ugc.api.Queries.Projection;
17 | import com.intuit.ugc.api.Relationship;
18 | import com.intuit.ugc.api.Attribute.Name;
19 | import com.intuit.ugc.api.Relationship.Mutation;
20 | import com.intuit.ugc.impl.core.queryplan.OperationPipeline;
21 | import com.intuit.ugc.impl.core.queryplan.operations.DeleteRelationship;
22 | import com.intuit.ugc.impl.core.queryplan.operations.UpdateRelationship;
23 |
24 | /**
25 | * Represents a Relationship Mutation in a graph persistence store.
26 | *
27 | * implements {@link com.intuit.ugc.api.Relationship.Mutation}
28 | * @author ajain17
29 | *
30 | */
31 | public class GraphRelationshipMutation implements Mutation {
32 |
33 | private Relationship relationship;
34 | private final OperationPipeline pipeline;
35 | private final BatchMutation batchMutation;
36 | private final GraphAttributeOperations operatons;
37 | /**
38 | * A boolean to differentiate between delete and update mutations
39 | */
40 | private boolean delete = false;
41 |
42 | public GraphRelationshipMutation(Relationship relationship,
43 | OperationPipeline pipeline,
44 | BatchMutation batchMutation) {
45 | this.relationship = relationship;
46 | this.pipeline = pipeline;
47 | this.batchMutation = batchMutation;
48 | this.operatons = new GraphAttributeOperations();
49 | }
50 |
51 | @Override
52 | public Mutation setAttribute(Name name, Object value) {
53 | operatons.setAttributeValue(name, value);
54 | return this;
55 | }
56 |
57 | @Override
58 | public Mutation deleteAttribute(Name name) {
59 | operatons.unsetAttributeValue(name);
60 | return this;
61 | }
62 |
63 | @Override
64 | public com.intuit.ugc.api.BatchMutation ready() {
65 | if (this.delete) {
66 | DeleteRelationship deleteRelationship = new DeleteRelationship(relationship);
67 | pipeline.add(deleteRelationship);
68 | } else {
69 | UpdateRelationship updateRelationship = new UpdateRelationship(relationship, operatons);
70 | pipeline.add(updateRelationship);
71 | }
72 | return batchMutation;
73 | }
74 |
75 | @Override
76 | public Mutation delete() {
77 | this.delete = true;
78 | return this;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/InstantTypeConversion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import java.time.Instant;
16 | import java.util.Date;
17 |
18 | import com.toddfast.util.convert.TypeConverter;
19 |
20 | /**
21 | * A class to support the conversion of a value in an {@link java.time.Instant} type
22 | *
23 | * @author ajain17
24 | */
25 | public class InstantTypeConversion implements TypeConverter.Conversion {
26 |
27 | @Override
28 | public Object[] getTypeKeys() {
29 | return new Object[] { Instant.class, Instant.class.getName() };
30 | }
31 |
32 | @Override
33 | public Instant convert(Object value) {
34 | if (value == null) {
35 | return null;
36 | }
37 | else
38 | if (value instanceof Instant) {
39 | return (Instant)value;
40 | }
41 | else
42 | if (value instanceof Date) {
43 | return ((Date)value).toInstant();
44 | }
45 | else
46 | if (value instanceof CharSequence) {
47 | return Instant.parse((CharSequence)value);
48 | }
49 | else {
50 | return Instant.parse(value.toString());
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/UUIDTypeConversion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import java.util.UUID;
16 |
17 | import com.toddfast.util.convert.TypeConverter;
18 |
19 | /**
20 | * A class to support the conversion of a value in an {@link java.util.UUID} type
21 | *
22 | * @author ajain17
23 | */
24 | public class UUIDTypeConversion implements TypeConverter.Conversion {
25 |
26 | @Override
27 | public Object[] getTypeKeys() {
28 | return new Object[] { UUID.class, UUID.class.getName() };
29 | }
30 |
31 | @Override
32 | public UUID convert(Object value) {
33 | if (value == null) {
34 | return null;
35 | }
36 | else
37 | if (value instanceof UUID) {
38 | return (UUID)value;
39 | }
40 | else
41 | if (value instanceof String) {
42 | return UUID.fromString((String)value);
43 | }
44 | else
45 | if (value.getClass().isArray()) {
46 | if (value.getClass().getComponentType() == Byte.TYPE) {
47 | return UUID.nameUUIDFromBytes((byte[])value);
48 | }
49 | else
50 | if (value.getClass().getComponentType() == Character.TYPE) {
51 | return UUID.fromString(String.valueOf((char[])value));
52 | }
53 | else {
54 | throw new IllegalArgumentException("Cannot convert to UUID "+
55 | "from array of \""+
56 | value.getClass().getComponentType()+"\"");
57 | }
58 | }
59 | else {
60 | return UUID.fromString(value.toString());
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/VisitOperationResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | /**
16 | * represents the result of a graph visit operation
17 | *
18 | * @author ajain17
19 | *
20 | */
21 | public interface VisitOperationResult {
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/predicate/AndPredicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import java.util.Collection;
16 | import java.util.Objects;
17 |
18 | import com.intuit.ugc.api.Attribute;
19 |
20 | /**
21 | *
22 | * @author ajain17
23 | *
24 | */
25 | public final class AndPredicate implements StreamPredicate, CompoundPredicate {
26 |
27 | protected StreamPredicate[] predicates;
28 |
29 | public AndPredicate() {
30 | }
31 |
32 | public AndPredicate(StreamPredicate... predicates) {
33 | this.predicates = predicates;
34 | }
35 |
36 |
37 | @Override
38 | public StreamPredicate[] getPredicates() {
39 | return predicates;
40 | }
41 |
42 | @Override
43 | public void setPredicates(StreamPredicate[] predicates) {
44 | //immutable
45 | if (Objects.isNull(this.predicates)) {
46 | this.predicates = predicates;
47 | } else {
48 | throw new IllegalStateException(
49 | "Cannot reset predicates in an AndPredicate after they have been already set");
50 | }
51 | }
52 |
53 | @Override
54 | public boolean apply(Collection attributes) {
55 | for (StreamPredicate predicate : predicates) {
56 | if (!predicate.apply(attributes)){
57 | return false;
58 | }
59 | }
60 | return true;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/predicate/CompoundPredicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | /**
16 | *
17 | * @author ajain17
18 | *
19 | */
20 | public interface CompoundPredicate {
21 |
22 | StreamPredicate[] getPredicates();
23 |
24 | void setPredicates(StreamPredicate[] predicates);
25 |
26 | }
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/predicate/EqualToPredicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import java.util.Collection;
16 | import java.util.Objects;
17 |
18 | import com.intuit.ugc.api.Attribute;
19 |
20 | /**
21 | *
22 | * @author ajain17
23 | *
24 | */
25 | public class EqualToPredicate implements StreamPredicate {
26 |
27 | private Attribute.Name attributeName;
28 | protected Object value;
29 |
30 | public EqualToPredicate() {
31 | }
32 |
33 | public EqualToPredicate(Attribute.Name attributeName) {
34 | this.attributeName = attributeName;
35 | }
36 |
37 | EqualToPredicate(Attribute.Name attributeName, Object value) {
38 | this.attributeName = attributeName;
39 | this.value = value;
40 | }
41 |
42 | @Override
43 | public boolean apply(Collection attributes) {
44 | return Objects.nonNull(attributeName)
45 | && Objects.nonNull(value)
46 | && attributes.stream()
47 | .anyMatch(attr ->
48 | attr.getName().equals(attributeName)
49 | && value.equals(attr.getValue(value.getClass()))
50 | );
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/predicate/OrPredicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import java.util.Collection;
16 | import java.util.Objects;
17 |
18 | import com.intuit.ugc.api.Attribute;
19 |
20 | /**
21 | *
22 | * @author ajain17
23 | *
24 | */
25 | public final class OrPredicate implements StreamPredicate, CompoundPredicate {
26 |
27 | protected StreamPredicate[] predicates;
28 |
29 | public OrPredicate() {
30 | }
31 |
32 | public OrPredicate(StreamPredicate... predicates) {
33 | this.predicates = predicates;
34 | }
35 |
36 |
37 | @Override
38 | public StreamPredicate[] getPredicates() {
39 | return predicates;
40 | }
41 |
42 | @Override
43 | public void setPredicates(StreamPredicate[] predicates) {
44 | //immutable
45 | if (Objects.isNull(this.predicates)) {
46 | this.predicates = predicates;
47 | } else {
48 | throw new IllegalStateException(
49 | "Cannot reset predicates in an OrPredicate after they have "+
50 | "been already set");
51 | }
52 | }
53 |
54 | @Override
55 | public boolean apply(Collection attributes) {
56 | for (StreamPredicate predicate : predicates) {
57 | if (predicate.apply(attributes)) {
58 | return true;
59 | }
60 | }
61 | return false;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/predicate/StreamComparison.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import com.intuit.ugc.api.Attribute;
16 | import com.intuit.ugc.api.Predicate.Comparison;
17 |
18 | /**
19 | *
20 | * @author ajain17
21 | *
22 | */
23 | public class StreamComparison implements Comparison {
24 | StreamPredicateBuilder pb;
25 |
26 | StreamComparison(StreamPredicateBuilder pb) {
27 | this.pb = pb;
28 | }
29 |
30 | public StreamComparison get(Attribute.Name name) {
31 | pb.setAttribute(name);
32 | return this;
33 | }
34 |
35 | private StreamPredicateBuilder addPredicate(StreamPredicate predicate) {
36 | pb.addPredicate(predicate);
37 | return pb;
38 | }
39 |
40 | @Override
41 | public StreamPredicateBuilder equalTo(Object value) {
42 | return addPredicate(StreamPredicates.equalTo(pb.getAttribute(), value));
43 | }
44 |
45 | @Override
46 | public StreamPredicateBuilder notEqualTo(Object o) throws UnsupportedOperationException {
47 | throw new UnsupportedOperationException();
48 | }
49 |
50 | @Override
51 | public StreamPredicateBuilder greaterThan(Object o) throws UnsupportedOperationException {
52 | throw new UnsupportedOperationException();
53 | }
54 |
55 | @Override
56 | public StreamPredicateBuilder lessThan(Object o) throws UnsupportedOperationException {
57 | throw new UnsupportedOperationException();
58 | }
59 | }
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/predicate/StreamPredicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import java.util.Collection;
16 |
17 | import com.intuit.ugc.api.Attribute;
18 |
19 | /**
20 | *
21 | * @author ajain17
22 | *
23 | */
24 | public interface StreamPredicate {
25 |
26 | boolean apply(Collection attributes);
27 | }
28 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/predicate/StreamPredicates.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import com.intuit.ugc.api.Attribute;
16 |
17 | /**
18 | *
19 | * @author ajain17
20 | *
21 | */
22 | public final class StreamPredicates {
23 | private StreamPredicates() {
24 | }
25 |
26 | public static StreamPredicate and(StreamPredicate... predicates){
27 | return new AndPredicate(predicates);
28 | }
29 |
30 | public static StreamPredicate or(StreamPredicate... predicates) {
31 | return new OrPredicate(predicates);
32 | }
33 |
34 | public static StreamPredicate equalTo(Attribute.Name attributeName, Object value) {
35 | return new EqualToPredicate(attributeName, value);
36 | }
37 |
38 | public static StreamPredicate notEqualTo(Object value) throws UnsupportedOperationException {
39 | throw new UnsupportedOperationException();
40 | }
41 |
42 | public static StreamPredicate greaterThan(Object value) throws UnsupportedOperationException {
43 | throw new UnsupportedOperationException();
44 | }
45 |
46 | public static StreamPredicate lessThan(Object value) throws UnsupportedOperationException {
47 | throw new UnsupportedOperationException();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/ContextOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan;
14 |
15 | import com.intuit.ugc.api.Predicate;
16 |
17 | /**
18 | *
19 | * @author ajain17
20 | *
21 | */
22 | public interface ContextOperation extends Operation {
23 |
24 | /**
25 | * Predicate for context operation
26 | *
27 | * @param predicate
28 | */
29 | public void condition(Predicate predicate);
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/MutationExecutorFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan;
14 |
15 | /**
16 | *
17 | * @author ajain17
18 | *
19 | */
20 | public interface MutationExecutorFactory {
21 |
22 | public OperationFeederImpl create(OperationPipeline pipeline);
23 | }
24 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/Operation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan;
14 |
15 | /**
16 | *
17 | * @author ajain17
18 | *
19 | */
20 | public interface Operation {
21 |
22 | }
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/OperationFeeder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan;
14 |
15 | import com.intuit.ugc.impl.core.VisitOperationResult;
16 |
17 | /**
18 | *
19 | * @author ajain17
20 | *
21 | */
22 | public interface OperationFeeder {
23 | public VisitOperationResult operationResult();
24 | }
25 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/OperationIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan;
14 |
15 | /**
16 | *
17 | * @author ajain17
18 | *
19 | */
20 | public interface OperationIterator {
21 | /**
22 | * Return true if AssemblyLine has any operation in queue
23 | *
24 | * @return
25 | */
26 | public boolean hasNext();
27 |
28 | /**
29 | * Get next operation from AssemblyLine queue
30 | * @return
31 | */
32 | public Operation next();
33 | }
34 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/OperationList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan;
14 |
15 | /**
16 | *
17 | * @author ajain17
18 | *
19 | */
20 | public interface OperationList {
21 | /**
22 | * Add an operation
23 | *
24 | * @param op
25 | */
26 | public void add(Operation op);
27 |
28 | /**
29 | * Get Current Operation
30 | *
31 | * @return
32 | */
33 | public Operation getTailOperation();
34 |
35 | /**
36 | * Get Iterator
37 | *
38 | * @return
39 | */
40 | public OperationIterator iterator();
41 |
42 | }
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/OperationPipeline.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | *
20 | * @author ajain17
21 | *
22 | */
23 | public class OperationPipeline implements OperationList {
24 |
25 | private final List operations = new ArrayList<>();
26 |
27 | public OperationPipeline() {
28 | }
29 |
30 | @Override
31 | public Operation getTailOperation() {
32 | if (operations.size() > 0) {
33 | return operations.get(operations.size()-1);
34 | }
35 | else {
36 | return null;
37 | }
38 | }
39 |
40 | @Override
41 | public void add(Operation op) {
42 | operations.add(op);
43 | }
44 |
45 | @Override
46 | public OperationIterator iterator() {
47 | return new OperationIteratorImpl(this.operations);
48 | }
49 |
50 | /**
51 | *
52 | *
53 | *
54 | */
55 | private class OperationIteratorImpl implements OperationIterator {
56 | private int position = 0;
57 | private final List operationsList;
58 |
59 | public OperationIteratorImpl(List operationsList) {
60 | this.operationsList = operationsList;
61 | }
62 |
63 | @Override
64 | public boolean hasNext() {
65 | if (position < operationsList.size()) {
66 | return true;
67 | }
68 | return false;
69 | }
70 |
71 | @Override
72 | public Operation next() {
73 | Operation operation = operationsList.get(position);
74 | position++;
75 | return operation;
76 | }
77 |
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/TerminalOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan;
14 |
15 | import com.intuit.ugc.api.Attribute;
16 |
17 | /**
18 | *
19 | * @author ajain17
20 | *
21 | */
22 | public interface TerminalOperation extends Operation {
23 |
24 | /**
25 | * Include Attribute in response
26 | *
27 | * @param name
28 | */
29 | public void include(Attribute.Name name);
30 |
31 | /**
32 | * Include Namespace in response
33 | *
34 | * @param namespace
35 | */
36 | public void include(Attribute.Family namespace);
37 | }
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/CreateEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import com.intuit.ugc.api.NewEntity;
16 | import com.intuit.ugc.impl.core.queryplan.Operation;
17 |
18 | /**
19 | * Represents an entity creation operation. The operation itself is stored in
20 | * the pipeline as an instance of this class. And once execution is started over
21 | * the pipeline, all the operations are executed one by one.
22 | *
23 | * @author ajain17
24 | *
25 | */
26 | public class CreateEntity implements Operation {
27 |
28 | private final NewEntity newEntity;
29 |
30 | public CreateEntity(NewEntity newEntity) {
31 | super();
32 | this.newEntity = newEntity;
33 | }
34 |
35 | public NewEntity newEntity() {
36 | return newEntity;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "Operation [Create Entity] Entity ID ["
42 | + newEntity.getEntityID().getRawID() + "]";
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/CreateRelationship.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import com.intuit.ugc.api.NewRelationship;
16 | import com.intuit.ugc.impl.core.queryplan.Operation;
17 |
18 | /**
19 | * Represents a relationship creation operation. The operation itself is stored in
20 | * the pipeline as an instance of this class. And once execution is started over
21 | * the pipeline, all the operations are executed one by one.
22 | *
23 | * @author ajain17
24 | *
25 | */
26 | public class CreateRelationship implements Operation {
27 | private final NewRelationship newRelationship;
28 |
29 | public CreateRelationship(NewRelationship newRelationship) {
30 | super();
31 | this.newRelationship = newRelationship;
32 | }
33 |
34 | public NewRelationship newRelationship() {
35 | return newRelationship;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return "Operation [Create Relationship] SOURCE ID ["
41 | + newRelationship.getSourceID() + "]" + " TARGET ID ["
42 | + newRelationship.getTargetID() + "]";
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/DeleteEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * nverma1 - API and implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.core.queryplan.operations;
13 |
14 | import com.intuit.ugc.api.Entity;
15 | import com.intuit.ugc.impl.core.queryplan.Operation;
16 |
17 | /**
18 | * Represents an entity deletion operation. The operation itself is stored in
19 | * the pipeline as an instance of this class. And once execution is started over
20 | * the pipeline, all the operations are executed one by one.
21 | * @author nverma1
22 | *
23 | */
24 | public class DeleteEntity implements Operation {
25 | private final Entity entity;
26 |
27 | public DeleteEntity(Entity entity){
28 | this.entity = entity;
29 | }
30 |
31 | public Entity getEntity(){
32 | return this.entity;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return "Operation [Delete Entity] entity id ["
38 | + entity.getID().getRawID() + "]";
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/DeleteRelationship.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * nverma1 - API and implementation and initial documentation
10 | */
11 |
12 | package com.intuit.ugc.impl.core.queryplan.operations;
13 |
14 | import com.intuit.ugc.api.Relationship;
15 | import com.intuit.ugc.impl.core.queryplan.Operation;
16 |
17 | /**
18 | * Represents a relationship deletion operation. The operation itself is stored in
19 | * the pipeline as an instance of this class. And once execution is started over
20 | * the pipeline, all the operations are executed one by one.
21 | *
22 | * @author nverma1
23 | *
24 | */
25 | public class DeleteRelationship implements Operation{
26 | private final Relationship relationship;
27 |
28 | public DeleteRelationship(Relationship relationship){
29 | this.relationship = relationship;
30 | }
31 |
32 | public Relationship getRelationship(){
33 | return this.relationship;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return "Operation [Delete Relationship] between source entity id ["
39 | + relationship.getSourceID().getRawID() + "]" + " and target entity id ["
40 | + relationship.getTargetID().getRawID() + "]";
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/GetBatchEntityByID.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import com.intuit.ugc.api.Entity;
19 | import com.intuit.ugc.impl.core.queryplan.Operation;
20 | import com.toddfast.util.preconditions.Preconditions;
21 |
22 | /**
23 | * Represents an operation to fetch batch of entities given their ids. The operation itself is stored in
24 | * the pipeline as an instance of this class. And once execution is started over
25 | * the pipeline, all the operations are executed one by one.
26 | *
27 | * @author ajain17
28 | *
29 | */
30 | public class GetBatchEntityByID implements Operation {
31 |
32 | private final List entityIDs;
33 |
34 | public GetBatchEntityByID(List entityIDs) {
35 | super();
36 | this.entityIDs = new ArrayList(
37 | Preconditions.collectionItemsNotNull(entityIDs, "entityIDs"));
38 | }
39 |
40 | public List getEntityIDs() {
41 | return entityIDs;
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return "Operation [Get Entity] Entity ID " + entityIDs;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/GetEntityByID.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import com.intuit.ugc.api.Entity.ID;
16 | import com.intuit.ugc.impl.core.queryplan.Operation;
17 |
18 | /**
19 | * Represents an operation to fetch an entity given it's id. The operation itself is stored in
20 | * the pipeline as an instance of this class. And once execution is started over
21 | * the pipeline, all the operations are executed one by one.
22 | *
23 | * @author ajain17
24 | *
25 | */
26 | public class GetEntityByID implements Operation {
27 |
28 | private final ID id;
29 |
30 | public GetEntityByID(ID id) {
31 | super();
32 | this.id = id;
33 | }
34 |
35 | public ID getId() {
36 | return id;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "Operation [Get Entity] Entity ID [" + id.getRawID() + "]";
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/GetEntityByProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import com.intuit.ugc.api.Attribute.Name;
16 | import com.intuit.ugc.impl.core.queryplan.Operation;
17 |
18 | /**
19 | * Represents an operation to fetch an entity given it's property. The operation itself is stored in
20 | * the pipeline as an instance of this class. And once execution is started over
21 | * the pipeline, all the operations are executed one by one.
22 | *
23 | * @author ajain17
24 | *
25 | */
26 | public class GetEntityByProperty implements Operation {
27 | private final Name name;
28 | private final String value;
29 |
30 | public GetEntityByProperty(Name name, String value) {
31 | super();
32 | this.name = name;
33 | this.value = value;
34 | }
35 |
36 | public Name getName() {
37 | return name;
38 | }
39 |
40 | public String getValue() {
41 | return value;
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return "Operation [Get Entity] Key [" + name.toString() + "] Value ["
47 | + value + "]";
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/GraphTerminalOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import java.util.ArrayList;
16 |
17 | import java.util.List;
18 |
19 | import com.intuit.ugc.api.Attribute.Family;
20 | import com.intuit.ugc.api.Attribute.Name;
21 | import com.intuit.ugc.impl.core.queryplan.TerminalOperation;
22 |
23 | /**
24 | * Represents a graph terminal operation. The operation itself is stored in
25 | * the pipeline as an instance of this class. And once execution is started over
26 | * the pipeline, all the operations are executed one by one.
27 | *
28 | * @author ajain17
29 | *
30 | */
31 | public class GraphTerminalOperation implements TerminalOperation {
32 | private final List nameList;
33 | private final List namespaceList;
34 |
35 | public GraphTerminalOperation() {
36 | super();
37 | nameList = new ArrayList<>();
38 | namespaceList = new ArrayList<>();
39 | }
40 |
41 | public List getNameList() {
42 | return nameList;
43 | }
44 |
45 | public List getNamespaceList() {
46 | return namespaceList;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return "Graph Terminal Operation";
52 | }
53 |
54 | @Override
55 | public void include(Name name) {
56 | nameList.add(name);
57 | }
58 |
59 | @Override
60 | public void include(Family namespace) {
61 | namespaceList.add(namespace);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/SelectEntities.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import com.intuit.ugc.api.Predicate;
16 | import com.intuit.ugc.api.Relationship;
17 | import com.intuit.ugc.api.Queries.GraphTraversal.Direction;
18 | import com.intuit.ugc.impl.core.queryplan.ContextOperation;
19 | import com.intuit.ugc.impl.core.spi.RepositoryException;
20 |
21 | /**
22 | * Represents an entity selection operation. The operation itself is stored in
23 | * the pipeline as an instance of this class. And once execution is started over
24 | * the pipeline, all the operations are executed one by one.
25 | *
26 | * @author ajain17
27 | *
28 | */
29 | public class SelectEntities implements ContextOperation {
30 |
31 | private final Relationship.Name relationName;
32 | private final Direction direction;
33 | private Predicate predicate = null;
34 |
35 | public SelectEntities(Relationship.Name relationName, Direction direction) {
36 | super();
37 | this.relationName = relationName;
38 | if (direction == null) {
39 | this.direction = Direction.IN_OUT;
40 | } else {
41 | this.direction = direction;
42 | }
43 | }
44 |
45 | public Relationship.Name getRelationName() {
46 | return relationName;
47 | }
48 |
49 | public Direction getDirection() {
50 | return direction;
51 | }
52 |
53 | public Predicate getPredicate() {
54 | return predicate;
55 | }
56 |
57 | @Override
58 | public String toString() {
59 | return "Operation [Select Entities] with relation label ["
60 | + relationName.toString() + "]";
61 | }
62 |
63 | @Override
64 | public void condition(Predicate predicate) {
65 | if (this.predicate != null) {
66 | throw new IllegalStateException(
67 | "Operation [Select Entities] is already initialized with predicate. Override is not allowed");
68 | }
69 | this.predicate = predicate;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/SelectRelationships.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import com.intuit.ugc.api.Predicate;
16 | import com.intuit.ugc.api.Relationship;
17 | import com.intuit.ugc.api.Queries.GraphTraversal.Direction;
18 | import com.intuit.ugc.impl.core.queryplan.ContextOperation;
19 |
20 | /**
21 | * Represents a relationship selection operation. The operation itself is stored in
22 | * the pipeline as an instance of this class. And once execution is started over
23 | * the pipeline, all the operations are executed one by one.
24 | *
25 | * @author ajain17
26 | *
27 | */
28 | public class SelectRelationships implements ContextOperation {
29 |
30 | private final Relationship.Name name;
31 | private final Direction direction;
32 | private Predicate predicate = null;
33 |
34 | public SelectRelationships(Relationship.Name name, Direction direction) {
35 | super();
36 | this.name = name;
37 | if (direction == null) {
38 | this.direction = Direction.IN_OUT;
39 | } else {
40 | this.direction = direction;
41 | }
42 | }
43 |
44 | public Relationship.Name getRelationshipName() {
45 | return name;
46 | }
47 |
48 | public Direction getDirection() {
49 | return direction;
50 | }
51 |
52 | public Predicate getPredicate() {
53 | return predicate;
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return "Operation [Select Relationships] with relation label ["
59 | + name.toString() + "]";
60 | }
61 |
62 | @Override
63 | public void condition(Predicate predicate) {
64 | if (this.predicate != null) {
65 | throw new IllegalStateException(
66 | "Operation [Select Relationships] is already initialized with predicate. Override is not allowed");
67 | }
68 | this.predicate = predicate;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/UpdateEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import com.intuit.ugc.api.Entity;
16 | import com.intuit.ugc.impl.core.GraphAttributeOperations;
17 | import com.intuit.ugc.impl.core.queryplan.Operation;
18 |
19 | /**
20 | * Represents an entity update operation. The operation itself is stored in
21 | * the pipeline as an instance of this class. And once execution is started over
22 | * the pipeline, all the operations are executed one by one.
23 | *
24 | * @author ajain17
25 | *
26 | */
27 | public class UpdateEntity implements Operation {
28 |
29 | private final Entity entity;
30 | private final GraphAttributeOperations operations;
31 |
32 | public UpdateEntity(Entity entity, GraphAttributeOperations operations) {
33 | super();
34 | this.entity = entity;
35 | this.operations = operations;
36 | }
37 |
38 | public Entity getEntity() {
39 | return entity;
40 | }
41 |
42 | public GraphAttributeOperations getOperations() {
43 | return operations;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "Operation [Update Entity] entity id ["
49 | + entity.getID().getRawID() + "]";
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/queryplan/operations/UpdateRelationship.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import com.intuit.ugc.api.Relationship;
16 | import com.intuit.ugc.impl.core.GraphAttributeOperations;
17 | import com.intuit.ugc.impl.core.queryplan.Operation;
18 |
19 | /**
20 | * Represents a relationship update operation. The operation itself is stored in
21 | * the pipeline as an instance of this class. And once execution is started over
22 | * the pipeline, all the operations are executed one by one.
23 | *
24 | * @author ajain17
25 | *
26 | */
27 | public class UpdateRelationship implements Operation {
28 |
29 | private final Relationship relationship;
30 | private final GraphAttributeOperations operations;
31 |
32 | public UpdateRelationship(Relationship relationship,
33 | GraphAttributeOperations operations) {
34 | super();
35 | this.relationship = relationship;
36 | this.operations = operations;
37 | }
38 |
39 | public Relationship getRelationship() {
40 | return relationship;
41 | }
42 |
43 | public GraphAttributeOperations getOperations() {
44 | return operations;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "Operation [Update Relationship] source id ["
50 | + relationship.getSourceID().getRawID() + "] target id ["
51 | + relationship.getTargetID().getRawID() + "]";
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/spi/QueryResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.spi;
14 |
15 | import java.util.List;
16 |
17 | import com.intuit.ugc.impl.core.VisitOperationResult;
18 |
19 | /**
20 | * Represents a specific
21 | * {@link com.intuit.ugc.impl.core.VisitOperationResult} wherein the query
22 | * operation returns a result as list of entities or a list of relationship or
23 | * both. For instance, result of a select query operation.
24 | *
25 | * @author ajain17
26 | */
27 | public interface QueryResult extends VisitOperationResult {
28 |
29 | public enum CurrentOperationType {
30 | ENTITY, RELATIONHIP
31 | };
32 |
33 | public CurrentOperationType getCurrentOperation();
34 |
35 | public void setEntityOpResponse(List entityList);
36 |
37 | public void setRelationshipOpResponse(List relationshipList);
38 |
39 | public List getEntityResponse();
40 |
41 | public List getRelationshipResponse();
42 | }
43 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/spi/QueryResultImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.spi;
14 |
15 | import java.util.Collections;
16 | import java.util.List;
17 |
18 | import com.intuit.ugc.api.Entity;
19 | import com.intuit.ugc.api.Relationship;
20 |
21 | /**
22 | *
23 | * An implementation of the {@link com.intuit.ugc.impl.core.spi.QueryResult}
24 | * This class should be used by graph specific provider to collect the result of the query executed.
25 | *
26 | * @author ajain17
27 | */
28 | public class QueryResultImpl implements QueryResult {
29 |
30 | private List entityList = Collections.emptyList();
31 | private List relationshipList = Collections.emptyList();
32 | private CurrentOperationType currentOperation = null;
33 |
34 | public QueryResultImpl(CurrentOperationType currentOperation) {
35 | this.currentOperation = currentOperation;
36 | }
37 |
38 | @Override
39 | public CurrentOperationType getCurrentOperation() {
40 | return this.currentOperation;
41 | }
42 |
43 | @Override
44 | public void setEntityOpResponse(List entityList) {
45 | this.entityList = entityList;
46 | }
47 |
48 | @Override
49 | public void setRelationshipOpResponse(List relationshipList) {
50 | this.relationshipList = relationshipList;
51 | }
52 |
53 | @Override
54 | public List getEntityResponse() {
55 | return entityList;
56 | }
57 |
58 | @Override
59 | public List getRelationshipResponse() {
60 | return relationshipList;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/java/com/intuit/ugc/impl/core/spi/RepositoryException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.spi;
14 |
15 | /**
16 | *
17 | *
18 | * @author ajain17
19 | */
20 | @SuppressWarnings("serial")
21 | public class RepositoryException extends RuntimeException {
22 |
23 | public RepositoryException(Throwable cause) {
24 | super(cause);
25 | }
26 |
27 | public RepositoryException(String m, Throwable cause) {
28 | super(m,cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 | ${LOGDIR}/sangria_ingestion.log
7 |
8 |
9 | ${LOGDIR}/universal_graph_client.%d{yyyy-MM-dd}.%i.log
10 |
11 |
13 |
14 | 50MB
15 |
16 |
17 | 3
18 |
19 |
20 | %d{dd MMM yyyy;HH:mm:ss.SSS} %-5level [%thread][%logger{0}]
21 | %m%n
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/GraphMutationResultTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import static org.testng.Assert.assertEquals;
16 | import static org.testng.Assert.assertNotNull;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.Collections;
21 | import java.util.List;
22 |
23 | import org.testng.annotations.Test;
24 |
25 | import com.intuit.ugc.impl.core.GraphMutationResult;
26 |
27 | /**
28 | *
29 | * @author nverma1
30 | *
31 | */
32 | public class GraphMutationResultTest {
33 |
34 | @Test
35 | public void testCreateGraphMutationResultWithEntityKeys(){
36 | List entityKeys = new ArrayList(Arrays.asList("Key1", "Key2", "Key3"));
37 | GraphMutationResult graphMutationResult = new GraphMutationResult(entityKeys );
38 | List entityKeysReturned = graphMutationResult.getEntityKeys();
39 | assertNotNull(entityKeysReturned);
40 | assertEquals(entityKeys.size(), entityKeysReturned.size());
41 | assertEquals(entityKeys, entityKeysReturned);
42 | }
43 |
44 | @Test
45 | public void testCreateGraphMutationResultWithoutKeys(){
46 | GraphMutationResult graphMutationResult = new GraphMutationResult();
47 | assertEquals(Collections.emptyList(), graphMutationResult.getEntityKeys());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/GraphProjectionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import static org.testng.Assert.assertNotNull;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.OperationResult;
20 | import com.intuit.ugc.api.Query;
21 | import com.intuit.ugc.api.Queries.Projection;
22 | import com.intuit.ugc.api.Query.Result;
23 | import com.intuit.ugc.impl.core.GraphProjection;
24 | import com.intuit.ugc.impl.core.helper.MockGraphVisitor;
25 | import com.intuit.ugc.impl.core.helper.TartanImplTestConstants;
26 | import com.intuit.ugc.impl.core.queryplan.OperationPipeline;
27 | import com.intuit.ugc.impl.core.queryplan.operations.GraphTerminalOperation;
28 | import com.intuit.ugc.impl.core.spi.GraphVisitor;
29 |
30 | /**
31 | *
32 | * @author nverma1
33 | *
34 | */
35 | public class GraphProjectionTest {
36 |
37 | @Test
38 | public void testIncludeAttribute(){
39 | GraphVisitor repository = new MockGraphVisitor();
40 | GraphProjection graphProjection = new GraphProjection(repository, new OperationPipeline());
41 | Projection includeAttribute = graphProjection.includeAttribute(TartanImplTestConstants.ATTR_DUMMY_ATTRIBUTE_NAME);
42 | assertNotNull(includeAttribute);
43 | }
44 |
45 | @Test
46 | public void testIncludeAttributesFamily(){
47 | GraphVisitor repository = new MockGraphVisitor();
48 | GraphProjection graphProjection = new GraphProjection(repository, new OperationPipeline());
49 | Projection includeAttributes = graphProjection.includeAttributes(TartanImplTestConstants.ATTR_DUMMY_FAMILY);
50 | assertNotNull(includeAttributes);
51 | }
52 |
53 | @Test
54 | public void testReadyAndExecute(){
55 | GraphVisitor repository = new MockGraphVisitor();
56 | GraphProjection graphProjection = new GraphProjection(repository, new OperationPipeline());
57 | Query ready = graphProjection.ready();
58 | OperationResult execute = ready.execute();
59 | assertNotNull(execute);
60 | }
61 |
62 | @Test
63 | public void testTerminalOperationProjection(){
64 | OperationPipeline operationPipeline = new OperationPipeline();
65 | GraphTerminalOperation terminalOperation = new GraphTerminalOperation();
66 | operationPipeline.add(terminalOperation);
67 | GraphVisitor repository = new MockGraphVisitor();
68 | GraphProjection graphProjection = new GraphProjection(repository, new OperationPipeline());
69 | Projection includeAttribute = graphProjection.includeAttribute(TartanImplTestConstants.ATTR_DUMMY_ATTRIBUTE_NAME);
70 | assertNotNull(includeAttribute);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/GraphRelationshipTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import static org.testng.Assert.assertEquals;
16 | import static org.testng.Assert.assertNotNull;
17 | import static org.testng.Assert.assertTrue;
18 |
19 | import java.util.UUID;
20 |
21 | import org.testng.annotations.Test;
22 |
23 | import com.intuit.ugc.api.Entity;
24 | import com.intuit.ugc.api.Attribute.Metadata;
25 | import com.intuit.ugc.api.Attribute.Name;
26 | import com.intuit.ugc.impl.core.GraphAttribute;
27 | import com.intuit.ugc.impl.core.GraphRelationship;
28 | import com.intuit.ugc.impl.core.helper.MockMetadata;
29 | import com.intuit.ugc.impl.core.helper.TartanImplTestConstants;
30 | import com.intuit.ugc.impl.core.helper.TartanImplTestUtil;
31 |
32 | /**
33 | *
34 | * @author nverma1
35 | *
36 | */
37 | public class GraphRelationshipTest {
38 |
39 | @Test
40 | public void testGraphRelationshipCreation(){
41 | TartanImplTestUtil util = new TartanImplTestUtil();
42 | Entity.ID sourceEntityID = Entity.ID.valueOf("urn:entity:" + TartanImplTestConstants.ATTR_PARENT_ID.getName()
43 | + "." + TartanImplTestConstants.ATTR_PARENT_ID.getName() + "/" + UUID.randomUUID());
44 | Entity.ID targetEntityID = Entity.ID.valueOf("urn:entity:" + TartanImplTestConstants.ATTR_CHILD_ID.getName()
45 | + "." + TartanImplTestConstants.ATTR_PARENT_ID.getName() + "/" + UUID.randomUUID());
46 | Name attributeName = TartanImplTestConstants.ATTR_DUMMY_ATTRIBUTE_NAME;
47 | String attributeValue = "Dummy Attribute";
48 | Metadata metadata = new MockMetadata();
49 | GraphAttribute graphAttribute = new GraphAttribute(attributeName, attributeValue, metadata);
50 | GraphRelationship graphRelationship = util.buildGraphRelationship(
51 | TartanImplTestConstants.ATTR_DUMMY_RELATIONSHIP_NAME, sourceEntityID, targetEntityID, graphAttribute);
52 | assertNotNull(graphRelationship);
53 | assertEquals(graphRelationship.getName(),TartanImplTestConstants.ATTR_DUMMY_RELATIONSHIP_NAME);
54 | assertEquals(graphRelationship.getSourceID(), sourceEntityID);
55 | assertEquals(graphRelationship.getTargetID(), targetEntityID);
56 | assertEquals(graphRelationship.getAttributes().size(), 1);
57 | assertEquals(graphRelationship.getAttribute(attributeName), graphAttribute);
58 | }
59 |
60 | @Test
61 | public void testCreateGraphRelationshipWithNullParams(){
62 | GraphRelationship.Builder builder = new GraphRelationship.Builder();
63 | try{
64 | builder.build();
65 | }catch(Exception e){
66 | assertTrue(e instanceof IllegalStateException);
67 | assertEquals(e.getMessage(), "Missing required properties: \"[name, sourceID, targetID]\"");
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/InstantTypeConversionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core;
14 |
15 | import static org.testng.Assert.assertEquals;
16 | import static org.testng.Assert.assertNull;
17 | import static org.testng.Assert.assertTrue;
18 |
19 | import java.time.Instant;
20 | import java.util.Date;
21 |
22 | import org.testng.annotations.Test;
23 |
24 | import com.intuit.ugc.impl.core.InstantTypeConversion;
25 |
26 | /**
27 | *
28 | * @author nverma1
29 | *
30 | */
31 | public class InstantTypeConversionTest {
32 | @Test
33 | public void testInstantTypeConversionWithNullInput(){
34 | InstantTypeConversion instantTypeConversion = new InstantTypeConversion();
35 | assertNull(instantTypeConversion.convert(null));
36 | }
37 |
38 | @Test
39 | public void testInstantTypeConversionWithInstantInput(){
40 | InstantTypeConversion instantTypeConversion = new InstantTypeConversion();
41 | Instant convertedInstant = instantTypeConversion.convert(Instant.EPOCH);
42 | assertEquals(convertedInstant, Instant.EPOCH);
43 | }
44 |
45 | @Test
46 | public void testInstantTypeConversionWithDateInput(){
47 | InstantTypeConversion instantTypeConversion = new InstantTypeConversion();
48 | assertTrue(instantTypeConversion.convert(new Date()) instanceof Instant);
49 | }
50 |
51 | @Test
52 | public void testInstantType(){
53 | InstantTypeConversion instantTypeConversion = new InstantTypeConversion();
54 | Object[] typeKeys = instantTypeConversion.getTypeKeys();
55 | assertEquals(typeKeys[0], Instant.class);
56 | assertEquals(typeKeys[1], Instant.class.getName());
57 | }
58 |
59 | @Test
60 | public void testIntantTypeConversionWithCharacterSequence(){
61 | InstantTypeConversion instantTypeConversion = new InstantTypeConversion();
62 | CharSequence instantCharSeq = "2014-12-03T10:15:30.00Z";
63 | Instant convertedInstant = instantTypeConversion.convert(instantCharSeq);
64 | assertEquals(convertedInstant.getNano(), Instant.parse(instantCharSeq).getNano());
65 | }
66 |
67 | @Test
68 | public void testInstantTypeConversionWithString(){
69 | InstantTypeConversion instantTypeConversion = new InstantTypeConversion();
70 | String instantStr = new String("2014-12-03T10:15:30.00Z");
71 | InstantFormat obj = new InstantFormat(instantStr);
72 | Instant convertedInstant = instantTypeConversion.convert(obj);
73 | assertEquals(convertedInstant.getNano(), Instant.parse(instantStr).getNano());
74 | }
75 | }
76 |
77 |
78 | class InstantFormat {
79 | private String instantStr;
80 |
81 | public InstantFormat(String instantStr){
82 | this.instantStr = instantStr;
83 | }
84 |
85 | @Override
86 | public String toString() {
87 | return this.instantStr;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/helper/MockBatchMutation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.helper;
14 |
15 | import com.intuit.ugc.api.AccessControlException;
16 | import com.intuit.ugc.api.BatchMutation;
17 | import com.intuit.ugc.api.Entity;
18 | import com.intuit.ugc.api.InvalidAttributeException;
19 | import com.intuit.ugc.api.NewEntity;
20 | import com.intuit.ugc.api.NewRelationship;
21 | import com.intuit.ugc.api.OperationResult;
22 | import com.intuit.ugc.api.Relationship;
23 | import com.intuit.ugc.api.Entity.Mutation;
24 |
25 | /**
26 | *
27 | * @author nverma1
28 | *
29 | */
30 | public class MockBatchMutation implements BatchMutation {
31 |
32 | @Override
33 | public BatchMutation createEntity(NewEntity newEntity) {
34 | // TODO Auto-generated method stub
35 | return null;
36 | }
37 |
38 | @Override
39 | public BatchMutation createRelationship(NewRelationship newRelationship) {
40 | return null;
41 | }
42 |
43 | @Override
44 | public Mutation withEntity(Entity entity) {
45 | return null;
46 | }
47 |
48 | @Override
49 | public com.intuit.ugc.api.Relationship.Mutation withRelationship(Relationship relationship) {
50 | return null;
51 | }
52 |
53 | @Override
54 | public OperationResult execute() throws InvalidAttributeException, AccessControlException {
55 | return null;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/helper/MockGraphPersistence.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.helper;
14 |
15 | import com.intuit.ugc.impl.core.AbstractGraphPersistence;
16 | import com.intuit.ugc.impl.core.queryplan.MutationExecutorFactory;
17 | import com.intuit.ugc.impl.core.spi.GraphVisitor;
18 |
19 | /**
20 | *
21 | * @author nverma1
22 | *
23 | */
24 | public class MockGraphPersistence extends AbstractGraphPersistence {
25 |
26 | public MockGraphPersistence(GraphVisitor repository, MutationExecutorFactory factory) {
27 | super(repository, factory);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/helper/MockGraphVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.helper;
14 |
15 | import com.intuit.ugc.impl.core.VisitOperationResult;
16 | import com.intuit.ugc.impl.core.queryplan.operations.CreateEntity;
17 | import com.intuit.ugc.impl.core.queryplan.operations.CreateRelationship;
18 | import com.intuit.ugc.impl.core.queryplan.operations.DeleteEntity;
19 | import com.intuit.ugc.impl.core.queryplan.operations.DeleteRelationship;
20 | import com.intuit.ugc.impl.core.queryplan.operations.GetBatchEntityByID;
21 | import com.intuit.ugc.impl.core.queryplan.operations.GetEntityByID;
22 | import com.intuit.ugc.impl.core.queryplan.operations.GetEntityByProperty;
23 | import com.intuit.ugc.impl.core.queryplan.operations.GraphTerminalOperation;
24 | import com.intuit.ugc.impl.core.queryplan.operations.SelectEntities;
25 | import com.intuit.ugc.impl.core.queryplan.operations.SelectRelationships;
26 | import com.intuit.ugc.impl.core.queryplan.operations.UpdateEntity;
27 | import com.intuit.ugc.impl.core.queryplan.operations.UpdateRelationship;
28 | import com.intuit.ugc.impl.core.spi.GraphVisitor;
29 |
30 | /**
31 | *
32 | * @author nverma1
33 | *
34 | */
35 | public class MockGraphVisitor implements GraphVisitor {
36 |
37 | @Override
38 | public void visit(CreateEntity operation) {
39 |
40 | }
41 |
42 | @Override
43 | public void visit(CreateRelationship operation) {
44 |
45 | }
46 |
47 | @Override
48 | public void visit(GetBatchEntityByID operation) {
49 |
50 | }
51 |
52 | @Override
53 | public void visit(GetEntityByID operation) {
54 |
55 | }
56 |
57 | @Override
58 | public void visit(GetEntityByProperty operation) {
59 |
60 | }
61 |
62 | @Override
63 | public void visit(GraphTerminalOperation operation) {
64 |
65 | }
66 |
67 | @Override
68 | public void visit(SelectEntities operation) {
69 | // TODO Auto-generated method stub
70 |
71 | }
72 |
73 | @Override
74 | public void visit(SelectRelationships operation) {
75 |
76 | }
77 |
78 | @Override
79 | public void visit(UpdateEntity operation) {
80 |
81 | }
82 |
83 | @Override
84 | public void visit(UpdateRelationship operation) {
85 |
86 | }
87 |
88 | @Override
89 | public VisitOperationResult getResult() {
90 | return new VisitOperationResult() {
91 | };
92 | }
93 |
94 | @Override
95 | public void visit(DeleteEntity operation) {
96 |
97 | }
98 |
99 | @Override
100 | public void visit(DeleteRelationship operation) {
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/helper/MockMetadata.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.helper;
14 |
15 | import com.intuit.ugc.api.Attribute.Metadata;
16 |
17 | /**
18 | *
19 | * @author nverma1
20 | *
21 | */
22 | public class MockMetadata implements Metadata {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/helper/MockMutationExecuterFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.helper;
14 |
15 | import com.intuit.ugc.impl.core.queryplan.MutationExecutorFactory;
16 | import com.intuit.ugc.impl.core.queryplan.OperationFeederImpl;
17 | import com.intuit.ugc.impl.core.queryplan.OperationPipeline;
18 |
19 | /**
20 | *
21 | * @author nverma1
22 | *
23 | */
24 | public class MockMutationExecuterFactory implements MutationExecutorFactory {
25 |
26 | @Override
27 | public OperationFeederImpl create(OperationPipeline pipeline) {
28 | return null;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/helper/TartanImplTestConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.helper;
14 |
15 | import com.intuit.ugc.api.Attribute;
16 | import com.intuit.ugc.api.Relationship;
17 |
18 | /**
19 | *
20 | * @author nverma1
21 | *
22 | */
23 | public class TartanImplTestConstants {
24 | public static final Attribute.Name ATTR_PARENT_KEY = Attribute.Name
25 | .valueOf("test.ugc.core.entity.ID");
26 | public static final Attribute.Name ATTR_PARENT_ID = Attribute.Name
27 | .valueOf("test.ugc.core.entity.ParentId");
28 | public static final Attribute.Name ATTR_CHILD_ID = Attribute.Name
29 | .valueOf("test.ugc.core.entity.ChildId");
30 | public static final Attribute.Name ATTR_CHILD_KEY = Attribute.Name
31 | .valueOf("test.ugc.core.entity.ID");
32 | public static final Relationship.Name ATTR_PARENT_CHILD_KEY = Relationship.Name
33 | .valueOf("test.ugc.core.parent.has.Child");
34 | public static final Attribute.Name ATTR_DUMMY_ATTRIBUTE_NAME = Attribute.Name
35 | .valueOf("test.ugc.core.attribute.Dummy");
36 | public static final Relationship.Name ATTR_DUMMY_RELATIONSHIP_NAME = Relationship.Name
37 | .valueOf("test.ugc.core.attribute.Dummy");
38 | public static final Relationship.Name RELATIONSHIP_ENTITYA_ENTITYB =
39 | Relationship.Name.valueOf("test.ugc.core.entitya.has.Entityb");
40 | public static final Attribute.Family ATTR_DUMMY_FAMILY = Attribute.Family
41 | .valueOf("test.ugc.core.attribute.family");
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/helper/TartanImplTestUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.helper;
14 |
15 | import java.util.UUID;
16 |
17 | import com.intuit.ugc.api.Entity;
18 | import com.intuit.ugc.api.NewEntity;
19 | import com.intuit.ugc.api.Relationship;
20 | import com.intuit.ugc.api.Attribute.Name;
21 | import com.intuit.ugc.impl.core.GraphAttribute;
22 | import com.intuit.ugc.impl.core.GraphRelationship;
23 |
24 | /**
25 | *
26 | * @author nverma1
27 | *
28 | */
29 | public class TartanImplTestUtil {
30 | public NewEntity createNewEntity(Name entityKey) {
31 | Entity.ID newEntityID = Entity.ID.valueOf("urn:entity:" + entityKey.getName()
32 | + "." + entityKey.getName() + "/" + UUID.randomUUID());
33 |
34 | NewEntity newEntity = NewEntity.newInstance(newEntityID).withAttribute(TartanImplTestConstants.ATTR_PARENT_ID)
35 | .value("RandomTestRealm" + UUID.randomUUID().toString()).build();
36 | return newEntity;
37 | }
38 |
39 | public GraphRelationship buildGraphRelationship(Relationship.Name name, Entity.ID sourceEntityID,
40 | Entity.ID targetEntityID, GraphAttribute graphAttribute) {
41 | GraphRelationship.Builder builder = new GraphRelationship.Builder();
42 | builder.setName(name);
43 | builder.setSourceID(sourceEntityID);
44 | builder.setTargetID(targetEntityID);
45 | builder.addAttribute(graphAttribute);
46 | return builder.build();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/predicate/AndPredicateTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import static org.testng.Assert.assertFalse;
16 | import static org.testng.Assert.assertNotNull;
17 | import static org.testng.Assert.assertTrue;
18 | import static org.testng.Assert.fail;
19 |
20 | import java.util.Collection;
21 | import java.util.Collections;
22 |
23 | import org.testng.annotations.Test;
24 |
25 | import com.intuit.ugc.api.Attribute;
26 |
27 | /**
28 | *
29 | * @author nverma1
30 | *
31 | */
32 | public class AndPredicateTest {
33 |
34 | @Test
35 | public void testAndPredicateInitWithNoArgs(){
36 | AndPredicate andPredicate = new AndPredicate();
37 | StreamPredicate[] predicates = new StreamPredicate[0];
38 | andPredicate.setPredicates(predicates);
39 | assertNotNull(andPredicate.getPredicates());
40 | }
41 |
42 | @Test
43 | public void testAndPredicateSetTwice(){
44 | StreamPredicate[] predicates = new StreamPredicate[0];
45 | AndPredicate andPredicate = new AndPredicate(predicates);
46 | try{
47 | andPredicate.setPredicates(predicates);
48 | fail("again setting predicates should throw");
49 | }catch(Exception e){
50 | assertTrue(e instanceof IllegalStateException);
51 | }
52 | }
53 |
54 | @Test
55 | public void testApplyPredicates(){
56 | StreamPredicate[] predicates = new StreamPredicate[0];
57 | AndPredicate andPredicate = new AndPredicate(predicates);
58 | Collection attributes = Collections.emptyList();
59 | assertTrue(andPredicate.apply(attributes));
60 | }
61 |
62 | @Test
63 | public void testApplyToNullPredicates(){
64 | StreamPredicate[] predicates = new StreamPredicate[1];
65 | predicates[0] = new EqualToPredicate();
66 | AndPredicate andPredicate = new AndPredicate(predicates);
67 | Collection attributes = Collections.emptyList();
68 | assertFalse(andPredicate.apply(attributes));
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/predicate/EqualToPredicateTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import static org.testng.Assert.assertFalse;
16 | import static org.testng.Assert.assertTrue;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.Collection;
21 | import java.util.Collections;
22 | import java.util.List;
23 |
24 | import org.testng.annotations.Test;
25 |
26 | import com.intuit.ugc.api.Attribute;
27 | import com.intuit.ugc.api.Attribute.Metadata;
28 | import com.intuit.ugc.impl.core.GraphAttribute;
29 | import com.intuit.ugc.impl.core.helper.MockMetadata;
30 |
31 | /**
32 | *
33 | * @author nverma1
34 | *
35 | */
36 | public class EqualToPredicateTest {
37 |
38 | @Test
39 | public void testEqualToPredicateInitWithoutParams(){
40 | EqualToPredicate equalToPredicate = new EqualToPredicate();
41 | Collection attributes = Collections.emptyList();
42 | assertFalse(equalToPredicate.apply(attributes));
43 | }
44 |
45 | @Test
46 | public void testEqualToPredicateInitWithOnlyAttrName(){
47 | Attribute.Name attributeName = Attribute.Name.valueOf("test-attr");
48 | EqualToPredicate equalToPredicate = new EqualToPredicate(attributeName);
49 | Collection attributes = Collections.emptyList();
50 | assertFalse(equalToPredicate.apply(attributes));
51 | }
52 |
53 | @Test
54 | public void testEqualToPredicateInitWithAttrNameAndValueNonMatch(){
55 | Attribute.Name attributeName = Attribute.Name.valueOf("test-attr");
56 | EqualToPredicate equalToPredicate = new EqualToPredicate(attributeName, "test-attr-value");
57 | Collection attributes = Collections.emptyList();
58 | assertFalse(equalToPredicate.apply(attributes));
59 | }
60 |
61 | @Test
62 | public void testEqualToPredicateInitWithAttrNameAndValueMatch(){
63 | Attribute.Name attributeName = Attribute.Name.valueOf("test-attr");
64 | Object attributeValue = "test-attr-value";
65 | EqualToPredicate equalToPredicate = new EqualToPredicate(attributeName, attributeValue);
66 | GraphAttribute graphAttribute = new GraphAttribute(attributeName, attributeValue, new MockMetadata());
67 | List attributes = new ArrayList(
68 | Arrays.asList(graphAttribute));
69 | assertTrue(equalToPredicate.apply(attributes));
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/predicate/StreamComparisonTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import static org.testng.Assert.assertEquals;
16 | import static org.testng.Assert.assertNotNull;
17 | import static org.testng.Assert.assertTrue;
18 |
19 | import org.testng.annotations.Test;
20 |
21 | import com.intuit.ugc.api.Attribute;
22 |
23 | /**
24 | *
25 | * @author nverma1
26 | *
27 | */
28 | public class StreamComparisonTest {
29 |
30 | @Test
31 | public void testStreamComparisonGreaterThan(){
32 | try{
33 | StreamPredicateBuilder pb = new StreamPredicateBuilder();
34 | StreamComparison streamComparison = new StreamComparison(pb );
35 | Object o = null;
36 | streamComparison.greaterThan(o);
37 | }catch(Exception e){
38 | assertTrue(e instanceof UnsupportedOperationException);
39 | }
40 | }
41 |
42 | @Test
43 | public void testStreamComparisonLessThan(){
44 | try{
45 | StreamPredicateBuilder pb = new StreamPredicateBuilder();
46 | StreamComparison streamComparison = new StreamComparison(pb );
47 | Object o = null;
48 | streamComparison.lessThan(o);
49 | }catch(Exception e){
50 | assertTrue(e instanceof UnsupportedOperationException);
51 | }
52 | }
53 |
54 | @Test
55 | public void testStreamComparisonNotEqualToThan(){
56 | try{
57 | StreamPredicateBuilder pb = new StreamPredicateBuilder();
58 | StreamComparison streamComparison = new StreamComparison(pb );
59 | Object o = null;
60 | streamComparison.notEqualTo(o);
61 | }catch(Exception e){
62 | assertTrue(e instanceof UnsupportedOperationException);
63 | }
64 | }
65 |
66 | @Test
67 | public void testStreamComparisonEqualsWithNullObject(){
68 | StreamPredicateBuilder pb = new StreamPredicateBuilder();
69 | StreamComparison streamComparison = new StreamComparison(pb);
70 | Attribute.Name attrName = Attribute.Name.valueOf("attr-name");
71 | StreamPredicate predicate = new EqualToPredicate(attrName);
72 | StreamPredicateBuilder equalToBuilder = streamComparison.get(attrName).equalTo(predicate);
73 | assertNotNull(equalToBuilder);
74 | assertEquals(equalToBuilder.getAttribute(), attrName);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/predicate/StreamPredicatesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.predicate;
14 |
15 | import static org.testng.Assert.assertTrue;
16 | import static org.testng.Assert.fail;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | /**
21 | *
22 | * @author nverma1
23 | *
24 | */
25 | public class StreamPredicatesTest {
26 |
27 | @Test
28 | public void testLessThan(){
29 | try{
30 | Object value = null;;
31 | StreamPredicates.lessThan(value);
32 | fail("Should have thrown");
33 | }catch(Exception e){
34 | assertTrue(e instanceof UnsupportedOperationException);
35 | }
36 | }
37 |
38 | @Test
39 | public void testGreaterThan(){
40 | try{
41 | Object value = null;;
42 | StreamPredicates.greaterThan(value);
43 | fail("Should have thrown");
44 | }catch(Exception e){
45 | assertTrue(e instanceof UnsupportedOperationException);
46 | }
47 | }
48 |
49 | @Test
50 | public void testNotEqualTo(){
51 | try{
52 | Object value = null;;
53 | StreamPredicates.notEqualTo(value);
54 | fail("Should have thrown");
55 | }catch(Exception e){
56 | assertTrue(e instanceof UnsupportedOperationException);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/CreateEntityTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import org.testng.AssertJUnit;
16 | import org.testng.annotations.BeforeClass;
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.NewEntity;
20 | import com.intuit.ugc.impl.core.helper.TartanImplTestConstants;
21 | import com.intuit.ugc.impl.core.helper.TartanImplTestUtil;
22 | import com.intuit.ugc.impl.core.queryplan.operations.CreateEntity;
23 |
24 | /**
25 | *
26 | * @author nverma1
27 | *
28 | */
29 | public class CreateEntityTest {
30 | private TartanImplTestUtil util;
31 |
32 | @BeforeClass
33 | public void setup(){
34 | util = new TartanImplTestUtil();
35 | }
36 |
37 | @Test
38 | public void testCreateEntity() {
39 | NewEntity newEntity = util.createNewEntity(TartanImplTestConstants.ATTR_PARENT_ID);
40 |
41 | CreateEntity createEntity = new CreateEntity(newEntity);
42 | NewEntity newEntity2 = createEntity.newEntity();
43 | AssertJUnit.assertEquals(newEntity2.getEntityID(), newEntity.getEntityID());
44 | String expectedToString = "Operation [Create Entity] Entity ID ["
45 | + newEntity.getEntityID().getRawID() + "]";
46 | AssertJUnit.assertEquals(expectedToString, createEntity.toString());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/CreateRelationshipTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import org.testng.annotations.BeforeClass;
18 | import org.testng.annotations.Test;
19 |
20 | import com.intuit.ugc.api.Entity;
21 | import com.intuit.ugc.api.NewEntity;
22 | import com.intuit.ugc.api.NewRelationship;
23 | import com.intuit.ugc.impl.core.helper.TartanImplTestConstants;
24 | import com.intuit.ugc.impl.core.helper.TartanImplTestUtil;
25 | import com.intuit.ugc.impl.core.queryplan.operations.CreateRelationship;
26 |
27 | /**
28 | *
29 | * @author nverma1
30 | *
31 | */
32 | public class CreateRelationshipTest {
33 | private TartanImplTestUtil util;
34 | Entity.ID realmEntityID;
35 |
36 | @BeforeClass
37 | public void setup() {
38 | util = new TartanImplTestUtil();
39 | }
40 |
41 | @Test
42 | public void testCreateRelationship() {
43 | NewEntity sourceEntity = util.createNewEntity(TartanImplTestConstants.ATTR_CHILD_KEY);
44 | NewEntity targetEntity = util.createNewEntity(TartanImplTestConstants.ATTR_PARENT_KEY);
45 | NewRelationship newRelationship = NewRelationship
46 | .between(sourceEntity.getEntityID(), targetEntity.getEntityID()).withLabel(TartanImplTestConstants.ATTR_PARENT_CHILD_KEY).build();
47 |
48 | CreateRelationship createRelationship = new CreateRelationship(newRelationship);
49 | assertEquals(newRelationship.getName(), createRelationship.newRelationship().getName());
50 | assertEquals(sourceEntity.getEntityID(), createRelationship.newRelationship().getSourceID());
51 | assertEquals(TartanImplTestConstants.ATTR_PARENT_CHILD_KEY.toString(), createRelationship.newRelationship().getName().toString());
52 | String expectedRelationString = "Operation [Create Relationship] SOURCE ID ["
53 | + newRelationship.getSourceID() + "]" + " TARGET ID ["
54 | + newRelationship.getTargetID() + "]";
55 | assertEquals(expectedRelationString, createRelationship.toString());
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/DeleteEntityTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.Entity;
20 | import com.intuit.ugc.impl.core.GraphEntity;
21 |
22 | /**
23 | *
24 | * @author nverma1
25 | *
26 | */
27 | public class DeleteEntityTest {
28 | @Test
29 | public void testCreateADeleteEntityInstance(){
30 | Entity entity = new GraphEntity.Builder().setID(Entity.ID.valueOf("test")).build() ;
31 | DeleteEntity deleteEntity = new DeleteEntity(entity);
32 | assertEquals(deleteEntity.getEntity(), entity);
33 | assertEquals(deleteEntity.toString(), "Operation [Delete Entity] entity id [test]");
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/DeleteRelationshipTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.Entity;
20 | import com.intuit.ugc.api.Relationship;
21 | import com.intuit.ugc.impl.core.GraphRelationship;
22 |
23 | /**
24 | *
25 | * @author nverma1
26 | *
27 | */
28 | public class DeleteRelationshipTest {
29 |
30 | @Test
31 | public void testInitializeDeleteRelationship(){
32 | Relationship relationship = new GraphRelationship.Builder().setName(Relationship.Name.valueOf("test-entity"))
33 | .setSourceID(Entity.ID.valueOf("test-source")).setTargetID(Entity.ID.valueOf("test-target")).build();
34 | DeleteRelationship deleteRelationship = new DeleteRelationship(relationship );
35 | assertEquals(deleteRelationship.getRelationship(), relationship);
36 | assertEquals(deleteRelationship.toString(),
37 | "Operation [Delete Relationship] between source entity id [test-source] and target entity id [test-target]");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/GetBatchEntityByIdTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import java.util.ArrayList;
18 | import java.util.Arrays;
19 | import java.util.List;
20 |
21 | import org.testng.annotations.Test;
22 |
23 | import com.intuit.ugc.api.Entity;
24 | import com.intuit.ugc.api.Entity.ID;
25 |
26 | /**
27 | *
28 | * @author nverma1
29 | *
30 | */
31 | public class GetBatchEntityByIdTest {
32 | @Test
33 | public void testGetBatchEntityById(){
34 | List entityIDs = new ArrayList(Arrays.asList(Entity.ID.valueOf("test-id-1"), Entity.ID.valueOf("test-id-2")));
35 | GetBatchEntityByID getBatchEntityById = new GetBatchEntityByID(entityIDs);
36 | assertEquals(getBatchEntityById.getEntityIDs(), entityIDs);
37 | assertEquals(getBatchEntityById.toString(), "Operation [Get Entity] Entity ID [test-id-1, test-id-2]");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/GetEntityByIdTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.Entity;
20 | import com.intuit.ugc.api.Entity.ID;
21 |
22 | /**
23 | *
24 | * @author nverma1
25 | *
26 | */
27 | public class GetEntityByIdTest {
28 |
29 | @Test
30 | public void testGetEntityById(){
31 | ID id = Entity.ID.valueOf("test-id");
32 | GetEntityByID getEntityById = new GetEntityByID(id);
33 | assertEquals(getEntityById.getId(), id);
34 | assertEquals(getEntityById.toString(), "Operation [Get Entity] Entity ID [test-id]");
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/GetEntityByPropertyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.Attribute;
20 | import com.intuit.ugc.api.Attribute.Name;
21 |
22 | /**
23 | *
24 | * @author nverma1
25 | *
26 | */
27 | public class GetEntityByPropertyTest {
28 |
29 | @Test
30 | public void testGetEntityByProperty(){
31 | Name name = Attribute.Name.valueOf("test-property");
32 | GetEntityByProperty getEntityByProperty = new GetEntityByProperty(name,
33 | "test-property-val");
34 | assertEquals(getEntityByProperty.getName(),name);
35 | assertEquals(getEntityByProperty.getValue(), "test-property-val");
36 | assertEquals(getEntityByProperty.toString(), "Operation [Get Entity] Key [test-property] Value [test-property-val]");
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/GraphTerminalOperationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.Attribute;
20 | import com.intuit.ugc.api.Attribute.Family;
21 | import com.intuit.ugc.api.Attribute.Name;
22 |
23 | /**
24 | *
25 | * @author nverma1
26 | *
27 | */
28 | public class GraphTerminalOperationTest {
29 |
30 | @Test
31 | public void testGraphTerminalOperation(){
32 | GraphTerminalOperation graphTerminalOperation = new GraphTerminalOperation();
33 | Name name = Attribute.Name.valueOf("test-name");
34 | graphTerminalOperation.include(name);
35 | Family namespace = Attribute.Family.valueOf("test-namespace");
36 | graphTerminalOperation.include(namespace);
37 | assertEquals(graphTerminalOperation.getNameList().get(0), name);
38 | assertEquals(graphTerminalOperation.getNamespaceList().get(0), namespace);
39 | assertEquals(graphTerminalOperation.toString(), "Graph Terminal Operation");
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/SelectEntitiesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 | import static org.testng.Assert.assertTrue;
17 | import static org.testng.Assert.fail;
18 |
19 | import org.testng.annotations.Test;
20 |
21 | import com.intuit.ugc.api.Predicate;
22 | import com.intuit.ugc.api.Queries.GraphTraversal.Direction;
23 | import com.intuit.ugc.api.Relationship;
24 | import com.intuit.ugc.api.Relationship.Name;
25 | import com.intuit.ugc.impl.core.GraphPredicate;
26 |
27 | /**
28 | *
29 | * @author nverma1
30 | *
31 | */
32 | public class SelectEntitiesTest {
33 |
34 | @Test
35 | public void testSelectEntities(){
36 | Name relationName = Relationship.Name.valueOf("test-relationship");
37 | Direction direction = Direction.IN_OUT;
38 | SelectEntities selectEntities = new SelectEntities(relationName , direction );
39 | assertEquals(selectEntities.getDirection(), direction);
40 | Predicate predicate = new GraphPredicate();
41 | selectEntities.condition(predicate);
42 | assertEquals(selectEntities.getPredicate(), predicate);
43 | assertEquals(selectEntities.getRelationName(), relationName);
44 | assertEquals(selectEntities.toString(), "Operation [Select Entities] with relation label [test-relationship]");
45 | try{
46 | selectEntities.condition(predicate);
47 | fail("resetting predicate should throw exception");
48 | }catch(Exception e){
49 | assertTrue(e instanceof IllegalStateException);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/SelectRelationshipTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 | import static org.testng.Assert.assertTrue;
17 | import static org.testng.Assert.fail;
18 |
19 | import org.testng.annotations.Test;
20 |
21 | import com.intuit.ugc.api.Predicate;
22 | import com.intuit.ugc.api.Queries.GraphTraversal.Direction;
23 | import com.intuit.ugc.api.Relationship.Name;
24 | import com.intuit.ugc.impl.core.GraphPredicate;
25 |
26 | /**
27 | *
28 | * @author nverma1
29 | *
30 | */
31 | public class SelectRelationshipTest {
32 |
33 | @Test
34 | public void testSelectRelationship(){
35 | Name name = Name.valueOf("test-relationships");
36 | Direction direction = Direction.IN_OUT;
37 | SelectRelationships selectRelationship = new SelectRelationships(name , direction );
38 | Predicate predicate = new GraphPredicate();
39 | selectRelationship.condition(predicate );
40 | assertEquals(selectRelationship.getDirection(), direction);
41 | assertEquals(selectRelationship.getPredicate(), predicate);
42 | assertEquals(selectRelationship.getRelationshipName(), name);
43 | assertEquals(selectRelationship.toString(), "Operation [Select Relationships] with relation label [test-relationships]");
44 | try{
45 | selectRelationship.condition(predicate);
46 | fail("resetting predicate should throw exception");
47 | }catch(Exception e){
48 | assertTrue(e instanceof IllegalStateException);
49 | }
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/UpdateEntityTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.Entity;
20 | import com.intuit.ugc.impl.core.GraphAttributeOperations;
21 | import com.intuit.ugc.impl.core.GraphEntity;
22 |
23 | /**
24 | *
25 | * @author nverma1
26 | *
27 | */
28 | public class UpdateEntityTest {
29 |
30 | @Test
31 | public void testUpdateEntity(){
32 | Entity entity = new GraphEntity.Builder().setID(Entity.ID.valueOf("test-entity")).build();
33 | GraphAttributeOperations operations = new GraphAttributeOperations();
34 | UpdateEntity updateEntity = new UpdateEntity(entity , operations );
35 | assertEquals(updateEntity.getEntity(), entity);
36 | assertEquals(updateEntity.getOperations(), operations);
37 | assertEquals(updateEntity.toString(), "Operation [Update Entity] entity id [test-entity]");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/queryplan/operations/UpdateRelationshipTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.queryplan.operations;
14 |
15 | import static org.testng.Assert.assertEquals;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | import com.intuit.ugc.api.Entity;
20 | import com.intuit.ugc.api.Relationship;
21 | import com.intuit.ugc.api.Relationship.Name;
22 | import com.intuit.ugc.impl.core.GraphAttributeOperations;
23 | import com.intuit.ugc.impl.core.GraphRelationship;
24 |
25 | /**
26 | *
27 | * @author nverma1
28 | *
29 | */
30 | public class UpdateRelationshipTest {
31 |
32 | @Test
33 | public void testUpdateRelationship(){
34 | Relationship relationship = new GraphRelationship.Builder().setName(Name.valueOf("test-relation"))
35 | .setSourceID(Entity.ID.valueOf("test-source")).setTargetID(Entity.ID.valueOf("test-target")).build();
36 | GraphAttributeOperations operations = new GraphAttributeOperations();
37 | UpdateRelationship updateRelationship = new UpdateRelationship(relationship , operations );
38 | assertEquals(updateRelationship.getOperations(), operations);
39 | assertEquals(updateRelationship.getRelationship(), relationship);
40 | assertEquals(updateRelationship.toString(), "Operation [Update Relationship] source id [test-source] target id [test-target]");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/spi/QueryResultImplUnitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.spi;
14 |
15 | import static org.testng.Assert.assertEquals;
16 | import static org.testng.Assert.assertNotNull;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.List;
21 |
22 | import org.testng.annotations.Test;
23 |
24 | import com.intuit.ugc.api.Entity;
25 | import com.intuit.ugc.api.Relationship;
26 | import com.intuit.ugc.impl.core.spi.QueryResultImpl;
27 | import com.intuit.ugc.impl.core.spi.QueryResult.CurrentOperationType;
28 |
29 | /**
30 | *
31 | * @author nverma1
32 | *
33 | */
34 | public class QueryResultImplUnitTest {
35 |
36 | @Test
37 | public void testQueryResultImplWithRelationshipCreation(){
38 | CurrentOperationType currentOperation = CurrentOperationType.RELATIONHIP;
39 | QueryResultImpl queryResultImpl = new QueryResultImpl(currentOperation );
40 | assertNotNull(queryResultImpl);
41 | List relationshipList = new ArrayList();
42 | queryResultImpl.setRelationshipOpResponse(relationshipList);
43 | assertNotNull(queryResultImpl.getRelationshipResponse());
44 | assertEquals(queryResultImpl.getEntityResponse(), Collections.emptyList());
45 | assertEquals(queryResultImpl.getCurrentOperation(), currentOperation);
46 | }
47 |
48 | @Test
49 | public void testQueryResultImplWithEntityCreation(){
50 | CurrentOperationType currentOperation = CurrentOperationType.ENTITY;
51 | QueryResultImpl queryResultImpl = new QueryResultImpl(currentOperation);
52 | assertNotNull(queryResultImpl);
53 | List entityList = new ArrayList();
54 | queryResultImpl.setEntityOpResponse(entityList);
55 | assertNotNull(queryResultImpl.getEntityResponse());
56 | assertEquals(queryResultImpl.getRelationshipResponse(), Collections.emptyList());
57 | assertEquals(queryResultImpl.getCurrentOperation(), currentOperation);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/java/com/intuit/ugc/impl/core/spi/RepositoryExceptionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017.
3 | * All rights reserved. This program and the accompanying materials
4 | * are made available under the terms of the Eclipse Public License v1.0
5 | * which accompanies this distribution, and is available at
6 | * http://www.eclipse.org/legal/epl-v10.html
7 | *
8 | * Contributors:
9 | * ajain17 - API and implementation and initial documentation
10 | * nverma1 - enhancements
11 | */
12 |
13 | package com.intuit.ugc.impl.core.spi;
14 |
15 | import static org.testng.Assert.fail;
16 |
17 | import org.testng.annotations.Test;
18 |
19 | /**
20 | *
21 | * @author nverma1
22 | *
23 | */
24 | public class RepositoryExceptionTest {
25 | @Test
26 | public void testCreateRepositoryException(){
27 | try{
28 | RepositoryException ex = new RepositoryException(new Exception());
29 | ex = new RepositoryException("test-exception", new Exception());
30 | }catch(Exception e){
31 | fail("Shouldn't have thrown an exception");
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 | %-4relative [%thread] %-5level %logger{35} - %msg %n
8 |
9 |
10 |
11 |
12 |
14 | universal_graph_client.log
15 |
16 |
17 | universal_graph_client.%d{yyyy-MM-dd}.%i.log
18 |
19 |
21 |
22 | 50MB
23 |
24 |
25 | 3
26 |
27 |
28 | %d{dd MMM yyyy;HH:mm:ss.SSS} %-5level [%thread][%logger{0}]
29 | %m%n
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/universal-graph-client-impl-core/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------