Skip to content

Commit 856dc4d

Browse files
committed
Fixing #5 - spec for plugins
Fixing #51 - distinguish between input and conformance flows Fixing #54 - add support for JSON envelopes Fixing #55 - add scaffolding for sis, xslt Fixing #57 - prompt if you want sis or xqy
1 parent c61ff5a commit 856dc4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+877
-362
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.marklogic.hub;
2+
3+
public enum FlowComplexity {
4+
SIMPLE("simple"), ADVANCED("advanced");
5+
6+
private String name;
7+
8+
FlowComplexity(String name) {
9+
this.name = name;
10+
}
11+
12+
public static FlowComplexity getFlowComplexity(String complexity) {
13+
for (FlowComplexity flowComplexity : FlowComplexity.values()) {
14+
if (flowComplexity.toString().equals(complexity)) {
15+
return flowComplexity;
16+
}
17+
}
18+
return null;
19+
}
20+
21+
public String toString() {
22+
return name;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.marklogic.hub;
2+
3+
public enum PluginFormat {
4+
JAVASCRIPT("sjs"), XQUERY("xqy");
5+
6+
private String name;
7+
8+
PluginFormat(String name) {
9+
this.name = name;
10+
}
11+
12+
public static PluginFormat getPluginFormat(String format) {
13+
for (PluginFormat pluginFormat : PluginFormat.values()) {
14+
if (pluginFormat.toString().equals(format)) {
15+
return pluginFormat;
16+
}
17+
}
18+
return null;
19+
}
20+
21+
public String toString() {
22+
return name;
23+
}
24+
}

data-hub/src/main/java/com/marklogic/hub/RestAssetLoader.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.HashSet;
2929
import java.util.Set;
3030

31+
import org.apache.commons.io.FilenameUtils;
32+
3133
import com.marklogic.client.DatabaseClient;
3234
import com.marklogic.client.admin.ExtensionLibrariesManager;
3335
import com.marklogic.client.admin.ExtensionLibraryDescriptor;
@@ -142,7 +144,19 @@ protected void loadFile(String uri, File f) {
142144
moduleDescriptor.setPath(uri);
143145

144146
FileHandle handle = new FileHandle(f);
145-
handle.setFormat(Format.TEXT);
147+
148+
String ext = FilenameUtils.getExtension(f.getName());
149+
switch(ext) {
150+
case "xml":
151+
handle.setFormat(Format.XML);
152+
break;
153+
case "json":
154+
handle.setFormat(Format.JSON);
155+
break;
156+
default:
157+
handle.setFormat(Format.TEXT);
158+
}
159+
146160
libsMgr.write(moduleDescriptor, handle);
147161

148162
if (modulesManager != null) {

data-hub/src/main/java/com/marklogic/hub/Scaffolding.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,66 @@
1818
import java.io.File;
1919
import java.io.IOException;
2020
import java.io.InputStream;
21+
import java.io.PrintWriter;
2122
import java.nio.file.Files;
2223
import java.nio.file.Path;
2324
import java.nio.file.Paths;
2425

26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
29+
import com.marklogic.client.io.Format;
30+
import com.marklogic.hub.flow.Flow;
31+
import com.marklogic.hub.flow.FlowType;
32+
import com.marklogic.hub.flow.SimpleFlow;
33+
2534
public class Scaffolding {
2635

36+
static final private Logger LOGGER = LoggerFactory.getLogger(Scaffolding.class);
37+
2738
public static void createDomain(String domainName, File userlandPath) {
2839
File domainDir = new File(userlandPath, domainName);
2940
domainDir.mkdirs();
3041
}
3142

32-
public static void createFlow(String name, String type, File domainPath)
43+
public static void createFlow(File domainPath, String domainName, String name, FlowType flowType, PluginFormat pluginFormat, Format dataFormat)
3344
throws IOException {
34-
File typeDir = new File(domainPath, type);
45+
File typeDir = new File(domainPath, flowType.toString());
3546
File flowDir = new File(typeDir, name);
3647

37-
File collectorDir = new File(flowDir, "collector");
38-
collectorDir.mkdirs();
39-
writeFile("scaffolding/collector.xqy",
40-
Paths.get(collectorDir.getPath(), "collector.xqy"));
48+
if (flowType.equals(FlowType.CONFORMANCE)) {
49+
File collectorDir = new File(flowDir, "collector");
50+
collectorDir.mkdirs();
51+
writeFile("scaffolding/" + flowType + "/" + pluginFormat + "/collector." + pluginFormat,
52+
Paths.get(collectorDir.getPath(), "collector." + pluginFormat));
53+
}
4154

4255
File contentDir = new File(flowDir, "content");
4356
contentDir.mkdirs();
44-
writeFile("scaffolding/content.xqy",
45-
Paths.get(contentDir.getPath(), "content.xqy"));
57+
writeFile("scaffolding/" + flowType + "/" + pluginFormat + "/content." + pluginFormat,
58+
Paths.get(contentDir.getPath(), "content." + pluginFormat));
4659

4760
File headerDir = new File(flowDir, "headers");
4861
headerDir.mkdirs();
49-
writeFile("scaffolding/headers.xqy",
50-
Paths.get(headerDir.getPath(), "headers.xqy"));
62+
writeFile("scaffolding/" + flowType + "/" + pluginFormat + "/headers." + pluginFormat,
63+
Paths.get(headerDir.getPath(), "headers." + pluginFormat));
5164

5265
File triplesDir = new File(flowDir, "triples");
5366
triplesDir.mkdirs();
54-
writeFile("scaffolding/triples.xqy",
55-
Paths.get(triplesDir.getPath(), "triples.xqy"));
67+
writeFile("scaffolding/" + flowType + "/" + pluginFormat + "/triples." + pluginFormat,
68+
Paths.get(triplesDir.getPath(), "triples." + pluginFormat));
69+
70+
SimpleFlow flow = new SimpleFlow(domainName, name, flowType, dataFormat);
71+
flow.serialize();
72+
File flowFile = new File(flowDir, name + ".xml");
73+
try(PrintWriter out = new PrintWriter(flowFile)) {
74+
out.println(flow.serialize());
75+
}
5676
}
5777

5878
private static void writeFile(String srcFile, Path dstFile)
5979
throws IOException {
80+
LOGGER.info(srcFile);
6081
InputStream inputStream = Scaffolding.class.getClassLoader()
6182
.getResourceAsStream(srcFile);
6283
Files.copy(inputStream, dstFile);

data-hub/src/main/java/com/marklogic/hub/flow/AbstractFlow.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.w3c.dom.NodeList;
2929

3030
import com.marklogic.client.MarkLogicIOException;
31+
import com.marklogic.client.io.Format;
32+
import com.marklogic.hub.FlowComplexity;
3133
import com.marklogic.hub.collector.Collector;
3234
import com.marklogic.hub.collector.QueryCollector;
3335
import com.marklogic.hub.collector.ServerCollector;
@@ -48,8 +50,9 @@ public abstract class AbstractFlow implements Flow {
4850

4951
private String domainName;
5052
private String flowName;
51-
private String type;
52-
private String format;
53+
private FlowType type;
54+
private Format dataFormat = Format.XML;
55+
private FlowComplexity flowComplexity;
5356
private Collector collector;
5457
private boolean envelopeEnabled = true;
5558
protected ArrayList<Plugin> plugins = new ArrayList<Plugin>();
@@ -59,11 +62,12 @@ public AbstractFlow(Element xml) {
5962
deserialize(xml);
6063
}
6164

62-
public AbstractFlow(String domainName, String flowName, String type, String format) {
65+
public AbstractFlow(String domainName, String flowName, FlowType type, Format dataFormat, FlowComplexity flowComplexity) {
6366
this.domainName = domainName;
6467
this.flowName = flowName;
6568
this.type = type;
66-
this.format = format;
69+
this.dataFormat = dataFormat;
70+
this.flowComplexity = flowComplexity;
6771
}
6872

6973
private void deserialize(Node xml) {
@@ -80,10 +84,13 @@ private void deserialize(Node xml) {
8084
this.flowName = node.getTextContent();
8185
break;
8286
case "type":
83-
this.type = node.getTextContent();
87+
this.type = FlowType.getFlowType(node.getTextContent());
8488
break;
85-
case "format":
86-
this.format = node.getTextContent();
89+
case "complexity":
90+
this.flowComplexity = FlowComplexity.getFlowComplexity(node.getTextContent());
91+
break;
92+
case "data-format":
93+
this.dataFormat = Format.getFromMimetype(node.getTextContent());
8794
break;
8895
case "domain":
8996
this.domainName = node.getTextContent();
@@ -176,16 +183,19 @@ public String getName() {
176183
* Retrieves the type of flow
177184
*/
178185
@Override
179-
public String getType() {
186+
public FlowType getType() {
180187
return this.type;
181188
}
182189

183-
/**
184-
* Retrieves the format of the flow
185-
*/
186-
public String getFormat() {
187-
return this.format;
190+
@Override
191+
public Format getDataFormat() {
192+
return this.dataFormat;
188193
}
194+
195+
public void setDataFormat(Format format) {
196+
this.dataFormat = format;
197+
}
198+
189199
/**
190200
* Retrieves the flow's collector
191201
*/
@@ -261,11 +271,15 @@ public String serialize() {
261271
serializer.writeEndElement();
262272

263273
serializer.writeStartElement("type");
264-
serializer.writeCharacters(this.type);
274+
serializer.writeCharacters(this.type.toString());
275+
serializer.writeEndElement();
276+
277+
serializer.writeStartElement("complexity");
278+
serializer.writeCharacters(this.flowComplexity.toString());
265279
serializer.writeEndElement();
266280

267-
serializer.writeStartElement("format");
268-
serializer.writeCharacters(this.format);
281+
serializer.writeStartElement("data-format");
282+
serializer.writeCharacters(this.dataFormat.getDefaultMimetype());
269283
serializer.writeEndElement();
270284

271285
if (this.collector != null) {

data-hub/src/main/java/com/marklogic/hub/flow/Flow.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717

1818
import java.util.List;
1919

20+
import com.marklogic.client.io.Format;
2021
import com.marklogic.hub.collector.Collector;
2122
import com.marklogic.hub.plugin.Plugin;
2223
import com.marklogic.hub.writer.Writer;
2324

2425
public interface Flow {
25-
static final String INPUT_FLOW = "input";
26-
static final String CANONICAL_FLOW = "canonical";
27-
2826
String getDomainName();
2927
String getName();
30-
String getType();
28+
FlowType getType();
29+
Format getDataFormat();
3130
String serialize();
3231

3332
Collector getCollector();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.marklogic.hub.flow;
2+
3+
public enum FlowType {
4+
INPUT("input"), CONFORMANCE("conformance");
5+
6+
private String type;
7+
FlowType(String type) {
8+
this.type = type;
9+
}
10+
11+
public static FlowType getFlowType(String type) {
12+
for (FlowType flowType : FlowType.values()) {
13+
if (flowType.toString().equals(type)) {
14+
return flowType;
15+
}
16+
}
17+
return null;
18+
}
19+
20+
public String toString() {
21+
return this.type;
22+
}
23+
}

data-hub/src/main/java/com/marklogic/hub/flow/SimpleFlow.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import org.w3c.dom.Element;
1919

20+
import com.marklogic.client.io.Format;
21+
import com.marklogic.hub.FlowComplexity;
2022
import com.marklogic.hub.plugin.Plugin;
2123
import com.marklogic.hub.plugin.ServerPlugin;
2224

@@ -26,8 +28,8 @@
2628
*/
2729
public class SimpleFlow extends AbstractFlow {
2830

29-
public SimpleFlow(String domainName, String flowName, String type) {
30-
super(domainName, flowName, type, "simple");
31+
public SimpleFlow(String domainName, String flowName, FlowType type, Format dataFormat) {
32+
super(domainName, flowName, type, dataFormat, FlowComplexity.SIMPLE);
3133
for (int i = 0; i < 3; i++) {
3234
super.addPlugin(null);
3335
}

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

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,43 @@ declare function debug:log($items)
4747
:)
4848
declare function debug:dump-env()
4949
{
50-
debug:log((
51-
"",
52-
"REQUEST DETAILS:",
53-
" " || xdmp:get-request-path(),
54-
"",
55-
" [Headers]",
56-
for $h in xdmp:get-request-header-names()
57-
return
58-
" " || $h || " => " || xdmp:get-request-header($h),
59-
"",
60-
" [Request Params]",
61-
for $p in xdmp:get-request-field-names()
62-
return
63-
" " || $p || " => " || xdmp:get-request-field($p),
64-
let $body := xdmp:get-request-body()
65-
return
66-
if (fn:exists($body)) then
67-
(
68-
"",
69-
" [Body]",
70-
$body
71-
)
72-
else (),
73-
"",
74-
""
75-
))
50+
let $request-path := xdmp:get-request-path()
51+
let $request-path :=
52+
if ($request-path = '/MarkLogic/rest-api/endpoints/resource-service-query.xqy') then
53+
let $params := fn:string-join(
54+
for $f in xdmp:get-request-field-names()[fn:starts-with(., "rs:")]
55+
return
56+
$f || "=" || xdmp:get-request-field($f),
57+
"&amp;")
58+
return
59+
"/v1/resources/" || xdmp:get-request-field("name") || "?" || $params
60+
else
61+
$request-path
62+
return
63+
debug:log((
64+
"",
65+
"REQUEST DETAILS:",
66+
" [" || xdmp:get-request-method() || "] " || $request-path,
67+
"",
68+
" [Headers]",
69+
for $h in xdmp:get-request-header-names()
70+
return
71+
" " || $h || " => " || xdmp:get-request-header($h),
72+
"",
73+
" [Request Params]",
74+
for $p in xdmp:get-request-field-names()
75+
return
76+
" " || $p || " => " || xdmp:get-request-field($p),
77+
let $body := xdmp:get-request-body()
78+
return
79+
if (fn:exists($body)) then
80+
(
81+
"",
82+
" [Body]",
83+
$body
84+
)
85+
else (),
86+
"",
87+
""
88+
))
7689
};

0 commit comments

Comments
 (0)