Skip to content

Commit b7e5760

Browse files
committed
working on scaffolding
1 parent 2792625 commit b7e5760

File tree

7 files changed

+653
-10
lines changed

7 files changed

+653
-10
lines changed

marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/LoadUserModulesCommand.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
import com.marklogic.appdeployer.command.modules.AssetModulesFinder;
88
import com.marklogic.client.DatabaseClient;
99
import com.marklogic.client.DatabaseClientFactory;
10+
import com.marklogic.client.document.JSONDocumentManager;
11+
import com.marklogic.client.io.DocumentMetadataHandle;
12+
import com.marklogic.client.io.Format;
13+
import com.marklogic.client.io.StringHandle;
14+
import com.marklogic.client.modulesloader.Modules;
1015
import com.marklogic.client.modulesloader.impl.DefaultModulesLoader;
1116
import com.marklogic.client.modulesloader.impl.PropertiesModuleManager;
1217
import com.marklogic.client.modulesloader.impl.XccAssetLoader;
1318
import com.marklogic.hub.HubConfig;
19+
import com.marklogic.hub.deploy.util.EntityDefModulesFinder;
1420
import com.marklogic.hub.deploy.util.HubFileFilter;
1521
import com.marklogic.hub.flow.FlowCacheInvalidator;
22+
import org.apache.commons.io.IOUtils;
23+
import org.springframework.core.io.Resource;
1624

1725
import java.io.File;
1826
import java.io.IOException;
@@ -52,15 +60,6 @@ private PropertiesModuleManager getModulesManager() {
5260
return pmm;
5361
}
5462

