diff --git a/appserver/java-spring/build.gradle b/appserver/java-spring/build.gradle index de637064..596a664a 100644 --- a/appserver/java-spring/build.gradle +++ b/appserver/java-spring/build.gradle @@ -8,17 +8,20 @@ configurations.all { /* spring boot build dependency */ buildscript { - ext { - springBootVersion = '1.2.1.RELEASE' - } + ext { + springBootVersion = '1.2.1.RELEASE' + } + repositories { - mavenCentral() + jcenter() maven { url "http://repo.spring.io/snapshot" } maven { url "http://repo.spring.io/milestone" } - jcenter() + maven {url "http://developer.marklogic.com/maven2/"} } + dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + classpath "com.marklogic:ml-gradle:2.0rc3" } } @@ -28,62 +31,43 @@ apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'spring-boot' +apply plugin: 'com.marklogic.ml-gradle' group = samplestackGroup version = samplestackVersion sourceCompatibility = samplestackSourceCompatibility -/* - * INIT - * Run this task to initialize a fresh MarkLogic server - * and install security objects. - */ -task dbInit(type: MarkLogicInitTask) -dbInit.roles = file("../../database/security/roles") -dbInit.users = file("../../database/security/users") - -/* - * TEARDOWN - * This task removes all trace of samplestack - */ -task dbTeardown(type: MarkLogicTeardownTask) - -/* - * CONFIGURE - * - * This task configures the database and REST API instance - * based on files in the database directory - */ -task dbConfigure(type: MarkLogicConfigureTask) - -task dbConfigureClean << { - delete("${buildDir}/database") +ext { + mlAppConfig { + modulePaths = ["../../database/ml-modules"] + } } +// mlDeploy calls mlDeployApp +mlDeployApp.dependsOn mlInit, mlInstallAdmin +mlInstallAdmin.mustRunAfter mlInit -dbConfigure.inputDir = file('../../database') -dbConfigure.outputDir = file("${buildDir}/database") -dbConfigure.inputProperty = project.properties['taskInputProperty'] ?: "original" -dbConfigure.shouldRunAfter dbInit -dbConfigure.shouldRunAfter dbConfigureClean -dbInit.dependsOn(dbConfigureClean) +mlInstallAdmin.adminUsername = mlAdminUsername +mlInstallAdmin.adminPassword = mlAdminPassword -task dbConfigureAll -dbConfigureAll.dependsOn dbConfigureClean -dbConfigureAll.dependsOn dbConfigure /** * ASSEMBLE */ -assemble.dependsOn(dbInit, dbConfigure, test) +assemble.dependsOn(mlDeploy) /** * FETCH SEED DATA */ -task seedDataFetch(type: MarkLogicFetchTask) { - url = project.hasProperty("seedDataUrl") ? project.seedDataUrl : "http://developer.marklogic.com/media/gh/seed-data1.8.2.tgz" - destFile = file("${buildDir}/seed.tgz") +task seedDataFetch { + doLast { + def url = project.hasProperty("seedDataUrl") ? project.seedDataUrl : "http://developer.marklogic.com/media/gh/seed-data1.8.2.tgz" + def destFile = file("${buildDir}/seed.tgz") + println "Fetching data from " + url + new URL(url).withInputStream{ i -> destFile.withOutputStream{ it << i }} + } } + seedDataFetch.dependsOn(processResources) task seedDataExtract { @@ -110,14 +94,9 @@ task dbLoad(type: MarkLogicSlurpTask) { } dbLoad.mustRunAfter(assemble) dbLoad.dependsOn(seedDataExtract) -/* never skip dbload if requested */ +// never skip dbload if requested dbLoad.outputs.upToDateWhen { false } -/* - * CLEAR - */ -task dbClear(type: MarkLogicClearTask) - /* use same properties for gradle and Java runtime */ task props(type: Copy) { @@ -138,6 +117,7 @@ task appserver << appserver.dependsOn(clean, assemble, dbLoad, bootRun) bootRun.shouldRunAfter(dbLoad) + /* The code repositories to consult for dependencies */ repositories { mavenCentral() @@ -173,7 +153,7 @@ task unitTest(type: Test) { } } -test.dependsOn(props, dbConfigure) +test.dependsOn(props, mlLoadModules) task dbTest(type: Test) { useJUnit { diff --git a/appserver/java-spring/buildSrc/build.gradle b/appserver/java-spring/buildSrc/build.gradle index 8d2def27..fb6fdc2e 100644 --- a/appserver/java-spring/buildSrc/build.gradle +++ b/appserver/java-spring/buildSrc/build.gradle @@ -2,17 +2,21 @@ apply plugin: 'groovy' repositories { mavenCentral() + maven {url "http://developer.marklogic.com/maven2/"} + jcenter() } dependencies { + // Need this in to resolve apache-http conflicts with http-builder and the java-client-api + // It has to be loaded first, otherwise the older version in http-builder wins and ml-gradle won't work + compile "com.marklogic:ml-gradle:2.0rc3" + compile gradleApi() - compile("org.codehaus.groovy:groovy-all:2.3.7") compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7") - compile('com.marklogic:java-client-api:3.0.1') { - exclude(group: 'org.slf4j') - exclude(group: 'ch.qos.logback') + compile('com.marklogic:java-client-api:3.0.2') { + exclude(group: 'org.slf4j') + exclude(group: 'ch.qos.logback') } - testCompile("junit:junit:4.10") } diff --git a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicClearTask.groovy b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicClearTask.groovy deleted file mode 100644 index 088d9b5c..00000000 --- a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicClearTask.groovy +++ /dev/null @@ -1,18 +0,0 @@ -import groovy.json.* -import groovyx.net.http.RESTClient -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.TaskAction - -public class MarkLogicClearTask extends MarkLogicTask { - - @TaskAction - void updateDatabase() { - logger.error("Saving Database Configuration") - RESTClient client = manageClient("databases/" + config.marklogic.rest.name) - def params = [:] - params.contentType = "application/json" - params.body = '{"operation":"clear-database"}' - post(client,params) - } - -} diff --git a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicConfigureTask.groovy b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicConfigureTask.groovy deleted file mode 100644 index 07a394d1..00000000 --- a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicConfigureTask.groovy +++ /dev/null @@ -1,186 +0,0 @@ -import groovy.json.* -import groovyx.net.http.RESTClient -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.TaskAction -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.Input -import org.gradle.api.file.FileCollection -import org.gradle.api.file.FileTree -import org.gradle.api.tasks.incremental.IncrementalTaskInputs - -public class MarkLogicConfigureTask extends MarkLogicTask { - - @InputDirectory - def File inputDir - - @OutputDirectory - def File outputDir - - @Input - def inputProperty - - def sep = java.io.File.separator - def database = "database" - def dbProperties = database + sep + "database-properties.json" - def transforms = database + sep + "transforms" - def restExtensions = database + sep + "ext" - def restServices = database + sep +"services" - def options = database + sep + "options" - def restProperties = database + sep + "rest-properties.json" - def file = null - - - @TaskAction - void configureREST(IncrementalTaskInputs inputs) { - logger.info(inputs.incremental ? "CHANGED inputs considered out of date" : "ALL inputs considered out of date") - logger.debug("File Separator: " + sep) - inputs.outOfDate { change -> - logger.debug("out of date: ${change.file.name}") - def targetFile = new File(outputDir, change.file.name) - targetFile.text = "done" - logger.debug("Processing file " + change.file.path) - def changeFile = change.file - if (changeFile.path =~ /\/\./) { - logger.info("Skipping hidden file " + change.file.name) - } - else if (changeFile.path =~ /seed-data/) { - logger.info("Skipping seed data") - } - else if (changeFile.path.contains(transforms)) { - logger.warn("Putting transform " + change.file.name) - putTransform(changeFile) - } - else if (changeFile.path.contains(restExtensions)) { - logger.warn("Putting library extension " + change.file.name) - putExtension(changeFile) - } - else if (changeFile.path.contains(restServices)) { - logger.warn("Putting service extension " + change.file.name) - putServiceExtension(changeFile) - } - else if (changeFile.path.contains(options)) { - logger.warn("Putting search options " + change.file.name) - putOptions(changeFile) - } - else if (changeFile.path.contains(dbProperties)) { - logger.warn("Putting database configuration " + change.file.name) - putDatabaseConfig(changeFile) - } - else if (changeFile.path.contains(restProperties)) { - putRESTProperties(changeFile) - } - else if (changeFile.path.contains("security")) { - logger.info("Skipping security configuration" + change.file.name) - } else { - logger.warn("Looks like " + change.file.path + " is not a MarkLogic configuration file... skipping") - } - } - - inputs.removed { change -> - logger.debug( "removed: ${change.file.name}") - def targetFile = new File(outputDir, change.file.path) - targetFile.delete() - } - - } - - void putDatabaseConfig(c) { - logger.info( "Saving Database Configuration") - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":8002/manage/v2/databases/" + config.marklogic.rest.name + "/properties") - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - def params = [:] - params.contentType = "application/json" - params.body = c.text - put(client,params) - } - - void putTransform(transform) { - def transformFileName = transform.getPath().replaceAll(~"\\\\","/") - def transformName = transformFileName.split("/")[-1].replaceAll(~"\\.[^\\.]+", "") - if (transformName) { - logger.info( "Saving transform " + transformName) - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":" + config.marklogic.rest.port + "/v1/config/transforms/" + transformName) - client.getEncoder().putAt("application/xquery", client.getEncoder().getAt("text/plain")) - client.getEncoder().putAt("application/javascript", client.getEncoder().getAt("text/plain")) - client.getEncoder().putAt("application/vnd.marklogic-javascript", client.getEncoder().getAt("text/plain")) - client.getParser().putAt("application/vnd.marklogic-javascript", client.getParser().getAt("text/plain")) - client.getParser().putAt("*/*", client.getParser().getAt("application/json")) - client.auth.basic config.marklogic.rest.admin.user, config.marklogic.rest.admin.password - def params = [:] - if (transformFileName.endsWith("sjs")) { - params.contentType = "application/javascript"; - } else { - params.contentType = "application/xquery" - } - params.body = transform.text - put(client, params) - } - else { - logger.debug( "Skipping filename " + transformName) - } - } - - void putExtension(extension) { - def extensionFileName = extension.getPath().replaceAll(~"\\\\","/") - def extensionName = - extensionFileName.replaceAll(~".*\\/","") - logger.info( "Saving library extension " + extensionFileName) - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":" + config.marklogic.rest.port + "/v1/ext/" + extensionName) - client.getEncoder().putAt("application/xquery", client.getEncoder().getAt("text/plain")) - client.getEncoder().putAt("application/javascript", client.getEncoder().getAt("text/plain")) - client.auth.basic config.marklogic.rest.admin.user, config.marklogic.rest.admin.password - def params = [:] - if (extensionFileName.endsWith("sjs")) { - params.contentType = "application/javascript" - } else { - params.contentType = "application/xquery" - } - params.body = extension.text - put(client,params) - } - - void putServiceExtension(extension) { - def extensionFileName = extension.getPath().replaceAll(~"\\\\","/") - def extensionName = - extensionFileName.replaceAll(~".*\\/","").replaceAll(~"\\.(sjs|xqy)","") - logger.info( "Saving service extension " + extensionFileName) - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":" + config.marklogic.rest.port + "/v1/config/resources/" + extensionName) - client.getEncoder().putAt("application/xquery", client.getEncoder().getAt("text/plain")) - client.getEncoder().putAt("application/javascript", client.getEncoder().getAt("text/plain")) - client.auth.basic config.marklogic.rest.admin.user, config.marklogic.rest.admin.password - def params = [:] - if (extensionFileName.endsWith("sjs")) { - params.contentType = "application/javascript" - } else { - params.contentType = "application/xquery" - } - params.body = extension.text - put(client,params) - } - - void putOptions(options) { - def optionsFileName = options.getPath().replaceAll(~"\\\\","/").replaceAll(~"\\.json","") - def optionsName = - optionsFileName.replaceAll(~".*\\/","") - logger.info( "Saving options " + optionsFileName) - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":" + config.marklogic.rest.port + "/v1/config/query/" + optionsName) - client.auth.basic config.marklogic.rest.admin.user, config.marklogic.rest.admin.password - def params = [:] - params.contentType = "application/json" - params.body = options.text - put(client,params) - } - - void putRESTProperties(File f) { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":" + config.marklogic.rest.port + "/v1/config/properties") - client.auth.basic config.marklogic.rest.admin.user, config.marklogic.rest.admin.password - def params = [:] - params.contentType = "application/json" - params.body = f.text - logger.info( "Configuring Properties") - put(client,params) - } - -} - diff --git a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicFetchTask.groovy b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicFetchTask.groovy deleted file mode 100644 index 4d7795c3..00000000 --- a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicFetchTask.groovy +++ /dev/null @@ -1,43 +0,0 @@ -import groovy.json.* -import groovyx.net.http.RESTClient -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.TaskAction -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.Input - -public class MarkLogicFetchTask extends MarkLogicTask { - - @Input - String url - - @OutputFile - File destFile - - @TaskAction - void fetchSeedData() { - logger.warn("Fetching data from " + url) - def is = new URL(url).openStream() - - try { - OutputStream os = new FileOutputStream(destFile); - boolean finished = false; - try { - byte[] buf = new byte[1024 * 10]; - int read; - while ((read = is.read(buf)) >= 0) { - os.write(buf, 0, read); - } - os.flush(); - finished = true; - } finally { - os.close(); - if (!finished) { - destFile.delete(); - } - } - } finally { - is.close(); - } - } - -} diff --git a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicInitTask.groovy b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicInitTask.groovy deleted file mode 100644 index b075d385..00000000 --- a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicInitTask.groovy +++ /dev/null @@ -1,124 +0,0 @@ -import groovy.json.* -import groovyx.net.http.RESTClient -import org.gradle.api.DefaultTask -import org.gradle.api.Project -import org.gradle.api.tasks.* -import java.net.URLDecoder - - -public class MarkLogicInitTask extends MarkLogicTask { - - def roles - def users - - @TaskAction - void initMarkLogic() { - adminInit() - adminSetup() - createUsers() - restBoot() - } - - void adminInit() { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":8001/admin/v1/init") - def params = [:] - params.contentType = "application/json" - params.body = "{}" - try { - def response = client.post(params) - logger.warn("MarkLogic initialized.") - delay() - } - catch (ex) { - if ( ex.response.status == 403 ) { - logger.warn("Unauthorized. Check your installation, try to start with a fresh one.") - throw new StopActionException(ex) - } - else if ( ex.response.status == 401 ) - logger.warn("Server already secured. Initialization skipped.") - else if ( ex.response.status == 500 ) - logger.warn("Server already initialized. Initialization skipped") - else - throw ex; - } - } - - void adminSetup() { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":8001/admin/v1/instance-admin") - def params = [:] - params.contentType = "application/json" - params.body = String.format('{ "admin-username" : "%s", "admin-password" : "%s", "realm" : "public" }', config.marklogic.admin.user, config.marklogic.admin.password) - try { - client.post(params) - logger.warn("MarkLogic admin secured.") - delay() - } - catch (ex) { - if ( ex.response.status == 403 ) { - logger.warn("Unauthorized. Check your installation, try to start with a fresh one.") - throw new StopActionException(ex) - } - else if ( ex.response.status == 401 ) - logger.warn("Server already secured. Initialization skipped") - else - logger.warn("Got " + ex.response.status) - } - } - - private void create(path, jsonObject) { - try { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":8002/manage/v2/" + path) - client.headers."accept" = "application/json" - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - - def params = [:] - params.contentType = "application/json" - params.body = jsonObject.text - client.post(params) - } catch (ex) { - if (ex.response) - { - try { - logger.warn("" + ex.response.data) - } catch (ex2) { - logger.warn("Error parsing JSON response: " + ex.response) - } - } - else - { - logger.warn("No response") - } - } - } - - void createUser(jsonUser) { - create("users", jsonUser) - } - - void createRole(jsonRole) { - create("roles", jsonRole) - } - - void createUsers() { - logger.warn("Creating users and roles...") - roles.listFiles().findAll { it.name.contains("guest") }.each { createRole(it) } - roles.listFiles().findAll { it.name.contains("writer") }.each { createRole(it) } - users.listFiles().each { createUser(it) } - } - - void restBoot() { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":8002/v1/rest-apis").with { - headers."accept" = "application/json" - auth.basic config.marklogic.admin.user, config.marklogic.admin.password - it - } - def params = [:] - params.contentType = "application/json" - params.body = String.format('{"rest-api" : { "name" : "%s", "port" : %s }}', config.marklogic.rest.name, config.marklogic.rest.port) - try { - post(client, params) - } catch (ex) { - logger.warn("Ignoring server creation error... ") - } - } -} diff --git a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicSlurpTask.groovy b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicSlurpTask.groovy index be8dfaf4..59386f9a 100644 --- a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicSlurpTask.groovy +++ b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicSlurpTask.groovy @@ -17,7 +17,7 @@ public class MarkLogicSlurpTask extends MarkLogicTask { File seedDirectory private writerClient() { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":" + config.marklogic.rest.port) + RESTClient client = new RESTClient("http://" + config.mlHost + ":" + config.mlRestPort) client.auth.basic config.marklogic.writer.user, config.marklogic.writer.password client.getEncoder().putAt("application/n-triples", client.getEncoder().getAt("text/plain")) client.getParser().putAt("application/n-triples", client.getParser().getAt("text/plain")) diff --git a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicTask.groovy b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicTask.groovy index 527781a1..975db236 100644 --- a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicTask.groovy +++ b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicTask.groovy @@ -16,78 +16,11 @@ public class MarkLogicTask extends DefaultTask { project.file("gradle.properties").withInputStream { props.load(it) } ext.config = new ConfigSlurper().parse(props) client = DatabaseClientFactory.newClient( - config.marklogic.rest.host, - Integer.parseInt(config.marklogic.rest.port), + config.mlHost, + Integer.parseInt(config.mlRestPort), config.marklogic.writer.user, config.marklogic.writer.password, Authentication.DIGEST) docMgr = client.newJSONDocumentManager() } - - /* returns a client that can use port 8002 to nanage MarkLogic */ - protected manageClient(String url) { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":8002/manage/v2/" + url) - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - return client; - } - - /* returns a client that can bootstrap and teardown REST APIs */ - protected bootstrapClient() { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":8002/v1/rest-apis/" + config.marklogic.rest.name) - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - return client; - } - - - protected storeJson(uri, handle) { - docMgr.write(uri, handle); - } - - - protected put(client, params) { - try { - def response = client.put(params) - logger.warn("Success: " + response.status) - } catch (ex) - { - if (ex.response) - { - logger.warn("" + ex.response.data.text) - } - else - { - logger.warn("No response") - } - } - } - - protected post(client, params) { - try { - def response = client.post(params) - logger.warn("Success: " + response.status) - } catch (ex) - { - if (ex.response) - { - logger.warn("" + ex.response.data) - } - else - { - logger.warn("No response") - } - } - } - - protected void delay() { - RESTClient client = new RESTClient("http://" + config.marklogic.rest.host + ":8001/admin/v1/timestamp") - def params = [:] - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - try { - Thread.sleep(1000) - client.get(params) - } catch (ex) { - logger.warn("Waiting for server restart..."); - delay(); - } - } } diff --git a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicTeardownTask.groovy b/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicTeardownTask.groovy deleted file mode 100644 index 8495ece4..00000000 --- a/appserver/java-spring/buildSrc/src/main/groovy/MarkLogicTeardownTask.groovy +++ /dev/null @@ -1,54 +0,0 @@ -import groovy.json.* -import groovyx.net.http.RESTClient -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.TaskAction - -public class MarkLogicTeardownTask extends MarkLogicTask { - - @TaskAction - void teardown() { - teardownRest(); - delay(); - removeUsers(); - } - - void teardownRest() { - RESTClient client = bootstrapClient(); - def params = [:] - params.queryString = "include=content&include=modules" - try { - client.delete(params) - } catch (ex) { - if (ex.response) - { - logger.error(": " + ex.response.data.text) - } - else - { - logger.warn("No response from server") - } - throw new RuntimeException("Failed Teardown. Check environment before proceeding.", ex) - } - } - - void removeUsers() { - def url = "http://" + config.marklogic.rest.host + ":8002/manage/v2/" - RESTClient client = new RESTClient(url + "users/samplestack-admin") - def params = [:] - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - client.delete(params) - client = new RESTClient(url + "users/samplestack-guest") - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - client.delete(params) - client = new RESTClient(url + "users/samplestack-contributor") - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - client.delete(params) - client = new RESTClient(url + "roles/samplestack-guest") - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - client.delete(params) - client = new RESTClient(url + "roles/samplestack-writer") - client.auth.basic config.marklogic.admin.user, config.marklogic.admin.password - client.delete(params) - } - -} diff --git a/appserver/java-spring/gradle.properties b/appserver/java-spring/gradle.properties index a8c2dbbe..65975f99 100644 --- a/appserver/java-spring/gradle.properties +++ b/appserver/java-spring/gradle.properties @@ -3,16 +3,23 @@ samplestackGroup=com.marklogic samplestackVersion=1.1.0 samplestackSourceCompatibility=1.7 +# ml-gradle properties +mlHost=localhost +mlAppName=samplestack +mlRestPort=8006 +mlConfigDir=../../database/ml-config -# dbInit secures the server with these credentials -# dbInit uses these credentials to create users and the REST instance -# dbConfigure uses these credentials to manage indexes and database properties -marklogic.admin.user=admin -marklogic.admin.password=admin +# ML admin user that is used to create samplestack users and roles +mlAdminUsername=admin +mlAdminPassword=admin -# dbConfigure uses these credentials to manage the REST API instance -marklogic.rest.admin.user=samplestack-admin -marklogic.rest.admin.password=samplestack-admin-password +# ML user that is used to manage application resources via the management REST API +mlManageUsername=admin +mlManagePassword=admin + +# User with rest-admin that can manage the REST API instance +mlUsername=samplestack-admin +mlPassword=samplestack-admin-password # dbLoad uses these credentials to load the database with seed data # the Java runtime uses these credentials for "contributor" access @@ -22,10 +29,3 @@ marklogic.writer.password=sc-pass # the Java runtime uses these credentials for "guest" access marklogic.guest.user=samplestack-guest marklogic.guest.password=sa-pass - -# the host for dbInit, dbConfigure and the MarkLogic REST API -marklogic.rest.host=localhost -# the port for the MarkLogic REST API -marklogic.rest.port=8006 -# the name of the MarkLogic REST API instance -marklogic.rest.name=samplestack diff --git a/appserver/java-spring/src/main/java/com/marklogic/samplestack/dbclient/Clients.java b/appserver/java-spring/src/main/java/com/marklogic/samplestack/dbclient/Clients.java index 6feae264..b294cd7f 100644 --- a/appserver/java-spring/src/main/java/com/marklogic/samplestack/dbclient/Clients.java +++ b/appserver/java-spring/src/main/java/com/marklogic/samplestack/dbclient/Clients.java @@ -52,8 +52,8 @@ public class Clients extends HashMap { * @return A DatabaseClient for accessing MarkLogic */ private DatabaseClient databaseClient(ClientRole role) { - String host = env.getProperty("marklogic.rest.host"); - Integer port = Integer.parseInt(env.getProperty("marklogic.rest.port")); + String host = env.getProperty("mlHost"); + Integer port = Integer.parseInt(env.getProperty("mlRestPort")); String username = env.getProperty(role.getUserParam()); String password = env.getProperty(role.getPasswordParam()); return DatabaseClientFactory.newClient(host, port, username, password, diff --git a/appserver/java-spring/src/main/resources/gradle.properties b/appserver/java-spring/src/main/resources/gradle.properties index b09b1380..93b9473f 100644 --- a/appserver/java-spring/src/main/resources/gradle.properties +++ b/appserver/java-spring/src/main/resources/gradle.properties @@ -1,8 +1,14 @@ org.gradle.daemon=false samplestackGroup=com.marklogic -samplestackVersion=1.0.1-SNAPSHOT +samplestackVersion=1.1.0 samplestackSourceCompatibility=1.7 +# ml-gradle properties +mlHost=localhost +mlRestPort=8006 +mlUserame=admin +mlPassword=admin +mlAppName=samplestack # dbInit secures the server with these credentials # dbInit uses these credentials to create users and the REST instance @@ -22,11 +28,3 @@ marklogic.writer.password=sc-pass # the Java runtime uses these credentials for "guest" access marklogic.guest.user=samplestack-guest marklogic.guest.password=sa-pass - -# the host for dbInit, dbConfigure and the MarkLogic REST API -marklogic.rest.host=localhost -# the port for the MarkLogic REST API -marklogic.rest.port=8006 -# the name of the MarkLogic REST API instance -marklogic.rest.name=samplestack - diff --git a/database/database-properties.json b/database/ml-config/databases/content-database.json similarity index 93% rename from database/database-properties.json rename to database/ml-config/databases/content-database.json index 8829c064..ccf6deba 100644 --- a/database/database-properties.json +++ b/database/ml-config/databases/content-database.json @@ -1,135 +1,130 @@ -{ - "database-name": "samplestack", - "element-word-lexicon": [ - { - "collation": "http://marklogic.com/collation/", - "localname": "tags", - "namespace-uri": "" - } - ], - "field": [ - { - "field-name": "default-samplestack-search", - "field-path": [ - { - "path": "/title", - "weight": 2 - }, - { - "path": "/text", - "weight": 2 - }, - { - "path": "/answers/text", - "weight": 1 - }, - { - "path": "//comments/text", - "weight": 0.5 - } - ], - "tokenizer-overrides": null - }, - { - "field-name": "", - "include-root": true, - "tokenizer-overrides": null - } - ], - "forest": [ - "samplestack-1", - "samplestack-2", - "samplestack-3" - ], - "range-element-index": [ - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "localname": "id", - "namespace-uri": "", - "range-value-positions": false, - "scalar-type": "string" - }, - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "localname": "lastActivityDate", - "namespace-uri": "", - "range-value-positions": false, - "scalar-type": "dateTime" - }, - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "localname": "tags", - "namespace-uri": "", - "range-value-positions": false, - "scalar-type": "string" - }, - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "localname": "userName", - "namespace-uri": "", - "range-value-positions": false, - "scalar-type": "string" - }, - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "localname": "voteCount", - "namespace-uri": "", - "range-value-positions": false, - "scalar-type": "long" - }, - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "localname": "answerCount", - "namespace-uri": "", - "range-value-positions": false, - "scalar-type": "long" - }, - { - "collation": "", - "invalid-values": "reject", - "localname": "reputation", - "namespace-uri": "", - "range-value-positions": false, - "scalar-type": "long" - }, - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "localname": "title", - "namespace-uri": "", - "range-value-positions": false, - "scalar-type": "string" - } - ], - "range-path-index": [ - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "path-expression": "/owner/displayName", - "range-value-positions": false, - "scalar-type": "string" - }, - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "path-expression": "/answers/owner/displayName", - "range-value-positions": false, - "scalar-type": "string" - }, - { - "collation": "http://marklogic.com/collation/", - "invalid-values": "reject", - "path-expression": "//comments/owner/displayName", - "range-value-positions": false, - "scalar-type": "string" - } - ], - "three-character-searches":true, - "triple-index": true -} +{ + "database-name": "%%DATABASE%%", + "element-word-lexicon": [ + { + "collation": "http://marklogic.com/collation/", + "localname": "tags", + "namespace-uri": "" + } + ], + "field": [ + { + "field-name": "default-samplestack-search", + "field-path": [ + { + "path": "/title", + "weight": 2 + }, + { + "path": "/text", + "weight": 2 + }, + { + "path": "/answers/text", + "weight": 1 + }, + { + "path": "//comments/text", + "weight": 0.5 + } + ], + "tokenizer-overrides": null + }, + { + "field-name": "", + "include-root": true, + "tokenizer-overrides": null + } + ], + "range-element-index": [ + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "localname": "id", + "namespace-uri": "", + "range-value-positions": false, + "scalar-type": "string" + }, + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "localname": "lastActivityDate", + "namespace-uri": "", + "range-value-positions": false, + "scalar-type": "dateTime" + }, + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "localname": "tags", + "namespace-uri": "", + "range-value-positions": false, + "scalar-type": "string" + }, + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "localname": "userName", + "namespace-uri": "", + "range-value-positions": false, + "scalar-type": "string" + }, + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "localname": "voteCount", + "namespace-uri": "", + "range-value-positions": false, + "scalar-type": "long" + }, + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "localname": "answerCount", + "namespace-uri": "", + "range-value-positions": false, + "scalar-type": "long" + }, + { + "collation": "", + "invalid-values": "reject", + "localname": "reputation", + "namespace-uri": "", + "range-value-positions": false, + "scalar-type": "long" + }, + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "localname": "title", + "namespace-uri": "", + "range-value-positions": false, + "scalar-type": "string" + } + ], + "range-path-index": [ + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "path-expression": "/owner/displayName", + "range-value-positions": false, + "scalar-type": "string" + }, + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "path-expression": "/answers/owner/displayName", + "range-value-positions": false, + "scalar-type": "string" + }, + { + "collation": "http://marklogic.com/collation/", + "invalid-values": "reject", + "path-expression": "//comments/owner/displayName", + "range-value-positions": false, + "scalar-type": "string" + } + ], + "three-character-searches":true, + "triple-index": true +} diff --git a/database/rest-properties.json b/database/ml-config/rest-properties.json similarity index 100% rename from database/rest-properties.json rename to database/ml-config/rest-properties.json diff --git a/database/security/roles/samplestack-guest.json b/database/ml-config/security/roles/samplestack-guest.json similarity index 100% rename from database/security/roles/samplestack-guest.json rename to database/ml-config/security/roles/samplestack-guest.json diff --git a/database/security/roles/samplestack-writer.json b/database/ml-config/security/roles/samplestack-writer.json similarity index 100% rename from database/security/roles/samplestack-writer.json rename to database/ml-config/security/roles/samplestack-writer.json diff --git a/database/security/users/samplestack-admin.json b/database/ml-config/security/users/samplestack-admin.json similarity index 100% rename from database/security/users/samplestack-admin.json rename to database/ml-config/security/users/samplestack-admin.json diff --git a/database/security/users/samplestack-contributor.json b/database/ml-config/security/users/samplestack-contributor.json similarity index 100% rename from database/security/users/samplestack-contributor.json rename to database/ml-config/security/users/samplestack-contributor.json diff --git a/database/security/users/samplestack-guest.json b/database/ml-config/security/users/samplestack-guest.json similarity index 100% rename from database/security/users/samplestack-guest.json rename to database/ml-config/security/users/samplestack-guest.json diff --git a/database/options/contributors.json b/database/ml-modules/options/contributors.json similarity index 100% rename from database/options/contributors.json rename to database/ml-modules/options/contributors.json diff --git a/database/options/questions.json b/database/ml-modules/options/questions.json similarity index 100% rename from database/options/questions.json rename to database/ml-modules/options/questions.json diff --git a/database/options/single-question.json b/database/ml-modules/options/single-question.json similarity index 100% rename from database/options/single-question.json rename to database/ml-modules/options/single-question.json diff --git a/database/options/tags.json b/database/ml-modules/options/tags.json similarity index 100% rename from database/options/tags.json rename to database/ml-modules/options/tags.json diff --git a/database/services/graphPermSetter.sjs b/database/ml-modules/services/graphPermSetter.sjs similarity index 100% rename from database/services/graphPermSetter.sjs rename to database/ml-modules/services/graphPermSetter.sjs diff --git a/database/services/relatedTags.sjs b/database/ml-modules/services/relatedTags.sjs similarity index 100% rename from database/services/relatedTags.sjs rename to database/ml-modules/services/relatedTags.sjs diff --git a/database/transforms/search-response.sjs b/database/ml-modules/transforms/search-response.sjs similarity index 100% rename from database/transforms/search-response.sjs rename to database/ml-modules/transforms/search-response.sjs diff --git a/database/transforms/single-question.sjs b/database/ml-modules/transforms/single-question.sjs similarity index 100% rename from database/transforms/single-question.sjs rename to database/ml-modules/transforms/single-question.sjs