Skip to content

Commit

Permalink
Merge pull request #5 from elvisisking/teiiddes-1467
Browse files Browse the repository at this point in the history
Teiiddes 1467 Add method to MED assistant class to allow passing object to retrieve property descriptors
  • Loading branch information
blafond committed Aug 14, 2012
2 parents 66baa56 + ab7ebe7 commit bda4e68
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 45 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@ target
.settings
bin
tmp

# OS X (Mac)
.DS_Store

# Eclipse
.metadata

# Designer indexing
COLUMNS.INDEX
TABLES.INDEX
larger_test.index
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.teiid.designer.core.ModelerCore.Util;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -157,9 +158,10 @@ public Properties getOverriddenValues( Object modelObject ) throws Exception {
* @param modelObject the model object whose property definition is being requested (cannot be <code>null</code>)
* @param propId the property identifier whose property definition is being requested (cannot be <code>null</code> or empty)
* @return the property definition or <code>null</code> if not found
* @throws Exception if accessing a property definition or value
*/
protected ModelExtensionPropertyDefinition getPropertyDefinition( Object modelObject,
String propId ) {
String propId ) throws Exception {
CoreArgCheck.isNotNull(modelObject, "modelObject is null"); //$NON-NLS-1$

// make sure right namespace
Expand All @@ -170,6 +172,29 @@ protected ModelExtensionPropertyDefinition getPropertyDefinition( Object modelOb
return null;
}

/**
* {@inheritDoc}
*
* @see org.teiid.designer.extension.definition.ModelObjectExtensionAssistant#getPropertyDefinitions(java.lang.Object)
*/
@Override
public Collection<ModelExtensionPropertyDefinition> getPropertyDefinitions(Object modelObject) throws Exception {
String metaclassName = modelObject.getClass().getName();
ModelExtensionDefinition med = getModelExtensionDefinition();
Collection<ModelExtensionPropertyDefinition> propDefinitions = new ArrayList<ModelExtensionPropertyDefinition>();

for (ModelExtensionPropertyDefinition potentialPropDefn : med.getPropertyDefinitions(metaclassName)) {
// let assistant determine if property definition is valid for model object
ModelExtensionPropertyDefinition propDefn = getPropertyDefinition(modelObject, potentialPropDefn.getId());

if (propDefn != null) {
propDefinitions.add(propDefn);
}
}

return propDefinitions;
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class ModelExtensionAssistantAggregator {

private final ModelExtensionRegistry registry;

/**
* @param registry the registry being used to find assistants to aggregate results (cannot be <code>null</code>)
*/
public ModelExtensionAssistantAggregator( ModelExtensionRegistry registry ) {
CoreArgCheck.isNotNull(registry, "registry is null"); //$NON-NLS-1$
this.registry = registry;
Expand All @@ -44,6 +47,11 @@ private ModelObjectExtensionAssistant getModelObjectExtensionAssistant( String n
return null;
}

/**
* @param modelObject the model object whose overridden property values are being requested (cannot be <code>null</code>)
* @return the properties whose default values have been changed (never <code>null</code>)
* @throws Exception if there is a problem obtaining the overridden property values
*/
public Properties getOverriddenValues( Object modelObject ) throws Exception {
Properties props = new Properties();

Expand All @@ -58,6 +66,11 @@ public Properties getOverriddenValues( Object modelObject ) throws Exception {
return props;
}

/**
* @param modelObject the model objects whose property definitions are being requested (cannot be <code>null</code>)
* @return the property definitions (never <code>null</code>)
* @throws Exception if there is a problem obtaining the property definitions
*/
public Collection<ModelExtensionPropertyDefinition> getPropertyDefinitions( Object modelObject ) throws Exception {
Collection<String> supportedNamespacePrefixes = getSupportedNamespacePrefixes(modelObject);

Expand All @@ -73,13 +86,22 @@ public Collection<ModelExtensionPropertyDefinition> getPropertyDefinitions( Obje
ModelExtensionAssistant assistant = this.registry.getModelExtensionAssistant(namespacePrefix);

if (assistant != null) {
propDefns.addAll(assistant.getModelExtensionDefinition().getPropertyDefinitions(metaclassName));
if (assistant instanceof ModelObjectExtensionAssistant) {
propDefns.addAll(((ModelObjectExtensionAssistant)assistant).getPropertyDefinitions(modelObject));
} else {
propDefns.addAll(assistant.getModelExtensionDefinition().getPropertyDefinitions(metaclassName));
}
}
}

return propDefns;
}

/**
* @param modelObject the model object whose property values are being requested (cannot be <code>null</code>)
* @return the properties (never <code>null</code>)
* @throws Exception if there is a problem obtaining the properties
*/
public Properties getPropertyValues( Object modelObject ) throws Exception {
Properties props = new Properties();

Expand All @@ -104,6 +126,11 @@ public Collection<String> getSupportedNamespacePrefixes( Object modelObject ) th
return assistant.getSupportedNamespaces(modelObject);
}

/**
* @param file the model file being checked (cannot be <code>null</code>)
* @return <code>true</code> if the model file contains extension properties
* @throws Exception if there is a problem determining if the model file has extension properties
*/
public boolean hasExtensionProperties( File file ) throws Exception {
for (String namespacePrefix : this.registry.getAllNamespacePrefixes()) {
ModelObjectExtensionAssistant assistant = getModelObjectExtensionAssistant(namespacePrefix);
Expand All @@ -116,6 +143,11 @@ public boolean hasExtensionProperties( File file ) throws Exception {
return false;
}

/**
* @param modelObject the model object being checked (cannot be <code>null</code>)
* @return <code>true</code> if the model object has extension properties
* @throws Exception if there is a problem determining if the model object has extension properties
*/
public boolean hasExtensionProperties( Object modelObject ) throws Exception {
for (String namespacePrefix : this.registry.getAllNamespacePrefixes()) {
ModelObjectExtensionAssistant assistant = getModelObjectExtensionAssistant(namespacePrefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.File;
import java.util.Collection;
import java.util.Properties;
import org.teiid.designer.extension.properties.ModelExtensionPropertyDefinition;

/**
*
Expand Down Expand Up @@ -54,6 +55,15 @@ public abstract String getOverriddenValue( Object modelObject,
*/
public abstract Properties getOverriddenValues( Object modelObject ) throws Exception;

/**
* @param modelObject the model object whose property definitions are being requested (cannot be <code>null</code>)
* @return the property definitions (never <code>null</code>(
* @throws Exception if there is a problem obtaining the extension property definitions
*/
public Collection<ModelExtensionPropertyDefinition> getPropertyDefinitions( Object modelObject ) throws Exception {
return getModelExtensionDefinition().getPropertyDefinitions(modelObject.getClass().getName());
}

/**
* Obtains from the model object, the property value of the specified property definition identifier. If the current value is
* empty, the default value is returned.
Expand Down
12 changes: 0 additions & 12 deletions plugins/org.teiid.designer.metamodels.function/function.mxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,21 @@
<p:extendedMetaclass name="org.teiid.designer.metamodels.function.impl.ScalarFunctionImpl">
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="aggregate" required="true" type="boolean">
<p:display locale="en">Aggregate</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="analytic" required="false" type="boolean">
<p:display locale="en">Analytic</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="allows-orderby" required="false" type="boolean">
<p:display locale="en">Allows Order-by</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="uses-distinct-rows" required="false" type="boolean">
<p:display locale="en">Uses Distinct Rows</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="allows-distinct" required="false" type="boolean">
<p:display locale="en">Allows Distinct</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="decomposable" required="false" type="boolean">
<p:display locale="en">Decomposable</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
</p:extendedMetaclass>
</modelExtension>
Original file line number Diff line number Diff line change
@@ -1,18 +1,119 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.metamodels.function.extension;

import org.eclipse.emf.ecore.EObject;
import org.teiid.core.util.CoreArgCheck;
import org.teiid.designer.core.extension.EmfModelObjectExtensionAssistant;
import org.teiid.designer.extension.properties.ModelExtensionPropertyDefinition;
import org.teiid.designer.metamodels.function.ScalarFunction;

/**
*
*/
public class FunctionModelExtensionAssistant extends
EmfModelObjectExtensionAssistant {
public class FunctionModelExtensionAssistant extends EmfModelObjectExtensionAssistant {

private static String getPropertyId(final String propName) {
return ModelExtensionPropertyDefinition.Utils.getPropertyId(FunctionModelExtensionConstants.NAMESPACE_PROVIDER, propName);
}

private enum PropertyName {

AGGREGATE(getPropertyId("aggregate")), //$NON-NLS-1$
ALLOWS_ORDER_BY(getPropertyId("allows-orderby")), //$NON-NLS-1$
ALLOWS_DISTINCT(getPropertyId("allows-distinct")), //$NON-NLS-1$
ANALYTIC(getPropertyId("analytic")), //$NON-NLS-1$
DECOMPOSABLE(getPropertyId("decomposable")), //$NON-NLS-1$
USES_DISTINCT_ROWS(getPropertyId("uses-distinct-rows")); //$NON-NLS-1$

public static boolean same(final PropertyName propName,
final String value) {
return propName.toString().equals(value);
}

private final String propName;

private PropertyName(final String propName) {
this.propName = propName;
}

/**
* {@inheritDoc}
*
* @see java.lang.Enum#toString()
*/
@Override
public String toString() {
return this.propName;
}
}

/**
* {@inheritDoc}
*
* @see org.teiid.designer.core.extension.EmfModelObjectExtensionAssistant#getPropertyDefinition(java.lang.Object, java.lang.String)
*/
@Override
protected ModelExtensionPropertyDefinition getPropertyDefinition(final Object modelObject,
final String propId) throws Exception {
CoreArgCheck.isInstanceOf(EObject.class, modelObject);

// make sure there is a property definition first
final ModelExtensionPropertyDefinition propDefn = super.getPropertyDefinition(modelObject, propId);

if ((propDefn != null) && (modelObject instanceof ScalarFunction)) {
if (PropertyName.same(PropertyName.ANALYTIC, propId) || PropertyName.same(PropertyName.ALLOWS_ORDER_BY, propId)
|| PropertyName.same(PropertyName.USES_DISTINCT_ROWS, propId)
|| PropertyName.same(PropertyName.ALLOWS_DISTINCT, propId)
|| PropertyName.same(PropertyName.DECOMPOSABLE, propId)) {
// aggregate must be true to have rest of the above properties
final String isAggregate = getPropertyValue(modelObject, PropertyName.AGGREGATE.toString());

if (Boolean.parseBoolean(isAggregate)) {
return propDefn;
}

// make sure model object does not have these extension properties for when aggregate is false
removeProperty(modelObject, PropertyName.ANALYTIC.toString());
removeProperty(modelObject, PropertyName.ALLOWS_ORDER_BY.toString());
removeProperty(modelObject, PropertyName.USES_DISTINCT_ROWS.toString());
removeProperty(modelObject, PropertyName.DECOMPOSABLE.toString());
removeProperty(modelObject, PropertyName.ALLOWS_DISTINCT.toString());

// EObject should not have the requested property definition
return null;
}

return propDefn;
}

// property definition not found
return null;
}

/**
* {@inheritDoc}
*
* @see org.teiid.designer.core.extension.EmfModelObjectExtensionAssistant#setPropertyValue(java.lang.Object, java.lang.String, java.lang.String)
*/
@Override
public void setPropertyValue(final Object modelObject,
final String propId,
final String newValue) throws Exception {
super.setPropertyValue(modelObject, propId, newValue);

// if setting aggregate to false remove these properties
if (PropertyName.same(PropertyName.AGGREGATE, propId) && !Boolean.parseBoolean(newValue)) {
removeProperty(modelObject, PropertyName.ANALYTIC.toString());
removeProperty(modelObject, PropertyName.ALLOWS_ORDER_BY.toString());
removeProperty(modelObject, PropertyName.USES_DISTINCT_ROWS.toString());
removeProperty(modelObject, PropertyName.ALLOWS_DISTINCT.toString());
removeProperty(modelObject, PropertyName.DECOMPOSABLE.toString());
}
}
}
20 changes: 2 additions & 18 deletions plugins/org.teiid.designer.metamodels.relational/relational.mxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,27 @@
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="deterministic" required="false" type="boolean">
<p:description locale="en">Specifies that the source function will always returns the same result for a specific input value</p:description>
<p:display locale="en">Deterministic</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" index="true" masked="false" name="non-prepared" required="false" type="boolean">
<p:display locale="en">Non Prepared</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="non-prepared" required="false" type="boolean">
<p:display locale="en">Non-Prepared</p:display>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="aggregate" required="true" type="boolean">
<p:display locale="en">Aggregate</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="analytic" required="false" type="boolean">
<p:display locale="en">Analytic</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="allows-orderby" required="false" type="boolean">
<p:display locale="en">Allows Order-by</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="uses-distinct-rows" required="false" type="boolean">
<p:display locale="en">Uses Distinct Rows</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="allows-distinct" required="false" type="boolean">
<p:display locale="en">Allows Distinct</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
<p:property advanced="false" defaultValue="false" index="true" masked="false" name="decomposable" required="false" type="boolean">
<p:display locale="en">Decomposable</p:display>
<p:allowedValue>true</p:allowedValue>
<p:allowedValue>false</p:allowedValue>
</p:property>
</p:extendedMetaclass>
<p:extendedMetaclass name="org.teiid.designer.metamodels.relational.impl.BaseTableImpl">
Expand Down

0 comments on commit bda4e68

Please sign in to comment.