Skip to content

Commit 1fba21f

Browse files
committed
Merge pull request #63 from paxtonhare/5_spec_for_plugins
5 spec for plugins
2 parents 0d5076d + 560650b commit 1fba21f

Some content is hidden

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

61 files changed

+1005
-441
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+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ public void runFlowsInParallel(Flow ... flows) {
204204
public static Flow flowFromXml(Element doc) {
205205
Flow f = null;
206206

207-
String format = null;
208-
NodeList elements = doc.getElementsByTagNameNS(HUB_NS, "format");
207+
String complexity = null;
208+
NodeList elements = doc.getElementsByTagNameNS(HUB_NS, "complexity");
209209
if (elements.getLength() == 1) {
210-
format = elements.item(0).getTextContent();
210+
complexity = elements.item(0).getTextContent();
211211
}
212212

213-
if (format.equals("simple")) {
213+
if (complexity.equals(FlowComplexity.SIMPLE.toString())) {
214214
SimpleFlow sf = new SimpleFlow(doc);
215215
f = sf;
216216
}
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/collector/AbstractCollector.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@
2020
import javax.xml.stream.XMLStreamException;
2121
import javax.xml.stream.XMLStreamWriter;
2222

23+
import com.marklogic.hub.plugin.PluginType;
24+
2325
public abstract class AbstractCollector implements Collector {
2426

25-
private String type;
27+
private PluginType type;
2628

27-
public AbstractCollector(String type) {
29+
public AbstractCollector(PluginType type) {
2830
this.type = type;
2931
}
3032

3133
@Override
32-
public String getType() {
34+
public PluginType getType() {
3335
return this.type;
3436
}
3537

data-hub/src/main/java/com/marklogic/hub/collector/Collector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import javax.xml.stream.XMLStreamException;
2121
import javax.xml.stream.XMLStreamWriter;
2222

23+
import com.marklogic.hub.plugin.PluginType;
24+
2325
public interface Collector {
2426

25-
String getType();
27+
PluginType getType();
2628
List<String> run();
2729
void serialize(XMLStreamWriter serializer) throws XMLStreamException;
2830
}

data-hub/src/main/java/com/marklogic/hub/collector/QueryCollector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
import java.util.List;
1919

20+
import com.marklogic.hub.plugin.PluginType;
21+
2022
public class QueryCollector extends ServerCollector {
2123

2224
public static final String MODULE = "/com.marklogic.hub/collectors/query.xqy";
2325

2426
public QueryCollector() {
25-
super("xquery", MODULE);
27+
super(PluginType.XQUERY, MODULE);
2628
}
2729

2830
@Override

data-hub/src/main/java/com/marklogic/hub/collector/ServerCollector.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
import com.marklogic.client.extensions.ResourceServices.ServiceResultIterator;
2828
import com.marklogic.client.io.JacksonDatabindHandle;
2929
import com.marklogic.client.util.RequestParameters;
30+
import com.marklogic.hub.plugin.PluginType;
3031

3132
public class ServerCollector extends AbstractCollector {
3233

3334
private DatabaseClient client = null;
3435
private String module;
3536

36-
public ServerCollector(String type, String module) {
37+
public ServerCollector(PluginType type, String module) {
3738
super(type);
3839
this.module = module;
3940
}
@@ -53,7 +54,7 @@ public String getModule() {
5354
@Override
5455
public void serialize(XMLStreamWriter serializer) throws XMLStreamException {
5556
serializer.writeStartElement("collector");
56-
serializer.writeAttribute("type", getType());
57+
serializer.writeAttribute("type", getType().toString());
5758
serializer.writeAttribute("module", this.module);
5859
serializer.writeEndElement();
5960

0 commit comments

Comments
 (0)