1818import java .io .File ;
1919import java .io .IOException ;
2020import java .util .ArrayList ;
21+ import java .util .Iterator ;
2122import java .util .List ;
2223
24+ import org .codehaus .jettison .json .JSONArray ;
25+ import org .codehaus .jettison .json .JSONException ;
26+ import org .codehaus .jettison .json .JSONObject ;
2327import org .slf4j .Logger ;
2428import org .slf4j .LoggerFactory ;
2529
@@ -54,7 +58,7 @@ public void addSourceDirectory(String directoryPath, SourceOptions options) {
5458 sources .add (source );
5559 }
5660
57- public void loadContent () throws IOException {
61+ public void loadContent () throws IOException , JSONException {
5862 for (MlcpSource source : sources ) {
5963 try {
6064 List <String > arguments = new ArrayList <>();
@@ -106,7 +110,7 @@ public String getSourcePath() {
106110 return sourcePath ;
107111 }
108112
109- public List <String > getMlcpArguments () throws IOException {
113+ public List <String > getMlcpArguments () throws IOException , JSONException {
110114 File file = new File (sourcePath );
111115 String canonicalPath = file .getCanonicalPath ();
112116
@@ -116,58 +120,51 @@ public List<String> getMlcpArguments() throws IOException {
116120
117121 arguments .add ("-input_file_path" );
118122 arguments .add (canonicalPath );
119- arguments .add ("-input_file_type" );
120- if (sourceOptions .getInputFileType () == null ) {
121- arguments .add ("documents" );
122- } else {
123- arguments .add (sourceOptions .getInputFileType ());
124- }
125-
126- if (sourceOptions .getInputFilePattern () != null ) {
127- arguments .add ("-input_file_pattern" );
128- arguments .add (sourceOptions .getInputFilePattern ());
129- }
130-
131- String collections = this .getOutputCollections ();
132- arguments .add ("-output_collections" );
133- arguments .add ("\" " + collections + "\" " );
134-
135- if (sourceOptions .getInputCompressed ()) {
136- arguments .add ("-input_compressed" );
137- }
123+ // arguments.add("-input_file_type");
124+ // if (sourceOptions.getInputFileType() == null) {
125+ // arguments.add("documents");
126+ // } else {
127+ // arguments.add(sourceOptions.getInputFileType());
128+ // }
129+
130+ // String collections = this.getOutputCollections();
131+ // arguments.add("-output_collections");
132+ // arguments.add("\"" + collections + "\"");
133+ //
134+ // if (sourceOptions.getInputCompressed()) {
135+ // arguments.add("-input_compressed");
136+ // }
138137
139138 // by default, cut the source directory path to make URIs shorter
140- String uriReplace = canonicalPath + ",''" ;
141- uriReplace = uriReplace .replaceAll ("\\ \\ " , "/" );
142-
143- arguments .add ("-output_uri_replace" );
144- arguments .add ("\" " + uriReplace + "\" " );
139+ // String uriReplace = canonicalPath + ",''";
140+ // uriReplace = uriReplace.replaceAll("\\\\", "/");
141+ //
142+ // arguments.add("-output_uri_replace");
143+ // arguments.add("\"" + uriReplace + "\"");
145144
146145 arguments .add ("-document_type" );
147146 arguments .add (sourceOptions .getDataFormat ());
148-
149- arguments .add ("-transform_module" );
150- arguments .add ("/com.marklogic.hub/mlcp-flow-transform.xqy" );
151- arguments .add ("-transform_namespace" );
152- arguments .add ("http://marklogic.com/data-hub/mlcp-flow-transform" );
153- arguments .add ("-transform_param" );
154- arguments .add ("\" " + sourceOptions .getTransformParams () + "\" " );
147+
148+ addOtherArguments (arguments , sourceOptions .getOtherOptions ());
155149 return arguments ;
156150 }
157151
158- private String getOutputCollections () {
159- StringBuilder collectionsBuilder = new StringBuilder ();
160- collectionsBuilder .append (sourceOptions .getEntityName ());
161- collectionsBuilder .append ("," );
162- collectionsBuilder .append (sourceOptions .getFlowName ());
163- collectionsBuilder .append ("," );
164- collectionsBuilder .append (sourceOptions .getFlowType ());
165- if (sourceOptions .getCollection () != null ) {
166- collectionsBuilder .append ("," );
167- collectionsBuilder .append (sourceOptions .getCollection ());
168- }
169- return collectionsBuilder .toString ();
170- }
152+ private void addOtherArguments (List <String > arguments ,
153+ String otherOptions ) throws JSONException {
154+ JSONArray jsonArray = new JSONArray (otherOptions );
155+ for (int i = 0 ; i < jsonArray .length (); i ++) {
156+ JSONObject jsonObject = jsonArray .getJSONObject (i );
157+ @ SuppressWarnings ("rawtypes" )
158+ Iterator keysIterator = jsonObject .keys ();
159+ while (keysIterator .hasNext ()) {
160+ String key = (String )keysIterator .next ();
161+ arguments .add (key );
162+ arguments .add (jsonObject .getString (key ));
163+ }
164+
165+ }
166+
167+ }
171168 }
172169
173170 public static class SourceOptions {
@@ -176,9 +173,7 @@ public static class SourceOptions {
176173 private String flowType ;
177174 private String dataFormat = "json" ;
178175 private String inputFileType ;
179- private String inputFilePattern ;
180- private String collection ;
181- private boolean inputCompressed = false ;
176+ private String otherOptions ;
182177
183178 public SourceOptions (String entityName , String flowName , String flowType , Format dataFormat ) {
184179 this .entityName = entityName ;
@@ -215,35 +210,13 @@ public String getInputFileType() {
215210 public void setInputFileType (String inputFileType ) {
216211 this .inputFileType = inputFileType ;
217212 }
213+
214+ public String getOtherOptions () {
215+ return otherOptions ;
216+ }
218217
219- public String getInputFilePattern () {
220- return inputFilePattern ;
221- }
222-
223- public void setInputFilePattern (String inputFilePattern ) {
224- this .inputFilePattern = inputFilePattern ;
225- }
226-
227- public String getCollection () {
228- return collection ;
229- }
230-
231- public void setCollection (String collection ) {
232- this .collection = collection ;
233- }
234-
235- public void setInputCompressed (boolean inputCompressed ) {
236- this .inputCompressed = inputCompressed ;
237- }
238-
239- public boolean getInputCompressed () {
240- return this .inputCompressed ;
241- }
242-
243- protected String getTransformParams () {
244- return String .format (
245- "<params><entity-name>%s</entity-name><flow-name>%s</flow-name><flow-type>%s</flow-type></params>" ,
246- entityName , flowName , flowType );
247- }
218+ public void setOtherOptions (String otherOptions ) {
219+ this .otherOptions = otherOptions ;
220+ }
248221 }
249222}
0 commit comments