Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build/
.gradle/
.idea
.project
.DS_Store
/.nb-gradle/
/eclipse_bin/
target/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Option | Description
**<a name="EXPORT-FILE-DIR"></a>EXPORT-FILE-DIR** | Export directory parameter is used by `com.marklogic.developer.corb.ExportBatchToFileTask` or similar custom task implementations. <br/>Optional: Alternatively, **EXPORT-FILE-NAME** can be specified with a full path.
**<a name="EXPORT-FILE-NAME"></a>EXPORT-FILE-NAME** | Shared file to write output of `com.marklogic.developer.corb.ExportBatchToFileTask` - should be a file name with our without full path. <ul><li>**EXPORT-FILE-DIR** Is not required if a full path is used.</li><li>If **EXPORT-FILE-NAME** is not specified, CoRB attempts to use **URIS\_BATCH\_REF** as the file name and this is especially useful in case of automated jobs where file name can only be determined by the **URIS-MODULE** - refer to **URIS\_BATCH\_REF** section below.</li></ul>
**<a name="EXPORT-FILE-PART-EXT"></a>EXPORT-FILE-PART-EXT** | The file extension for export files being processed. ex: .tmp - if specified, `com.marklogic.developer.corb.PreBatchUpdateFileTask` adds this temporary extension to the export file name to indicate **EXPORT-FILE-NAME** is being actively modified. To remove this temporary extension after **EXPORT-FILE-NAME** is complete, `com.marklogic.developer.corb.PostBatchUpdateFileTask` must be specified as **POST-BATCH-TASK**.
**<a name="EXPORT-FILE-REQUIRE-PROCESS-MODULE"></a>EXPORT-FILE-REQUIRE-PROCESS-MODULE** | Boolean value indicating whether or not to require a **PROCESS-MODULE** when an Export*ToFile PROCESS-TASK is specified. This can help avoid confusion when the **PROCESS-MODULE** was accidentally not configured and no files are generated. Default is `true`
**<a name="EXPORT-FILE-SORT"></a>EXPORT-FILE-SORT** | If `ascending` or `descending`, lines will be sorted. If <code>&#124;distinct</code> is specified after the sort direction, duplicate lines from **EXPORT-FILE-NAME** will be removed. i.e. <code>ascending&#124;distinct</code> or <code>descending&#124;distinct</code>
**<a name="EXPORT-FILE-SORT-COMPARATOR"></a>EXPORT-FILE-SORT-COMPARATOR** | A java class that must implement `java.util.Comparator`. If specified, CoRB will use this class for sorting in place of ascending or descending string comparator even if a value was specified for **EXPORT-FILE-SORT**.
**<a name="EXPORT-FILE-TOP-CONTENT"></a>EXPORT-FILE-TOP-CONTENT** | Used by `com.marklogic.developer.corb.PreBatchUpdateFileTask` to insert content at the top of **EXPORT-FILE-NAME** before batch process starts. If it includes the string `@URIS_BATCH_REF`, it is replaced by the batch reference returned by **URIS-MODULE**.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ bootstrapVersion=3.4.1
externalsortinginjavaVersion=0.6.0
jqueryVersion=3.6.0
# 2.1.2 First version built and published with Gradle
version=2.5.4
version=2.5.5
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.marklogic.developer.corb.util.StringUtils.isNotEmpty;
import static com.marklogic.developer.corb.util.StringUtils.trimToEmpty;

import com.marklogic.developer.corb.util.StringUtils;
import com.marklogic.xcc.ResultSequence;

import java.io.*;
Expand Down Expand Up @@ -108,4 +109,12 @@ protected String processResult(ResultSequence seq) throws CorbException {
}
}

