├── .github └── ISSUE_TEMPLATE │ └── custom.md ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DESIGN.md ├── LICENSE ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── config ├── checkstyle.xml ├── findbugs-exclude.xml ├── gremlin-server-ci.properties └── gremlin-server-ci.yaml ├── examples ├── LICENSE ├── example │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── example │ │ │ │ └── springdata │ │ │ │ └── gremlin │ │ │ │ ├── Application.java │ │ │ │ ├── config │ │ │ │ ├── GremlinProperties.java │ │ │ │ └── UserRepositoryConfiguration.java │ │ │ │ ├── domain │ │ │ │ ├── Network.java │ │ │ │ ├── Person.java │ │ │ │ └── Relation.java │ │ │ │ └── repository │ │ │ │ ├── NetworkRepository.java │ │ │ │ ├── PersonRepository.java │ │ │ │ └── RelationRepository.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ ├── java │ │ └── example │ │ │ └── springdata │ │ │ └── gremlin │ │ │ ├── GremlinRepositoryIntegrationTest.java │ │ │ └── RepositoryConfiguration.java │ │ └── resources │ │ └── application.yml ├── pom.xml └── web-service │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── web │ │ └── service │ │ └── springdata │ │ └── gremlin │ │ ├── Application.java │ │ ├── config │ │ ├── GremlinProperties.java │ │ └── UserRepositoryConfiguration.java │ │ ├── domain │ │ ├── MicroService.java │ │ ├── ServicesDataFlow.java │ │ └── SpringCloudServiceNetwork.java │ │ ├── repository │ │ ├── MicroServiceRepository.java │ │ ├── ServicesDataFlowRepository.java │ │ └── SpringCloudServiceNetworkRepository.java │ │ └── web │ │ ├── Controller │ │ └── WebController.java │ │ └── domain │ │ └── Greeting.java │ └── resources │ └── application.yml ├── package └── apache-tinkerpop-gremlin-server-minimal-3.3.4.tar.gz ├── pom.xml ├── script └── integration-test-setup.sh └── src ├── main ├── java │ └── com │ │ └── microsoft │ │ └── spring │ │ └── data │ │ └── gremlin │ │ ├── annotation │ │ ├── Edge.java │ │ ├── EdgeFrom.java │ │ ├── EdgeSet.java │ │ ├── EdgeTo.java │ │ ├── GeneratedValue.java │ │ ├── Graph.java │ │ ├── Vertex.java │ │ └── VertexSet.java │ │ ├── common │ │ ├── Constants.java │ │ ├── GremlinConfig.java │ │ ├── GremlinEntityType.java │ │ ├── GremlinFactory.java │ │ └── GremlinUtils.java │ │ ├── config │ │ ├── AbstractGremlinConfiguration.java │ │ └── GremlinConfigurationSupport.java │ │ ├── conversion │ │ ├── MappingGremlinConverter.java │ │ ├── result │ │ │ ├── AbstractGremlinResultReader.java │ │ │ ├── GremlinResultEdgeReader.java │ │ │ ├── GremlinResultVertexReader.java │ │ │ ├── GremlinResultsGraphReader.java │ │ │ └── GremlinResultsReader.java │ │ ├── script │ │ │ ├── AbstractGremlinScriptLiteral.java │ │ │ ├── GremlinScriptLiteral.java │ │ │ ├── GremlinScriptLiteralEdge.java │ │ │ ├── GremlinScriptLiteralGraph.java │ │ │ └── GremlinScriptLiteralVertex.java │ │ └── source │ │ │ ├── AbstractGremlinSource.java │ │ │ ├── AbstractGremlinSourceReader.java │ │ │ ├── GremlinSource.java │ │ │ ├── GremlinSourceEdge.java │ │ │ ├── GremlinSourceEdgeReader.java │ │ │ ├── GremlinSourceEdgeWriter.java │ │ │ ├── GremlinSourceGraph.java │ │ │ ├── GremlinSourceGraphReader.java │ │ │ ├── GremlinSourceGraphWriter.java │ │ │ ├── GremlinSourceReader.java │ │ │ ├── GremlinSourceVertex.java │ │ │ ├── GremlinSourceVertexReader.java │ │ │ ├── GremlinSourceVertexWriter.java │ │ │ └── GremlinSourceWriter.java │ │ ├── exception │ │ ├── GremlinEntityInformationException.java │ │ ├── GremlinIllegalConfigurationException.java │ │ ├── GremlinInvalidEntityIdFieldException.java │ │ ├── GremlinQueryException.java │ │ ├── GremlinUnexpectedEntityTypeException.java │ │ └── GremlinUnexpectedSourceTypeException.java │ │ ├── mapping │ │ ├── BasicGremlinPersistentEntity.java │ │ ├── BasicGremlinPersistentProperty.java │ │ ├── GremlinMappingContext.java │ │ ├── GremlinPersistentEntity.java │ │ └── GremlinPersistentProperty.java │ │ ├── query │ │ ├── GremlinEntityMetadata.java │ │ ├── GremlinOperations.java │ │ ├── GremlinTemplate.java │ │ ├── SimpleGremlinEntityMetadata.java │ │ ├── criteria │ │ │ ├── Criteria.java │ │ │ └── CriteriaType.java │ │ ├── paramerter │ │ │ ├── GremlinParameter.java │ │ │ ├── GremlinParameterAccessor.java │ │ │ ├── GremlinParameters.java │ │ │ └── GremlinParametersParameterAccessor.java │ │ └── query │ │ │ ├── AbstractGremlinQuery.java │ │ │ ├── GremlinQuery.java │ │ │ ├── GremlinQueryCreator.java │ │ │ ├── GremlinQueryExecution.java │ │ │ ├── GremlinQueryMethod.java │ │ │ ├── PartTreeGremlinQuery.java │ │ │ ├── QueryFindScriptGenerator.java │ │ │ └── QueryScriptGenerator.java │ │ ├── repository │ │ ├── GremlinRepository.java │ │ ├── config │ │ │ ├── EnableGremlinRepositories.java │ │ │ ├── GremlinRepositoryConfigurationExtension.java │ │ │ └── GremlinRepositoryRegistrar.java │ │ └── support │ │ │ ├── GremlinEntityInformation.java │ │ │ ├── GremlinRepositoryFactory.java │ │ │ ├── GremlinRepositoryFactoryBean.java │ │ │ └── SimpleGremlinRepository.java │ │ └── telemetry │ │ ├── MacAddress.java │ │ ├── PropertyLoader.java │ │ ├── TelemetryEventData.java │ │ └── TelemetrySender.java └── resources │ ├── META-INF │ ├── project.properties │ └── spring.factories │ ├── application.properties │ └── telemetry.config └── test ├── java └── com │ └── microsoft │ └── spring │ └── data │ └── gremlin │ ├── annotation │ ├── AnnotationEdgeUnitTest.java │ ├── AnnotationGraphUnitTest.java │ └── AnnotationVertexUnitTest.java │ ├── common │ ├── GremlinFactoryUnitTest.java │ ├── GremlinUtilsUnitTest.java │ ├── MacAddressUnitTest.java │ ├── TestConstants.java │ ├── TestGremlinProperties.java │ ├── TestRepositoryConfiguration.java │ ├── TestUtils.java │ ├── domain │ │ ├── AdvancedUser.java │ │ ├── Book.java │ │ ├── BookReference.java │ │ ├── Dependency.java │ │ ├── Group.java │ │ ├── GroupOwner.java │ │ ├── InvalidDependency.java │ │ ├── Library.java │ │ ├── Master.java │ │ ├── Neighbor.java │ │ ├── Network.java │ │ ├── Orange.java │ │ ├── Person.java │ │ ├── Project.java │ │ ├── Relationship.java │ │ ├── Roadmap.java │ │ ├── Service.java │ │ ├── ServiceType.java │ │ ├── SimpleDependency.java │ │ ├── Student.java │ │ ├── User.java │ │ └── UserDomain.java │ └── repository │ │ ├── AdvancedUserRepository.java │ │ ├── BookReferenceRepository.java │ │ ├── BookRepository.java │ │ ├── GroupOwnerRepository.java │ │ ├── GroupRepository.java │ │ ├── MasterRepository.java │ │ ├── NeighborRepository.java │ │ ├── NetworkRepository.java │ │ ├── OrangeRepository.java │ │ ├── PersonRepository.java │ │ ├── ProjectRepository.java │ │ ├── RelationshipRepository.java │ │ ├── ServiceRepository.java │ │ ├── SimpleDependencyRepository.java │ │ ├── StudentRepository.java │ │ └── UserDomainRepository.java │ ├── config │ ├── AbstractGremlinConfigurationIT.java │ └── GremlinConfigurationSupportUnitTest.java │ ├── conversion │ ├── MappingGremlinConverterUnitTest.java │ ├── result │ │ └── GremlinResultUnitTest.java │ ├── script │ │ ├── AbstractGremlinScriptLiteralUnitTest.java │ │ ├── GremlinScriptLiteralEdgeUnitTest.java │ │ ├── GremlinScriptLiteralVertexUnitTest.java │ │ └── GremlinScriptUnitTest.java │ └── source │ │ └── GremlinSourceUnitTest.java │ ├── mapping │ ├── BasicGremlinPersistentEntityUnitTest.java │ ├── BasicGremlinPersistentPropertyUnitTest.java │ └── GremlinMappingContextUnitTest.java │ ├── query │ ├── GremlinTemplateIT.java │ ├── SimpleGremlinEntityMetadataUnitTest.java │ ├── criteria │ │ └── CriteriaUnitTest.java │ └── parameter │ │ └── GremlinParameterUnitTest.java │ └── repository │ ├── AdvancedUserRepositoryIT.java │ ├── BookReferenceRepositoryIT.java │ ├── BookRepositoryIT.java │ ├── GroupRepositoryIT.java │ ├── MasterRepositoryIT.java │ ├── NeighborRepositoryIT.java │ ├── NetworkRepositoryIT.java │ ├── OrangeRepositoryIT.java │ ├── PersonRepositoryIT.java │ ├── RelationshipRepositoryIT.java │ ├── ServiceRepositoryIT.java │ ├── StudentRepositoryIT.java │ ├── UserDomainRepositoryIT.java │ ├── config │ ├── GremlinRepositoryConfigurationExtensionUnitTest.java │ └── GremlinRepositoryRegistrarUnitTest.java │ └── support │ ├── GremlinEntityInformationUnitTest.java │ ├── GremlinRepositoryFactoryBeanUnitTest.java │ └── GremlinRepositoryFactoryUnitTest.java └── resources ├── application.properties ├── application.yml └── telemetry.config /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | 5 | --- 6 | 7 | **Your issue may already be reported! Please search before creating a new one.** 8 | 9 | ## Expected Behavior 10 | * placeholder 11 | 12 | ## Current Behavior 13 | * placeholder 14 | 15 | ## Possible Solution 16 | * placeholder 17 | 18 | ## Steps to Reproduce (for bugs) 19 | * step-1 20 | * step-2 21 | * ... 22 | 23 | ## Snapshot Code for Reproduce 24 | ```java 25 | @SpringBootApplication 26 | public class Application { 27 | public static void main(String... args) { 28 | SpringApplication.run(Application.class, args); 29 | } 30 | } 31 | ``` 32 | 33 | ## Branch 34 | * placeholder 35 | 36 | ## Your Environment 37 | * Version used: 38 | * Operating System and version (desktop or mobile): 39 | * SDK version: 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | .idea* 25 | target/* 26 | *.patch 27 | *.iml 28 | 29 | **/target 30 | 31 | #Eclipse generated files 32 | .classpath 33 | .project 34 | .settings/ 35 | /.apt_generated/ 36 | /.apt_generated_tests/ 37 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk8 4 | 5 | before_script: 6 | # - wget http://www-us.apache.org/dist/tinkerpop/3.3.4/apache-tinkerpop-gremlin-server-3.3.4-bin.zip 7 | # - unzip apache-tinkerpop-gremlin-server-3.3.4-bin.zip > /dev/null 8 | # - cp -v config/gremlin-server-ci.yaml apache-tinkerpop-gremlin-server-3.3.4/conf/ 9 | # - cp -v config/gremlin-server-ci.properties apache-tinkerpop-gremlin-server-3.3.4/conf/ 10 | # - apache-tinkerpop-gremlin-server-3.3.4/bin/ 11 | - tar -zvxf package/apache-tinkerpop-gremlin-server-minimal-3.3.4.tar.gz 12 | - apache-tinkerpop-gremlin-server-minimal-3.3.4/bin/gremlin-server.sh conf/gremlin-server-ci.yaml & 13 | - sleep 10 14 | 15 | script: 16 | - set -o pipefail 17 | - mvn clean -P full-test cobertura:cobertura-integration-test | grep -v "DEBUG" 18 | 19 | after_success: 20 | - bash <(curl -s https://codecov.io/bash) 21 | 22 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Build and Contribute 2 | Below are guidelines for building and code contribution. 3 | 4 | ## Prerequisites 5 | - JDK 1.8 and above 6 | - [Maven](http://maven.apache.org/) 3.0 and above 7 | 8 | ## Build from source 9 | To build the project, run maven commands. 10 | 11 | ```bash 12 | git clone https://github.com/Microsoft/azure-spring-boot.git 13 | cd azure-spring-boot 14 | mvn clean install 15 | ``` 16 | 17 | ## Test 18 | 19 | - Run unit tests 20 | ```bash 21 | mvn clean install 22 | ``` 23 | 24 | - [Run integration tests]() 25 | 26 | - Skip test execution 27 | ```bash 28 | mvn clean install -DskipTests 29 | ``` 30 | 31 | ## Version management 32 | Developing version naming convention is like `0.1.0-SNAPSHOT`. Release version naming convention is like `2.0.0`. Please don't update version if no release plan. 33 | 34 | ## CI 35 | [Travis](https://travis-ci.org/Microsoft/spring-data-gremlin) 36 | [Codecov](https://codecov.io/gh/Microsoft/spring-data-gremlin) 37 | [Codacy](https://app.codacy.com/project/Incarnation-p-lee/spring-data-gremlin/dashboard) 38 | 39 | ## Contribution 40 | Code contribution is welcome. To contribute to existing code or add a new starter, please make sure below check list is checked. 41 | - [ ] Build pass. Checkstyle and findbugs is enabled by default. Please check [checkstyle.xml](config/checkstyle.xml) to learn detailed checkstyle configuration. 42 | - [ ] Documents are updated to align with code. 43 | - [ ] New starter must have sample folder containing sample code and corresponding readme file. 44 | - [ ] Keep Code coverage for repository >= 90%. Code coverage check is not enabled, as you may need to split feature code and test code in different PR. 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | ------------------------------------------- START OF LICENSE ----------------------------------------- 3 | Spring Data Gremlin 4 | Copyright (c) Microsoft Corporation 5 | All rights reserved. 6 | 7 | MIT License 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 14 | 15 | ----------------------------------------------- END OF LICENSE ------------------------------------------ 16 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | A few sentences describing the overall goals of the pull request's commits. 3 | 4 | ## Related PRs 5 | List related PRs against other branches: 6 | 7 | branch | PR 8 | ------ | ------ 9 | other_pr_production | [link]() 10 | other_pr_master | [link]() 11 | 12 | ## Todos 13 | - [ ] Tests 14 | - [ ] Documentation 15 | 16 | ## Steps to Test 17 | Steps to test code change 18 | -------------------------------------------------------------------------------- /config/findbugs-exclude.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /config/gremlin-server-ci.properties: -------------------------------------------------------------------------------- 1 | gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph 2 | gremlin.tinkergraph.vertexIdManager=ANY 3 | -------------------------------------------------------------------------------- /config/gremlin-server-ci.yaml: -------------------------------------------------------------------------------- 1 | host: localhost 2 | port: 8889 3 | gremlinPool: 8 4 | threadPoolWorker: 8 5 | scriptEvaluationTimeout: 30000 6 | channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer 7 | graphs: { graph: conf/gremlin-server-ci.properties } 8 | 9 | scriptEngines: { 10 | gremlin-groovy: { 11 | plugins: { org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {}, 12 | org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {}, 13 | org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]}, 14 | org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [scripts/empty-sample.groovy]}}}} 15 | 16 | serializers: 17 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }} 18 | ssl: { enabled: false } 19 | 20 | -------------------------------------------------------------------------------- /examples/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Pan Li 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | spring-data-gremlin-example 7 | Spring Data gremlin - Example 8 | 9 | 10 | com.microsoft.spring.data.gremlin.examples 11 | spring-data-gremlin-examples 12 | 0.0.1.BUILD-SNAPSHOT 13 | ../pom.xml 14 | 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-autoconfigure 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package example.springdata.gremlin; 17 | 18 | import com.microsoft.spring.data.gremlin.common.GremlinFactory; 19 | import example.springdata.gremlin.domain.Network; 20 | import example.springdata.gremlin.domain.Person; 21 | import example.springdata.gremlin.domain.Relation; 22 | import example.springdata.gremlin.repository.NetworkRepository; 23 | import example.springdata.gremlin.repository.PersonRepository; 24 | import example.springdata.gremlin.repository.RelationRepository; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.boot.SpringApplication; 27 | import org.springframework.boot.autoconfigure.SpringBootApplication; 28 | 29 | import javax.annotation.PostConstruct; 30 | import javax.annotation.PreDestroy; 31 | 32 | @SpringBootApplication 33 | public class Application { 34 | 35 | private static final String PERSON_ID = "89757"; 36 | private static final String PERSON_ID_0 = "0123456789"; 37 | private static final String PERSON_ID_1 = "666666"; 38 | private static final String PERSON_NAME = "person-name"; 39 | private static final String PERSON_NAME_0 = "person-No.0"; 40 | private static final String PERSON_NAME_1 = "person-No.1"; 41 | private static final String PERSON_AGE = "4"; 42 | private static final String PERSON_AGE_0 = "18"; 43 | private static final String PERSON_AGE_1 = "27"; 44 | 45 | private static final String RELATION_ID = "2333"; 46 | private static final String RELATION_NAME = "brother"; 47 | 48 | private final Person person = new Person(PERSON_ID, PERSON_NAME, PERSON_AGE); 49 | private final Person person0 = new Person(PERSON_ID_0, PERSON_NAME_0, PERSON_AGE_0); 50 | private final Person person1 = new Person(PERSON_ID_1, PERSON_NAME_1, PERSON_AGE_1); 51 | private final Relation relation = new Relation(RELATION_ID, RELATION_NAME, person0, person1); 52 | private final Network network = new Network(); 53 | 54 | @Autowired 55 | private PersonRepository personRepo; 56 | 57 | @Autowired 58 | private RelationRepository relationRepo; 59 | 60 | @Autowired 61 | private NetworkRepository networkRepo; 62 | 63 | @Autowired 64 | private GremlinFactory factory; 65 | 66 | public static void main(String... args) { 67 | SpringApplication.run(Application.class, args); 68 | } 69 | 70 | @PostConstruct 71 | public void setup() { 72 | this.networkRepo.deleteAll(); 73 | 74 | this.network.getEdges().add(this.relation); 75 | this.network.getVertexes().add(this.person); 76 | this.network.getVertexes().add(this.person0); 77 | this.network.getVertexes().add(this.person1); 78 | 79 | this.networkRepo.save(this.network); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/config/GremlinProperties.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package example.springdata.gremlin.config; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | import org.apache.tinkerpop.gremlin.driver.ser.Serializers; 14 | import org.springframework.boot.context.properties.ConfigurationProperties; 15 | 16 | @Getter 17 | @Setter 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | @ConfigurationProperties("gremlin") 21 | public class GremlinProperties { 22 | private String endpoint; 23 | 24 | private int port; 25 | 26 | private String username; 27 | 28 | private String password; 29 | 30 | private boolean sslEnabled; 31 | 32 | private boolean telemetryAllowed = true; 33 | 34 | private String serializer = Serializers.GRAPHSON.toString(); 35 | 36 | private int maxContentLength; 37 | } 38 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/config/UserRepositoryConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package example.springdata.gremlin.config; 17 | 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.context.annotation.PropertySource; 22 | 23 | import com.microsoft.spring.data.gremlin.common.GremlinConfig; 24 | import com.microsoft.spring.data.gremlin.config.AbstractGremlinConfiguration; 25 | import com.microsoft.spring.data.gremlin.repository.config.EnableGremlinRepositories; 26 | 27 | 28 | @Configuration 29 | @EnableGremlinRepositories(basePackages = "example.springdata.gremlin.repository") 30 | @EnableConfigurationProperties(GremlinProperties.class) 31 | @PropertySource("classpath:application.yml") 32 | public class UserRepositoryConfiguration extends AbstractGremlinConfiguration { 33 | 34 | @Autowired 35 | private GremlinProperties gremlinProps; 36 | 37 | @Override 38 | public GremlinConfig getGremlinConfig() { 39 | return new GremlinConfig( 40 | gremlinProps.getEndpoint(), 41 | gremlinProps.getPort(), 42 | gremlinProps.getUsername(), 43 | gremlinProps.getPassword(), 44 | gremlinProps.isSslEnabled(), 45 | gremlinProps.isTelemetryAllowed(), 46 | gremlinProps.getSerializer(), 47 | gremlinProps.getMaxContentLength() 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/domain/Network.java: -------------------------------------------------------------------------------- 1 | package example.springdata.gremlin.domain; 2 | 3 | import com.microsoft.spring.data.gremlin.annotation.EdgeSet; 4 | import com.microsoft.spring.data.gremlin.annotation.Graph; 5 | import com.microsoft.spring.data.gremlin.annotation.VertexSet; 6 | import lombok.Getter; 7 | import org.springframework.data.annotation.Id; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | @Graph 13 | public class Network { 14 | 15 | @Id 16 | private String id; 17 | 18 | public Network() { 19 | this.edges = new ArrayList(); 20 | this.vertexes = new ArrayList(); 21 | } 22 | 23 | @EdgeSet 24 | @Getter 25 | private List edges; 26 | 27 | @VertexSet 28 | @Getter 29 | private List vertexes; 30 | } 31 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/domain/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package example.springdata.gremlin.domain; 17 | 18 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 19 | import lombok.AllArgsConstructor; 20 | import lombok.Data; 21 | import lombok.NoArgsConstructor; 22 | import org.springframework.data.annotation.Id; 23 | 24 | @Data 25 | @Vertex 26 | @AllArgsConstructor 27 | @NoArgsConstructor 28 | public class Person { 29 | 30 | @Id 31 | private String id; 32 | 33 | private String name; 34 | 35 | private String age; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/domain/Relation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.springdata.gremlin.domain; 18 | 19 | import com.microsoft.spring.data.gremlin.annotation.Edge; 20 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 21 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Data; 24 | import lombok.NoArgsConstructor; 25 | import org.springframework.data.annotation.Id; 26 | 27 | 28 | @Data 29 | @Edge 30 | @AllArgsConstructor 31 | @NoArgsConstructor 32 | public class Relation { 33 | 34 | @Id 35 | private String id; 36 | 37 | private String name; 38 | 39 | @EdgeFrom 40 | private Person personFrom; 41 | 42 | @EdgeTo 43 | private Person personTo; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/repository/NetworkRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.springdata.gremlin.repository; 18 | 19 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 20 | import example.springdata.gremlin.domain.Network; 21 | import org.springframework.stereotype.Repository; 22 | 23 | @Repository 24 | public interface NetworkRepository extends GremlinRepository { 25 | } 26 | 27 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.springdata.gremlin.repository; 18 | 19 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 20 | import example.springdata.gremlin.domain.Person; 21 | import org.springframework.data.rest.webmvc.RepositoryRestController; 22 | import org.springframework.stereotype.Repository; 23 | 24 | 25 | @Repository 26 | @RepositoryRestController 27 | public interface PersonRepository extends GremlinRepository { 28 | } 29 | 30 | -------------------------------------------------------------------------------- /examples/example/src/main/java/example/springdata/gremlin/repository/RelationRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package example.springdata.gremlin.repository; 18 | 19 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 20 | import example.springdata.gremlin.domain.Relation; 21 | import org.springframework.stereotype.Repository; 22 | 23 | @Repository 24 | public interface RelationRepository extends GremlinRepository { 25 | } 26 | 27 | -------------------------------------------------------------------------------- /examples/example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | gremlin: 2 | endpoint: localhost 3 | port: 8889 4 | username: your-username 5 | password: your-password 6 | sslEnabled: false 7 | telemetryAllowed: true 8 | maxContentLength: 1000 9 | -------------------------------------------------------------------------------- /examples/example/src/test/java/example/springdata/gremlin/RepositoryConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package example.springdata.gremlin; 17 | 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.context.annotation.PropertySource; 22 | 23 | import com.microsoft.spring.data.gremlin.common.GremlinConfig; 24 | import com.microsoft.spring.data.gremlin.config.AbstractGremlinConfiguration; 25 | import com.microsoft.spring.data.gremlin.repository.config.EnableGremlinRepositories; 26 | 27 | import example.springdata.gremlin.config.GremlinProperties; 28 | 29 | 30 | @Configuration 31 | @EnableGremlinRepositories(basePackages = "example.springdata.gremlin.repository") 32 | @EnableConfigurationProperties(GremlinProperties.class) 33 | @PropertySource("classpath:application.yml") 34 | public class RepositoryConfiguration extends AbstractGremlinConfiguration { 35 | 36 | @Autowired 37 | private GremlinProperties gremlinProps; 38 | 39 | @Override 40 | public GremlinConfig getGremlinConfig() { 41 | return new GremlinConfig( 42 | gremlinProps.getEndpoint(), 43 | gremlinProps.getPort(), 44 | gremlinProps.getUsername(), 45 | gremlinProps.getPassword(), 46 | gremlinProps.isSslEnabled(), 47 | gremlinProps.isTelemetryAllowed(), 48 | gremlinProps.getSerializer(), 49 | gremlinProps.getMaxContentLength() 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/example/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | gremlin: 2 | endpoint: your-endpoint.gremlin.cosmosdb.azure.com 3 | port: 443 4 | username: your-username 5 | password: your-password 6 | sslEnabled: false 7 | telemetryAllowed: true 8 | -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.microsoft.spring.data.gremlin.examples 8 | spring-data-gremlin-examples 9 | 0.0.1.BUILD-SNAPSHOT 10 | pom 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.3.0.RELEASE 16 | 17 | 18 | 19 | 20 | UTF-8 21 | 22 | 23 | Spring Data gremlin - Examples 24 | Sample projects for Spring Data gremlin 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | test 31 | 32 | 33 | 34 | org.projectlombok 35 | lombok 36 | provided 37 | 38 | 39 | 40 | org.springframework.data 41 | spring-data-commons 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-data-rest 47 | 48 | 49 | 50 | com.microsoft.spring.data.gremlin 51 | spring-data-gremlin 52 | 2.3.0 53 | 54 | 55 | 56 | 57 | example 58 | web-service 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /examples/web-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring-data-gremlin-web-service 8 | Spring Data gremlin - Web Service 9 | 10 | 11 | com.microsoft.spring.data.gremlin.examples 12 | spring-data-gremlin-examples 13 | 0.0.1.BUILD-SNAPSHOT 14 | ../pom.xml 15 | 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-autoconfigure 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | com.jayway.jsonpath 35 | json-path 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package web.service.springdata.gremlin; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | @SpringBootApplication 23 | public class Application { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(Application.class, args); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/config/GremlinProperties.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package web.service.springdata.gremlin.config; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | import org.apache.tinkerpop.gremlin.driver.ser.Serializers; 14 | import org.springframework.boot.context.properties.ConfigurationProperties; 15 | 16 | @Getter 17 | @Setter 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | @ConfigurationProperties("gremlin") 21 | public class GremlinProperties { 22 | private String endpoint; 23 | 24 | private int port; 25 | 26 | private String username; 27 | 28 | private String password; 29 | 30 | private boolean sslEnabled; 31 | 32 | private boolean telemetryAllowed = true; 33 | 34 | private String serializer = Serializers.GRAPHSON.toString(); 35 | 36 | private int maxContentLength; 37 | } 38 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/config/UserRepositoryConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package web.service.springdata.gremlin.config; 17 | 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.context.annotation.PropertySource; 22 | 23 | import com.microsoft.spring.data.gremlin.common.GremlinConfig; 24 | import com.microsoft.spring.data.gremlin.config.AbstractGremlinConfiguration; 25 | import com.microsoft.spring.data.gremlin.repository.config.EnableGremlinRepositories; 26 | 27 | 28 | @Configuration 29 | @EnableGremlinRepositories(basePackages = "web.service.springdata.gremlin.repository") 30 | @EnableConfigurationProperties(GremlinProperties.class) 31 | @PropertySource("classpath:application.yml") 32 | public class UserRepositoryConfiguration extends AbstractGremlinConfiguration { 33 | 34 | @Autowired 35 | private GremlinProperties gremlinProps; 36 | 37 | @Override 38 | public GremlinConfig getGremlinConfig() { 39 | return new GremlinConfig( 40 | gremlinProps.getEndpoint(), 41 | gremlinProps.getPort(), 42 | gremlinProps.getUsername(), 43 | gremlinProps.getPassword(), 44 | gremlinProps.isSslEnabled(), 45 | gremlinProps.isTelemetryAllowed(), 46 | gremlinProps.getSerializer(), 47 | gremlinProps.getMaxContentLength() 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/domain/MicroService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package web.service.springdata.gremlin.domain; 17 | 18 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 19 | import lombok.AllArgsConstructor; 20 | import lombok.Data; 21 | import lombok.NoArgsConstructor; 22 | import org.springframework.data.annotation.Id; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | @Data 28 | @Vertex 29 | @AllArgsConstructor 30 | @NoArgsConstructor 31 | public class MicroService { 32 | 33 | @Id 34 | private String id; 35 | 36 | private Map properties = new HashMap<>(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/domain/ServicesDataFlow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package web.service.springdata.gremlin.domain; 18 | 19 | import com.microsoft.spring.data.gremlin.annotation.Edge; 20 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 21 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Data; 24 | import lombok.NoArgsConstructor; 25 | import org.springframework.data.annotation.Id; 26 | 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | 31 | @Data 32 | @Edge 33 | @AllArgsConstructor 34 | @NoArgsConstructor 35 | public class ServicesDataFlow { 36 | 37 | @Id 38 | private String id; 39 | 40 | @EdgeFrom 41 | private MicroService serviceFrom; 42 | 43 | @EdgeTo 44 | private MicroService serviceTo; 45 | 46 | private Map properties = new HashMap<>(); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/domain/SpringCloudServiceNetwork.java: -------------------------------------------------------------------------------- 1 | package web.service.springdata.gremlin.domain; 2 | 3 | import com.microsoft.spring.data.gremlin.annotation.EdgeSet; 4 | import com.microsoft.spring.data.gremlin.annotation.Graph; 5 | import com.microsoft.spring.data.gremlin.annotation.VertexSet; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import org.springframework.data.annotation.Id; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @Graph 14 | @NoArgsConstructor 15 | public class SpringCloudServiceNetwork { 16 | 17 | @Id 18 | private String id; 19 | 20 | @EdgeSet 21 | @Getter 22 | private List edges = new ArrayList<>(); 23 | 24 | @VertexSet 25 | @Getter 26 | private List vertexes = new ArrayList<>(); 27 | } 28 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/repository/MicroServiceRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package web.service.springdata.gremlin.repository; 18 | 19 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 20 | import org.springframework.stereotype.Repository; 21 | import web.service.springdata.gremlin.domain.MicroService; 22 | 23 | @Repository 24 | public interface MicroServiceRepository extends GremlinRepository { 25 | } 26 | 27 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/repository/ServicesDataFlowRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package web.service.springdata.gremlin.repository; 18 | 19 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 20 | import org.springframework.stereotype.Repository; 21 | import web.service.springdata.gremlin.domain.ServicesDataFlow; 22 | 23 | @Repository 24 | public interface ServicesDataFlowRepository extends GremlinRepository { 25 | } 26 | 27 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/repository/SpringCloudServiceNetworkRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package web.service.springdata.gremlin.repository; 18 | 19 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 20 | import org.springframework.stereotype.Repository; 21 | import web.service.springdata.gremlin.domain.SpringCloudServiceNetwork; 22 | 23 | @Repository 24 | public interface SpringCloudServiceNetworkRepository extends GremlinRepository { 25 | } 26 | 27 | -------------------------------------------------------------------------------- /examples/web-service/src/main/java/web/service/springdata/gremlin/web/domain/Greeting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package web.service.springdata.gremlin.web.domain; 17 | 18 | import lombok.AllArgsConstructor; 19 | import lombok.Getter; 20 | 21 | @AllArgsConstructor 22 | public class Greeting { 23 | 24 | @Getter 25 | private String id; 26 | 27 | @Getter 28 | private String content; 29 | } 30 | -------------------------------------------------------------------------------- /examples/web-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | gremlin: 2 | endpoint: your-endpoint.gremlin.cosmosdb.azure.com 3 | port: 443 4 | username: your-username 5 | password: your-password 6 | sslEnabled: false 7 | telemetryAllowed: true 8 | maxContentLength: 1000 9 | -------------------------------------------------------------------------------- /package/apache-tinkerpop-gremlin-server-minimal-3.3.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/spring-data-gremlin/f8f600feff71f5ba137d18f1ce1ae1fd37c4d96d/package/apache-tinkerpop-gremlin-server-minimal-3.3.4.tar.gz -------------------------------------------------------------------------------- /script/integration-test-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cat << EOF 4 | 5 | gremlin.endpoint=localhost 6 | gremlin.port=9889 7 | gremlin.username="anonymous" 8 | gremlin.password="anonymous" 9 | gremlin.sslEnabled=false 10 | 11 | EOF 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/annotation/Edge.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import com.microsoft.spring.data.gremlin.common.Constants; 9 | import org.springframework.data.annotation.Persistent; 10 | 11 | import java.lang.annotation.*; 12 | 13 | /** 14 | * Specifies the class as edge in graph, with one optional label(String). 15 | */ 16 | @Persistent 17 | @Inherited 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Target(ElementType.TYPE) 20 | public @interface Edge { 21 | /** 22 | * The label(gremlin reserved) of given Edge, can add Edge by label. 23 | * @return class name if not specify. 24 | */ 25 | String label() default Constants.DEFAULT_EDGE_LABEL; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeFrom.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import org.springframework.data.annotation.Persistent; 9 | 10 | import java.lang.annotation.*; 11 | 12 | /** 13 | * Specifies the field as source of one edge. 14 | */ 15 | @Persistent 16 | @Inherited 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target(ElementType.FIELD) 19 | public @interface EdgeFrom { 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import org.springframework.data.annotation.Persistent; 9 | 10 | import java.lang.annotation.*; 11 | 12 | /** 13 | * Specifies the field as EdgeSet of graph. 14 | */ 15 | @Persistent 16 | @Inherited 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target(ElementType.FIELD) 19 | public @interface EdgeSet { 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeTo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import org.springframework.data.annotation.Persistent; 9 | 10 | import java.lang.annotation.*; 11 | 12 | /** 13 | * Specifies the field as target of one edge. 14 | */ 15 | @Persistent 16 | @Inherited 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target(ElementType.FIELD) 19 | public @interface EdgeTo { 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/annotation/GeneratedValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import java.lang.annotation.ElementType; 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.RetentionPolicy; 11 | import java.lang.annotation.Target; 12 | 13 | /** 14 | * Specifies that a field's value is to be generated (and not explicitly specified in the domain object). 15 | * This annotation should only be used on an id field. 16 | */ 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target(ElementType.FIELD) 19 | public @interface GeneratedValue { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/annotation/Graph.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import com.microsoft.spring.data.gremlin.common.Constants; 9 | import org.springframework.data.annotation.Persistent; 10 | 11 | import java.lang.annotation.*; 12 | 13 | /** 14 | * Specifies the domain class as graph, with one optional collection(String). 15 | */ 16 | @Persistent 17 | @Inherited 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Target({ElementType.TYPE}) 20 | public @interface Graph { 21 | /** 22 | * The collection of given Graph. 23 | * @return class name if not specify. 24 | */ 25 | String collection() default Constants.DEFAULT_COLLECTION_NAME; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/annotation/Vertex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import com.microsoft.spring.data.gremlin.common.Constants; 9 | import org.springframework.data.annotation.Persistent; 10 | 11 | import java.lang.annotation.*; 12 | 13 | /** 14 | * Specifies the class as vertex in graph, with one optional label(String). 15 | */ 16 | @Persistent 17 | @Inherited 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Target(ElementType.TYPE) 20 | public @interface Vertex { 21 | /** 22 | * The label(gremlin reserved) of given Vertex, can add Vertex by label. 23 | * @return class name if not specify. 24 | */ 25 | String label() default Constants.DEFAULT_VERTEX_LABEL; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/annotation/VertexSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import org.springframework.data.annotation.Persistent; 9 | 10 | import java.lang.annotation.*; 11 | 12 | /** 13 | * Specifies the field as VertexSet of graph. 14 | */ 15 | @Persistent 16 | @Inherited 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target(ElementType.FIELD) 19 | public @interface VertexSet { 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/common/GremlinConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import lombok.AccessLevel; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Builder; 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | import org.apache.tinkerpop.gremlin.driver.ser.Serializers; 14 | 15 | @Getter 16 | @Setter 17 | @Builder(builderMethodName = "defaultBuilder") 18 | @AllArgsConstructor(access = AccessLevel.PUBLIC) 19 | public class GremlinConfig { 20 | private String endpoint; 21 | 22 | private int port; 23 | 24 | private String username; 25 | 26 | private String password; 27 | 28 | private boolean sslEnabled; 29 | 30 | private boolean telemetryAllowed; 31 | 32 | private String serializer; 33 | 34 | private int maxContentLength; 35 | 36 | 37 | public static GremlinConfigBuilder builder(String endpoint, String username, String password) { 38 | return defaultBuilder() 39 | .endpoint(endpoint) 40 | .username(username) 41 | .password(password) 42 | .port(Constants.DEFAULT_ENDPOINT_PORT) 43 | .sslEnabled(true) 44 | .serializer(Serializers.GRAPHSON.toString()) 45 | .telemetryAllowed(true); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/common/GremlinEntityType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 9 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; 10 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; 11 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; 12 | import org.springframework.lang.NonNull; 13 | 14 | import java.util.function.Supplier; 15 | 16 | public enum GremlinEntityType { 17 | 18 | VERTEX(GremlinSourceVertex::new), 19 | EDGE(GremlinSourceEdge::new), 20 | GRAPH(GremlinSourceGraph::new); 21 | 22 | private Supplier creator; 23 | 24 | GremlinEntityType(@NonNull Supplier creator) { 25 | this.creator = creator; 26 | } 27 | 28 | public GremlinSource createGremlinSource() { 29 | return this.creator.get(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/common/GremlinFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import com.microsoft.spring.data.gremlin.exception.GremlinIllegalConfigurationException; 9 | import com.microsoft.spring.data.gremlin.telemetry.TelemetrySender; 10 | import org.apache.tinkerpop.gremlin.driver.Client; 11 | import org.apache.tinkerpop.gremlin.driver.Cluster; 12 | import org.apache.tinkerpop.gremlin.driver.ser.Serializers; 13 | import org.springframework.lang.NonNull; 14 | 15 | import javax.annotation.PostConstruct; 16 | 17 | public class GremlinFactory { 18 | 19 | private Cluster gremlinCluster; 20 | 21 | private GremlinConfig gremlinConfig; 22 | 23 | public GremlinFactory(@NonNull GremlinConfig gremlinConfig) { 24 | final int port = gremlinConfig.getPort(); 25 | if (port <= 0 || port > 65535) { 26 | gremlinConfig.setPort(Constants.DEFAULT_ENDPOINT_PORT); 27 | } 28 | 29 | final int maxContentLength = gremlinConfig.getMaxContentLength(); 30 | if (maxContentLength <= 0) { 31 | gremlinConfig.setMaxContentLength(Constants.DEFAULT_MAX_CONTENT_LENGTH); 32 | } 33 | 34 | this.gremlinConfig = gremlinConfig; 35 | } 36 | 37 | private Cluster createGremlinCluster() throws GremlinIllegalConfigurationException { 38 | final Cluster cluster; 39 | 40 | try { 41 | cluster = Cluster.build(this.gremlinConfig.getEndpoint()) 42 | .serializer(Serializers.valueOf(this.gremlinConfig.getSerializer()).simpleInstance()) 43 | .credentials(this.gremlinConfig.getUsername(), this.gremlinConfig.getPassword()) 44 | .enableSsl(this.gremlinConfig.isSslEnabled()) 45 | .maxContentLength(this.gremlinConfig.getMaxContentLength()) 46 | .port(this.gremlinConfig.getPort()) 47 | .create(); 48 | } catch (IllegalArgumentException e) { 49 | throw new GremlinIllegalConfigurationException("Invalid configuration of Gremlin", e); 50 | } 51 | 52 | return cluster; 53 | } 54 | 55 | public Client getGremlinClient() { 56 | 57 | if (this.gremlinCluster == null) { 58 | this.gremlinCluster = this.createGremlinCluster(); 59 | } 60 | 61 | return this.gremlinCluster.connect(); 62 | } 63 | 64 | @PostConstruct 65 | private void sendTelemetry() { 66 | 67 | if (gremlinConfig.isTelemetryAllowed()) { 68 | final TelemetrySender sender = new TelemetrySender(); 69 | 70 | sender.send(this.getClass().getSimpleName()); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/config/AbstractGremlinConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.config; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinConfig; 9 | import com.microsoft.spring.data.gremlin.common.GremlinFactory; 10 | import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; 11 | import com.microsoft.spring.data.gremlin.query.GremlinTemplate; 12 | import org.springframework.context.annotation.Bean; 13 | 14 | public abstract class AbstractGremlinConfiguration extends GremlinConfigurationSupport { 15 | 16 | public abstract GremlinConfig getGremlinConfig(); 17 | 18 | @Bean 19 | public GremlinFactory gremlinFactory() { 20 | return new GremlinFactory(getGremlinConfig()); 21 | } 22 | 23 | @Bean 24 | public MappingGremlinConverter mappingGremlinConverter() throws ClassNotFoundException { 25 | return new MappingGremlinConverter(gremlinMappingContext()); 26 | } 27 | 28 | @Bean 29 | public GremlinTemplate gremlinTemplate(GremlinFactory factory) throws ClassNotFoundException { 30 | return new GremlinTemplate(factory, mappingGremlinConverter()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/config/GremlinConfigurationSupport.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.config; 7 | 8 | import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; 9 | import org.springframework.beans.factory.config.BeanDefinition; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; 12 | import org.springframework.core.type.filter.AnnotationTypeFilter; 13 | import org.springframework.data.annotation.Persistent; 14 | import org.springframework.lang.NonNull; 15 | import org.springframework.util.Assert; 16 | import org.springframework.util.ClassUtils; 17 | import org.springframework.util.StringUtils; 18 | 19 | import java.util.Collection; 20 | import java.util.Collections; 21 | import java.util.HashSet; 22 | import java.util.Set; 23 | 24 | public abstract class GremlinConfigurationSupport { 25 | 26 | protected Collection getMappingBasePackages() { 27 | final Package basePackage = this.getClass().getPackage(); 28 | 29 | return Collections.singleton(basePackage == null ? null : basePackage.getName()); 30 | } 31 | 32 | protected Set> scanEntities(@NonNull String basePackage) throws ClassNotFoundException { 33 | if (!StringUtils.hasText(basePackage)) { 34 | return Collections.emptySet(); 35 | } 36 | 37 | final Set> entitySet = new HashSet<>(); 38 | final ClassPathScanningCandidateComponentProvider provider = 39 | new ClassPathScanningCandidateComponentProvider(false); 40 | 41 | provider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class)); 42 | 43 | for (final BeanDefinition candidate : provider.findCandidateComponents(basePackage)) { 44 | final String className = candidate.getBeanClassName(); 45 | Assert.notNull(GremlinConfigurationSupport.class.getClassLoader(), "Class loader cannot be null"); 46 | 47 | entitySet.add(ClassUtils.forName(className, GremlinConfigurationSupport.class.getClassLoader())); 48 | } 49 | 50 | return entitySet; 51 | } 52 | 53 | protected Set> getInitialEntitySet() throws ClassNotFoundException { 54 | final Set> entitySet = new HashSet<>(); 55 | 56 | for (final String basePackage : this.getMappingBasePackages()) { 57 | entitySet.addAll(this.scanEntities(basePackage)); 58 | } 59 | 60 | return entitySet; 61 | } 62 | 63 | @Bean 64 | public GremlinMappingContext gremlinMappingContext() throws ClassNotFoundException { 65 | final GremlinMappingContext context = new GremlinMappingContext(); 66 | 67 | context.setInitialEntitySet(this.getInitialEntitySet()); 68 | 69 | return context; 70 | } 71 | 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/result/AbstractGremlinResultReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.result; 7 | 8 | import com.microsoft.spring.data.gremlin.common.Constants; 9 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 10 | import lombok.NoArgsConstructor; 11 | import org.springframework.lang.NonNull; 12 | import org.springframework.util.Assert; 13 | 14 | import java.util.ArrayList; 15 | import java.util.LinkedHashMap; 16 | import java.util.Map; 17 | 18 | @NoArgsConstructor 19 | // TODO: seems only for Vertex. 20 | public abstract class AbstractGremlinResultReader { 21 | 22 | /** 23 | * properties's organization is a little complicated. 24 | *

