try {
String[] allValues = digester.getLine();
List<HhDatumRaw> hhData = new ArrayList<HhDatumRaw>();
while (allValues != null && !shouldHalt()) {
if (allValues.length < 2) {
throw new UserException(
"There must be an 'Action' field followed "
+ "by a 'Type' field.");
}
Hiber.setReadWrite();
String action = allValues[0].trim().toLowerCase();
String type = allValues[1].trim().toLowerCase();
if (type.equals("hh-datum")) {
try {
long startProchh = System.currentTimeMillis();
if (action.equals("insert")) {
String mpanCore = allValues[2];
boolean isImport = Boolean
.parseBoolean(allValues[4]);
boolean isKwh = Boolean.parseBoolean(allValues[5]);
HhStartDate startDate = new HhStartDate(
allValues[3]);
String hhString = allValues[6].trim();
if (hhString.endsWith(",")) {
hhString = hhString + " ";
}
String[] vals = hhString.split(",");
if (vals.length % 2 != 0) {
StringBuilder valsBuilder = new StringBuilder();
for (String val : vals) {
valsBuilder.append(val + " ");
}
throw new UserException(
"There must be an even number of values in the list of hh data. This list is "
+ valsBuilder + ".");
}
for (int i = 0; i < vals.length; i += 2) {
String bigDecimal = vals[i];
if (bigDecimal.length() > 0) {
Character status = null;
String statusString = vals[i + 1].trim();
if (statusString.length() > 0) {
status = statusString.charAt(0);
}
hhData.add(new HhDatumRaw(mpanCore,
isImport, isKwh, startDate,
new BigDecimal(bigDecimal), status));
}
startDate = startDate.getNext();
}
HhDatum.insert(hhData.iterator(), halt);
hhData.clear();
}
totalHhTime = totalHhTime + System.currentTimeMillis()
- startProchh;
} catch (UserException e) {
StringBuilder message = new StringBuilder(
"Problem loading a HH datum with values: ");
for (String value : allValues) {
message.append(value + ", ");
}
throw new UserException(message + ". Message: "
+ e.getMessage());
}
} else {
csvElement = doc.createElement("csvLine");
// try {
addField(csvElement, "Action", allValues, 0);
addField(csvElement, "Type", allValues, 1);
if (!action.equals("insert") && !action.equals("update")
&& !action.equals("delete")) {
throw new UserException("The 'Action' field can "
+ "only be 'insert', 'update', 'delete'.");
}
String[] values = Arrays.copyOfRange(allValues, 2,
allValues.length);
if (type.equals("site")) {
Site.generalImport(action, values, csvElement);
} else if (type.equals("site-supply-generation")) {
SiteSupplyGeneration.generalImport(action, values,
csvElement);
} else if (type.equals("supply")) {
Supply.generalImport(action, values, csvElement);
} else if (type.equals("supply-generation")) {
SupplyGeneration.generalImport(action, values,
csvElement);
} else if (type.equals("report")) {
Report.generalImport(action, values, csvElement);
} else if (type.equals("hhdc-contract-rate-script")) {
RateScript
.generalImportHhdc(action, values, csvElement);
} else if (type.equals("non-core-contract")) {
NonCoreContract.generalImport(action, values,
csvElement);
} else if (type.equals("non-core-contract-rate-script")) {
RateScript.generalImportNonCore(action, values,
csvElement);
} else if (type.equals("supplier-contract")) {
SupplierContract.generalImport(action, values,
csvElement);
} else if (type.equals("supplier-contract-rate-script")) {
RateScript.generalImportSupplier(action, values,
csvElement);
} else if (type.equals("user")) {
User.generalImport(action, values, csvElement);
} else if (type.equals("dno-contract")) {
DnoContract.generalImport(action, values, csvElement);
} else if (type.equals("dno-contract-rate-script")) {
RateScript.generalImportDno(action, values, csvElement);
} else if (type.equals("configuration")) {
Configuration.generalImport(action, values, csvElement);
} else if (type.equals("channel-snag-ignore")) {
ChannelSnag.generalImport(action, values, csvElement);
} else if (type.equals("site-snag-ignore")) {
SiteSnag.generalImport(action, values, csvElement);
} else if (type.equals("batch")) {
Batch.generalImport(action, values, csvElement);
} else if (type.equals("bill")) {
Bill.generalImport(action, values, csvElement);
} else if (type.equals("register-read")) {
RegisterRead.generalImport(action, values, csvElement);
} else if (type.equals("mop-contract")) {
MopContract.generalImport(action, values, csvElement);
} else if (type.equals("mop-contract-rate-script")) {
RateScript.generalImportMop(action, values, csvElement);
} else {
throw new UserException("The type " + type
+ " isn't recognized.");
}
csvElement = null;
}
Hiber.commit();