diff --git a/examples/entity-services-project/README.md b/examples/entity-services-project/README.md new file mode 100644 index 000000000..1c52b3823 --- /dev/null +++ b/examples/entity-services-project/README.md @@ -0,0 +1,13 @@ +This project shows where Entity Services (part of ML9) model definitions can be stored so that ml-gradle can be used +to generate artifacts for the models. Generating artifacts depends on the application having been deployed +already as a REST API server is required. Thus, a typical workflow is: + +1. Stub out a project with a build.gradle and gradle.properties file +2. Run "gradle mlDeploy" to deploy the application +3. Create one or more model definitions in ./data/entity-services +4. Run "gradle mlGenerateModelArtifacts" (should be able to abbreviate it as "gradle mlgen") to use Entity Services +to generate model artifacts for each of the model definitions +5. Run "gradle mlDeploy" to deploy all of the model artifacts, which will include creating a schemas database if one +doesn't exist already + +You can of course shorten the last 2 steps to "gradle mlgen mldeploy". diff --git a/examples/entity-services-project/build.gradle b/examples/entity-services-project/build.gradle new file mode 100644 index 000000000..929589386 --- /dev/null +++ b/examples/entity-services-project/build.gradle @@ -0,0 +1,3 @@ +plugins { + id "com.marklogic.ml-gradle" version "2.5.0" +} diff --git a/examples/entity-services-project/data/entity-services/race.json b/examples/entity-services-project/data/entity-services/race.json new file mode 100644 index 000000000..85d455ecd --- /dev/null +++ b/examples/entity-services-project/data/entity-services/race.json @@ -0,0 +1,84 @@ +{ + "info": { + "title": "Race", + "version": "0.0.1", + "baseUri": "http://grechaw.github.io/entity-types", + "description":"This schema represents a Runner who runs Runs and has the potential of winning Races. We'll start with this entity-type, then decide on and populate instances, tie the data in with an external RDF-based model, and query it. There are interesting problems with the bare-bones approach in this entity-type." + }, + "definitions": { + "Race": { + "properties": { + "name": { + "datatype": "string", + "description":"The name of the race." + }, + "comprisedOfRuns": { + "datatype": "array", + "description":"An array of Runs that comprise the race.", + "items":{ + "$ref": "#/definitions/Run" + } + }, + "wonByRunner": { + "$ref":"#/definitions/Runner", + "description":"The (single) winner of the race. (rule) Should match the run of shortest duration." + }, + "courseLength": { + "datatype":"decimal", + "description":"Length of the course in a scalar unit (decimal miles)" + } + }, + "primaryKey":"name" + }, + "Run": { + "properties": { + "id": { + "datatype": "string", + "description":"A unique id for the run. maybe date/runByRunner (assumes one run per day per person)" + }, + "date": { + "datatype": "date", + "description":"The date on which the run occurred." + }, + "distance": { + "datatype": "decimal", + "description":"The distance covered, in a scalar value." + }, + "distanceLabel": { + "datatype": "string", + "description":"The distance covered, in a conventional notation." + }, + "duration": { + "datatype": "dayTimeDuration", + "description":"The duration of the run." + }, + "runByRunner": { + "$ref": "#/definitions/Runner" + } + }, + "primaryKey":"id", + "required":["date","distance","duration","runByRunner"], + "rangeIndex":["date", "distance", "duration", "runByRunner"] + }, + "Runner": { + "properties": { + "name": { + "datatype": "string", + "description":"The name of the runner. In this early model, unique and a PK." + }, + "age": { + "datatype": "int", + "description":"age, in years." + }, + "gender" : { + "datatype" : "string", + "description": "The gender of the runner (for the purposes of race categories.)" + } + }, + "primaryKey": "name", + "wordLexicon": ["name"], + "required": ["name", "age"] + } + } +} + diff --git a/examples/entity-services-project/gradle.properties b/examples/entity-services-project/gradle.properties new file mode 100644 index 000000000..65b82a8ba --- /dev/null +++ b/examples/entity-services-project/gradle.properties @@ -0,0 +1,5 @@ +mlHost=localhost +mlAppName=es-gradle-example +mlRestPort=82345 +mlUsername=admin +mlPassword=admin diff --git a/examples/local-testing-project/build.gradle b/examples/local-testing-project/build.gradle index c90466317..7435abeac 100644 --- a/examples/local-testing-project/build.gradle +++ b/examples/local-testing-project/build.gradle @@ -1,7 +1,7 @@ buildscript { repositories { + mavenLocal() jcenter() - mavenLocal() } dependencies { classpath "com.marklogic:ml-gradle:${mlGradleVersion}" @@ -12,8 +12,8 @@ apply plugin: "java" apply plugin: "com.marklogic.ml-gradle" repositories { - jcenter() mavenLocal() + jcenter() } ext { diff --git a/examples/local-testing-project/gradle.properties b/examples/local-testing-project/gradle.properties index 345ea96ff..2b7129810 100644 --- a/examples/local-testing-project/gradle.properties +++ b/examples/local-testing-project/gradle.properties @@ -1,6 +1,6 @@ # Set this to the version you used when running # "gradle -Pversion=(something) publishToMavenLocal" on your local ml-gradle repo -mlGradleVersion=shell +mlGradleVersion=changeme mlHost=localhost mlAppName=example diff --git a/gradle.properties b/gradle.properties index fa5be0383..1ba63e9aa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.marklogic -version=2.4.0 -mlAppDeployerDependency=com.marklogic:ml-app-deployer:2.4.0 +version=es2 +mlAppDeployerDependency=com.marklogic:ml-app-deployer:es2 mlcpUtilDependency=com.marklogic:mlcp-util:0.3.0 diff --git a/src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy b/src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy index bcb85c80c..33ea94f8d 100644 --- a/src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy +++ b/src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy @@ -3,6 +3,7 @@ package com.marklogic.gradle import com.marklogic.appdeployer.command.databases.DeployOtherDatabasesCommand import com.marklogic.appdeployer.command.forests.DeployCustomForestsCommand import com.marklogic.gradle.task.databases.DeleteCollectionTask +import com.marklogic.gradle.task.es.GenerateModelArtifactsTask import com.marklogic.gradle.task.forests.DeployCustomForestsTask import com.marklogic.gradle.task.groups.SetTraceEventsTask import com.marklogic.gradle.task.qconsole.ExportWorkspacesTask @@ -186,6 +187,9 @@ class MarkLogicPlugin implements Plugin { project.task("mlCreateTransform", type: CreateTransformTask, group: devGroup, description: "Create a new transform in the modules transforms directory") project.task("mlPrepareRestApiDependencies", type: PrepareRestApiDependenciesTask, group: devGroup, dependsOn: project.configurations["mlRestApi"], description: "Downloads (if necessary) and unzips in the build directory all mlRestApi dependencies") + String esGroup = "ml-gradle Entity Services" + project.task("mlGenerateModelArtifacts", type: GenerateModelArtifactsTask, group: esGroup, description: "Generate model artifacts for the Entity Services models in the default directory of ./data/entity-services") + String flexrepGroup = "ml-gradle Flexible Replication" project.task("mlDeleteAllFlexrepConfigs", type: DeleteAllFlexrepConfigsTask, group: flexrepGroup, description: "Delete all Flexrep configs and their associated targets") project.task("mlDeployFlexrep", type: DeployFlexrepTask, group: flexrepGroup, description: "Deploy Flexrep configs and targets in the configuration directory") diff --git a/src/main/groovy/com/marklogic/gradle/task/es/GenerateModelArtifactsTask.groovy b/src/main/groovy/com/marklogic/gradle/task/es/GenerateModelArtifactsTask.groovy new file mode 100644 index 000000000..a29f2fc34 --- /dev/null +++ b/src/main/groovy/com/marklogic/gradle/task/es/GenerateModelArtifactsTask.groovy @@ -0,0 +1,13 @@ +package com.marklogic.gradle.task.es + +import com.marklogic.appdeployer.command.es.GenerateModelArtifactsCommand +import com.marklogic.gradle.task.MarkLogicTask +import org.gradle.api.tasks.TaskAction + +class GenerateModelArtifactsTask extends MarkLogicTask { + + @TaskAction + void generateModelArtifacts() { + new GenerateModelArtifactsCommand().execute(getCommandContext()) + } +}