@Override
protected String[] invokeModule() throws CorbException {
if (StringUtils.isEmpty(adhocQuery) && StringUtils.isEmpty(moduleUri)
&& StringUtils.stringToBoolean(getProperty(Options.EXPORT_FILE_REQUIRE_PROCESS_MODULE), true)) {
throw new CorbException(Options.PROCESS_MODULE + " must be specified.");
}
return super.invokeModule();
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/marklogic/developer/corb/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,16 @@ public final class Options {
+ "must be specified as POST-BATCH-TASK.")
public static final String EXPORT_FILE_PART_EXT = "EXPORT-FILE-PART-EXT";

/**
* Boolean value indicating whether or not to require a PROCESS-MODULE when an Export*ToFile {@value #PROCESS_TASK} is specified.
* This can help avoid confusion when the {@PROCESS_MODULE} was accidentally not configured and no files are generated.
* Default is true
*
* @since 2.5.5
*/
@Usage(description = "Boolean value indicating whether or not to require a PROCESS-MODULE when an Export*ToFile PROCESS-TASK is specified. This can help avoid confusion when the PROCESS-MODULE was accidentally not configured and no files are generated. Default is true")
public static final String EXPORT_FILE_REQUIRE_PROCESS_MODULE = "EXPORT-FILE-REQUIRE-PROCESS-MODULE";

/**
* If "{@code ascending}" or "{@code descending}", lines will be sorted. If
* "{@code |distinct}" is specified after the sort direction, duplicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,43 @@ public void testCleanup() {
assertNull(instance.exportDir);
}

@Test
public void testCall() {
@Test (expected=CorbException.class)
public void testCall()throws CorbException {
ExportToFileTask instance = new ExportToFileTask();
String[] result;
try {
result = instance.call();
assertNotNull(result);
assertTrue(result.length == 0);
instance.call();
} catch (CorbException ex) {
throw ex;
} catch (Exception ex) {
LOG.log(Level.SEVERE, null, ex);
fail();
}
fail();
}

@Test (expected=CorbException.class)
public void testInvokeModule() throws CorbException {
ExportToFileTask exportToFileTask = new ExportToFileTask();
exportToFileTask.invokeModule();
fail();
}

@Test
public void testInvokeModuleNoModuleNotRequired() {
ExportToFileTask exportToFileTask = new ExportToFileTask();
exportToFileTask.properties.setProperty(Options.EXPORT_FILE_REQUIRE_PROCESS_MODULE, "false");
try {
String[] result = exportToFileTask.invokeModule();
assertEquals(result.length, 0);
} catch (CorbException ex) {
fail();
}
}

@Test (expected = CorbException.class)
public void testInvokeModuleNoModuleRequired() throws CorbException {
ExportToFileTask exportToFileTask = new ExportToFileTask();
exportToFileTask.properties.setProperty(Options.EXPORT_FILE_REQUIRE_PROCESS_MODULE, "true");
exportToFileTask.invokeModule();
fail();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ public void testNoResultsPrePostBatchAlwaysExecuteTrue() {
props.setProperty(Options.POST_BATCH_MINIMUM_COUNT, Integer.toString(0));
props.setProperty(Options.EXPORT_FILE_TOP_CONTENT, "top content");
props.setProperty(Options.PRE_BATCH_TASK, PRE_BATCH_TASK);
props.setProperty(Options.EXPORT_FILE_REQUIRE_PROCESS_MODULE,"false");
props.setProperty(Options.EXPORT_FILE_BOTTOM_CONTENT, "bottom content");
props.setProperty(Options.POST_BATCH_TASK, POST_BATCH_TASK);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public void testCallRemoveDuplicatesAndSortEmptyFileExtensionWithoutDot() {
props.setProperty(Options.EXPORT_FILE_SORT, Boolean.toString(true));
props.setProperty(Options.EXPORT_FILE_NAME, file.toString());
props.setProperty(Options.EXPORT_FILE_PART_EXT, "pt");
props.setProperty(Options.EXPORT_FILE_REQUIRE_PROCESS_MODULE, "false");
PostBatchUpdateFileTask instance = new PostBatchUpdateFileTask();
instance.properties = props;
instance.call();
Expand All @@ -423,6 +424,7 @@ public void testCallRemoveDuplicatesAndSortEmptyFileEmptyExtension() {
props.setProperty(Options.EXPORT_FILE_SORT, Boolean.TRUE.toString());
props.setProperty(Options.EXPORT_FILE_NAME, file.toString());
props.setProperty(Options.EXPORT_FILE_PART_EXT, "");
props.setProperty(Options.EXPORT_FILE_REQUIRE_PROCESS_MODULE, "false");
PostBatchUpdateFileTask instance = new PostBatchUpdateFileTask();
instance.properties = props;
instance.call();
Expand Down Expand Up @@ -452,7 +454,7 @@ private String testRemoveDuplicatesAndSort(File fileToSort, Properties props)

props.setProperty(Options.EXPORT_FILE_AS_ZIP, Boolean.FALSE.toString());
props.setProperty(Options.EXPORT_FILE_NAME, fileToSort.toString());

props.setProperty(Options.EXPORT_FILE_REQUIRE_PROCESS_MODULE, "false");
PostBatchUpdateFileTask instance = new PostBatchUpdateFileTask();
instance.properties = props;
instance.call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void testCall() {
Properties props = new Properties();
props.setProperty(Options.EXPORT_FILE_TOP_CONTENT, content);
props.setProperty(Options.EXPORT_FILE_NAME, tempFile.getName());

props.setProperty(Options.EXPORT_FILE_REQUIRE_PROCESS_MODULE, "false");
PreBatchUpdateFileTask instance = new PreBatchUpdateFileTask();
instance.properties = props;
instance.exportDir = tempDir.toString();
Expand Down