@Override public String getProperties(String definitionName, String formName) { notNull(definitionName, "Connection name cannot be null."); final Definition<?> definition = propertiesHelpers.getDefinition(definitionName); notNull(definition, "Could not find connection definition of name %s", definitionName); log.debug("Found connection definition {} for {}", definition, definitionName); return jsonSerializationHelper.toJson( definitionServiceDelegate.createProperties(definition, definitionName + " properties"), formName, definitionName); }
private void updateProperties() { String selectedFileFormatDefinitionStr = format.getValue(); if (!StringUtils.isEmpty(selectedFileFormatDefinitionStr) && !StringUtils.equals(previousFormatValue, selectedFileFormatDefinitionStr)) { V props = referenceMemento.get(selectedFileFormatDefinitionStr); if (props == null) { Definition<V> fileFormatDefinition = getDefinitionRegistry().getDefinitionsMapByType(getDefinitionClass()) .get(selectedFileFormatDefinitionStr); props = getDefinitionRegistry().createProperties(fileFormatDefinition, FORMAT_PROPERTIES_NAME); referenceMemento.put(selectedFileFormatDefinitionStr, props); } formatProperties = props; } else if (!StringUtils.isEmpty(selectedFileFormatDefinitionStr) && StringUtils.equals(previousFormatValue, selectedFileFormatDefinitionStr)) { // After deserialization we already have formatProperties, but we need to put them to referenceMemento referenceMemento.put(selectedFileFormatDefinitionStr, (V) formatProperties); } previousFormatValue = selectedFileFormatDefinitionStr; }
private void updateProperties() { String selectedFileFormatDefinitionStr = format.getValue(); if (!StringUtils.isEmpty(selectedFileFormatDefinitionStr) && !StringUtils.equals(previousFormatValue, selectedFileFormatDefinitionStr)) { V props = referenceMemento.get(selectedFileFormatDefinitionStr); if (props == null) { Definition<V> fileFormatDefinition = getDefinitionRegistry().getDefinitionsMapByType(getDefinitionClass()) .get(selectedFileFormatDefinitionStr); props = getDefinitionRegistry().createProperties(fileFormatDefinition, FORMAT_PROPERTIES_NAME); referenceMemento.put(selectedFileFormatDefinitionStr, props); } formatProperties = props; } else if (!StringUtils.isEmpty(selectedFileFormatDefinitionStr) && StringUtils.equals(previousFormatValue, selectedFileFormatDefinitionStr)) { // After deserialization we already have formatProperties, but we need to put them to referenceMemento referenceMemento.put(selectedFileFormatDefinitionStr, (V) formatProperties); } previousFormatValue = selectedFileFormatDefinitionStr; }
/** * returns a Properties instance if any found according to the json description and the registry. * The returned properties has been initialized (call to {@link Properties#init()}. */ static Properties fromJsonNode(DefinitionRegistryService defRegistryService, JsonNode jsonNode) throws NoSuchMethodException, IOException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { JsonNode defNameNode = jsonNode.get(JsonSchemaConstants.DEFINITION_NAME_JSON_METADATA); if (defNameNode == null) { throw TalendRuntimeException.build(CommonErrorCodes.UNABLE_TO_PARSE_JSON).create(); } // else we got one definition so try to use it Definition<?> definition = defRegistryService.getDefinitionsMapByType(Definition.class).get(defNameNode.asText()); if (definition == null) {// we are trying to use a definition that is not registered throw TalendRuntimeException.build(CommonErrorCodes.UNREGISTERED_DEFINITION).set(defNameNode.asText()); } // else we got a definition so let's use it to create the instance. return fromJson(jsonNode, (defRegistryService.createProperties(definition, "root")).init()); }
.thenReturn(singletonList(datastoreDefinition)); when(delegate.createProperties(any(Definition.class), anyString())).thenAnswer(i -> { Properties properties = PropertiesImpl.createNewInstance( ((Definition<Properties>) i.getArguments()[0]).getPropertiesClass(), (String) i.getArguments()[1]);
@Test public void testCreateNewPropertiesWithInjected() { DefinitionRegistryService registry = new DefinitionRegistry(); TestInjectComponentDefinition def = new TestInjectComponentDefinition(); TestInjectComponentProperties testProps = (TestInjectComponentProperties) registry.createProperties(def, "testProps"); assertThat(testProps.getDefinitionRegistry(), equalTo(registry)); }
@Test public void testCreateNewPropertiesWithNestedInjected() { DefinitionRegistryService registry = new DefinitionRegistry(); TestNestedInjectComponentDefinition def = new TestNestedInjectComponentDefinition(); TestNestedInjectComponentProperties testProps = (TestNestedInjectComponentProperties) registry.createProperties(def, "testProps"); assertThat(testProps.getNestedProperties().getDefinitionRegistry(), equalTo(registry)); }