List<IModelViewEntityDescriptor> list = getDataSource().getConfiguration().loadViews();
if(list.size() > 0) {
for (int i=0; i<list.size(); i++){
IModelViewEntityDescriptor viewDescriptor = list.get(i);
ModelViewEntity viewEntity = new ModelViewEntity(viewDescriptor, modelName, modelStructure, null);
addedViewsEntities.add(viewEntity);
propertiesInitializer.addProperties(viewEntity);
modelStructure.addRootEntity(modelName, viewEntity);
}
}
/*
* 2) Re-scan model structure to add nodes referencing view (inbound relations to Business Views)
*/
//visit all entities
List<IModelEntity> allEntities = visitModelStructure(modelStructure,modelName);
for (int i=0; i<list.size(); i++){
IModelViewEntityDescriptor viewDescriptor = list.get(i);
List<IModelViewRelationshipDescriptor> viewRelationshipsDescriptors = viewDescriptor.getRelationshipDescriptors();
for (IModelViewRelationshipDescriptor viewRelationshipDescriptor : viewRelationshipsDescriptors){
if (!viewRelationshipDescriptor.isOutbound()){
String sourceEntityUniqueName = viewRelationshipDescriptor.getSourceEntityUniqueName();
IModelEntity entity = modelStructure.getEntity(sourceEntityUniqueName);
logger.debug("Source Entity Unique name: "+entity.getUniqueName());
//Add node for first level entities (using UniqueName)
ModelViewEntity viewEntity = new ModelViewEntity(viewDescriptor, modelName, modelStructure, entity);
propertiesInitializer.addProperties(viewEntity);
entity.addSubEntity(viewEntity);
//Add node for subentities (using Entity Type matching)
for(IModelEntity modelEntity : allEntities){
logger.debug("Searched Entity type: "+entity.getType());
logger.debug("Current Entity type: "+modelEntity.getType());
if (modelEntity.getType().equals(entity.getType())){
ModelViewEntity viewEntitySub = new ModelViewEntity(viewDescriptor, modelName, modelStructure, modelEntity);
propertiesInitializer.addProperties(viewEntitySub);
logger.debug(" ** Found matching for: "+modelEntity.getType()+" with "+entity.getType());
modelEntity.addSubEntity(viewEntitySub);
addedViewsEntities.add(viewEntitySub);
}