// First update simple properties
super.updateResourceConfiguration(report);
// Then update models
ManagementView managementView = null;
ComponentType componentType = new ComponentType(
PluginConstants.ComponentType.VDB.TYPE,
PluginConstants.ComponentType.VDB.SUBTYPE);
ManagedComponent managedComponent = null;
CollectionValueSupport modelsMetaValue = null;
report.setStatus(ConfigurationUpdateStatus.SUCCESS);
try {
managementView = getConnection().getManagementView();
managedComponent = managementView.getComponent(this.name,
componentType);
modelsMetaValue = (CollectionValueSupport) managedComponent
.getProperty("models").getValue();
GenericValue[] models = (GenericValue[]) modelsMetaValue
.getElements();
List<Property> multiSourceModelsPropertyList = resourceConfiguration
.getList("multiSourceModels").getList();
List<Property> singleSourceModelsPropertyList = resourceConfiguration
.getList("singleSourceModels").getList();
ArrayList<List<Property>> sourceMappingList = new ArrayList<List<Property>>();
sourceMappingList.add(singleSourceModelsPropertyList);
sourceMappingList.add(multiSourceModelsPropertyList);
PropertyMap model = null;
Iterator<List<Property>> sourceMappingListIterator = sourceMappingList
.iterator();
while (sourceMappingListIterator.hasNext()) {
List<Property> sourceList = sourceMappingListIterator.next();
for (int i = 0; i < sourceList.size(); i++) {
model = (PropertyMap) sourceList.get(i);
String sourceName = ((PropertySimple) model
.get("sourceName")).getStringValue(); //$NON-NLS-1$
if (sourceName.equals("See below"))
continue; // This is a multisource model which we will
// handle separately
String modelName = ((PropertySimple) model.get("name")) //$NON-NLS-1$
.getStringValue();
String dsName = ((PropertySimple) model.get("jndiName")) //$NON-NLS-1$
.getStringValue();
ManagedObject managedModel = null;
if (models != null && models.length != 0) {
for (GenericValue genValue : models) {
ManagedObject mo = (ManagedObject) ((GenericValueSupport) genValue)
.getValue();
String name = ProfileServiceUtil.getSimpleValue(mo,
"name", String.class); //$NON-NLS-1$
if (modelName.equals(name)) {
managedModel = mo;
break;
}
}
}
ManagedProperty sourceMappings = null;
if (managedModel != null) {
sourceMappings = managedModel
.getProperty("sourceMappings");//$NON-NLS-1$
if (sourceMappings != null) {
CollectionValueSupport mappings = (CollectionValueSupport) sourceMappings
.getValue();
GenericValue[] mappingsArray = (GenericValue[]) mappings
.getElements();
for (GenericValue sourceGenValue : mappingsArray) {
ManagedObject sourceMo = (ManagedObject) ((GenericValueSupport) sourceGenValue)
.getValue();
String sName = ProfileServiceUtil
.getSimpleValue(sourceMo,
"name", String.class);//$NON-NLS-1$
if (sName.equals(sourceName)) {
// set the jndi name for the ds.
ManagedProperty jndiProperty = sourceMo
.getProperty("connectionJndiName"); //$NON-NLS-1$
jndiProperty
.setValue(ProfileServiceUtil.wrap(
SimpleMetaType.STRING,
dsName));
break;
}
}
}
}
}
}
try {
managementView.updateComponent(managedComponent);
managementView.load();
} catch (Exception e) {
LOG.error("Unable to update component ["
+ managedComponent.getName() + "] of type "
+ componentType + ".", e);
report.setStatus(ConfigurationUpdateStatus.FAILURE);