protected boolean isAPossibleValue(Object possibleValue) { if (getPossibleValues() != null) { return getPossibleValues().contains(possibleValue); } // no possible values so this should not be called, return false. return false; }
private void addEnumsToProperty(ArrayNode enumList, ArrayNode enumNames, Property property) { List possibleValues = property.getPossibleValues(); for (Object possibleValue : possibleValues) { String value = possibleValue.toString(); if (NamedThing.class.isAssignableFrom(possibleValue.getClass())) { value = ((NamedThing) possibleValue).getName(); } enumList.add(value); enumNames.add(property.getPossibleValuesDisplayName(possibleValue)); } }
private void updatePossibleValues(){ this.column.setPossibleValues(columnPossibleValues); if(columnPossibleValues.isEmpty()){ dbtype.setValue(null); } if(this.dbtype.getPossibleValues() == null || this.dbtype.getPossibleValues().isEmpty()){ this.dbtype.setPossibleValues(dbTypePossibleValues); } }
private void resolveEnum(ObjectNode schema, Property property) { schema.put(JsonSchemaConstants.TAG_TYPE, JsonSchemaConstants.TYPE_STRING); ArrayNode enumNames = schema.putArray(JsonSchemaConstants.TAG_ENUM_NAMES); ArrayNode enumValues = schema.putArray(JsonSchemaConstants.TAG_ENUM); List possibleValues = property.getPossibleValues(); for (Object possibleValue : possibleValues) { enumValues.add(possibleValue.toString()); enumNames.add(property.getPossibleValuesDisplayName(possibleValue)); } }
private void updatePossibleValues(){ this.column.setPossibleValues(columnPossibleValues); if(columnPossibleValues.isEmpty()){ dbtype.setValue(null); } if(this.dbtype.getPossibleValues() == null || this.dbtype.getPossibleValues().isEmpty()){ this.dbtype.setPossibleValues(dbTypePossibleValues); } }
public void afterDatastoreRef() { //the current method is called at some strange place, need to skip it if bucket list have been set if(!this.bucket.getPossibleValues().isEmpty()) { return; } S3DatasetDefinition definition = new S3DatasetDefinition(); RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this); try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) { IS3DatasetRuntime runtime = (IS3DatasetRuntime) sandboxedInstance.getInstance(); runtime.initialize(null, this); this.bucket.setPossibleValues(new ArrayList<String>(runtime.listBuckets())); } catch (Exception e) { //TalendRuntimeException.build(ComponentsErrorCode.IO_EXCEPTION, e).throwIt(); //ignore the exception here, as the trigger method should not block to save the data set properties action. //And as the current after data store trigger method is called at some strange place, the exception should not break something. LOGGER.warn(e.getClass() + " : " + e.getMessage()); } }
public void afterDatastoreRef() { //the current method is called at some strange place, need to skip it if bucket list have been set if(!this.bucket.getPossibleValues().isEmpty()) { return; } S3DatasetDefinition definition = new S3DatasetDefinition(); RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this); try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) { IS3DatasetRuntime runtime = (IS3DatasetRuntime) sandboxedInstance.getInstance(); runtime.initialize(null, this); this.bucket.setPossibleValues(new ArrayList<String>(runtime.listBuckets())); } catch (Exception e) { //TalendRuntimeException.build(ComponentsErrorCode.IO_EXCEPTION, e).throwIt(); //ignore the exception here, as the trigger method should not block to save the data set properties action. //And as the current after data store trigger method is called at some strange place, the exception should not break something. LOGGER.warn(e.getClass() + " : " + e.getMessage()); } }
private ObjectNode processTProperty(Property property) { ObjectNode schema = JsonNodeFactory.instance.objectNode(); schema.put(JsonSchemaConstants.TAG_TITLE, property.getDisplayName()); if (!property.getPossibleValues().isEmpty()) { if (property instanceof EnumProperty) { resolveEnum(schema, property); } else if (property instanceof EnumListProperty) { resolveList(schema, property); } else { resolveDefault(schema, property); } } else if (isListClass(property.getType())) { resolveList(schema, property); } else { schema.put(JsonSchemaConstants.TAG_TYPE, JsonSchemaConstants.getTypeMapping().get(property.getType())); if (Date.class.getName().equals(property.getType())) { schema.put(JsonSchemaConstants.TAG_FORMAT, "date-time");// Do not support other format for date till // Property // support it } } return schema; }
Collection values = ((Property) n).getPossibleValues(); if (values != null) { sb.append(" Values: " + values);
@Override public ValidationResult validate(RuntimeContainer container) { ValidationResult validationResult = super.validate(container); if (validationResult.getStatus() == ValidationResult.Result.ERROR) { return validationResult; } this.tableOutputProperties = (TAzureStorageOutputTableProperties) properties; tableOutputProperties.updatePartitionKeyAndRowKey(); if (!tableOutputProperties.partitionKey.getPossibleValues().contains(tableOutputProperties.partitionKey.getStringValue()) || !tableOutputProperties.rowKey.getPossibleValues().contains(tableOutputProperties.rowKey.getStringValue())) { return new ValidationResult(ValidationResult.Result.ERROR, i18nMessages.getMessage("error.invalidPartitionOrRowKey")); } if (tableOutputProperties.partitionKey.getStringValue().equals(tableOutputProperties.rowKey.getStringValue())) { return new ValidationResult(ValidationResult.Result.ERROR, i18nMessages.getMessage("error.equalPartitionOrRowKey")); } return ValidationResult.OK; }
@Override public ValidationResult validate(RuntimeContainer container) { ValidationResult validationResult = super.validate(container); if (validationResult.getStatus() == ValidationResult.Result.ERROR) { return validationResult; } this.tableOutputProperties = (TAzureStorageOutputTableProperties) properties; tableOutputProperties.updatePartitionKeyAndRowKey(); if (!tableOutputProperties.partitionKey.getPossibleValues().contains(tableOutputProperties.partitionKey.getStringValue()) || !tableOutputProperties.rowKey.getPossibleValues().contains(tableOutputProperties.rowKey.getStringValue())) { return new ValidationResult(ValidationResult.Result.ERROR, i18nMessages.getMessage("error.invalidPartitionOrRowKey")); } if (tableOutputProperties.partitionKey.getStringValue().equals(tableOutputProperties.rowKey.getStringValue())) { return new ValidationResult(ValidationResult.Result.ERROR, i18nMessages.getMessage("error.equalPartitionOrRowKey")); } return ValidationResult.OK; }
/** * Performs initialization of {@link #apiVersion} property for old components * that didn't have this property. */ private void migrateApiVersion() { if (apiVersion.getValue() == null) { if (endpoint.getValue() != null) { String endpointUrl = endpoint.getStringValue(); try { NetSuiteVersion nsVersion = NetSuiteVersion.detectVersion(endpointUrl); apiVersion.setValue(nsVersion.getMajorAsString(".")); } catch (IllegalArgumentException e) { // API version couldn't be detected, use default version apiVersion.setValue(DEFAULT_API_VERSION.getMajorAsString(".")); } catch (Exception e) { // do nothing } } } // Initialize possible values for apiVersion property. if (apiVersion.getPossibleValues().isEmpty()) { apiVersion.setPossibleValues(API_VERSIONS); } } }
@Override public ComponentProperties getOutputComponentProperties() { TSalesforceBulkExecProperties bulkExecProperties = new TSalesforceBulkExecProperties("bulkExecProperties"); bulkExecProperties.init(); bulkExecProperties.copyValuesFrom(this, true, true); // we need to pass also the possible values, only way from the studio to know it comes from a combo box (need to // add quotes for generation) bulkExecProperties.upsertRelationTable.columnName.setPossibleValues(upsertRelationTable.columnName.getPossibleValues()); bulkExecProperties.connection.referencedComponent.componentInstanceId.setTaggedValue(UpsertRelationTable.ADD_QUOTES, true); bulkExecProperties.module.connection.referencedComponent.componentInstanceId .setTaggedValue(UpsertRelationTable.ADD_QUOTES, true); for (Form form : bulkExecProperties.getForms()) { bulkExecProperties.refreshLayout(form); } return bulkExecProperties; }
/** * Performs initialization of {@link #apiVersion} property for old components * that didn't have this property. */ private void migrateApiVersion() { if (apiVersion.getValue() == null) { if (endpoint.getValue() != null) { String endpointUrl = endpoint.getStringValue(); try { NetSuiteVersion nsVersion = NetSuiteVersion.detectVersion(endpointUrl); apiVersion.setValue(nsVersion.getMajorAsString(".")); } catch (IllegalArgumentException e) { // API version couldn't be detected, use default version apiVersion.setValue(DEFAULT_API_VERSION.getMajorAsString(".")); } catch (Exception e) { // do nothing } } } // Initialize possible values for apiVersion property. if (apiVersion.getPossibleValues().isEmpty()) { apiVersion.setPossibleValues(API_VERSIONS); } } }
@Test public void testGetSchemaNames() throws Exception { JDBCDatastoreProperties properties = new JDBCDatastoreProperties("input"); properties.init(); List<?> dbTypes = properties.dbTypes.getPossibleValues(); assertTrue("the list should not be empty", dbTypes != null && !dbTypes.isEmpty()); assertTrue("The size of list is not right", dbTypes.size() == 3); assertTrue("The first element is not right", "MYSQL".equals(dbTypes.get(0))); assertTrue("The second element is not right", "DERBY".equals(dbTypes.get(1))); assertTrue("The default value is not right", "MYSQL".equals(properties.dbTypes.getValue())); AllSetting setting = properties.getRuntimeSetting(); assertTrue("the driver class is not right : " + setting.getDriverClass(), "org.gjt.mm.mysql.Driver".equals(setting.getDriverClass())); assertTrue("the driver paths is not right : " + setting.getDriverPaths(), setting.getDriverPaths() != null && !setting.getDriverPaths().isEmpty() && "mvn:org.talend.libraries/mysql-connector-java-5.1.30-bin/6.0.0/jar".equals(setting.getDriverPaths().get(0))); properties.dbTypes.setValue("DERBY"); properties.afterDbTypes(); setting = properties.getRuntimeSetting(); assertTrue("the driver class is not right : " + setting.getDriverClass(), "org.apache.derby.jdbc.ClientDriver".equals(setting.getDriverClass())); assertTrue("the driver paths is not right : " + setting.getDriverPaths(), setting.getDriverPaths() != null && !setting.getDriverPaths().isEmpty() && "mvn:org.apache.derby/derby/10.12.1.1".equals(setting.getDriverPaths().get(0))); }
@Override public ComponentProperties getOutputComponentProperties() { TSalesforceBulkExecProperties bulkExecProperties = new TSalesforceBulkExecProperties("bulkExecProperties"); bulkExecProperties.init(); bulkExecProperties.copyValuesFrom(this, true, true); // we need to pass also the possible values, only way from the studio to know it comes from a combo box (need to // add quotes for generation) bulkExecProperties.upsertRelationTable.columnName .setPossibleValues(upsertRelationTable.columnName.getPossibleValues()); bulkExecProperties.connection.referencedComponent.componentInstanceId .setTaggedValue(UpsertRelationTable.ADD_QUOTES, true); bulkExecProperties.module.connection.referencedComponent.componentInstanceId .setTaggedValue(UpsertRelationTable.ADD_QUOTES, true); // Seems that properties copy can't copy the reference properties if (isUseExistConnection()) { bulkExecProperties.connection.referencedComponent .setReference(connection.getReferencedConnectionProperties()); } for (Form form : bulkExecProperties.getForms()) { bulkExecProperties.refreshLayout(form); } return bulkExecProperties; }
@Override public ComponentProperties getOutputComponentProperties() { TSalesforceBulkExecProperties bulkExecProperties = new TSalesforceBulkExecProperties("bulkExecProperties"); bulkExecProperties.init(); bulkExecProperties.copyValuesFrom(this, true, true); // we need to pass also the possible values, only way from the studio to know it comes from a combo box (need to // add quotes for generation) bulkExecProperties.upsertRelationTable.columnName .setPossibleValues(upsertRelationTable.columnName.getPossibleValues()); bulkExecProperties.connection.referencedComponent.componentInstanceId .setTaggedValue(UpsertRelationTable.ADD_QUOTES, true); bulkExecProperties.module.connection.referencedComponent.componentInstanceId .setTaggedValue(UpsertRelationTable.ADD_QUOTES, true); // Seems that properties copy can't copy the reference properties if (isUseExistConnection()) { bulkExecProperties.connection.referencedComponent .setReference(connection.getReferencedConnectionProperties()); } for (Form form : bulkExecProperties.getForms()) { bulkExecProperties.refreshLayout(form); } return bulkExecProperties; }
@Test public void testProperties() throws Throwable { FormatPropertiesProvider<AbstractTestFormatProperties> propertiesProvider = new FormatPropertiesProvider<AbstractTestFormatProperties>( "propertiesProvider", AbstractTestFormatDefinition.class) { }; DefinitionRegistry reg = new DefinitionRegistry(); TestFormatDefinition1Impl def1 = new TestFormatDefinition1Impl(); TestFormatDefinition2Impl def2 = new TestFormatDefinition2Impl(); reg.registerDefinition(Arrays.asList(def1, def2)); reg.injectDefinitionRegistry(propertiesProvider); propertiesProvider.init(); // Check that possible format values include both of registered definitions Assert.assertEquals(propertiesProvider.format.getPossibleValues().size(), 2); // Set the format value to first registered definition propertiesProvider.format.setValue(def1.getName()); PropertiesDynamicMethodHelper.afterProperty(propertiesProvider, propertiesProvider.format.getName()); AbstractTestFormatProperties formatProperties = propertiesProvider.getFormatProperties(); Assert.assertNotEquals(def2.getName(), propertiesProvider.format.getValue()); Assert.assertEquals(def1.getName(), propertiesProvider.format.getValue()); // Format properties class in PropertiesProvider should be the same as properties class for definition Assert.assertEquals(def1.getPropertiesClass(), formatProperties.getClass()); propertiesProvider.format.setValue(def2.getName()); PropertiesDynamicMethodHelper.afterProperty(propertiesProvider, propertiesProvider.format.getName()); formatProperties = propertiesProvider.getFormatProperties(); Assert.assertNotEquals(def1.getName(), propertiesProvider.format.getValue()); Assert.assertEquals(def2.getName(), propertiesProvider.format.getValue()); Assert.assertEquals(TestFormatProperties2Impl.class, formatProperties.getClass()); }
outputBulkProperties.upsertRelationTable.columnName.setPossibleValues(upsertRelationTable.columnName.getPossibleValues()); outputBulkProperties.upsertRelationTable.columnName.setStoredValue(upsertRelationTable.columnName.getStoredValue()); outputBulkProperties.upsertRelationTable.columnName.setValueEvaluator(upsertRelationTable.columnName.getValueEvaluator());
.setPossibleValues(upsertRelationTable.columnName.getPossibleValues()); outputBulkProperties.upsertRelationTable.columnName .setStoredValue(upsertRelationTable.columnName.getStoredValue());