if (viewName == null || viewName.isEmpty()) {
throw new IllegalArgumentException("View name must be provided");
}
viewName = ViewEntity.getViewName(viewName, version);
ViewInstanceEntity viewInstanceEntity = new ViewInstanceEntity();
viewInstanceEntity.setName(name);
viewInstanceEntity.setViewName(viewName);
ViewEntity viewEntity = new ViewEntity();
viewEntity.setName(viewName);
viewEntity.setVersion(version);
viewInstanceEntity.setViewEntity(viewEntity);
Collection<ViewInstancePropertyEntity> instanceProperties = new HashSet<ViewInstancePropertyEntity>();
Collection<ViewInstanceDataEntity> instanceData = new HashSet<ViewInstanceDataEntity>();
for (Map.Entry<String, Object> entry : properties.entrySet()) {
String propertyName = entry.getKey();
if (propertyName.startsWith(PROPERTIES_PREFIX)) {
ViewInstancePropertyEntity viewInstancePropertyEntity = new ViewInstancePropertyEntity();
viewInstancePropertyEntity.setViewName(viewName);
viewInstancePropertyEntity.setViewInstanceName(name);
viewInstancePropertyEntity.setName(entry.getKey().substring(PROPERTIES_PREFIX.length()));
viewInstancePropertyEntity.setValue((String) entry.getValue());
viewInstancePropertyEntity.setViewInstanceEntity(viewInstanceEntity);
instanceProperties.add(viewInstancePropertyEntity);
} else if (propertyName.startsWith(DATA_PREFIX)) {
ViewInstanceDataEntity viewInstanceDataEntity = new ViewInstanceDataEntity();
viewInstanceDataEntity.setViewName(viewName);
viewInstanceDataEntity.setViewInstanceName(name);
viewInstanceDataEntity.setName(entry.getKey().substring(DATA_PREFIX.length()));
viewInstanceDataEntity.setValue((String) entry.getValue());
viewInstanceDataEntity.setViewInstanceEntity(viewInstanceEntity);
instanceData.add(viewInstanceDataEntity);
}
}
viewInstanceEntity.setProperties(instanceProperties);
viewInstanceEntity.setData(instanceData);
return viewInstanceEntity;
}