55-
private PropertiesModuleManager getContentManager() {
56-
File timestampFile = Paths.get(hubConfig.projectDir, ".tmp", USER_CONTENT_DEPLOY_TIMESTAMPS_PROPERTIES).toFile();
57-
PropertiesModuleManager pmm = new PropertiesModuleManager(timestampFile);
58-
if (forceLoad) {
59-
pmm.deletePropertiesFile();
60-
}
61-
return pmm;
62-
}
63-
6463
private DefaultModulesLoader getStagingModulesLoader(AppConfig config) {
6564
XccAssetLoader assetLoader = config.newXccAssetLoader();
6665
assetLoader.setFileFilter(new HubFileFilter());
@@ -69,7 +68,7 @@ private DefaultModulesLoader getStagingModulesLoader(AppConfig config) {
6968
modulesLoader.setModulesManager(getModulesManager());
7069
return modulesLoader;
7170
}
72-
71+
7372
@Override
7473
public void execute(CommandContext context) {
7574
AppConfig config = context.getAppConfig();
@@ -86,6 +85,8 @@ public void execute(CommandContext context) {
8685
DefaultModulesLoader modulesLoader = getStagingModulesLoader(config);
8786
modulesLoader.loadModules(baseDir, new AssetModulesFinder(), stagingClient);
8887

88+
JSONDocumentManager entityDocMgr = stagingClient.newJSONDocumentManager();
89+
8990
AllButAssetsModulesFinder allButAssetsModulesFinder = new AllButAssetsModulesFinder();
9091

9192
try {
@@ -109,6 +110,18 @@ else if (dirStr.matches(".*[/\\\\]harmonize[/\\\\].*")) {
109110
}
110111
return FileVisitResult.SKIP_SUBTREE;
111112
}
113+
else if (dirStr.matches(startPath.toAbsolutePath() + "[/\\\\][^/\\\\]+$")) {
114+
EntityDefModulesFinder entityDefModulesFinder = new EntityDefModulesFinder();
115+
Modules modules = entityDefModulesFinder.findModules(dir.toFile());
116+
DocumentMetadataHandle meta = new DocumentMetadataHandle();
117+
meta.getCollections().add("http://marklogic.com/entity-services/models");
118+
meta.setFormat(Format.JSON);
119+
for (Resource r : modules.getAssets()) {
120+
StringHandle handle = new StringHandle(IOUtils.toString(r.getInputStream()));
121+
entityDocMgr.write("/entities/" + r.getFilename(), meta, handle);
122+
}
123+
return FileVisitResult.CONTINUE;
124+
}
112125
else {
113126
return FileVisitResult.CONTINUE;
114127
}

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/flow-lib.xqy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,8 @@ declare function flow:run-plugin(
844844

845845
let $resp :=
846846
typeswitch($resp)
847+
case map:map return
848+
$resp
847849
case object-node() | json:object return
848850
if ($data-format = $XML) then
849851
json:transform-from-json($resp, json:config("custom"))
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
xquery version "1.0-ml";
2+
3+
module namespace hent = "http://marklogic.com/data-hub/hub-entities";
4+
5+
import module namespace esi = "http://marklogic.com/entity-services-impl"
6+
at "/MarkLogic/entity-services/entity-services-impl.xqy";
7+
8+
declare variable $ENTITY-MODEL-COLLECTION := "http://marklogic.com/entity-services/models";
9+
10+
declare option xdmp:mapping "false";
11+
12+
declare function hent:dump-indexes()
13+
{
14+
let $uber-model := map:map()
15+
let $definitions :=
16+
let $m := map:map()
17+
let $_ :=
18+
for $model as map:map in fn:collection($ENTITY-MODEL-COLLECTION)/object-node()
19+
let $defs := map:get($model, "definitions")
20+
for $key in map:keys($defs)
21+
return
22+
map:put($m, $key, map:get($defs, $key))
23+
return
24+
map:put($uber-model, "definitions", $m)
25+
return
26+
hent:database-properties-generate($uber-model)
27+
};
28+
29+
declare function hent:database-properties-generate(
30+
$model as map:map
31+
) as document-node()
32+
{
33+
let $definitions := map:get($model, "definitions")
34+
let $entity-type-names := map:keys($definitions)
35+
let $range-path-indexes := json:array()
36+
let $word-lexicons := json:array()
37+
let $_ :=
38+
for $entity-type-name in $entity-type-names
39+
let $entity-type := map:get($definitions, $entity-type-name)
40+
let $properties := map:get($entity-type, "properties")
41+
let $range-index-properties := map:get($entity-type, "rangeIndex")
42+
return (
43+
for $range-index-property in $range-index-properties ! json:array-values(.)
44+
let $ri-map := json:object()
45+
let $property := map:get($properties, $range-index-property)
46+
let $specified-datatype := esi:resolve-datatype($model, $entity-type-name, $range-index-property)
47+
let $datatype := esi:indexable-datatype($specified-datatype)
48+
let $collation := head( (map:get($property, "collation"), "http://marklogic.com/collation/en") )
49+
let $_ := map:put($ri-map, "collation", $collation)
50+
let $invalid-values := "reject"
51+
let $_ := map:put($ri-map, "invalid-values", $invalid-values)
52+
let $_ := map:put($ri-map, "path-expression", "//es:instance/" || $entity-type-name || "/" || $range-index-property)
53+
let $_ := map:put($ri-map, "range-value-positions", false())
54+
let $_ := map:put($ri-map, "scalar-type", $datatype)
55+
return json:array-push($range-path-indexes, $ri-map)
56+
,
57+
let $word-lexicon-properties := map:get($entity-type, "wordLexicon")
58+
for $word-lexicon-property in $word-lexicon-properties ! json:array-values(.)
59+
let $wl-map := json:object()
60+
let $property := map:get($properties, $word-lexicon-property)
61+
let $collation := head( (map:get($property, "collation"), "http://marklogic.com/collation/en") )
62+
let $_ := map:put($wl-map, "collation", $collation)
63+
let $_ := map:put($wl-map, "localname", $word-lexicon-property)
64+
let $_ := map:put($wl-map, "namespace-uri", "")
65+
return json:array-push($word-lexicons, $wl-map)
66+
)
67+
let $path-namespaces := json:array()
68+
let $pn := json:object()
69+
let $_ := map:put($pn, "prefix", "es")
70+
let $_ := map:put($pn, "namespace-uri", "http://marklogic.com/entity-services")
71+
let $_ := json:array-push($path-namespaces, $pn)
72+
let $database-properties := json:object()
73+
let $_ := map:put($database-properties, "path-namespace", $path-namespaces)
74+
let $_ := map:put($database-properties, "element-word-lexicon", $word-lexicons)
75+
let $_ := map:put($database-properties, "range-path-index", $range-path-indexes)
76+
return xdmp:to-json($database-properties)
77+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(:
2+
Copyright 2012-2016 MarkLogic Corporation
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+
xquery version "1.0-ml";
17+
18+
module namespace service = "http://marklogic.com/rest-api/resource/db-configs";
19+
20+
import module namespace debug = "http://marklogic.com/data-hub/debug"
21+
at "/com.marklogic.hub/lib/debug-lib.xqy";
22+
23+
import module namespace hent = "http://marklogic.com/data-hub/hub-entities"
24+
at "/com.marklogic.hub/lib/hub-entities.xqy";
25+
26+
import module namespace perf = "http://marklogic.com/data-hub/perflog-lib"
27+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
28+
29+
declare namespace rapi = "http://marklogic.com/rest-api";
30+
31+
declare namespace hub = "http://marklogic.com/data-hub";
32+
33+
declare option xdmp:mapping "false";
34+
35+
(:~
36+
: Entry point for java to get entity(s).
37+
:
38+
: if the "entity-name" param is given then return a entity. Otherwise
39+
: return all entities.
40+
:
41+
:)
42+
declare function get(
43+
$context as map:map,
44+
$params as map:map
45+
) as document-node()*
46+
{
47+
debug:dump-env("GET ENTITY(s)"),
48+
49+
perf:log('/v1/resources/entity:get', function() {
50+
document {
51+
hent:dump-indexes()
52+
}
53+
})
54+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- Copyright 2016 MarkLogic Corporation. All Rights Reserved. -->
2+
<metadata>
3+
<title>db-configs</title>
4+
<description>
5+
<div>
6+
Entry point to retrieve index settings for a database
7+
</div>
8+
</description>
9+
<method name="GET"/>
10+
</metadata>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Copyright 2016 MarkLogic Corporation. All Rights Reserved. -->
2+
<metadata>
3+
<title>scaffold-content</title>
4+
<description>
5+
<div>
6+
Scaffold for Content plugins
7+
</div>
8+
</description>
9+
<method name="POST">
10+
<param name="entity" type="xs:string"/>
11+
<param name="pluginFormat" type="xs:string"/>
12+
</method>
13+
</metadata>

0 commit comments

Comments
 (0)