Skip to content

Commit 6f31c54

Browse files
authored
Merge pull request #670 from BillFarber/task/createQbvExample
DEVEXP-576: Deploy QBV example project
2 parents 15780d7 + fac2e84 commit 6f31c54

File tree

11 files changed

+134
-0
lines changed

11 files changed

+134
-0
lines changed

examples/qbv-example/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/bin
2+
.classpath
3+
.project
4+
/build
5+
.gradle
6+
.settings

examples/qbv-example/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This project shows an example of how MarkLogic 11 QBVs can be generated from an Optic
2+
query and loaded into a schemas database from src/main/ml-schemas/qbv.
3+
4+
Note that in order for this to work, a schemas database must be created and the content-database.json file must specify
5+
that schema database. This example is already setup to meet those requirements with a schemas-database.json file.

examples/qbv-example/build.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
plugins {
2+
id "com.marklogic.ml-gradle" version "4.6.0"
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
configurations {
10+
mlcp
11+
}
12+
13+
dependencies {
14+
mlcp 'com.marklogic:mlcp:11.0.3'
15+
mlcp files("lib")
16+
}
17+
18+
/**
19+
* Using an MlcpTask to load the data into the content database.
20+
* See the mlcp example project (examples/mlcp-project) for more information on this technique.
21+
*/
22+
task importEmployeeData(type: com.marklogic.gradle.task.MlcpTask) {
23+
classpath = configurations.mlcp
24+
command = "IMPORT"
25+
database = mlAppConfig.contentDatabaseName
26+
output_collections = "sample-import"
27+
output_permissions = "rest-reader,read,rest-writer,update"
28+
output_uri_replace = ".*import,'/import'"
29+
input_file_path = "data"
30+
input_file_type = "delimited_text"
31+
delimited_root_name = "Employee"
32+
}
33+
34+
task getEngineeringEmployees(type: com.marklogic.gradle.task.ServerEvalTask) {
35+
description = "Using a ServerEvalTask to evaluate a JS script on the server in order to test the Engineering QBV."
36+
javascript = "const op = require('/MarkLogic/optic'); op.fromView('HR', 'Engineering').result();"
37+
}
38+
39+
task getSalesEmployees(type: com.marklogic.gradle.task.ServerEvalTask) {
40+
description = "Using a ServerEvalTask to evaluate an XQuery script on the server in order to test the Sales QBV."
41+
xquery = 'xquery version "1.0-ml"; import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy"; op:from-view("HR", "Sales") => op:result()'
42+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ID,FirstName,LastName,Department
2+
1,John,Doe,Sales
3+
2,Sally,Smith,Engineering
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mlHost=localhost
2+
mlAppName=qbv-project
3+
mlRestPort=8150
4+
mlUsername=admin
5+
mlPassword=admin
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<configuration>
2+
3+
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
4+
5+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
6+
<encoder>
7+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
8+
</encoder>
9+
</appender>
10+
11+
<root level="INFO">
12+
<appender-ref ref="STDOUT" />
13+
</root>
14+
15+
<logger name="com.marklogic" level="INFO" additivity="false">
16+
<appender-ref ref="STDOUT" />
17+
</logger>
18+
19+
</configuration>
20+
21+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"database-name": "%%DATABASE%%",
3+
"schema-database": "%%SCHEMAS_DATABASE%%"
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"database-name": "%%SCHEMAS_DATABASE%%"
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const op = require('/MarkLogic/optic');
3+
op.fromView('HR', 'employees')
4+
.where(op.eq(op.col('Department'), "Engineering"))
5+
.generateView('HR', 'Engineering');
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
xquery version "1.0-ml";
2+
3+
import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy";
4+
5+
op:from-view("HR", "employees")
6+
=> op:where(op:eq(op:col('Department'), "Sales"))
7+
=> op:generate-view("HR", "Sales")

0 commit comments

Comments
 (0)