Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check-empty-type support to explicit load calls. #584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion framework/src/main/java/org/moqui/Moqui.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,31 @@ public static void loadData(Map<String, String> argMap) {

// set the data load parameters
EntityDataLoader edl = ec.getEntity().makeDataLoader();
Set<String> loadTypes = new HashSet<>();
if (argMap.containsKey("types")) {
String types = argMap.get("types");
if (!"all".equals(types)) edl.dataTypes(new HashSet<>(Arrays.asList(types.split(","))));
if (!"all".equals(types)) loadTypes.addAll(Arrays.asList(types.split(",")));
}
if (argMap.containsKey("check-empty-types")) {
String checkEmptyTypesStr = (String) argMap.get("check-empty-types");
List<String> checkEmptyTypes = new ArrayList(Arrays.asList(checkEmptyTypesStr.split(",")));
// Remove always-load types from the checkEmpty list
if (!loadTypes.isEmpty()) checkEmptyTypes.removeAll(loadTypes);
if ("all".equals(checkEmptyTypesStr)) {
logger.info("Check empty types set to \"all\", skipping empty database check");
} else if (checkEmptyTypes.isEmpty()) {
logger.info("Check empty types (" + checkEmptyTypesStr + ") in the always-load list, not checking for empty database");
} else {
long enumCount = ec.getEntity().find("moqui.basic.Enumeration").disableAuthz().count();
if (enumCount == 0) {
logger.info("Found " + enumCount + " Enumeration records, loading data types (" + String.join(",", checkEmptyTypes) + ")");
loadTypes.addAll(checkEmptyTypes);
} else {
logger.info("Found " + enumCount + " Enumeration records, NOT loading data types (" + String.join(",", checkEmptyTypes) + ")");
}
}
}
if (!loadTypes.isEmpty()) edl.dataTypes(loadTypes);
if (argMap.containsKey("components")) edl.componentNameList(Arrays.asList(argMap.get("components").split(",")));
if (argMap.containsKey("location")) edl.location(argMap.get("location"));
if (argMap.containsKey("timeout")) edl.transactionTimeout(Integer.valueOf(argMap.get("timeout")));
Expand Down