String fileToRedirect = "";
try {
for (Object o : fileItemsMap.keySet()) {
String fieldName = (String) o;
if ("factFilename".equals(fieldName)) {
FileItemData fileItemData = fileItemsMap.get(fieldName).get(0);
String fileName = getFileName(fileItemData.getFileItem().getName());
checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);
if (fileName.endsWith(".jar")) {
String[] facts =
adminClient.uploadFacts(ruleServiceName,
fileName, fileItemData.getDataHandler(), request);
request.getSession().setAttribute(RuleServiceAdminClient.FACTS, facts);
String[] allFacts = ((String[]) request.getSession().getAttribute("allFacts"));
if (allFacts != null) {
if (allFacts.length > 0) {
HashSet<String> factSet = new HashSet<String>();
for (String fact : allFacts) {
factSet.add(fact);
}
for (String fact : facts) {
factSet.add(fact);
}
String[] mergedFacts = factSet.toArray(new String[factSet.size()]);
request.getSession().setAttribute("allFacts", mergedFacts);
}
} else {
HashSet<String> factSet = new HashSet<String>();
for (String fact : facts) {
factSet.add(fact);
}
String[] mergedFacts = factSet.toArray(new String[factSet.size()]);
request.getSession().setAttribute("allFacts", mergedFacts);
}
} else {
throw new CarbonException("File with extension " + fileName
+ " is not supported!");
}
msg = "Facts file uploaded successfully.";
fileToRedirect = "/ruleservices/rule_service_wizard_step3.jsp";
} else if ("ruleFilename".equals(fieldName)) {
FileItemData fileItemData = fileItemsMap.get(fieldName).get(0);
String fileName = getFileName(fileItemData.getFileItem().getName());
adminClient.uploadRuleFile(ruleServiceName,
fileName, fileItemData.getDataHandler(), request);
msg = "Rule Script file uploaded successfully.";
fileToRedirect = "/ruleservices/rule_service_wizard_step2.jsp";
}
}
response.setContentType("text/html; charset=utf-8");