25 | * properties is LinkedHashMap 26 | * K is String 27 | * V is ArrayList 28 | * T is LinkedHashMap 29 | */ 30 | private Object readProperty(@NonNull Object value) { 31 | Assert.isInstanceOf(ArrayList.class, value, "should be instance of ArrayList"); 32 | 33 | @SuppressWarnings("unchecked") final ArrayList> mapList 34 | = (ArrayList>) value; 35 | 36 | Assert.isTrue(mapList.size() == 1, "should be only 1 element in ArrayList"); 37 | 38 | return mapList.get(0).get(Constants.PROPERTY_VALUE); 39 | } 40 | 41 | protected void readResultProperties(@NonNull Map properties, @NonNull GremlinSource source) { 42 | source.getProperties().clear(); 43 | properties.forEach((key, value) -> source.setProperty(key, this.readProperty(value))); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultVertexReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.result; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinUtils; 9 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 10 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; 11 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; 12 | import lombok.NoArgsConstructor; 13 | import org.apache.tinkerpop.gremlin.driver.Result; 14 | import org.springframework.lang.NonNull; 15 | import org.springframework.util.Assert; 16 | 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | import static com.microsoft.spring.data.gremlin.common.Constants.*; 21 | 22 | @NoArgsConstructor 23 | public class GremlinResultVertexReader extends AbstractGremlinResultReader implements GremlinResultsReader { 24 | 25 | private void validate(List results, GremlinSource source) { 26 | Assert.notNull(results, "Results should not be null."); 27 | Assert.notNull(source, "GremlinSource should not be null."); 28 | Assert.isTrue(results.size() == 1, "Vertex should contain only one result."); 29 | 30 | final Result result = results.get(0); 31 | 32 | Assert.isInstanceOf(Map.class, result.getObject(), "should be one instance of Map"); 33 | 34 | @SuppressWarnings("unchecked") final Map map = (Map) result.getObject(); 35 | 36 | Assert.isTrue(map.containsKey(PROPERTY_ID), "should contain id property"); 37 | Assert.isTrue(map.containsKey(PROPERTY_LABEL), "should contain label property"); 38 | Assert.isTrue(map.containsKey(PROPERTY_TYPE), "should contain type property"); 39 | Assert.isTrue(map.containsKey(PROPERTY_PROPERTIES), "should contain properties property"); 40 | Assert.isTrue(map.get(PROPERTY_TYPE).equals(RESULT_TYPE_VERTEX), "must be vertex type"); 41 | 42 | Assert.isInstanceOf(Map.class, map.get(PROPERTY_PROPERTIES), "should be one instance of Map"); 43 | } 44 | 45 | @Override 46 | @SuppressWarnings("unchecked") 47 | public void read(@NonNull List results, @NonNull GremlinSource source) { 48 | if (!(source instanceof GremlinSourceVertex)) { 49 | throw new GremlinUnexpectedSourceTypeException("Should be instance of GremlinSourceVertex"); 50 | } 51 | 52 | validate(results, source); 53 | 54 | final Map map = (Map) results.get(0).getObject(); 55 | final Map properties = (Map) map.get(PROPERTY_PROPERTIES); 56 | 57 | super.readResultProperties(properties, source); 58 | 59 | final String className = source.getProperties().get(GREMLIN_PROPERTY_CLASSNAME).toString(); 60 | 61 | source.setIdField(GremlinUtils.getIdField(GremlinUtils.toEntityClass(className))); 62 | source.setId(map.get(PROPERTY_ID)); 63 | source.setLabel(map.get(PROPERTY_LABEL).toString()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultsGraphReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.result; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 9 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; 10 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; 11 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; 12 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; 13 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; 14 | import org.apache.tinkerpop.gremlin.driver.Result; 15 | import org.springframework.lang.NonNull; 16 | import org.springframework.util.Assert; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import static com.microsoft.spring.data.gremlin.common.Constants.*; 22 | import static java.util.Collections.singletonList; 23 | 24 | public class GremlinResultsGraphReader extends AbstractGremlinResultReader implements GremlinResultsReader { 25 | 26 | private final GremlinResultVertexReader vertexResultReader; 27 | private final GremlinResultEdgeReader edgeResultReader; 28 | 29 | public GremlinResultsGraphReader() { 30 | vertexResultReader = new GremlinResultVertexReader(); 31 | edgeResultReader = new GremlinResultEdgeReader(); 32 | } 33 | 34 | @Override 35 | public void read(@NonNull List results, @NonNull GremlinSource source) { 36 | if (!(source instanceof GremlinSourceGraph)) { 37 | throw new GremlinUnexpectedSourceTypeException("Should be instance of GremlinSourceGraph"); 38 | } 39 | 40 | final GremlinSourceGraph graphSource = (GremlinSourceGraph) source; 41 | 42 | graphSource.getVertexSet().clear(); 43 | graphSource.getEdgeSet().clear(); 44 | 45 | results.stream().map(this::processResult).forEach(graphSource::addGremlinSource); 46 | } 47 | 48 | private GremlinSource processResult(Result result) { 49 | final GremlinSource source; 50 | final Object obj = result.getObject(); 51 | 52 | Assert.isInstanceOf(Map.class, obj, "should be an instance of Map"); 53 | @SuppressWarnings("unchecked") final Map map = (Map) result.getObject(); 54 | 55 | Assert.isTrue(map.containsKey(PROPERTY_TYPE), "should contain a type property"); 56 | final String type = (String) map.get(PROPERTY_TYPE); 57 | 58 | switch (type) { 59 | case RESULT_TYPE_VERTEX: 60 | source = new GremlinSourceVertex(); 61 | vertexResultReader.read(singletonList(result), source); 62 | break; 63 | case RESULT_TYPE_EDGE: 64 | source = new GremlinSourceEdge(); 65 | edgeResultReader.read(singletonList(result), source); 66 | break; 67 | default: 68 | throw new GremlinUnexpectedEntityTypeException("Unexpected result type: " + type); 69 | } 70 | 71 | return source; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultsReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.result; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 9 | import org.apache.tinkerpop.gremlin.driver.Result; 10 | 11 | import java.util.List; 12 | 13 | public interface GremlinResultsReader { 14 | /** 15 | * Read the Gremlin returned Results to GremlinSource. 16 | */ 17 | void read(List results, GremlinSource source); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteral.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.script; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Provider interface to generate different query to gremlin server. 14 | * The scripts return queries in steps, organized by List. 15 | */ 16 | public interface GremlinScriptLiteral { 17 | /** 18 | * Generate the insert query from source (Vertex, Edge or Graph). 19 | */ 20 | List generateInsertScript(GremlinSource source); 21 | 22 | /** 23 | * Generate the deleteAll query from source (Vertex, Edge or Graph). 24 | */ 25 | List generateDeleteAllScript(); 26 | 27 | /** 28 | * Generate the deleteAll By Domain Class query from source (Vertex, Edge or Graph). 29 | */ 30 | List generateDeleteAllByClassScript(GremlinSource source); 31 | 32 | /** 33 | * Generate the findById query from source (Vertex, Edge). 34 | */ 35 | List generateFindByIdScript(GremlinSource source); 36 | 37 | /** 38 | * Generate the update query from source (Vertex, Edge or Graph). 39 | */ 40 | List generateUpdateScript(GremlinSource source); 41 | 42 | /** 43 | * Generate the findAll query from source (Vertex, Edge or Graph). 44 | */ 45 | List generateFindAllScript(GremlinSource source); 46 | 47 | /** 48 | * Generate the DeleteById query from source (Vertex, Edge or Graph). 49 | */ 50 | List generateDeleteByIdScript(GremlinSource source); 51 | 52 | /** 53 | * Generate the Count query from Source (Vertex, Edge) 54 | */ 55 | List generateCountScript(GremlinSource source); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/AbstractGremlinSourceReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinUtils; 9 | import com.microsoft.spring.data.gremlin.exception.GremlinEntityInformationException; 10 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; 11 | import lombok.NonNull; 12 | import org.apache.tinkerpop.shaded.jackson.databind.JavaType; 13 | import org.apache.tinkerpop.shaded.jackson.databind.type.TypeFactory; 14 | import org.springframework.data.mapping.PersistentProperty; 15 | import org.springframework.lang.Nullable; 16 | import org.springframework.util.Assert; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Field; 20 | import java.util.Date; 21 | 22 | public abstract class AbstractGremlinSourceReader { 23 | 24 | protected Object readProperty(@NonNull PersistentProperty property, @Nullable Object value) { 25 | final Class type = property.getTypeInformation().getType(); 26 | final JavaType javaType = TypeFactory.defaultInstance().constructType(property.getType()); 27 | 28 | if (value == null) { 29 | return null; 30 | } else if (type == int.class || type == Integer.class 31 | || type == Boolean.class || type == boolean.class 32 | || type == String.class) { 33 | return value; 34 | } else if (type == Date.class) { 35 | Assert.isTrue(value instanceof Long, "Date store value must be instance of long"); 36 | return new Date((Long) value); 37 | } else { 38 | final Object object; 39 | 40 | try { 41 | object = GremlinUtils.getObjectMapper().readValue(value.toString(), javaType); 42 | } catch (IOException e) { 43 | throw new GremlinUnexpectedEntityTypeException("Failed to read String to Object", e); 44 | } 45 | 46 | return object; 47 | } 48 | } 49 | 50 | protected Object getGremlinSourceId(@NonNull GremlinSource source) { 51 | if (!source.getId().isPresent()) { 52 | return null; 53 | } 54 | 55 | final Object id = source.getId().get(); 56 | final Field idField = source.getIdField(); 57 | 58 | if (idField.getType() == String.class) { 59 | return id.toString(); 60 | } else if (idField.getType() == Integer.class) { 61 | Assert.isTrue(id instanceof Integer, "source Id should be Integer."); 62 | return id; 63 | } else if (idField.getType() == Long.class && id instanceof Integer) { 64 | return Long.valueOf((Integer) id); 65 | } else if (idField.getType() == Long.class && id instanceof Long) { 66 | return id; 67 | } 68 | 69 | throw new GremlinEntityInformationException("unsupported id field type: " + id.getClass().getSimpleName()); 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdge.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultEdgeReader; 9 | import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralEdge; 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | public class GremlinSourceEdge extends AbstractGremlinSource { 14 | 15 | @Getter 16 | @Setter 17 | private Object vertexIdFrom; 18 | 19 | @Getter 20 | @Setter 21 | private Object vertexIdTo; 22 | 23 | public GremlinSourceEdge() { 24 | super(); 25 | initializeGremlinStrategy(); 26 | } 27 | 28 | public GremlinSourceEdge(Class domainClass) { 29 | super(domainClass); 30 | initializeGremlinStrategy(); 31 | } 32 | 33 | private void initializeGremlinStrategy() { 34 | this.setGremlinScriptStrategy(new GremlinScriptLiteralEdge()); 35 | this.setGremlinResultReader(new GremlinResultEdgeReader()); 36 | this.setGremlinSourceReader(new GremlinSourceEdgeReader()); 37 | this.setGremlinSourceWriter(new GremlinSourceEdgeWriter()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdgeReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 9 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 10 | import com.microsoft.spring.data.gremlin.common.GremlinUtils; 11 | import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; 12 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; 13 | import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; 14 | import lombok.NoArgsConstructor; 15 | import org.apache.commons.lang3.reflect.FieldUtils; 16 | import org.springframework.data.annotation.Id; 17 | import org.springframework.data.mapping.PersistentProperty; 18 | import org.springframework.data.mapping.model.ConvertingPropertyAccessor; 19 | import org.springframework.lang.NonNull; 20 | import org.springframework.util.Assert; 21 | 22 | import java.lang.reflect.Field; 23 | 24 | import static com.microsoft.spring.data.gremlin.common.Constants.PROPERTY_ID; 25 | 26 | @NoArgsConstructor 27 | public class GremlinSourceEdgeReader extends AbstractGremlinSourceReader implements GremlinSourceReader { 28 | 29 | @Override 30 | public T read(@NonNull Class domainClass, @NonNull MappingGremlinConverter converter, 31 | @NonNull GremlinSource source) { 32 | if (!(source instanceof GremlinSourceEdge)) { 33 | throw new GremlinUnexpectedSourceTypeException("should be instance of GremlinSourceEdge"); 34 | } 35 | 36 | final T domain = GremlinUtils.createInstance(domainClass); 37 | final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(domain); 38 | final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(domainClass); 39 | 40 | for (final Field field : FieldUtils.getAllFields(domainClass)) { 41 | final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); 42 | if (property == null) { 43 | continue; 44 | } 45 | if (field.getName().equals(PROPERTY_ID) || field.getAnnotation(Id.class) != null) { 46 | accessor.setProperty(property, super.getGremlinSourceId(source)); 47 | continue; 48 | } else if (field.getAnnotation(EdgeFrom.class) != null || field.getAnnotation(EdgeTo.class) != null) { 49 | // We cannot do that here as the gremlin will not tell more information about vertex except Id. After 50 | // the query of Edge end, we can get the Id of vertex from/to. And then we will do extra 2 query to 51 | // obtain the 2 vertex and complete the edge. 52 | // 53 | // That work will be wrapped in GremlinTemplate insert, and skip the property here. 54 | continue; 55 | } 56 | 57 | final Object value = super.readProperty(property, source.getProperties().get(field.getName())); 58 | accessor.setProperty(property, value); 59 | } 60 | 61 | return domain; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraph.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultsGraphReader; 9 | import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultsReader; 10 | import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralGraph; 11 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; 12 | import lombok.Getter; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class GremlinSourceGraph extends AbstractGremlinSource { 18 | 19 | @Getter 20 | private List vertexSet = new ArrayList<>(); 21 | 22 | @Getter 23 | private List edgeSet = new ArrayList<>(); 24 | 25 | @Getter 26 | private GremlinResultsReader resultsReader; 27 | 28 | public GremlinSourceGraph() { 29 | super(); 30 | initializeGremlinStrategy(); 31 | this.setGremlinSourceReader(new GremlinSourceGraphReader()); 32 | this.resultsReader = new GremlinResultsGraphReader(); 33 | } 34 | 35 | public GremlinSourceGraph(Class domainClass) { 36 | super(domainClass); 37 | initializeGremlinStrategy(); 38 | this.setGremlinSourceReader(new GremlinSourceGraphReader()); 39 | this.resultsReader = new GremlinResultsGraphReader(); 40 | } 41 | 42 | public void addGremlinSource(GremlinSource source) { 43 | if (source instanceof GremlinSourceVertex) { 44 | this.vertexSet.add(source); 45 | } else if (source instanceof GremlinSourceEdge) { 46 | this.edgeSet.add(source); 47 | } else { 48 | throw new GremlinUnexpectedSourceTypeException("source type can only be Vertex or Edge"); 49 | } 50 | } 51 | 52 | private void initializeGremlinStrategy() { 53 | this.setGremlinScriptStrategy(new GremlinScriptLiteralGraph()); 54 | this.setGremlinSourceWriter(new GremlinSourceGraphWriter()); 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; 9 | 10 | /** 11 | * Provider Entity type dependent read method. 12 | */ 13 | public interface GremlinSourceReader { 14 | /** 15 | * Read data from GremlinSource to domain 16 | */ 17 | T read(Class domainClass, MappingGremlinConverter converter, GremlinSource source); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultVertexReader; 9 | import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralVertex; 10 | 11 | public class GremlinSourceVertex extends AbstractGremlinSource { 12 | 13 | public GremlinSourceVertex() { 14 | super(); 15 | initializeGremlinStrategy(); 16 | } 17 | 18 | public GremlinSourceVertex(Class domainClass) { 19 | super(domainClass); 20 | initializeGremlinStrategy(); 21 | } 22 | 23 | private void initializeGremlinStrategy() { 24 | this.setGremlinScriptStrategy(new GremlinScriptLiteralVertex()); 25 | this.setGremlinResultReader(new GremlinResultVertexReader()); 26 | this.setGremlinSourceReader(new GremlinSourceVertexReader()); 27 | this.setGremlinSourceWriter(new GremlinSourceVertexWriter()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertexReader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.common.Constants; 9 | import com.microsoft.spring.data.gremlin.common.GremlinUtils; 10 | import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; 11 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; 12 | import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; 13 | import lombok.NoArgsConstructor; 14 | import org.apache.commons.lang3.reflect.FieldUtils; 15 | import org.springframework.data.annotation.Id; 16 | import org.springframework.data.mapping.PersistentProperty; 17 | import org.springframework.data.mapping.model.ConvertingPropertyAccessor; 18 | import org.springframework.lang.NonNull; 19 | import org.springframework.util.Assert; 20 | 21 | import java.lang.reflect.Field; 22 | 23 | @NoArgsConstructor 24 | public class GremlinSourceVertexReader extends AbstractGremlinSourceReader implements GremlinSourceReader { 25 | 26 | @Override 27 | public T read(@NonNull Class domainClass, @NonNull MappingGremlinConverter converter, 28 | @NonNull GremlinSource source) { 29 | if (!(source instanceof GremlinSourceVertex)) { 30 | throw new GremlinUnexpectedSourceTypeException("should be instance of GremlinSourceVertex"); 31 | } 32 | 33 | final T domain = GremlinUtils.createInstance(domainClass); 34 | final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(domain); 35 | final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(domainClass); 36 | 37 | for (final Field field : FieldUtils.getAllFields(domainClass)) { 38 | final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); 39 | if (property == null) { 40 | continue; 41 | } 42 | 43 | if (field.getName().equals(Constants.PROPERTY_ID) || field.getAnnotation(Id.class) != null) { 44 | accessor.setProperty(property, super.getGremlinSourceId(source)); 45 | } else { 46 | final Object value = super.readProperty(property, source.getProperties().get(field.getName())); 47 | accessor.setProperty(property, value); 48 | } 49 | } 50 | 51 | return domain; 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertexWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; 9 | import com.microsoft.spring.data.gremlin.exception.GremlinEntityInformationException; 10 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; 11 | import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; 12 | import lombok.NoArgsConstructor; 13 | import org.apache.commons.lang3.reflect.FieldUtils; 14 | import org.springframework.data.annotation.Id; 15 | import org.springframework.data.mapping.PersistentProperty; 16 | import org.springframework.data.mapping.model.ConvertingPropertyAccessor; 17 | import org.springframework.lang.NonNull; 18 | import org.springframework.util.Assert; 19 | 20 | import java.lang.reflect.Field; 21 | 22 | import static com.microsoft.spring.data.gremlin.common.Constants.GREMLIN_PROPERTY_CLASSNAME; 23 | import static com.microsoft.spring.data.gremlin.common.Constants.PROPERTY_ID; 24 | 25 | @NoArgsConstructor 26 | public class GremlinSourceVertexWriter implements GremlinSourceWriter { 27 | 28 | @Override 29 | public void write(@NonNull Object domain, @NonNull MappingGremlinConverter converter, 30 | @NonNull GremlinSource source) { 31 | if (!(source instanceof GremlinSourceVertex)) { 32 | throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); 33 | } 34 | 35 | source.setId(converter.getIdFieldValue(domain)); 36 | 37 | final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(domain.getClass()); 38 | final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(domain); 39 | 40 | for (final Field field : FieldUtils.getAllFields(domain.getClass())) { 41 | final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); 42 | if (property == null) { 43 | continue; 44 | } 45 | 46 | if (field.getName().equals(PROPERTY_ID) || field.getAnnotation(Id.class) != null) { 47 | continue; 48 | } else if (field.getName().equals(GREMLIN_PROPERTY_CLASSNAME)) { 49 | throw new GremlinEntityInformationException("Domain Cannot use pre-defined field name: " 50 | + GREMLIN_PROPERTY_CLASSNAME); 51 | } 52 | 53 | source.setProperty(field.getName(), accessor.getProperty(property)); 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceWriter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.source; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; 9 | 10 | /** 11 | * Provider Entity type dependent write method. 12 | */ 13 | public interface GremlinSourceWriter { 14 | /** 15 | * Write the domain class information to GremlinSource 16 | */ 17 | void write(Object domain, MappingGremlinConverter converter, GremlinSource source); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinEntityInformationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.exception; 7 | 8 | import org.springframework.dao.TypeMismatchDataAccessException; 9 | 10 | public class GremlinEntityInformationException extends TypeMismatchDataAccessException { 11 | 12 | public GremlinEntityInformationException(String msg) { 13 | super(msg); 14 | } 15 | 16 | public GremlinEntityInformationException(String msg, Throwable cause) { 17 | super(msg, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinIllegalConfigurationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.exception; 7 | 8 | import org.springframework.dao.InvalidDataAccessApiUsageException; 9 | 10 | public class GremlinIllegalConfigurationException extends InvalidDataAccessApiUsageException { 11 | 12 | public GremlinIllegalConfigurationException(String msg) { 13 | super(msg); 14 | } 15 | 16 | public GremlinIllegalConfigurationException(String msg, Throwable cause) { 17 | super(msg, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinInvalidEntityIdFieldException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.exception; 7 | 8 | public class GremlinInvalidEntityIdFieldException extends GremlinEntityInformationException { 9 | 10 | public GremlinInvalidEntityIdFieldException(String msg) { 11 | super(msg); 12 | } 13 | 14 | public GremlinInvalidEntityIdFieldException(String msg, Throwable cause) { 15 | super(msg, cause); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinQueryException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.exception; 7 | 8 | import org.springframework.dao.DataAccessResourceFailureException; 9 | 10 | public class GremlinQueryException extends DataAccessResourceFailureException { 11 | 12 | public GremlinQueryException(String msg) { 13 | super(msg); 14 | } 15 | 16 | public GremlinQueryException(String msg, Throwable cause) { 17 | super(msg, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinUnexpectedEntityTypeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.exception; 7 | 8 | public class GremlinUnexpectedEntityTypeException extends GremlinEntityInformationException { 9 | 10 | public GremlinUnexpectedEntityTypeException(String msg) { 11 | super(msg); 12 | } 13 | 14 | public GremlinUnexpectedEntityTypeException(String msg, Throwable cause) { 15 | super(msg, cause); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinUnexpectedSourceTypeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.exception; 7 | 8 | import org.springframework.dao.TypeMismatchDataAccessException; 9 | 10 | public class GremlinUnexpectedSourceTypeException extends TypeMismatchDataAccessException { 11 | 12 | public GremlinUnexpectedSourceTypeException(String msg) { 13 | super(msg); 14 | } 15 | 16 | public GremlinUnexpectedSourceTypeException(String msg, Throwable cause) { 17 | super(msg, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.mapping; 7 | 8 | import org.springframework.beans.BeansException; 9 | import org.springframework.context.ApplicationContext; 10 | import org.springframework.context.ApplicationContextAware; 11 | import org.springframework.context.expression.BeanFactoryAccessor; 12 | import org.springframework.context.expression.BeanFactoryResolver; 13 | import org.springframework.data.mapping.model.BasicPersistentEntity; 14 | import org.springframework.data.util.TypeInformation; 15 | import org.springframework.expression.spel.support.StandardEvaluationContext; 16 | 17 | public class BasicGremlinPersistentEntity extends BasicPersistentEntity 18 | implements GremlinPersistentEntity, ApplicationContextAware { 19 | 20 | private final StandardEvaluationContext context; 21 | 22 | public BasicGremlinPersistentEntity(TypeInformation information) { 23 | super(information); 24 | 25 | this.context = new StandardEvaluationContext(); 26 | } 27 | 28 | @Override 29 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 30 | this.context.addPropertyAccessor(new BeanFactoryAccessor()); 31 | this.context.setBeanResolver(new BeanFactoryResolver(applicationContext)); 32 | this.context.setRootObject(applicationContext); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentProperty.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.mapping; 7 | 8 | import com.microsoft.spring.data.gremlin.common.Constants; 9 | import org.springframework.data.mapping.Association; 10 | import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; 11 | import org.springframework.data.mapping.model.Property; 12 | import org.springframework.data.mapping.model.SimpleTypeHolder; 13 | 14 | public class BasicGremlinPersistentProperty extends AnnotationBasedPersistentProperty 15 | implements GremlinPersistentProperty { 16 | 17 | public BasicGremlinPersistentProperty(Property property, GremlinPersistentEntity owner, 18 | SimpleTypeHolder holder) { 19 | super(property, owner, holder); 20 | } 21 | 22 | @Override 23 | protected Association createAssociation() { 24 | return new Association<>(this, null); 25 | } 26 | 27 | @Override 28 | public boolean isIdProperty() { 29 | return super.isIdProperty() || getName().equals(Constants.PROPERTY_ID); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinMappingContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.mapping; 7 | 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.data.mapping.context.AbstractMappingContext; 10 | import org.springframework.data.mapping.model.Property; 11 | import org.springframework.data.mapping.model.SimpleTypeHolder; 12 | import org.springframework.data.util.TypeInformation; 13 | 14 | public class GremlinMappingContext 15 | extends AbstractMappingContext, GremlinPersistentProperty> { 16 | private ApplicationContext context; 17 | 18 | @Override 19 | public void setApplicationContext(ApplicationContext context) { 20 | this.context = context; 21 | } 22 | 23 | @Override 24 | public GremlinPersistentProperty createPersistentProperty(Property property, 25 | BasicGremlinPersistentEntity owner, 26 | SimpleTypeHolder holder) { 27 | return new BasicGremlinPersistentProperty(property, owner, holder); 28 | } 29 | 30 | @Override 31 | protected BasicGremlinPersistentEntity createPersistentEntity(TypeInformation typeInformation) { 32 | final BasicGremlinPersistentEntity entity = new BasicGremlinPersistentEntity<>(typeInformation); 33 | 34 | if (this.context != null) { 35 | entity.setApplicationContext(this.context); 36 | } 37 | 38 | return entity; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinPersistentEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.mapping; 7 | 8 | import org.springframework.data.mapping.PersistentEntity; 9 | 10 | public interface GremlinPersistentEntity extends PersistentEntity { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinPersistentProperty.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.mapping; 7 | 8 | import org.springframework.data.mapping.PersistentProperty; 9 | 10 | public interface GremlinPersistentProperty extends PersistentProperty { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/GremlinEntityMetadata.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query; 7 | 8 | import org.springframework.data.repository.core.EntityMetadata; 9 | 10 | public interface GremlinEntityMetadata extends EntityMetadata { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/GremlinOperations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinEntityType; 9 | import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; 10 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 11 | import com.microsoft.spring.data.gremlin.query.query.GremlinQuery; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Provider interface for basic Operations with Gremlin 17 | */ 18 | public interface GremlinOperations { 19 | 20 | void deleteAll(); 21 | 22 | void deleteAll(GremlinEntityType type); 23 | 24 | void deleteAll(GremlinSource source); 25 | 26 | boolean isEmptyGraph(GremlinSource source); 27 | 28 | boolean existsById(Object id, GremlinSource source); 29 | 30 | void deleteById(Object id, GremlinSource source); 31 | 32 | T insert(T object, GremlinSource source); 33 | 34 | T findById(Object id, GremlinSource source); 35 | 36 | T findVertexById(Object id, GremlinSource source); 37 | 38 | T findEdgeById(Object id, GremlinSource source); 39 | 40 | T update(T object, GremlinSource source); 41 | 42 | T save(T object, GremlinSource source); 43 | 44 | List findAll(GremlinSource source); 45 | 46 | long vertexCount(); 47 | 48 | long edgeCount(); 49 | 50 | List find(GremlinQuery query, GremlinSource source); 51 | 52 | MappingGremlinConverter getMappingConverter(); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/SimpleGremlinEntityMetadata.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query; 7 | 8 | public class SimpleGremlinEntityMetadata implements GremlinEntityMetadata { 9 | 10 | private final Class type; 11 | 12 | public SimpleGremlinEntityMetadata(Class type) { 13 | this.type = type; 14 | } 15 | 16 | public Class getJavaType() { 17 | return this.type; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/criteria/Criteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.criteria; 7 | 8 | import lombok.Getter; 9 | import org.springframework.lang.NonNull; 10 | import org.springframework.util.Assert; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | @Getter 16 | public class Criteria { 17 | 18 | private String subject; 19 | private List subValues; 20 | private final CriteriaType type; 21 | private final List subCriteria; 22 | 23 | private Criteria(CriteriaType type) { 24 | this.type = type; 25 | this.subCriteria = new ArrayList<>(); 26 | } 27 | 28 | private static boolean isBinaryOperation(CriteriaType type) { 29 | switch (type) { 30 | case AND: 31 | case OR: 32 | return true; 33 | default: 34 | return false; 35 | } 36 | } 37 | 38 | private static boolean isUnaryOperation(CriteriaType type) { 39 | switch (type) { 40 | case EXISTS: 41 | case AFTER: 42 | case BEFORE: 43 | case BETWEEN: 44 | case IS_EQUAL: 45 | return true; 46 | default: 47 | return false; 48 | } 49 | } 50 | 51 | public static Criteria getUnaryInstance(CriteriaType type, @NonNull String subject, @NonNull List values) { 52 | Assert.isTrue(isUnaryOperation(type), "type should be Unary operation"); 53 | 54 | final Criteria criteria = new Criteria(type); 55 | 56 | criteria.subject = subject; 57 | criteria.subValues = values; 58 | 59 | return criteria; 60 | } 61 | 62 | public static Criteria getBinaryInstance(CriteriaType type, @NonNull Criteria left, @NonNull Criteria right) { 63 | Assert.isTrue(isBinaryOperation(type), "type should be Binary operation"); 64 | 65 | final Criteria criteria = new Criteria(type); 66 | 67 | criteria.subCriteria.add(left); 68 | criteria.subCriteria.add(right); 69 | 70 | Assert.isTrue(criteria.getSubCriteria().size() == 2, "Binary should contain 2 subCriteria"); 71 | 72 | return criteria; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/criteria/CriteriaType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.criteria; 7 | 8 | import static com.microsoft.spring.data.gremlin.common.Constants.*; 9 | 10 | public enum CriteriaType { 11 | IS_EQUAL, 12 | OR, 13 | AND, 14 | EXISTS, 15 | AFTER, 16 | BEFORE, 17 | BETWEEN; 18 | 19 | public static String criteriaTypeToGremlin(CriteriaType type) { 20 | switch (type) { 21 | case OR: 22 | return GREMLIN_PRIMITIVE_OR; 23 | case AND: 24 | return GREMLIN_PRIMITIVE_AND; 25 | case AFTER: 26 | return GREMLIN_PRIMITIVE_IS_GT; 27 | case BEFORE: 28 | return GREMLIN_PRIMITIVE_IS_LT; 29 | case BETWEEN: 30 | return GREMLIN_PRIMITIVE_IS_BETWEEN; 31 | default: 32 | throw new UnsupportedOperationException("Unsupported criteria type."); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.paramerter; 7 | 8 | import org.springframework.core.MethodParameter; 9 | import org.springframework.data.repository.query.Parameter; 10 | 11 | public class GremlinParameter extends Parameter { 12 | 13 | public GremlinParameter(MethodParameter parameter) { 14 | super(parameter); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameterAccessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.paramerter; 7 | 8 | import org.springframework.data.repository.query.ParameterAccessor; 9 | 10 | public interface GremlinParameterAccessor extends ParameterAccessor { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameters.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.paramerter; 7 | 8 | import org.springframework.core.MethodParameter; 9 | import org.springframework.data.repository.query.Parameters; 10 | 11 | import java.lang.reflect.Method; 12 | import java.util.List; 13 | 14 | public class GremlinParameters extends Parameters { 15 | 16 | public GremlinParameters(Method method) { 17 | super(method); 18 | } 19 | 20 | private GremlinParameters(List parameters) { 21 | super(parameters); 22 | } 23 | 24 | @Override 25 | protected GremlinParameters createFrom(List parameters) { 26 | return new GremlinParameters(parameters); 27 | } 28 | 29 | @Override 30 | protected GremlinParameter createParameter(MethodParameter parameter) { 31 | return new GremlinParameter(parameter); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParametersParameterAccessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.paramerter; 7 | 8 | import com.microsoft.spring.data.gremlin.query.query.GremlinQueryMethod; 9 | import org.springframework.data.repository.query.ParametersParameterAccessor; 10 | 11 | public class GremlinParametersParameterAccessor extends ParametersParameterAccessor 12 | implements GremlinParameterAccessor { 13 | 14 | public GremlinParametersParameterAccessor(GremlinQueryMethod method, Object[] values) { 15 | super(method.getParameters(), values); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/query/AbstractGremlinQuery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.query; 7 | 8 | import com.microsoft.spring.data.gremlin.query.GremlinOperations; 9 | import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameterAccessor; 10 | import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParametersParameterAccessor; 11 | import org.springframework.data.repository.query.RepositoryQuery; 12 | import org.springframework.data.repository.query.ResultProcessor; 13 | import org.springframework.lang.NonNull; 14 | 15 | public abstract class AbstractGremlinQuery implements RepositoryQuery { 16 | 17 | private final GremlinQueryMethod method; 18 | private final GremlinOperations operations; 19 | 20 | public AbstractGremlinQuery(@NonNull GremlinQueryMethod method, @NonNull GremlinOperations operations) { 21 | this.method = method; 22 | this.operations = operations; 23 | } 24 | 25 | protected abstract GremlinQuery createQuery(GremlinParameterAccessor accessor); 26 | 27 | protected boolean isDeleteQuery() { 28 | // panli: always return false as only take care find in one PR. 29 | return false; 30 | } 31 | 32 | @Override 33 | public Object execute(@NonNull Object[] parameters) { 34 | final GremlinParameterAccessor accessor = new GremlinParametersParameterAccessor(this.method, parameters); 35 | 36 | final GremlinQuery query = this.createQuery(accessor); 37 | final ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor); 38 | final GremlinQueryExecution execution = this.getExecution(); 39 | 40 | return execution.execute(query, processor.getReturnedType().getDomainType()); 41 | } 42 | 43 | @Override 44 | @NonNull 45 | public GremlinQueryMethod getQueryMethod() { 46 | return this.method; 47 | } 48 | 49 | @NonNull 50 | private GremlinQueryExecution getExecution() { 51 | if (this.isDeleteQuery()) { 52 | throw new UnsupportedOperationException("Not implemented yet"); 53 | } else { 54 | return new GremlinQueryExecution.FindExecution(this.operations); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQuery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.query; 7 | 8 | import com.microsoft.spring.data.gremlin.query.criteria.Criteria; 9 | import lombok.Getter; 10 | import lombok.NonNull; 11 | 12 | public class GremlinQuery { 13 | 14 | @Getter 15 | private final Criteria criteria; 16 | 17 | public GremlinQuery(@NonNull Criteria criteria) { 18 | this.criteria = criteria; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryExecution.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.query; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinUtils; 9 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 10 | import com.microsoft.spring.data.gremlin.query.GremlinOperations; 11 | import org.springframework.lang.NonNull; 12 | 13 | public interface GremlinQueryExecution { 14 | Object execute(GremlinQuery query, Class type); 15 | 16 | final class FindExecution implements GremlinQueryExecution { 17 | 18 | private final GremlinOperations operations; 19 | 20 | public FindExecution(@NonNull GremlinOperations operations) { 21 | this.operations = operations; 22 | } 23 | 24 | @Override 25 | public Object execute(@NonNull GremlinQuery query, @NonNull Class domainClass) { 26 | final GremlinSource source = GremlinUtils.toGremlinSource(domainClass); 27 | 28 | return this.operations.find(query, source); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.query; 7 | 8 | import com.microsoft.spring.data.gremlin.query.GremlinEntityMetadata; 9 | import com.microsoft.spring.data.gremlin.query.SimpleGremlinEntityMetadata; 10 | import org.springframework.data.projection.ProjectionFactory; 11 | import org.springframework.data.repository.core.EntityMetadata; 12 | import org.springframework.data.repository.core.RepositoryMetadata; 13 | import org.springframework.data.repository.query.QueryMethod; 14 | 15 | import java.lang.reflect.Method; 16 | 17 | public class GremlinQueryMethod extends QueryMethod { 18 | 19 | private GremlinEntityMetadata metadata; 20 | 21 | public GremlinQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { 22 | super(method, metadata, factory); 23 | } 24 | 25 | @Override 26 | public EntityMetadata getEntityInformation() { 27 | @SuppressWarnings("unchecked") final Class domainClass = (Class) super.getDomainClass(); 28 | 29 | this.metadata = new SimpleGremlinEntityMetadata<>(domainClass); 30 | 31 | return this.metadata; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/query/PartTreeGremlinQuery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.query; 7 | 8 | import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentProperty; 9 | import com.microsoft.spring.data.gremlin.query.GremlinOperations; 10 | import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameterAccessor; 11 | import org.springframework.data.mapping.context.MappingContext; 12 | import org.springframework.data.repository.query.ResultProcessor; 13 | import org.springframework.data.repository.query.parser.PartTree; 14 | import org.springframework.lang.NonNull; 15 | 16 | public class PartTreeGremlinQuery extends AbstractGremlinQuery { 17 | 18 | private final PartTree partTree; 19 | private final ResultProcessor processor; 20 | private final MappingContext mappingContext; 21 | 22 | public PartTreeGremlinQuery(@NonNull GremlinQueryMethod method, @NonNull GremlinOperations operations) { 23 | super(method, operations); 24 | 25 | this.processor = method.getResultProcessor(); 26 | this.partTree = new PartTree(method.getName(), processor.getReturnedType().getDomainType()); 27 | this.mappingContext = operations.getMappingConverter().getMappingContext(); 28 | } 29 | 30 | @Override 31 | protected GremlinQuery createQuery(@NonNull GremlinParameterAccessor accessor) { 32 | final GremlinQueryCreator creator = new GremlinQueryCreator(this.partTree, accessor, this.mappingContext); 33 | 34 | if (this.partTree.isLimiting()) { 35 | throw new UnsupportedOperationException("Limitation is not supported yet"); 36 | } 37 | 38 | return creator.createQuery(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/query/query/QueryScriptGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.query; 7 | 8 | import java.util.List; 9 | 10 | public interface QueryScriptGenerator { 11 | 12 | List generate(GremlinQuery query); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/repository/GremlinRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinEntityType; 9 | import org.springframework.data.repository.CrudRepository; 10 | import org.springframework.data.repository.NoRepositoryBean; 11 | 12 | import java.io.Serializable; 13 | 14 | @NoRepositoryBean 15 | public interface GremlinRepository extends CrudRepository { 16 | 17 | Iterable findAll(Class domainClass); 18 | 19 | void deleteAll(GremlinEntityType type); 20 | 21 | void deleteAll(Class domainClass); 22 | 23 | long vertexCount(); 24 | 25 | long edgeCount(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/repository/config/EnableGremlinRepositories.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository.config; 7 | 8 | import com.microsoft.spring.data.gremlin.repository.support.GremlinRepositoryFactoryBean; 9 | import org.springframework.context.annotation.ComponentScan.Filter; 10 | import org.springframework.context.annotation.Import; 11 | import org.springframework.data.repository.config.DefaultRepositoryBaseClass; 12 | 13 | import java.lang.annotation.*; 14 | 15 | import static com.microsoft.spring.data.gremlin.common.Constants.DEFAULT_REPOSITORY_IMPLEMENT_POSTFIX; 16 | 17 | @Target(ElementType.TYPE) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Documented 20 | @Inherited 21 | @Import(GremlinRepositoryRegistrar.class) 22 | public @interface EnableGremlinRepositories { 23 | 24 | /** 25 | * Alias for basePackages. 26 | */ 27 | String[] value() default {}; 28 | 29 | /** 30 | * Base packages to scan for components with annotations. 31 | */ 32 | String[] basePackages() default {}; 33 | 34 | /** 35 | * Type-safe version of basePackages. 36 | */ 37 | Class[] basePackageClasses() default {}; 38 | 39 | /** 40 | * Specifies types for component scan. 41 | */ 42 | Filter[] includeFilters() default {}; 43 | 44 | /** 45 | * Specifies types for skipping component scan. 46 | */ 47 | Filter[] excludeFilters() default {}; 48 | 49 | /** 50 | * Specifics the postfix to be used for custom repository implementation class name. 51 | */ 52 | String repositoryImplementationPostfix() default DEFAULT_REPOSITORY_IMPLEMENT_POSTFIX; 53 | 54 | /** 55 | * Configures the repository base class to be used to create repository. 56 | */ 57 | Class repositoryBaseClass() default DefaultRepositoryBaseClass.class; 58 | 59 | /** 60 | * Configures whether nested repository interface. 61 | */ 62 | boolean considerNestedRepositories() default false; 63 | 64 | /** 65 | * Configure the class of repository factory bean. 66 | */ 67 | Class repositoryFactoryBeanClass() default GremlinRepositoryFactoryBean.class; 68 | 69 | /** 70 | * Specific the namedQuery location. 71 | */ 72 | String namedQueriesLocation() default ""; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryConfigurationExtension.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository.config; 7 | 8 | import com.microsoft.spring.data.gremlin.common.Constants; 9 | import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; 10 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 11 | import org.apache.commons.lang3.NotImplementedException; 12 | import org.springframework.beans.factory.support.AbstractBeanDefinition; 13 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; 14 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 15 | import org.springframework.beans.factory.support.RootBeanDefinition; 16 | import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport; 17 | import org.springframework.data.repository.config.RepositoryConfigurationSource; 18 | 19 | import java.lang.annotation.Annotation; 20 | import java.util.Collection; 21 | import java.util.Collections; 22 | 23 | public class GremlinRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport { 24 | 25 | @Override 26 | public String getModuleName() { 27 | return Constants.GREMLIN_MODULE_NAME; 28 | } 29 | 30 | @Override 31 | public String getModulePrefix() { 32 | return Constants.GREMLIN_MODULE_PREFIX; 33 | } 34 | 35 | @Override 36 | public String getRepositoryFactoryBeanClassName() { 37 | throw new NotImplementedException("Gremlin RepositoryFactoryBean is not implemented"); 38 | } 39 | 40 | @Override 41 | public Collection> getIdentifyingTypes() { 42 | return Collections.singleton(GremlinRepository.class); 43 | } 44 | 45 | @Override 46 | public Collection> getIdentifyingAnnotations() { 47 | return Collections.emptyList(); 48 | } 49 | 50 | @Override 51 | public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource config) { 52 | super.registerBeansForRoot(registry, config); 53 | 54 | if (!registry.containsBeanDefinition(Constants.GREMLIN_MAPPING_CONTEXT)) { 55 | final RootBeanDefinition definition = new RootBeanDefinition(GremlinMappingContext.class); 56 | 57 | definition.setRole(AbstractBeanDefinition.ROLE_INFRASTRUCTURE); 58 | definition.setSource(config.getSource()); 59 | 60 | registry.registerBeanDefinition(Constants.GREMLIN_MAPPING_CONTEXT, definition); 61 | } 62 | } 63 | 64 | @Override 65 | public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSource source) { 66 | super.postProcess(builder, source); 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryRegistrar.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository.config; 7 | 8 | import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport; 9 | import org.springframework.data.repository.config.RepositoryConfigurationExtension; 10 | 11 | import java.lang.annotation.Annotation; 12 | 13 | public class GremlinRepositoryRegistrar extends RepositoryBeanDefinitionRegistrarSupport { 14 | 15 | @Override 16 | protected Class getAnnotation() { 17 | return EnableGremlinRepositories.class; 18 | } 19 | 20 | @Override 21 | protected RepositoryConfigurationExtension getExtension() { 22 | return new GremlinRepositoryConfigurationExtension(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryBean.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository.support; 7 | 8 | import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; 9 | import com.microsoft.spring.data.gremlin.query.GremlinOperations; 10 | import org.springframework.beans.BeansException; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.context.ApplicationContext; 13 | import org.springframework.context.ApplicationContextAware; 14 | import org.springframework.data.mapping.context.MappingContext; 15 | import org.springframework.data.repository.Repository; 16 | import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; 17 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 18 | 19 | import java.io.Serializable; 20 | 21 | public class GremlinRepositoryFactoryBean, S, ID extends Serializable> 22 | extends RepositoryFactoryBeanSupport implements ApplicationContextAware { 23 | 24 | private ApplicationContext context; 25 | private GremlinOperations operations; 26 | private boolean mappingContextConfigured = false; 27 | 28 | public GremlinRepositoryFactoryBean(Class repositoryInterface) { 29 | super(repositoryInterface); 30 | } 31 | 32 | @Autowired 33 | public void setGremlinOperations(GremlinOperations operations) { 34 | this.operations = operations; 35 | } 36 | 37 | protected RepositoryFactorySupport getFactoryInstance(ApplicationContext context) { 38 | return new GremlinRepositoryFactory(this.operations, context); 39 | } 40 | 41 | @Override 42 | protected final RepositoryFactorySupport createRepositoryFactory() { 43 | return this.getFactoryInstance(this.context); 44 | } 45 | 46 | @Override 47 | public void setApplicationContext(ApplicationContext context) throws BeansException { 48 | this.context = context; 49 | } 50 | 51 | @Override 52 | protected void setMappingContext(MappingContext mappingContext) { 53 | super.setMappingContext(mappingContext); 54 | 55 | this.mappingContextConfigured = true; 56 | } 57 | 58 | @Override 59 | public void afterPropertiesSet() { 60 | super.afterPropertiesSet(); 61 | 62 | if (!this.mappingContextConfigured) { 63 | if (this.operations == null) { 64 | this.setMappingContext(new GremlinMappingContext()); 65 | } else { 66 | this.setMappingContext(this.operations.getMappingConverter().getMappingContext()); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/telemetry/PropertyLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.telemetry; 7 | 8 | import lombok.AccessLevel; 9 | import lombok.NoArgsConstructor; 10 | import org.springframework.lang.NonNull; 11 | 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.util.Properties; 15 | 16 | @NoArgsConstructor(access = AccessLevel.PRIVATE) 17 | public class PropertyLoader { 18 | 19 | private static final String PROJECT_PROPERTY_FILE = "/META-INF/project.properties"; 20 | 21 | private static final String TELEMETRY_CONFIG_FILE = "/telemetry.config"; 22 | 23 | public static String getProjectVersion() { 24 | return getPropertyByName("project.version", PROJECT_PROPERTY_FILE); 25 | } 26 | 27 | public static String getTelemetryInstrumentationKey() { 28 | return getPropertyByName("telemetry.instrumentationKey", TELEMETRY_CONFIG_FILE); 29 | } 30 | 31 | private static String getPropertyByName(@NonNull String name, @NonNull String filename) { 32 | final Properties properties = new Properties(); 33 | final InputStream inputStream = PropertyLoader.class.getResourceAsStream(filename); 34 | 35 | if (inputStream == null) { 36 | return null; 37 | } 38 | 39 | try { 40 | properties.load(inputStream); 41 | } catch (IOException e) { 42 | // Omitted 43 | } finally { 44 | try { 45 | inputStream.close(); 46 | } catch (IOException e) { 47 | // Omitted 48 | } 49 | } 50 | 51 | return properties.getProperty(name); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/telemetry/TelemetryEventData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.telemetry; 7 | 8 | import com.fasterxml.jackson.annotation.JsonProperty; 9 | import lombok.AccessLevel; 10 | import lombok.Getter; 11 | import lombok.NonNull; 12 | import lombok.Setter; 13 | import org.springframework.util.Assert; 14 | 15 | import java.time.Instant; 16 | import java.util.Map; 17 | 18 | @Getter 19 | public class TelemetryEventData { 20 | 21 | private final String name; 22 | 23 | @JsonProperty("iKey") 24 | private final String instrumentationKey; 25 | 26 | private final Tags tags = new Tags("Spring-on-azure", "Java-maven-plugin"); 27 | 28 | private final EventData data = new EventData("EventData"); 29 | 30 | private final String time; 31 | 32 | public TelemetryEventData(String eventName, @NonNull Map properties) { 33 | Assert.hasText(eventName, "Event name should contain text."); 34 | 35 | name = "Microsoft.ApplicationInsights.Event"; 36 | instrumentationKey = PropertyLoader.getTelemetryInstrumentationKey(); 37 | 38 | data.getBaseData().setName(eventName); 39 | data.getBaseData().setProperties(properties); 40 | time = Instant.now().toString(); 41 | } 42 | 43 | @Getter 44 | private static class Tags { 45 | 46 | @JsonProperty("ai.cloud.roleInstance") 47 | private final String aiCloudRoleInstance; 48 | 49 | @JsonProperty("ai.internal.sdkVersion") 50 | private final String aiInternalSdkVersion; 51 | 52 | public Tags(String instance, String sdkVersion) { 53 | aiCloudRoleInstance = instance; 54 | aiInternalSdkVersion = sdkVersion; 55 | } 56 | } 57 | 58 | @Getter 59 | private static class EventData { 60 | 61 | private final String baseType; 62 | 63 | private final CustomData baseData = new CustomData(); 64 | 65 | public EventData(String baseType) { 66 | this.baseType = baseType; 67 | } 68 | 69 | @Getter 70 | @Setter(AccessLevel.PRIVATE) 71 | private static class CustomData { 72 | 73 | private final Integer ver = 2; 74 | 75 | private String name; 76 | 77 | private Map properties; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/spring/data/gremlin/telemetry/TelemetrySender.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.telemetry; 7 | 8 | import com.fasterxml.jackson.databind.ObjectMapper; 9 | import lombok.NonNull; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.http.*; 12 | import org.springframework.util.Assert; 13 | import org.springframework.web.client.RestTemplate; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON; 19 | 20 | @Slf4j 21 | public class TelemetrySender { 22 | 23 | private static final String PROPERTY_INSTALLATION_ID = "installationId"; 24 | 25 | private static final String PROPERTY_VERSION = "version"; 26 | 27 | private static final String PROPERTY_SERVICE_NAME = "serviceName"; 28 | 29 | private static final String PROJECT_INFO = "spring-data-gremlin/" + PropertyLoader.getProjectVersion(); 30 | 31 | private static final String TELEMETRY_TARGET_URL = "https://dc.services.visualstudio.com/v2/track"; 32 | 33 | private static final ObjectMapper MAPPER = new ObjectMapper(); 34 | 35 | private static final int RETRY_LIMIT = 3; // Align the retry times with sdk 36 | 37 | private static final RestTemplate REST_TEMPLATE = new RestTemplate(); 38 | 39 | private static final HttpHeaders HEADERS = new HttpHeaders(); 40 | 41 | static { 42 | HEADERS.add(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON.toString()); 43 | } 44 | 45 | private ResponseEntity executeRequest(final TelemetryEventData eventData) { 46 | 47 | try { 48 | final HttpEntity body = new HttpEntity<>(MAPPER.writeValueAsString(eventData), HEADERS); 49 | 50 | return REST_TEMPLATE.exchange(TELEMETRY_TARGET_URL, HttpMethod.POST, body, String.class); 51 | } catch (Exception ignore) { 52 | log.trace("Failed to exchange telemetry request, {}.", ignore.getMessage()); 53 | } 54 | 55 | return null; 56 | } 57 | 58 | private void sendTelemetryData(@NonNull TelemetryEventData eventData) { 59 | ResponseEntity response = null; 60 | 61 | for (int i = 0; i < RETRY_LIMIT; i++) { 62 | response = executeRequest(eventData); 63 | 64 | if (response != null && response.getStatusCode() == HttpStatus.OK) { 65 | return; 66 | } 67 | } 68 | 69 | if (response != null && response.getStatusCode() != HttpStatus.OK) { 70 | log.trace("Failed to send telemetry data, response status code {}.", response.getStatusCode().toString()); 71 | } 72 | } 73 | 74 | public void send(String name) { 75 | Assert.hasText(name, "Event name should contain text."); 76 | 77 | sendTelemetryData(new TelemetryEventData(name, getProperties())); 78 | } 79 | 80 | private Map getProperties() { 81 | final Map properties = new HashMap<>(); 82 | 83 | properties.put(PROPERTY_VERSION, PROJECT_INFO); 84 | properties.put(PROPERTY_SERVICE_NAME, "gremlin"); 85 | properties.put(PROPERTY_INSTALLATION_ID, MacAddress.getHashMac()); 86 | 87 | return properties; 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/project.properties: -------------------------------------------------------------------------------- 1 | project.version=@project.version@ 2 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.data.repository.core.support.RepositoryFactorySupport=com.microsoft.spring.data.gremlin.repository.support.GremlinRepositoryFactory 2 | 3 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | gremlin.endpoint=endpoint.gremlin.cosmosdb.azure.com 2 | gremlin.port=443 3 | gremlin.username=/dbs/database/colls/collection 4 | gremlin.password=password 5 | -------------------------------------------------------------------------------- /src/main/resources/telemetry.config: -------------------------------------------------------------------------------- 1 | telemetry.instrumentationKey=@telemetry.instrumentationKey@ -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationEdgeUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinUtils; 9 | import com.microsoft.spring.data.gremlin.common.TestConstants; 10 | import com.microsoft.spring.data.gremlin.common.domain.Dependency; 11 | import com.microsoft.spring.data.gremlin.common.domain.Relationship; 12 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 13 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; 14 | import org.junit.Assert; 15 | import org.junit.Test; 16 | 17 | public class AnnotationEdgeUnitTest { 18 | 19 | @Test 20 | public void testAnnotationEdgeDefaultLabel() { 21 | final GremlinSource source = GremlinUtils.toGremlinSource(Dependency.class); 22 | 23 | Assert.assertTrue(source instanceof GremlinSourceEdge); 24 | Assert.assertNotNull(source.getLabel()); 25 | Assert.assertEquals(source.getLabel(), Dependency.class.getSimpleName()); 26 | } 27 | 28 | @Test 29 | public void testAnnotationEdgeSpecifiedLabel() { 30 | final GremlinSource source = GremlinUtils.toGremlinSource(Relationship.class); 31 | 32 | Assert.assertTrue(source instanceof GremlinSourceEdge); 33 | Assert.assertNotNull(source.getLabel()); 34 | Assert.assertEquals(source.getLabel(), TestConstants.EDGE_RELATIONSHIP_LABEL); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationGraphUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinUtils; 9 | import com.microsoft.spring.data.gremlin.common.domain.Network; 10 | import com.microsoft.spring.data.gremlin.common.domain.Roadmap; 11 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 12 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; 13 | import org.junit.Assert; 14 | import org.junit.Test; 15 | 16 | public class AnnotationGraphUnitTest { 17 | 18 | @Test 19 | public void testAnnotationGraphDefaultCollection() { 20 | final GremlinSource source = GremlinUtils.toGremlinSource(Network.class); 21 | 22 | Assert.assertTrue(source instanceof GremlinSourceGraph); 23 | Assert.assertTrue(source.getLabel().isEmpty()); 24 | } 25 | 26 | @Test 27 | public void testAnnotationGraphSpecifiedCollection() { 28 | final GremlinSource source = GremlinUtils.toGremlinSource(Roadmap.class); 29 | 30 | Assert.assertTrue(source instanceof GremlinSourceGraph); 31 | Assert.assertTrue(source.getLabel().isEmpty()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationVertexUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.annotation; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinUtils; 9 | import com.microsoft.spring.data.gremlin.common.TestConstants; 10 | import com.microsoft.spring.data.gremlin.common.domain.Library; 11 | import com.microsoft.spring.data.gremlin.common.domain.Person; 12 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; 13 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; 14 | import org.junit.Assert; 15 | import org.junit.Test; 16 | 17 | public class AnnotationVertexUnitTest { 18 | 19 | @Test 20 | public void testAnnotationVertexDefaultLabel() { 21 | final GremlinSource source = GremlinUtils.toGremlinSource(Library.class); 22 | 23 | Assert.assertTrue(source instanceof GremlinSourceVertex); 24 | Assert.assertNotNull(source.getLabel()); 25 | Assert.assertEquals(source.getLabel(), Library.class.getSimpleName()); 26 | } 27 | 28 | @Test 29 | public void testAnnotationVertexSpecifiedLabel() { 30 | final GremlinSource source = GremlinUtils.toGremlinSource(Person.class); 31 | 32 | Assert.assertTrue(source instanceof GremlinSourceVertex); 33 | Assert.assertNotNull(source.getLabel()); 34 | Assert.assertEquals(source.getLabel(), TestConstants.VERTEX_PERSON_LABEL); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/GremlinFactoryUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import com.microsoft.spring.data.gremlin.exception.GremlinIllegalConfigurationException; 9 | import lombok.NoArgsConstructor; 10 | import org.apache.tinkerpop.gremlin.driver.Client; 11 | import org.junit.Assert; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import static com.microsoft.spring.data.gremlin.common.TestConstants.EMPTY_STRING; 21 | import static com.microsoft.spring.data.gremlin.common.TestConstants.ILLEGAL_ENDPOINT_PORT; 22 | 23 | @ContextConfiguration(classes = {GremlinFactoryUnitTest.TestConfiguration.class}) 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | public class GremlinFactoryUnitTest { 26 | 27 | @Autowired 28 | private GremlinFactory factory; 29 | 30 | @Test(expected = GremlinIllegalConfigurationException.class) 31 | public void testGremlinFactoryException() { 32 | final GremlinConfig config = GremlinConfig.builder(TestConstants.FAKE_ENDPOINT, TestConstants.FAKE_USERNAME, 33 | TestConstants.FAKE_PASSWORD).build(); 34 | 35 | new GremlinFactory(config).getGremlinClient(); 36 | } 37 | 38 | @Test 39 | public void testGremlinFactoryNormal() { 40 | final Client client = factory.getGremlinClient(); 41 | 42 | Assert.assertEquals(client.getCluster().getPort(), TestConstants.DEFAULT_ENDPOINT_PORT); 43 | Assert.assertFalse(client.getSettings().getSession().isPresent()); 44 | } 45 | 46 | @Configuration 47 | @NoArgsConstructor 48 | static class TestConfiguration { 49 | 50 | @Bean 51 | public GremlinFactory getGremlinFactory() { 52 | return new GremlinFactory(getGremlinConfig()); 53 | } 54 | 55 | @Bean 56 | public GremlinConfig getGremlinConfig() { 57 | return GremlinConfig.builder(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING) 58 | .port(ILLEGAL_ENDPOINT_PORT) 59 | .build(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/GremlinUtilsUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Service; 9 | import com.microsoft.spring.data.gremlin.conversion.source.AbstractGremlinSource; 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | public class GremlinUtilsUnitTest { 14 | 15 | @Test(expected = IllegalArgumentException.class) 16 | public void testCreateIntegerInstance() { 17 | GremlinUtils.createInstance(Integer.class); 18 | } 19 | 20 | @Test(expected = IllegalArgumentException.class) 21 | public void testCreateTestConstantsInstance() { 22 | GremlinUtils.createInstance(TestConstants.class); 23 | } 24 | 25 | @Test(expected = IllegalArgumentException.class) 26 | public void testCreateAbstractInstance() { 27 | GremlinUtils.createInstance(AbstractGremlinSource.class); 28 | } 29 | 30 | @Test(expected = UnsupportedOperationException.class) 31 | public void testTimeToMilliSecondsException() { 32 | GremlinUtils.timeToMilliSeconds(new Service()); 33 | } 34 | 35 | @Test(expected = UnsupportedOperationException.class) 36 | public void testToPrimitiveLongException() { 37 | GremlinUtils.toPrimitiveLong((short) 2); 38 | } 39 | 40 | @Test 41 | public void testToPrimitiveLong() { 42 | Assert.assertEquals((long) 3, GremlinUtils.toPrimitiveLong(new Long(3))); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/MacAddressUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import com.microsoft.spring.data.gremlin.telemetry.MacAddress; 9 | import org.junit.Assert; 10 | import org.junit.Test; 11 | 12 | public class MacAddressUnitTest { 13 | 14 | @Test 15 | public void testGetHashMacNormal() { 16 | Assert.assertNotNull(MacAddress.getHashMac()); 17 | Assert.assertFalse(MacAddress.getHashMac().isEmpty()); 18 | Assert.assertFalse(MacAddress.isValidHashMacFormat("")); 19 | Assert.assertTrue(MacAddress.isValidHashMacFormat(MacAddress.getHashMac())); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/TestConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import lombok.AccessLevel; 9 | import lombok.NoArgsConstructor; 10 | 11 | @NoArgsConstructor(access = AccessLevel.PRIVATE) 12 | public class TestConstants { 13 | 14 | public static final int DEFAULT_ENDPOINT_PORT = 443; 15 | public static final int ILLEGAL_ENDPOINT_PORT = -1; 16 | public static final String FAKE_ENDPOINT = "XXX-xxx.XXX-xxx.cosmosdb.azure.com"; 17 | public static final String FAKE_USERNAME = "XXX-xxx.username"; 18 | public static final String FAKE_PASSWORD = "XXX-xxx.password"; 19 | public static final String EMPTY_STRING = ""; 20 | 21 | public static final String PROPERTY_ID = "id"; 22 | public static final String PROPERTY_NAME = "name"; 23 | public static final String PROPERTY_LOCATION = "location"; 24 | 25 | public static final String VERTEX_PERSON_LABEL = "label-person"; 26 | public static final String VERTEX_PROJECT_LABEL = "label-project"; 27 | public static final String EDGE_RELATIONSHIP_LABEL = "label-relationship"; 28 | public static final String GRAPH_ROADMAP_COLLECTION_NAME = "roadmap-collection"; 29 | 30 | public static final String VERTEX_PERSON_ID = "233333"; 31 | public static final String VERTEX_PERSON_NAME = "incarnation-p-lee"; 32 | 33 | public static final String VERTEX_PERSON_0_ID = "000000"; 34 | public static final String VERTEX_PERSON_0_NAME = "silencer"; 35 | 36 | public static final String VERTEX_PERSON_1_ID = "111111"; 37 | public static final String VERTEX_PERSON_1_NAME = "templar-assassin"; 38 | 39 | public static final String VERTEX_PROJECT_ID = "666666"; 40 | public static final String VERTEX_PROJECT_NAME = "spring-data-gremlin"; 41 | public static final String VERTEX_PROJECT_URI = "https://github.com/Incarnation-p-lee/spring-data-gremlin.git"; 42 | 43 | public static final String VERTEX_PROJECT_0_ID = "222222"; 44 | public static final String VERTEX_PROJECT_0_NAME = "spring-data-documentdb"; 45 | public static final String VERTEX_PROJECT_0_URI = "https://github.com/Microsoft/spring-data-documentdb"; 46 | 47 | public static final String EDGE_RELATIONSHIP_ID = "999999"; 48 | public static final String EDGE_RELATIONSHIP_NAME = "created"; 49 | public static final String EDGE_RELATIONSHIP_LOCATION = "shanghai"; 50 | 51 | public static final String EDGE_RELATIONSHIP_0_ID = "333333"; 52 | public static final String EDGE_RELATIONSHIP_0_NAME = "contributed"; 53 | public static final String EDGE_RELATIONSHIP_0_LOCATION = "war3"; 54 | 55 | public static final String EDGE_RELATIONSHIP_1_ID = "444444"; 56 | public static final String EDGE_RELATIONSHIP_1_NAME = "contributed"; 57 | public static final String EDGE_RELATIONSHIP_1_LOCATION = "dota"; 58 | 59 | public static final String EDGE_RELATIONSHIP_2_ID = "555555"; 60 | public static final String EDGE_RELATIONSHIP_2_NAME = "create"; 61 | public static final String EDGE_RELATIONSHIP_2_LOCATION = "shanghai"; 62 | 63 | public static final String VERTEX_LABEL = "label-vertex"; 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/TestGremlinProperties.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | import org.apache.tinkerpop.gremlin.driver.ser.SerTokens; 13 | import org.apache.tinkerpop.gremlin.driver.ser.Serializers; 14 | import org.springframework.boot.context.properties.ConfigurationProperties; 15 | 16 | @Getter 17 | @Setter 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | @ConfigurationProperties("gremlin") 21 | public class TestGremlinProperties { 22 | private String endpoint; 23 | 24 | private int port; 25 | 26 | private String username; 27 | 28 | private String password; 29 | 30 | private boolean sslEnabled = true; 31 | 32 | private boolean telemetryAllowed = true; 33 | 34 | private String serializer = Serializers.GRAPHSON.toString(); 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/TestRepositoryConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import com.microsoft.spring.data.gremlin.config.AbstractGremlinConfiguration; 9 | import com.microsoft.spring.data.gremlin.repository.config.EnableGremlinRepositories; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 12 | import org.springframework.context.annotation.PropertySource; 13 | 14 | @EnableGremlinRepositories 15 | @PropertySource(value = {"classpath:application.properties"}) 16 | @EnableConfigurationProperties(TestGremlinProperties.class) 17 | public class TestRepositoryConfiguration extends AbstractGremlinConfiguration { 18 | 19 | @Autowired 20 | private TestGremlinProperties testProps; 21 | 22 | @Override 23 | public GremlinConfig getGremlinConfig() { 24 | return GremlinConfig.builder(testProps.getEndpoint(), testProps.getUsername(), testProps.getPassword()) 25 | .port(testProps.getPort()) 26 | .telemetryAllowed(testProps.isTelemetryAllowed()) 27 | .sslEnabled(testProps.isSslEnabled()) 28 | .serializer(testProps.getSerializer()) 29 | .build(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/TestUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common; 7 | 8 | import lombok.AccessLevel; 9 | import lombok.NoArgsConstructor; 10 | import org.junit.Assert; 11 | 12 | import java.util.Comparator; 13 | import java.util.List; 14 | 15 | @NoArgsConstructor(access = AccessLevel.PRIVATE) 16 | public class TestUtils { 17 | 18 | public static void assertEntitiesEquals(List expect, List actual) { 19 | Assert.assertEquals(actual.size(), expect.size()); 20 | 21 | actual.sort(Comparator.comparing(T::toString)); 22 | expect.sort(Comparator.comparing(T::toString)); 23 | 24 | Assert.assertEquals(actual, expect); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/AdvancedUser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | @Vertex 14 | @Getter 15 | @Setter 16 | @NoArgsConstructor 17 | public class AdvancedUser extends User { 18 | 19 | private int level; 20 | 21 | public AdvancedUser(String id, String name, int level) { 22 | super(id, name); 23 | 24 | this.level = level; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Data; 11 | import lombok.NoArgsConstructor; 12 | import org.springframework.data.annotation.Id; 13 | 14 | @Data 15 | @Vertex 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class Book { 19 | 20 | @Id 21 | private Integer serialNumber; 22 | 23 | private String name; 24 | 25 | private Double price; 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/BookReference.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Edge; 9 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 10 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 11 | import lombok.AllArgsConstructor; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | 15 | @Edge 16 | @Data 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | public class BookReference { 20 | 21 | private Integer id; 22 | 23 | @EdgeFrom 24 | private Integer fromSerialNumber; 25 | 26 | @EdgeTo 27 | private Integer toSerialNumber; 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Dependency.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Edge; 9 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 10 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 11 | import lombok.AllArgsConstructor; 12 | import lombok.Data; 13 | 14 | @Edge 15 | @Data 16 | @AllArgsConstructor 17 | public class Dependency { 18 | 19 | private String id; 20 | 21 | private String type; 22 | 23 | @EdgeFrom 24 | private Library source; 25 | 26 | @EdgeTo 27 | private Library target; 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Group.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Edge; 9 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 10 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 11 | import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | import org.springframework.data.annotation.Id; 15 | 16 | @Edge 17 | @Data 18 | @NoArgsConstructor 19 | public class Group { 20 | 21 | @Id 22 | @GeneratedValue 23 | private Long id; 24 | 25 | @EdgeFrom 26 | private Student student; 27 | 28 | @EdgeTo 29 | private GroupOwner groupOwner; 30 | 31 | public Group(Student student, GroupOwner groupOwner) { 32 | this.student = student; 33 | this.groupOwner = groupOwner; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/GroupOwner.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Data; 11 | import lombok.NoArgsConstructor; 12 | import org.springframework.data.annotation.Id; 13 | 14 | @Vertex 15 | @Data 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class GroupOwner { 19 | 20 | @Id 21 | private String name; 22 | 23 | private Integer expireDays; 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/InvalidDependency.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Edge; 9 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 10 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 11 | import lombok.AllArgsConstructor; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | 15 | @Data 16 | @Edge 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class InvalidDependency { 20 | 21 | private String id; 22 | 23 | @EdgeFrom 24 | private String name; 25 | 26 | @EdgeFrom 27 | private String fromId; 28 | 29 | @EdgeTo 30 | private String toId; 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Library.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Data; 11 | 12 | @Vertex 13 | @Data 14 | @AllArgsConstructor 15 | public class Library { 16 | 17 | private String id; 18 | 19 | private String name; 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Master.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import com.microsoft.spring.data.gremlin.common.TestConstants; 10 | import lombok.AllArgsConstructor; 11 | import lombok.Data; 12 | import lombok.NoArgsConstructor; 13 | 14 | @Data 15 | @Vertex(label = TestConstants.VERTEX_LABEL) 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class Master { 19 | 20 | private Long id; 21 | 22 | private String name; 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Neighbor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Edge; 9 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 10 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 11 | import lombok.AllArgsConstructor; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | 15 | @Edge 16 | @Data 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class Neighbor { 20 | 21 | private Long id; 22 | 23 | private Long distance; 24 | 25 | @EdgeFrom 26 | private Student studentFrom; 27 | 28 | @EdgeTo 29 | private Student studentTo; 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Network.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.EdgeSet; 9 | import com.microsoft.spring.data.gremlin.annotation.Graph; 10 | import com.microsoft.spring.data.gremlin.annotation.VertexSet; 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | @Graph 18 | public class Network { 19 | 20 | @Getter 21 | @Setter 22 | private String id; 23 | 24 | @Getter 25 | @VertexSet 26 | private List vertexList; 27 | 28 | @Getter 29 | @EdgeSet 30 | private List edgeList; 31 | 32 | public Network() { 33 | this.vertexList = new ArrayList<>(); 34 | this.edgeList = new ArrayList<>(); 35 | } 36 | 37 | public void vertexAdd(Object object) { 38 | this.vertexList.add(object); 39 | } 40 | 41 | public void edgeAdd(Object object) { 42 | this.edgeList.add(object); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Orange.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; 9 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 10 | import lombok.Data; 11 | import lombok.NoArgsConstructor; 12 | import org.springframework.data.annotation.Id; 13 | 14 | @Vertex 15 | @Data 16 | @NoArgsConstructor 17 | public class Orange { 18 | 19 | @Id 20 | @GeneratedValue 21 | private String id; 22 | 23 | private String location; 24 | 25 | private Double price; 26 | 27 | public Orange(String location, Double price) { 28 | this.location = location; 29 | this.price = price; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Person.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import com.microsoft.spring.data.gremlin.common.TestConstants; 10 | import lombok.AllArgsConstructor; 11 | import lombok.Data; 12 | import lombok.NoArgsConstructor; 13 | 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Vertex(label = TestConstants.VERTEX_PERSON_LABEL) 18 | public class Person { 19 | 20 | private String id; 21 | 22 | private String name; 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Project.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import com.microsoft.spring.data.gremlin.common.TestConstants; 10 | import lombok.AllArgsConstructor; 11 | import lombok.Data; 12 | import lombok.NoArgsConstructor; 13 | 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Vertex(label = TestConstants.VERTEX_PROJECT_LABEL) 18 | public class Project { 19 | 20 | private String id; 21 | 22 | private String name; 23 | 24 | private String uri; 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Relationship.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Edge; 9 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 10 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 11 | import com.microsoft.spring.data.gremlin.common.TestConstants; 12 | import lombok.AllArgsConstructor; 13 | import lombok.Data; 14 | import lombok.NoArgsConstructor; 15 | 16 | @Data 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | @Edge(label = TestConstants.EDGE_RELATIONSHIP_LABEL) 20 | public class Relationship { 21 | 22 | private String id; 23 | 24 | private String name; 25 | 26 | private String location; 27 | 28 | @EdgeFrom 29 | private Person person; 30 | 31 | @EdgeTo 32 | private Project project; 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Roadmap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.EdgeSet; 9 | import com.microsoft.spring.data.gremlin.annotation.Graph; 10 | import com.microsoft.spring.data.gremlin.annotation.VertexSet; 11 | import com.microsoft.spring.data.gremlin.common.TestConstants; 12 | import lombok.Getter; 13 | import lombok.Setter; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | @Graph(collection = TestConstants.GRAPH_ROADMAP_COLLECTION_NAME) 19 | public class Roadmap { 20 | 21 | @Getter 22 | @Setter 23 | private String id; 24 | 25 | @VertexSet 26 | private List vertexList; 27 | 28 | @EdgeSet 29 | private List edgeList; 30 | 31 | public Roadmap() { 32 | this.vertexList = new ArrayList<>(); 33 | this.edgeList = new ArrayList<>(); 34 | } 35 | 36 | public void vertexAdd(Object object) { 37 | this.vertexList.add(object); 38 | } 39 | 40 | public void edgeAdd(Object object) { 41 | this.edgeList.add(object); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Service.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Data; 11 | import lombok.NoArgsConstructor; 12 | import org.springframework.data.annotation.Id; 13 | 14 | import java.util.Date; 15 | import java.util.Map; 16 | 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | @Data 20 | @Vertex 21 | public class Service { 22 | 23 | @Id 24 | private String id; 25 | 26 | private int instanceCount; 27 | 28 | private boolean active; 29 | 30 | private String name; 31 | 32 | private ServiceType type; 33 | 34 | private Date createAt; 35 | 36 | private Map properties; 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/ServiceType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | public enum ServiceType { 9 | FRONT_END, 10 | BACK_END, 11 | BOTH 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/SimpleDependency.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Edge; 9 | import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; 10 | import com.microsoft.spring.data.gremlin.annotation.EdgeTo; 11 | import lombok.AllArgsConstructor; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | 15 | @Data 16 | @Edge 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class SimpleDependency { 20 | 21 | private String id; 22 | 23 | private String name; 24 | 25 | @EdgeFrom 26 | private String fromId; 27 | 28 | @EdgeTo 29 | private String toId; 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/Student.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import com.microsoft.spring.data.gremlin.common.TestConstants; 10 | import lombok.AllArgsConstructor; 11 | import lombok.Data; 12 | import lombok.NoArgsConstructor; 13 | 14 | @Data 15 | @Vertex(label = TestConstants.VERTEX_LABEL) 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class Student { 19 | 20 | private Long id; 21 | 22 | private String name; 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | @Getter 14 | @Setter 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | public class User { 18 | 19 | private String id; 20 | 21 | private String name; 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/domain/UserDomain.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.domain; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Data; 11 | import lombok.NoArgsConstructor; 12 | import org.springframework.data.annotation.Id; 13 | 14 | @Vertex 15 | @Data 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class UserDomain { 19 | 20 | @Id 21 | private String name; 22 | 23 | private int level; 24 | 25 | private boolean enabled; 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/AdvancedUserRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.AdvancedUser; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | public interface AdvancedUserRepository extends GremlinRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/BookReferenceRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.BookReference; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | public interface BookReferenceRepository extends GremlinRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Book; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | import java.util.List; 12 | 13 | public interface BookRepository extends GremlinRepository { 14 | 15 | List findByNameOrPrice(String name, Double price); 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/GroupOwnerRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.GroupOwner; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | public interface GroupOwnerRepository extends GremlinRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/GroupRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Group; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | public interface GroupRepository extends GremlinRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/MasterRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Master; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | public interface MasterRepository extends GremlinRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/NeighborRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Neighbor; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | public interface NeighborRepository extends GremlinRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/NetworkRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Network; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | import org.springframework.stereotype.Repository; 11 | 12 | import java.util.List; 13 | 14 | @Repository 15 | public interface NetworkRepository extends GremlinRepository { 16 | 17 | List findByEdgeList(List edgeList); 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/OrangeRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Orange; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | public interface OrangeRepository extends GremlinRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Person; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | import org.springframework.stereotype.Repository; 11 | 12 | @Repository 13 | public interface PersonRepository extends GremlinRepository { 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/ProjectRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Project; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | import org.springframework.stereotype.Repository; 11 | 12 | @Repository 13 | public interface ProjectRepository extends GremlinRepository { 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/RelationshipRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Relationship; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | import org.springframework.stereotype.Repository; 11 | 12 | import java.util.List; 13 | 14 | @Repository 15 | public interface RelationshipRepository extends GremlinRepository { 16 | 17 | List findByLocation(String location); 18 | 19 | List findByNameAndLocation(String name, String location); 20 | 21 | List findByNameOrId(String name, String id); 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/ServiceRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Service; 9 | import com.microsoft.spring.data.gremlin.common.domain.ServiceType; 10 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 11 | import org.springframework.stereotype.Repository; 12 | 13 | import java.util.Date; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | @Repository 18 | public interface ServiceRepository extends GremlinRepository { 19 | 20 | List findByName(String name); 21 | 22 | List findByInstanceCount(int instanceCount); 23 | 24 | List findByActive(boolean isActive); 25 | 26 | List findByCreateAt(Date createAt); 27 | 28 | List findByProperties(Map properties); 29 | 30 | List findByNameAndInstanceCount(String name, int instanceCount); 31 | 32 | List findByNameOrInstanceCount(String name, int instanceCount); 33 | 34 | List findByNameAndInstanceCountAndType(String name, int instanceCount, ServiceType type); 35 | 36 | List findByNameAndActiveOrProperties(String name, boolean isActive, Map properties); 37 | 38 | List findByNameOrInstanceCountAndType(String name, int instanceCount, ServiceType type); 39 | 40 | List findByNameAndInstanceCountOrType(String name, int instanceCount, ServiceType type); 41 | 42 | List findByActiveExists(); 43 | 44 | List findByCreateAtAfter(Date expiryDate); 45 | 46 | List findByNameOrTypeAndInstanceCountAndCreateAtAfter(String name, ServiceType type, int instanceCount, 47 | Date expiryDate); 48 | 49 | List findByCreateAtBefore(Date expiryDate); 50 | 51 | List findByCreateAtAfterAndCreateAtBefore(Date startDate, Date endDate); 52 | 53 | List findByCreateAtBetween(Date start, Date end); 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/SimpleDependencyRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.SimpleDependency; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | public interface SimpleDependencyRepository extends GremlinRepository { 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/StudentRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Student; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | import java.util.List; 12 | 13 | public interface StudentRepository extends GremlinRepository { 14 | 15 | List findByName(String name); 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/common/repository/UserDomainRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.common.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.UserDomain; 9 | import com.microsoft.spring.data.gremlin.repository.GremlinRepository; 10 | 11 | import java.util.List; 12 | 13 | public interface UserDomainRepository extends GremlinRepository { 14 | 15 | List findByName(String name); 16 | 17 | List findByEnabledExists(); 18 | 19 | List findByLevelBetween(int low, int high); 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/config/AbstractGremlinConfigurationIT.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.config; 7 | 8 | import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; 9 | import lombok.SneakyThrows; 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.test.context.ContextConfiguration; 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 16 | 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | @ContextConfiguration(classes = TestRepositoryConfiguration.class) 19 | public class AbstractGremlinConfigurationIT { 20 | 21 | @Autowired 22 | private TestRepositoryConfiguration testConfig; 23 | 24 | @Test 25 | public void testGremlinFactory() { 26 | Assert.assertNotNull(this.testConfig.gremlinFactory()); 27 | } 28 | 29 | @Test 30 | @SneakyThrows 31 | public void testMappingGremlinConverter() { 32 | Assert.assertNotNull(this.testConfig.mappingGremlinConverter()); 33 | } 34 | 35 | @Test 36 | @SneakyThrows 37 | public void testGremlinTemplate() { 38 | Assert.assertNotNull(this.testConfig.gremlinTemplate(testConfig.gremlinFactory())); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/config/GremlinConfigurationSupportUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.config; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.*; 9 | import lombok.NoArgsConstructor; 10 | import lombok.SneakyThrows; 11 | import org.junit.Assert; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | 15 | import java.util.Arrays; 16 | import java.util.Collection; 17 | import java.util.HashSet; 18 | import java.util.Set; 19 | 20 | public class GremlinConfigurationSupportUnitTest { 21 | 22 | private static final String TEST_CONFIG_PACKAGE_NAME = "com.microsoft.spring.data.gremlin.config"; 23 | private static final String TEST_DOMAIN_PACKAGE_NAME = "com.microsoft.spring.data.gremlin.common.domain"; 24 | private TestConfig config; 25 | 26 | @Before 27 | public void setup() { 28 | this.config = new TestConfig(); 29 | } 30 | 31 | @Test 32 | public void testGetMappingBasePackages() { 33 | final Collection basePackages = this.config.getMappingBasePackages(); 34 | 35 | Assert.assertNotNull(basePackages); 36 | Assert.assertEquals(basePackages.size(), 1); 37 | Assert.assertEquals(basePackages.toArray()[0], TEST_CONFIG_PACKAGE_NAME); 38 | } 39 | 40 | @Test 41 | public void testGremlinMappingContext() throws ClassNotFoundException { 42 | Assert.assertNotNull(this.config.gremlinMappingContext()); 43 | } 44 | 45 | @Test 46 | @SneakyThrows 47 | public void testScanEntity() { 48 | final Set> entities = this.config.scanEntities(TEST_DOMAIN_PACKAGE_NAME); 49 | final Set> references = new HashSet<>(Arrays.asList( 50 | Dependency.class, Library.class, Network.class, Person.class, Project.class, 51 | Relationship.class, Roadmap.class, Service.class, SimpleDependency.class, InvalidDependency.class, 52 | UserDomain.class, AdvancedUser.class, Student.class, Book.class, BookReference.class, 53 | Neighbor.class, Master.class, Group.class, GroupOwner.class, Orange.class) 54 | ); 55 | 56 | Assert.assertNotNull(entities); 57 | Assert.assertEquals(entities.size(), references.size()); 58 | 59 | references.forEach(entity -> Assert.assertTrue(entities.contains(entity))); 60 | } 61 | 62 | @Test 63 | @SneakyThrows 64 | public void testScanEntityEmpty() { 65 | final Set> entities = this.config.scanEntities(""); 66 | 67 | Assert.assertTrue(entities.isEmpty()); 68 | } 69 | 70 | @NoArgsConstructor 71 | private class TestConfig extends GremlinConfigurationSupport { 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.result; 7 | 8 | import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralEdge; 9 | import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralGraph; 10 | import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralVertex; 11 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; 12 | import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; 13 | import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; 14 | import org.junit.Test; 15 | 16 | public class GremlinResultUnitTest { 17 | 18 | @Test(expected = GremlinUnexpectedSourceTypeException.class) 19 | public void testVertexInsertException() { 20 | new GremlinScriptLiteralVertex().generateInsertScript(new GremlinSourceEdge()); 21 | } 22 | 23 | @Test(expected = GremlinUnexpectedSourceTypeException.class) 24 | public void testVertexUpdateException() { 25 | new GremlinScriptLiteralVertex().generateUpdateScript(new GremlinSourceEdge()); 26 | } 27 | 28 | @Test(expected = GremlinUnexpectedSourceTypeException.class) 29 | public void testVertexFindByIdException() { 30 | new GremlinScriptLiteralVertex().generateFindByIdScript(new GremlinSourceEdge()); 31 | } 32 | 33 | @Test(expected = GremlinUnexpectedSourceTypeException.class) 34 | public void testEdgeInsertException() { 35 | new GremlinScriptLiteralEdge().generateInsertScript(new GremlinSourceVertex()); 36 | } 37 | 38 | @Test(expected = GremlinUnexpectedSourceTypeException.class) 39 | public void testEdgeUpdateException() { 40 | new GremlinScriptLiteralEdge().generateUpdateScript(new GremlinSourceVertex()); 41 | } 42 | 43 | @Test(expected = GremlinUnexpectedSourceTypeException.class) 44 | public void testEdgeFindByIdException() { 45 | new GremlinScriptLiteralEdge().generateFindByIdScript(new GremlinSourceVertex()); 46 | } 47 | 48 | @Test(expected = GremlinUnexpectedSourceTypeException.class) 49 | public void testGraphInsertException() { 50 | new GremlinScriptLiteralGraph().generateInsertScript(new GremlinSourceVertex()); 51 | } 52 | 53 | @Test(expected = GremlinUnexpectedSourceTypeException.class) 54 | public void testGraphUpdateException() { 55 | new GremlinScriptLiteralGraph().generateUpdateScript(new GremlinSourceVertex()); 56 | } 57 | 58 | @Test(expected = UnsupportedOperationException.class) 59 | public void testGraphFindByIdException() { 60 | new GremlinScriptLiteralGraph().generateFindByIdScript(new GremlinSourceVertex()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/conversion/script/AbstractGremlinScriptLiteralUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.conversion.script; 7 | 8 | import com.microsoft.spring.data.gremlin.common.GremlinEntityType; 9 | import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; 10 | import org.junit.Test; 11 | 12 | public class AbstractGremlinScriptLiteralUnitTest extends AbstractGremlinScriptLiteral { 13 | 14 | @Test(expected = GremlinInvalidEntityIdFieldException.class) 15 | public void testEntityInvalidIdType() { 16 | final Double id = 12.342; 17 | AbstractGremlinScriptLiteral.generateEntityWithRequiredId(id, GremlinEntityType.EDGE); 18 | } 19 | 20 | @Test(expected = GremlinInvalidEntityIdFieldException.class) 21 | public void testPropertyInvalidIdType() { 22 | final Double id = 12.342; 23 | AbstractGremlinScriptLiteral.generatePropertyWithRequiredId(id); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentEntityUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.mapping; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Edge; 9 | import com.microsoft.spring.data.gremlin.annotation.Graph; 10 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 11 | import com.microsoft.spring.data.gremlin.common.TestConstants; 12 | import com.microsoft.spring.data.gremlin.common.domain.Network; 13 | import com.microsoft.spring.data.gremlin.common.domain.Person; 14 | import com.microsoft.spring.data.gremlin.common.domain.Relationship; 15 | import org.junit.Assert; 16 | import org.junit.Test; 17 | import org.springframework.data.util.ClassTypeInformation; 18 | 19 | public class BasicGremlinPersistentEntityUnitTest { 20 | 21 | @Test 22 | public void testVertexPersistentEntity() { 23 | final BasicGremlinPersistentEntity entity = 24 | new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Person.class)); 25 | final Vertex annotation = entity.findAnnotation(Vertex.class); 26 | 27 | Assert.assertEquals(entity.getType(), Person.class); 28 | Assert.assertEquals(annotation.annotationType(), Vertex.class); 29 | Assert.assertEquals(annotation.label(), TestConstants.VERTEX_PERSON_LABEL); 30 | } 31 | 32 | @Test 33 | public void testEdgePersistentEntity() { 34 | final BasicGremlinPersistentEntity entity = 35 | new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Relationship.class)); 36 | final Edge annotation = entity.findAnnotation(Edge.class); 37 | 38 | Assert.assertEquals(entity.getType(), Relationship.class); 39 | Assert.assertEquals(annotation.annotationType(), Edge.class); 40 | Assert.assertEquals(annotation.label(), TestConstants.EDGE_RELATIONSHIP_LABEL); 41 | } 42 | 43 | @Test 44 | public void testGraphPersistentEntity() { 45 | final BasicGremlinPersistentEntity entity = 46 | new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Network.class)); 47 | final Graph annotation = entity.findAnnotation(Graph.class); 48 | 49 | Assert.assertEquals(entity.getType(), Network.class); 50 | Assert.assertEquals(annotation.annotationType(), Graph.class); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/mapping/GremlinMappingContextUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.mapping; 7 | 8 | import com.microsoft.spring.data.gremlin.annotation.Vertex; 9 | import com.microsoft.spring.data.gremlin.common.TestConstants; 10 | import com.microsoft.spring.data.gremlin.common.domain.Project; 11 | import org.junit.Assert; 12 | import org.junit.Test; 13 | import org.springframework.data.util.ClassTypeInformation; 14 | 15 | public class GremlinMappingContextUnitTest { 16 | 17 | @Test 18 | public void testCreatePersistentProperty() { 19 | final GremlinMappingContext context = new GremlinMappingContext(); 20 | final BasicGremlinPersistentEntity entity = context.createPersistentEntity( 21 | ClassTypeInformation.from(Project.class)); 22 | 23 | Assert.assertNotNull(entity); 24 | Assert.assertNotNull(entity.findAnnotation(Vertex.class)); 25 | Assert.assertEquals(entity.findAnnotation(Vertex.class).label(), TestConstants.VERTEX_PROJECT_LABEL); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/query/SimpleGremlinEntityMetadataUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Person; 9 | import org.junit.Assert; 10 | import org.junit.Test; 11 | 12 | public class SimpleGremlinEntityMetadataUnitTest { 13 | 14 | @Test 15 | public void testSimpleGremlinEntityMetadata() { 16 | final SimpleGremlinEntityMetadata metadata = new SimpleGremlinEntityMetadata<>(Person.class); 17 | 18 | Assert.assertNotNull(metadata); 19 | Assert.assertEquals(metadata.getJavaType(), Person.class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/query/criteria/CriteriaUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.criteria; 7 | 8 | import org.junit.Test; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import static com.microsoft.spring.data.gremlin.query.criteria.CriteriaType.IS_EQUAL; 14 | import static com.microsoft.spring.data.gremlin.query.criteria.CriteriaType.OR; 15 | 16 | public class CriteriaUnitTest { 17 | 18 | @Test(expected = IllegalArgumentException.class) 19 | public void testGetUnaryInstanceException() { 20 | final List values = new ArrayList<>(); 21 | 22 | Criteria.getUnaryInstance(OR, "fake-name", values); 23 | } 24 | 25 | @Test(expected = IllegalArgumentException.class) 26 | public void testGetBinaryInstanceException() { 27 | final List values = new ArrayList<>(); 28 | final Criteria left = Criteria.getUnaryInstance(IS_EQUAL, "fake-name", values); 29 | final Criteria right = Criteria.getUnaryInstance(IS_EQUAL, "fake-name", values); 30 | 31 | Criteria.getBinaryInstance(IS_EQUAL, left, right); 32 | } 33 | 34 | @Test(expected = UnsupportedOperationException.class) 35 | public void testCriteriaTypeToGremlinException() { 36 | CriteriaType.criteriaTypeToGremlin(IS_EQUAL); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/query/parameter/GremlinParameterUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.query.parameter; 7 | 8 | import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameter; 9 | import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameters; 10 | import lombok.SneakyThrows; 11 | import org.junit.Assert; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.springframework.core.MethodParameter; 15 | import org.springframework.lang.NonNull; 16 | 17 | import java.lang.reflect.Method; 18 | 19 | public class GremlinParameterUnitTest { 20 | 21 | private Method method; 22 | private MethodParameter methodParameter; 23 | 24 | public String handle(@NonNull String name) { 25 | return "handle: " + name; 26 | } 27 | 28 | @Before 29 | @SneakyThrows 30 | public void setup() { 31 | method = this.getClass().getMethod("handle", String.class); 32 | methodParameter = new MethodParameter(this.getClass().getMethod("handle", String.class), 0); 33 | } 34 | 35 | @Test 36 | public void testGremlinParameter() { 37 | final GremlinParameter parameter = new GremlinParameter(this.methodParameter); 38 | 39 | Assert.assertNotNull(parameter); 40 | Assert.assertEquals(parameter.getType(), String.class); 41 | Assert.assertEquals(parameter.getIndex(), 0); 42 | } 43 | 44 | @Test 45 | public void testGremlinParameters() { 46 | final GremlinParameters gremlinParameters = new GremlinParameters(this.method); 47 | 48 | Assert.assertNotNull(gremlinParameters); 49 | Assert.assertEquals(gremlinParameters.getNumberOfParameters(), 1); 50 | Assert.assertNotNull(gremlinParameters.getParameter(0)); 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/repository/AdvancedUserRepositoryIT.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; 9 | import com.microsoft.spring.data.gremlin.common.domain.AdvancedUser; 10 | import com.microsoft.spring.data.gremlin.common.repository.AdvancedUserRepository; 11 | import org.assertj.core.util.Lists; 12 | import org.junit.Assert; 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | import org.junit.runner.RunWith; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.test.context.ContextConfiguration; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | import java.util.Arrays; 21 | import java.util.List; 22 | import java.util.Optional; 23 | 24 | @RunWith(SpringJUnit4ClassRunner.class) 25 | @ContextConfiguration(classes = TestRepositoryConfiguration.class) 26 | public class AdvancedUserRepositoryIT { 27 | 28 | private static final String ID_0 = "id-8000"; 29 | private static final String ID_1 = "id-8001"; 30 | 31 | private static final String NAME_0 = "name-9000"; 32 | private static final String NAME_1 = "name-9001"; 33 | 34 | private static final int LEVEL_0 = 4; 35 | private static final int LEVEL_1 = 38; 36 | 37 | private static final AdvancedUser USER_0 = new AdvancedUser(ID_0, NAME_0, LEVEL_0); 38 | private static final AdvancedUser USER_1 = new AdvancedUser(ID_1, NAME_1, LEVEL_1); 39 | 40 | @Autowired 41 | private AdvancedUserRepository repository; 42 | 43 | @Before 44 | public void setup() { 45 | this.repository.deleteAll(); 46 | } 47 | 48 | @Test 49 | public void testCrudRepository() { 50 | final List users = Arrays.asList(USER_0, USER_1); 51 | this.repository.saveAll(users); 52 | 53 | final Optional optional = this.repository.findById(USER_0.getId()); 54 | 55 | Assert.assertTrue(optional.isPresent()); 56 | Assert.assertEquals(USER_0.getId(), optional.get().getId()); 57 | Assert.assertEquals(USER_0.getName(), optional.get().getName()); 58 | Assert.assertEquals(USER_0.getLevel(), optional.get().getLevel()); 59 | 60 | final List foundUsers = Lists.newArrayList(this.repository.findAll(AdvancedUser.class)); 61 | Assert.assertEquals(foundUsers.size(), users.size()); 62 | 63 | this.repository.deleteById(USER_0.getId()); 64 | 65 | Assert.assertFalse(this.repository.findById(USER_0.getId()).isPresent()); 66 | Assert.assertTrue(this.repository.findById(USER_1.getId()).isPresent()); 67 | 68 | this.repository.deleteAll(); 69 | 70 | Assert.assertFalse(this.repository.findById(USER_1.getId()).isPresent()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/repository/MasterRepositoryIT.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository; 7 | 8 | import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; 9 | import com.microsoft.spring.data.gremlin.common.domain.Master; 10 | import com.microsoft.spring.data.gremlin.common.domain.Student; 11 | import com.microsoft.spring.data.gremlin.common.repository.MasterRepository; 12 | import com.microsoft.spring.data.gremlin.common.repository.StudentRepository; 13 | import org.assertj.core.util.Lists; 14 | import org.junit.After; 15 | import org.junit.Assert; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.junit.runner.RunWith; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.test.context.ContextConfiguration; 21 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 22 | 23 | import java.util.List; 24 | 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @ContextConfiguration(classes = TestRepositoryConfiguration.class) 27 | public class MasterRepositoryIT { 28 | 29 | private static final Long ID_STUDENT = 1L; 30 | private static final Long ID_MASTER = 2L; 31 | 32 | private static final String NAME = "name"; 33 | 34 | private static final Student STUDENT = new Student(ID_STUDENT, NAME); 35 | 36 | private static final Master MASTER = new Master(ID_MASTER, NAME); 37 | 38 | @Autowired 39 | private MasterRepository masterRepository; 40 | 41 | @Autowired 42 | private StudentRepository studentRepository; 43 | 44 | @Before 45 | public void setup() { 46 | this.masterRepository.deleteAll(); 47 | this.studentRepository.deleteAll(); 48 | } 49 | 50 | @After 51 | public void cleanup() { 52 | this.masterRepository.deleteAll(); 53 | this.studentRepository.deleteAll(); 54 | } 55 | 56 | @Test 57 | public void testDuplicatedLabelFindAll() { 58 | this.studentRepository.save(STUDENT); 59 | this.masterRepository.save(MASTER); 60 | 61 | final List masters = Lists.newArrayList(this.masterRepository.findAll(Master.class)); 62 | 63 | Assert.assertEquals(masters.size(), 1); 64 | Assert.assertEquals(masters.get(0), MASTER); 65 | 66 | final List students = Lists.newArrayList(this.studentRepository.findAll(Student.class)); 67 | 68 | Assert.assertEquals(students.size(), 1); 69 | Assert.assertEquals(students.get(0), STUDENT); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryRegistrarUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository.config; 7 | 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | public class GremlinRepositoryRegistrarUnitTest { 13 | 14 | private GremlinRepositoryRegistrar registrar; 15 | 16 | @Before 17 | public void setup() { 18 | this.registrar = new GremlinRepositoryRegistrar(); 19 | } 20 | 21 | @Test 22 | public void testGremlinRepositoryRegistrarGetters() { 23 | Assert.assertSame(this.registrar.getAnnotation(), EnableGremlinRepositories.class); 24 | Assert.assertTrue(this.registrar.getExtension() instanceof GremlinRepositoryConfigurationExtension); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryBeanUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository.support; 7 | 8 | import com.microsoft.spring.data.gremlin.common.TestConstants; 9 | import com.microsoft.spring.data.gremlin.common.domain.Person; 10 | import com.microsoft.spring.data.gremlin.common.repository.PersonRepository; 11 | import org.junit.Assert; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.context.ApplicationContext; 17 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 18 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 | 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | public class GremlinRepositoryFactoryBeanUnitTest { 22 | 23 | @Autowired 24 | private ApplicationContext context; 25 | 26 | private GremlinRepositoryFactoryBean factoryBean; 27 | 28 | @Before 29 | @SuppressWarnings("unchecked") 30 | public void setup() { 31 | this.factoryBean = new GremlinRepositoryFactoryBean(PersonRepository.class); 32 | } 33 | 34 | @Test 35 | public void testGetFactoryInstance() { 36 | final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); 37 | final RepositoryFactorySupport factorySupport = this.factoryBean.getFactoryInstance(this.context); 38 | 39 | Assert.assertNotNull(factorySupport); 40 | Assert.assertEquals(factorySupport.getEntityInformation(Person.class).getIdType(), String.class); 41 | Assert.assertEquals(factorySupport.getEntityInformation(Person.class).getId(person), person.getId()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See LICENSE in the project root for 4 | * license information. 5 | */ 6 | package com.microsoft.spring.data.gremlin.repository.support; 7 | 8 | import com.microsoft.spring.data.gremlin.common.domain.Person; 9 | import com.microsoft.spring.data.gremlin.query.GremlinOperations; 10 | import org.junit.Assert; 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.mockito.Mock; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.context.ApplicationContext; 17 | import org.springframework.data.repository.core.EntityInformation; 18 | import org.springframework.data.repository.query.QueryLookupStrategy; 19 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 20 | 21 | import java.util.Optional; 22 | 23 | @RunWith(SpringJUnit4ClassRunner.class) 24 | public class GremlinRepositoryFactoryUnitTest { 25 | 26 | @Mock 27 | private GremlinOperations operations; 28 | 29 | @Autowired 30 | private ApplicationContext context; 31 | 32 | private GremlinRepositoryFactory factory; 33 | 34 | @Before 35 | public void setup() { 36 | this.factory = new GremlinRepositoryFactory(this.operations, this.context); 37 | } 38 | 39 | @Test 40 | public void testGetRepositoryBaseClass() { 41 | Assert.assertEquals(SimpleGremlinRepository.class, this.factory.getRepositoryBaseClass(null)); 42 | } 43 | 44 | @Test 45 | public void testGetEntityInformation() { 46 | final EntityInformation information = this.factory.getEntityInformation(Person.class); 47 | 48 | Assert.assertNotNull(information); 49 | Assert.assertEquals(information.getIdType(), String.class); 50 | } 51 | 52 | @Test 53 | public void testGetQueryLookupStrategy() { 54 | final Optional strategyOptional = this.factory. 55 | getQueryLookupStrategy(QueryLookupStrategy.Key.CREATE, null); 56 | 57 | Assert.assertTrue(strategyOptional.isPresent()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | gremlin.endpoint=localhost 2 | gremlin.port=8889 3 | gremlin.username=${your-username} 4 | gremlin.password=${your-password} 5 | gremlin.sslEnabled=false 6 | 7 | ## Valid serializer(case sensitive): GRAPHSON(default), GRAPHSON_V1D0, GRAPHSON_V2D0, GRYO_V1D0, GRYO_LITE_V1D0 8 | # gremlin.serializer=GRAPHSON 9 | -------------------------------------------------------------------------------- /src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | gremlin: 2 | endpoint: endpoint.gremlin.cosmosdb.azure.com 3 | port: 443 4 | username: /dbs/database/colls/collection 5 | password: password 6 | telemetryAllowed: true 7 | -------------------------------------------------------------------------------- /src/test/resources/telemetry.config: -------------------------------------------------------------------------------- 1 | telemetry.instrumentationKey=@telemetry.instrumentationKey@ --------------------------------------------------------------------------------