dl.setSql("common.getCustomField");
dl.setString(1, recordType);
Collection col = dl.executeQuery();
Iterator it = col.iterator();
while (it.hasNext()) {
CustomFieldVO field = new CustomFieldVO();
HashMap hm = (HashMap) it.next();
int fieldID = ((Long) hm.get("customfieldid")).intValue();
String label = (String) hm.get("name");
String fieldType = (String) hm.get("fieldtype");
int recordTypeID = ((Long) hm.get("recordtype")).intValue();
field.setFieldID(fieldID);
field.setLabel(label);
field.setFieldType(fieldType);
field.setRecordTypeID(recordTypeID);
cusData.put(String.valueOf(fieldID), field);
} // end of while
dl.setSqlQueryToNull();
// now get the all the values of custom fields for this record
String str = " SELECT cf.customfieldid, cf.name, cf.fieldtype,cf.recordType,cfv.valueid,cfv.value ,cfm.valueID as selected from customfield cf,customfieldvalue cfv left outer join customfieldmultiple cfm on ( cfv.customfieldid = cfm.customfieldid and cfv.valueid = cfm.valueid and cfm.recordid = "
+ recordID
+ " ),cvtable where cf.customfieldid = cfv.customfieldid and cf.recordtype = cvtable.tableid and cvtable.name = '"
+ recordType + "' ";
str = str
+ " union SELECT cf.customfieldid, cf.name, cf.fieldtype,cf.recordType,null ,cfs.value ,null as seleted from customfield cf,customfieldscalar cfs ,cvtable where cf.customfieldid = cfs.customfieldid and cf.recordtype = cvtable.tableid and cvtable.name = '"
+ recordType + "' and cfs.recordid = " + recordID + " order by value";
dl.setSqlQuery(str);
col = dl.executeQuery();
it = col.iterator();
while (it.hasNext()) {
HashMap hm = (HashMap) it.next();
int fieldID = ((Number) hm.get("customfieldid")).intValue();
String fieldType = (String) hm.get("fieldtype");
// The query returns scalars with the ID as NULL
// Also some non-selected multiples give NULL
// So we have to do something about that
Object valueIdObject = hm.get("valueid");
int valueId = 0;
if (valueIdObject != null) {
try {
valueId = Integer.parseInt(valueIdObject.toString());
} catch (NumberFormatException nfe) {}
}
String value = (String) hm.get("value");
Object selectedObject = hm.get("selected");
String selected;
if (selectedObject != null) {
selected = selectedObject.toString();
} else {
selected = "";
}
// Dig the custom field back out and set the options and values on it.
CustomFieldVO cf = (CustomFieldVO) cusData.get(String.valueOf(fieldID));
if (fieldType.equals("MULTIPLE")) {
Vector optionsVector = cf.getOptionValues();
if (optionsVector == null) {
optionsVector = new Vector();
DDNameValue dd = new DDNameValue(valueId, value);
optionsVector.add(dd);
} else {
DDNameValue dd = new DDNameValue(valueId, value);
optionsVector.add(dd);
}
cf.setOptionValues(optionsVector);
if (!selected.equals("")) {
cf.setValue(selected);
}
} else if (fieldType.equals("SCALAR")) {
cf.setValue(value);
}
} // end of while loop on values query
} catch (Exception e) {
logger.error("[getCustomFieldData] Exception thrown.", e);
throw new EJBException(e);