Skip to content

Commit

Permalink
TEIIDDES-1870 OData Importing Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Oct 2, 2013
1 parent 5104328 commit f047f77
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 21 deletions.
Expand Up @@ -47,6 +47,17 @@
*/
public class TeiidDdlImporter extends StandardImporter {

private static final String NS_TEIID_ODATA = "teiid_odata"; //$NON-NLS-1$
private static final String NS_TEIID_WEBSERVICE= "teiid_ws"; //$NON-NLS-1$
private static final String NS_TEIID_MONGO = "teiid_mongo"; //$NON-NLS-1$
private static final String NS_TEIID_SALESFORCE = "teiid_sf"; //$NON-NLS-1$
private static final String NS_TEIID_RELATIONAL = "teiid_rel"; //$NON-NLS-1$
private static final String NS_DESIGNER_ODATA = "odata"; //$NON-NLS-1$
private static final String NS_DESIGNER_WEBSERVICE= "ws"; //$NON-NLS-1$
private static final String NS_DESIGNER_MONGO = "mongo"; //$NON-NLS-1$
private static final String NS_DESIGNER_SALESFORCE = "salesforce"; //$NON-NLS-1$
private static final String NS_DESIGNER_RELATIONAL = "relational"; //$NON-NLS-1$

private class TeiidInfo extends Info {

/**
Expand Down Expand Up @@ -693,6 +704,10 @@ private void processTeiidExtensionOptions(List<AstNode> optionNodes, RelationalR
String optionName = optionNode.getName();
Object optionValue = optionNode.getProperty(StandardDdlLexicon.VALUE);
if(!CoreStringUtil.isEmpty(optionName)) {
// Translate incoming Teiid-namespaced ExtProps into the equivalent Designer MED NS
if(isNamespaced(optionName)) {
optionName = translateNamespacedOptionName(optionName);
}
String optionValueStr = (String)optionValue;
if(!CoreStringUtil.isEmpty(optionValueStr)) {
relationalEntity.addExtensionProperty(optionName, optionValueStr);
Expand All @@ -702,4 +717,91 @@ private void processTeiidExtensionOptions(List<AstNode> optionNodes, RelationalR
}
}

/**
* Translate a namespaced extension property name, translating teiid namespaces to designer MED namespaces
* @param namespacedPropName the extension property name, including namespace
* @return the equivalent designer-namespaced PropName.
*/
private String translateNamespacedOptionName(String namespacedPropName) {
if(isNamespaced(namespacedPropName)) {
// Get the namespace and convert to designer equivalent
String propNs = getExtensionPropertyNamespace(namespacedPropName);
String designerNs = translateTeiidNSToDesignerNS(propNs);

// Get name portion of incoming name
String propName = getExtensionPropertyName(namespacedPropName);

// return reassembled namespaced name
return designerNs+':'+propName;
}
return namespacedPropName;
}

/**
* Get the Namespace from the extension property name. The propertyName may or may not be namespaced.
* If it's not a null is returned
* @param propName the extension property name, including namespace
* @return the namespace, if present. 'null' if not namespaced
*/
private String getExtensionPropertyNamespace(String propName) {
String namespace = null;
if(!CoreStringUtil.isEmpty(propName)) {
int index = propName.indexOf(':');
if(index!=-1) {
namespace = propName.substring(0,index);
}
}
return namespace;
}

/**
* Get the Name from the extension property name. If its not namespaced, just return the name. Otherwise strip off the namespace
* @param propName the extension property name, with or without namespace
* @return the name without namespace, if present.
*/
private String getExtensionPropertyName(String propName) {
String name = propName;
if(isNamespaced(propName)) {
int index = propName.indexOf(':');
name = propName.substring(index+1);
}
return name;
}

/**
* Determine if the property name has a leading namespace
* @param propName the extension property name, including namespace
* @return 'true' if a namespace is present, 'false' if not.
*/
private boolean isNamespaced(String propName) {
boolean isNamespaced = false;
if(!CoreStringUtil.isEmpty(propName)) {
isNamespaced = propName.indexOf(':') != -1;
}
return isNamespaced;
}

/**
* Translate a Teiid ExtensionProperty namespace into the Designer equivalent.
* @param teiidNamespace
* @return the designer MED namespace equivalent
*/
private String translateTeiidNSToDesignerNS(String teiidNamespace) {
String designerNS = teiidNamespace;
if(NS_TEIID_ODATA.equals(teiidNamespace)) {
designerNS = NS_DESIGNER_ODATA;
} else if(NS_TEIID_RELATIONAL.equals(teiidNamespace)) {
designerNS = NS_DESIGNER_RELATIONAL;
} else if(NS_TEIID_WEBSERVICE.equals(teiidNamespace)) {
designerNS = NS_DESIGNER_WEBSERVICE;
} else if(NS_TEIID_SALESFORCE.equals(teiidNamespace)) {
designerNS = NS_DESIGNER_SALESFORCE;
} else if(NS_TEIID_MONGO.equals(teiidNamespace)) {
designerNS = NS_DESIGNER_MONGO;
}
return designerNS;
}



}
23 changes: 21 additions & 2 deletions plugins/org.teiid.designer.dqp/meds/odata.mxd
Expand Up @@ -10,8 +10,27 @@
<p:modelType>PHYSICAL</p:modelType>

<p:extendedMetaclass name="org.teiid.designer.metamodels.relational.impl.BaseTableImpl">
<p:property name="EntityAlias" type="string" advanced="false" index="true" masked="false" required="false">
<p:display locale="en_US">Entity Alias</p:display>
<p:property name="EntityType" type="string" advanced="false" index="true" masked="false" required="false">
<p:display locale="en_US">Entity Type</p:display>
</p:property>
<p:property name="LinkTables" type="string" advanced="false" index="true" masked="false" required="false">
<p:display locale="en_US">Link Tables</p:display>
</p:property>
</p:extendedMetaclass>
<p:extendedMetaclass name="org.teiid.designer.metamodels.relational.impl.ColumnImpl">
<p:property name="JoinColumn" type="string" advanced="false" index="true" masked="false" required="false">
<p:display locale="en_US">Join Column</p:display>
</p:property>
<p:property name="ComplexType" type="string" advanced="false" index="true" masked="false" required="false">
<p:display locale="en_US">Complex Type</p:display>
</p:property>
<p:property name="ColumnGroup" type="string" advanced="false" index="true" masked="false" required="false">
<p:display locale="en_US">Column Group</p:display>
</p:property>
</p:extendedMetaclass>
<p:extendedMetaclass name="org.teiid.designer.metamodels.relational.impl.ProcedureImpl">
<p:property name="HttpMethod" type="string" advanced="false" index="true" masked="false" required="false">
<p:display locale="en_US">Http Method</p:display>
</p:property>
<p:property name="EntityType" type="string" advanced="false" index="true" masked="false" required="false">
<p:display locale="en_US">Entity Type</p:display>
Expand Down
Expand Up @@ -18,6 +18,8 @@
import org.teiid.designer.extension.properties.ModelExtensionPropertyDefinition;
import org.teiid.designer.metamodels.core.ModelType;
import org.teiid.designer.metamodels.relational.BaseTable;
import org.teiid.designer.metamodels.relational.Column;
import org.teiid.designer.metamodels.relational.Procedure;
import org.teiid.designer.metamodels.relational.RelationalPackage;
import org.teiid.designer.runtime.extension.odata.ODataModelExtensionConstants.PropertyIds;

Expand Down Expand Up @@ -60,10 +62,18 @@ protected ModelExtensionPropertyDefinition getPropertyDefinition(final Object mo
// make sure there is a property definition first
final ModelExtensionPropertyDefinition propDefn = super.getPropertyDefinition(modelObject, propId);

if (propDefn != null) {
// must be table in a physical model
if ((modelObject instanceof BaseTable) && ModelUtil.isPhysical(modelObject)) {
if (PropertyIds.ENTITY_ALIAS.equals(propId) || PropertyIds.ENTITY_TYPE.equals(propId)) {
// must be table in a physical model
if (propDefn != null && ModelUtil.isPhysical(modelObject)) {
if (modelObject instanceof BaseTable) {
if (PropertyIds.LINK_TABLES.equals(propId) || PropertyIds.ENTITY_TYPE.equals(propId)) {
return propDefn;
}
} else if (modelObject instanceof Column) {
if (PropertyIds.JOIN_COLUMN.equals(propId) || PropertyIds.COMPLEX_TYPE.equals(propId) || PropertyIds.COLUMN_GROUP.equals(propId)) {
return propDefn;
}
} else if (modelObject instanceof Procedure) {
if (PropertyIds.HTTP_METHOD.equals(propId) || PropertyIds.ENTITY_TYPE.equals(propId)) {
return propDefn;
}
}
Expand Down
Expand Up @@ -47,18 +47,43 @@ public String getNamespaceUri() {
* The fully qualified extension property definition identifiers.
*/
interface PropertyIds {

/**
* The property definition identifier for the LinkTables.
* @since 8.3
*/
String LINK_TABLES = ModelExtensionPropertyDefinition.Utils.getPropertyId(NAMESPACE_PROVIDER, "LinkTables"); //$NON-NLS-1$

/**
* The property definition identifier for the entityalias.
* @since 8.2
* The property definition identifier for the HttpMethod.
* @since 8.3
*/
String ENTITY_ALIAS = ModelExtensionPropertyDefinition.Utils.getPropertyId(NAMESPACE_PROVIDER, "EntityAlias"); //$NON-NLS-1$

String HTTP_METHOD = ModelExtensionPropertyDefinition.Utils.getPropertyId(NAMESPACE_PROVIDER, "HttpMethod"); //$NON-NLS-1$

/**
* The property definition identifier for the JoinColumn.
* @since 8.3
*/
String JOIN_COLUMN = ModelExtensionPropertyDefinition.Utils.getPropertyId(NAMESPACE_PROVIDER, "JoinColumn"); //$NON-NLS-1$

/**
* The property definition identifier for the entitytype.
* The property definition identifier for the EntityType.
* @since 8.2
*/
String ENTITY_TYPE = ModelExtensionPropertyDefinition.Utils.getPropertyId(NAMESPACE_PROVIDER, "EntityType"); //$NON-NLS-1$

/**
* The property definition identifier for the ComplexType.
* @since 8.3
*/
String COMPLEX_TYPE = ModelExtensionPropertyDefinition.Utils.getPropertyId(NAMESPACE_PROVIDER, "ComplexType"); //$NON-NLS-1$

/**
* The property definition identifier for the ColumnGroup.
* @since 8.3
*/
String COLUMN_GROUP = ModelExtensionPropertyDefinition.Utils.getPropertyId(NAMESPACE_PROVIDER, "ColumnGroup"); //$NON-NLS-1$

}

}
Expand Up @@ -1249,21 +1249,75 @@ private ModelObjectExtensionAssistant getModelExtensionAssistant( String eObject
return null;
}

// find the assistant for the property
for (ModelExtensionAssistant assistant : assistants) {
// Prepend the assistant namespace to the propertyId, since it doesnt have one
String namespacedId = assistant.getNamespacePrefix()+':'+propId;

if(hasMatchingPropertyName(assistant.getModelExtensionDefinition(), eObjectClassName, namespacedId)) {
return ((assistant instanceof ModelObjectExtensionAssistant) ? (ModelObjectExtensionAssistant)assistant : null);
}
// If property is namespaced, get the assistant with matching namespace
if(isNamespaced(propId)) {
ModelObjectExtensionAssistant matchingAssistant = getAssistantWithNamespace(getExtensionPropertyNamespace(propId),assistants);
if(matchingAssistant!=null) return matchingAssistant;
} else {
// find the assistant for the property
for (ModelExtensionAssistant assistant : assistants) {
// Prepend the assistant namespace to the propertyId, since it doesnt have one
String namespacedId = assistant.getNamespacePrefix()+':'+propId;

if(hasMatchingPropertyName(assistant.getModelExtensionDefinition(), eObjectClassName, namespacedId)) {
return ((assistant instanceof ModelObjectExtensionAssistant) ? (ModelObjectExtensionAssistant)assistant : null);
}
}
}

this.propsWithNoAssistant.add(propId);
return null;
}

private String getMetaclassShortName(String metaclass) {

/**
* Get the ModelExtensionAssistant matching the supplied namespace
* @param namespace the namespace
* @param assistants the list of assistants
* @return the assistant which matches the supplied namespace
*
*/
private ModelObjectExtensionAssistant getAssistantWithNamespace( String namespace, Collection<ModelObjectExtensionAssistant> assistants ) {
ModelObjectExtensionAssistant result = null;
for(ModelObjectExtensionAssistant assistant: assistants) {
if(assistant.getNamespacePrefix().equalsIgnoreCase(namespace)) {
result = assistant;
break;
}
}
return result;
}

/**
* Get the Namespace from the extension property name. The propertyName may or may not be namespaced.
* If it's not a null is returned
* @param propName the extension property name, including namespace
* @return the namespace, if present. 'null' if not namespaced
*/
private String getExtensionPropertyNamespace(String propName) {
String namespace = null;
if(!CoreStringUtil.isEmpty(propName)) {
int index = propName.indexOf(':');
if(index!=-1) {
namespace = propName.substring(0,index);
}
}
return namespace;
}

/**
* Determine if the property name has a leading namespace
* @param propName the extension property name, including namespace
* @return 'true' if a namespace is present, 'false' if not.
*/
private boolean isNamespaced(String propName) {
boolean isNamespaced = false;
if(!CoreStringUtil.isEmpty(propName)) {
isNamespaced = propName.indexOf(':') != -1;
}
return isNamespaced;
}

private String getMetaclassShortName(String metaclass) {
return AbstractMetaclassNameProvider.getLabel(metaclass);
}

Expand Down

0 comments on commit f047f77

Please sign in to comment.