}
@Override
public void loadAdditionalComponentAttributes() throws FactoryException, JAXBException {
com.salesforce.ide.api.metadata.types.ReportType reportType = null;
DescribeSObjectResult primaryObject = null;
DescribeObjectRegistry describeObjectRegistry = null;
try {
reportType = (com.salesforce.ide.api.metadata.types.ReportType) component.getDefaultMetadataExtInstance();
describeObjectRegistry = getComponentFactory().getConnectionFactory().getDescribeObjectRegistry();
// BaseObject here is plural form save from user inpurt in Ui
primaryObject =
describeObjectRegistry.getCachedDescribeByPluralLabel(getProject(), reportType.getBaseObject());
} catch (InstantiationException e) {
logger.warn("Unable to instantiate default metadataExt instance for Report Type", e);
} catch (IllegalAccessException e) {
logger.warn("Unable to instantiate default metadataExt instance for Report Type", e);
} catch (Exception e) {
logger.warn("Unable to get describeObject for " + reportType.getBaseObject(), e);
}
if (Utils.isEmpty(primaryObject)) {
logger.error("Unable to load additional component attributes for Report Type '" + reportType.getLabel()
+ "' due to unable to locate primary object '" + reportType.getBaseObject()
+ "' from DescribeObjectRegistry");
return;
}
// load all fields & sections from primary object
ReportLayoutSection section = new ReportLayoutSection();
section.setMasterLabel(primaryObject.getLabelPlural()); // Master label is plural label of describeObject
// exclude fields that describeSObject returned as extra: default + sobject specific set.
List<String> excludeFieldList = new ArrayList<String>();
List<String> defaultExcludeFieldList =
describeObjectRegistry.getExcludedCrtFields().get(DEFAULT_EXCLUDED_FIELD_KEY);
excludeFieldList.addAll(defaultExcludeFieldList);
List<String> sObjectSpecificExcludedList =
describeObjectRegistry.getExcludedCrtFields().get(primaryObject.getName());
if (Utils.isNotEmpty(sObjectSpecificExcludedList)) {
excludeFieldList.addAll(sObjectSpecificExcludedList);
}
String tableName = primaryObject.getName(); // Table label is name of describeSObject
Field[] fields = primaryObject.getFields();
for (Field field : fields) {
if (excludeFieldList.contains(field.getName()))
continue;
// skip Person Account related fields
if (tableName.equalsIgnoreCase("Account")
&& (field.getName().contains("Person") || field.getName().endsWith("__pc")))
continue;
String fieldName = field.getName();
// use relationshipName instead when soapType is Id
if (field.getType() == com.sforce.soap.partner.wsc.FieldType.reference
&& !field.getName().equalsIgnoreCase("Id")) {
// if relationshipName is null then use fieldName but remove trailing "Id"
fieldName =
Utils.isNotEmpty(field.getRelationshipName()) ? field.getRelationshipName() : fieldName
.substring(0, fieldName.length() - 2);
}
ReportTypeColumn column = new ReportTypeColumn();
column.setCheckedByDefault(false);
column.setField(fieldName);
column.setTable(tableName);
section.getColumns().add(column);
}
reportType.getSections().clear(); // spring bean, reportTypeMetadata is singleton; therefore, content from
// previous session won't be clean-up.
reportType.getSections().add(section);
reportType.setBaseObject(primaryObject.getName()); // replace Ui input string which is in plural label form
// with name of describeSObject.
// unmarshall component and init componet body
saveMetadata(component);
if (logger.isDebugEnabled()) {