dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18396
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7742: local/in: Fix in Generate Global Config Module
------------------------------------------------------------
revno: 7742
committer: Gaurav <gaurav08021@xxxxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-07-27 17:46:33 +0530
message:
local/in: Fix in Generate Global Config Module
modified:
local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultGlobalConfigService.java
local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultGlobalConfigService.java'
--- local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultGlobalConfigService.java 2012-07-02 07:12:06 +0000
+++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultGlobalConfigService.java 2012-07-27 12:16:33 +0000
@@ -25,7 +25,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
/**
* <gaurav>,Date: 6/25/12, Time: 12:42 PM
*/
@@ -80,6 +79,17 @@
return raFile.listFiles();
}
+ public static boolean isParsable2Int(String intString) {
+ if (intString.trim().isEmpty()) {
+ return false;
+ }
+ for (char c : intString.trim().toCharArray()) {
+ if (!Character.isDigit(c)) return false;
+ }
+
+ return true;
+ }
+
//----------------------------------------------------------------------------------------------
// Implementation: Replace local De-Code Values with auto-generated Global Values
//----------------------------------------------------------------------------------------------
@@ -105,13 +115,14 @@
Document doc = docBuilder.parse(file);
- NodeList listofDECodes = doc.getElementsByTagName("de-code");
+ NodeList listOfDECodes = doc.getElementsByTagName("de-code");
- int totalCodes = listofDECodes.getLength();
+ int totalCodes = listOfDECodes.getLength();
for (int i = 0; i < totalCodes; i++) {
- Element deCodeElemnt = (Element) listofDECodes.item(i);
- NodeList textCodeList = deCodeElemnt.getChildNodes();
+
+ Element deCodeElement = (Element) listOfDECodes.item(i);
+ NodeList textCodeList = deCodeElement.getChildNodes();
String expression = (textCodeList.item(0).getNodeValue().trim());
String res;
@@ -120,24 +131,30 @@
String gconfig;
while (matcher.find()) {
+
res = matcher.group(1);
- if (!(globalValueMap.containsKey(res))) {
- globalValueMap.put(res, globalID.toString());
-
- globalID++;
+
+ if (!(globalValueMap.containsKey(res)))
+ {
+ globalValueMap.put(res, globalID.toString());
+
+ globalID++;
}
- gconfig = globalValueMap.get(res);
- expression = expression.replace("[" + res + "]", "[" + gconfig + "]");
+ gconfig = globalValueMap.get(res);
+
+ expression = expression.replace("[" + res + "]", "[" + gconfig + "]");
+
}
-
res = expression;
textCodeList.item(0).setNodeValue(res);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
+
Transformer transformer = null;
+
try {
transformer = transformerFactory.newTransformer();
@@ -158,12 +175,14 @@
if (!newOutFile.exists()) {
boolean isCreated = newOutFile.createNewFile();
+
if (isCreated == false) {
System.out.println("*ERROR: [FAILED TO CREATE UPDATED XML FILE: " + newOutFile.getName() + " ]");
}
}
StreamResult result = new StreamResult(newOutFile);
+
try {
transformer.transform(source, result);
} catch (TransformerException e) {
@@ -226,57 +245,66 @@
replaceString = replaceString.substring(0, replaceString.indexOf('.'));
- int dataElementId = Integer.parseInt(replaceString);
- int optionComboId = Integer.parseInt(optionComboIdStr);
-
- if (dataElementService == null) {
- System.out.println("*ERROR:[Dataelement service is NULL]");
- }
- DataElement dataElement = dataElementService.getDataElement(dataElementId);
- DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo(optionComboId);
-
-
- if (dataElement != null && optionCombo != null) {
-
- if (optionComboId == 1) {
- Attr deNameAttr = doc.createAttribute("de-name");
- String deName = dataElement.getName().replace('\"', ' ').replace('\'', ' ');
- deNameAttr.setValue(deName);
- gConfig.setAttributeNode(deNameAttr);
+ int dataElementId;
+ int optionComboId;
+
+ if (isParsable2Int(replaceString) && isParsable2Int(optionComboIdStr)) {
+
+ dataElementId = Integer.parseInt(replaceString);
+ optionComboId = Integer.parseInt(optionComboIdStr);
+
+
+ if (dataElementService == null) {
+ System.out.println("*ERROR:[Data-element service is NULL]");
+ }
+
+ DataElement dataElement = dataElementService.getDataElement(dataElementId);
+ DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo(optionComboId);
+
+
+ if (dataElement != null && optionCombo != null) {
+
+ if (optionComboId == 1) {
+ Attr deNameAttr = doc.createAttribute("de-name");
+ String deName = dataElement.getName().replace('\"', ' ').replace('\'', ' ');
+ deNameAttr.setValue(deName);
+ gConfig.setAttributeNode(deNameAttr);
+ } else {
+ Attr deNameAttr = doc.createAttribute("de-name");
+ String optionName = optionCombo.getName().replace('(', ' ').replace(')', ' ');
+ String deName = dataElement.getName().replace('\"', ' ').replace('\'', ' ');
+ deNameAttr.setValue(deName + " [" + optionName + "]");
+ gConfig.setAttributeNode(deNameAttr);
+ }
+
} else {
+
+ System.out.println("\n* INFO [ DATA-ELEMENT OR OPTION_COMBO MISSING (" + dataElementId + ")]");
+
Attr deNameAttr = doc.createAttribute("de-name");
- String optionName = optionCombo.getName().replace('(', ' ').replace(')', ' ');
- String deName = dataElement.getName().replace('\"', ' ').replace('\'', ' ');
- deNameAttr.setValue(deName + " [" + optionName + "]");
+ deNameAttr.setValue("NA" + "(NA)");
gConfig.setAttributeNode(deNameAttr);
+
}
- } else {
-
- System.out.println("\n* INFO [ DATAELEMENT OR OPTION_COMBO MISSING (" + dataElementId + ")]");
-
- Attr deNameAttr = doc.createAttribute("de-name");
- deNameAttr.setValue("NA" + "(NA)");
- gConfig.setAttributeNode(deNameAttr);
-
}
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+ DOMSource source = new DOMSource(doc);
+
+ StreamResult result = new StreamResult(new File(OUTPUT_FOLDER + "/" + SETTINGS_XML));
+ transformer.transform(source, result);
}
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- Transformer transformer = transformerFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-
- DOMSource source = new DOMSource(doc);
-
- StreamResult result = new StreamResult(new File(OUTPUT_FOLDER + "/" + SETTINGS_XML));
- transformer.transform(source, result);
-
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (TransformerException tfe) {
tfe.printStackTrace();
}
+
}
=== modified file 'local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java'
--- local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java 2012-07-26 09:20:56 +0000
+++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java 2012-07-27 12:16:33 +0000
@@ -403,9 +403,6 @@
Pattern p = Pattern.compile( "\\[(.*?)\\]" );
Matcher matcher = p.matcher( expression );
-
- System.out.println( "*INFO :Expression: " + expression );
-
String localValue;
while ( matcher.find() )
@@ -416,9 +413,6 @@
}
result = expression;
-
- System.out.println( "*INFO :Result:" + result );
-
return result;
}