Skip to content

Commit

Permalink
TEIIDDES-1879 Implemented changes to allow server version 8.6 or high…
Browse files Browse the repository at this point in the history
…er to access translator property definitions.
  • Loading branch information
blafond committed Jan 15, 2014
1 parent 51b32fb commit 79e2995
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.teiid.designer.runtime.spi.ITeiidDataSource;
import org.teiid.designer.runtime.spi.ITeiidServer;
import org.teiid.designer.runtime.spi.ITeiidTranslator;
import org.teiid.designer.runtime.spi.TeiidPropertyDefinition;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion;
import org.teiid.designer.vdb.VdbModelEntry;
import org.teiid.designer.vdb.connections.SourceHandler;
import org.teiid.designer.vdb.connections.VdbSourceConnection;
Expand Down Expand Up @@ -282,41 +284,44 @@ public PropertyDefinition[] getTranslatorDefinitions( String translatorName ) {
if (translator != null) {
Collection<PropertyDefinition> props = new ArrayList<PropertyDefinition>();

// NOTE: Currently translator.getPropertyDefinitions() will only return property definitions for
// the resource-adapter properties and NOT the translator, so need to comment this out for the time
// being
// for (TeiidPropertyDefinition propDefn : translator.getPropertyDefinitions()) {
// TranslatorProperty prop = new TranslatorProperty(propDefn.getPropertyTypeClassName());
// prop.advanced = propDefn.isAdvanced();
// prop.description = propDefn.getDescription();
// prop.displayName = propDefn.getDisplayName();
// prop.id = propDefn.getName();
// prop.masked = propDefn.isMasked();
// prop.modifiable = propDefn.isModifiable();
// prop.required = propDefn.isRequired();
//
// prop.defaultValue = (propDefn.getDefaultValue() == null) ? StringUtilities.EMPTY_STRING
// : propDefn.getDefaultValue().toString();
//
// if (propDefn.isConstrainedToAllowedValues()) {
// Collection values = propDefn.getAllowedValues();
// prop.allowedValues = new String[values.size()];
// int i = 0;
//
// for (Object value : values) {
// prop.allowedValues[i++] = value.toString();
// }
// } else {
// // if boolean type turn into allowed values
// String type = propDefn.getPropertyTypeClassName();
//
// if (Boolean.class.getName().equals(type) || Boolean.TYPE.getName().equals(type)) {
// prop.allowedValues = new String[] { Boolean.TRUE.toString(), Boolean.FALSE.toString() };
// }
// }
//
// props.add(prop);
// }
// NOTE: For server versions prior to 8.6, translator.getPropertyDefinitions() will only return property definitions for
// the resource-adapter properties and NOT the translator.
// So added the check and ignore getting translator properties if version < 8.6

if( !defaultServer.getServerVersion().isLessThan(TeiidServerVersion.TEIID_8_6_SERVER)) {
for (TeiidPropertyDefinition propDefn : translator.getPropertyDefinitions()) {
TranslatorProperty prop = new TranslatorProperty(propDefn.getPropertyTypeClassName());
prop.advanced = propDefn.isAdvanced();
prop.description = propDefn.getDescription();
prop.displayName = propDefn.getDisplayName();
prop.id = propDefn.getName();
prop.masked = propDefn.isMasked();
prop.modifiable = propDefn.isModifiable();
prop.required = propDefn.isRequired();

prop.defaultValue = (propDefn.getDefaultValue() == null) ? StringUtilities.EMPTY_STRING
: propDefn.getDefaultValue().toString();

if (propDefn.isConstrainedToAllowedValues()) {
Collection values = propDefn.getAllowedValues();
prop.allowedValues = new String[values.size()];
int i = 0;

for (Object value : values) {
prop.allowedValues[i++] = value.toString();
}
} else {
// if boolean type turn into allowed values
String type = propDefn.getPropertyTypeClassName();

if (Boolean.class.getName().equals(type) || Boolean.TYPE.getName().equals(type)) {
prop.allowedValues = new String[] { Boolean.TRUE.toString(), Boolean.FALSE.toString() };
}
}

props.add(prop);
}
}

return props.toArray(new PropertyDefinition[props.size()]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public interface ITeiidServerVersion {
String DEFAULT_TEIID_7_SERVER_ID = SEVEN + DOT + SEVEN + DOT + ZERO;


/**
* teiid 8.6 server version - required due to method added to Admin API
*/
String TEIID_8_6_SERVER_ID = EIGHT + DOT + SIX + DOT + ZERO;


/**
* @return the major version segment
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class TeiidServerVersion implements ITeiidServerVersion {
* The default teiid 7 server version
*/
public static final ITeiidServerVersion DEFAULT_TEIID_7_SERVER = new TeiidServerVersion(DEFAULT_TEIID_7_SERVER_ID);

/**
* The teiid 8.6 server version - this version introduced an Admin API change
*/
public static final ITeiidServerVersion TEIID_8_6_SERVER = new TeiidServerVersion(TEIID_8_6_SERVER_ID);

/**
* The default preferred server
Expand Down

0 comments on commit 79e2995

Please sign in to comment.