public Definition<?> getDefinition(String definitionName) { return definitionServiceDelegate.getDefinitionsMapByType(Definition.class).get(definitionName); }
public <T extends Definition> T getFirstDefinitionFromProperties(Properties properties) { Iterable<Definition> definitionForPropertiesType = definitionServiceDelegate .getDefinitionForPropertiesType(properties.getClass()); Validate.isTrue(definitionForPropertiesType.iterator().hasNext(), "Could not find a definition for the datastore properties %s", properties.getClass().getName()); T datastoreDefinition = (T) definitionForPropertiesType.iterator().next(); return datastoreDefinition; }
@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; }
public <T extends Definition> T getDefinition(Class<T> clazz, String definitionName) { return definitionServiceDelegate.getDefinitionsMapByType(clazz).get(definitionName); }
@Test public void testCreateNewPropertiesWithInjected() { DefinitionRegistryService registry = new DefinitionRegistry(); TestInjectComponentDefinition def = new TestInjectComponentDefinition(); TestInjectComponentProperties testProps = (TestInjectComponentProperties) registry.createProperties(def, "testProps"); assertThat(testProps.getDefinitionRegistry(), equalTo(registry)); }
/** * resolve the referenced properties between a group of properties. And also may call the * after<ReferecenProperties.getName()> callback if any and if callAfterCallback is true * * @param properties list of all references to resolve * @param definitionRegistry used to find the definitions compatible with current properties */ public static void resolveReferenceProperties(Iterable<? extends Properties> properties, DefinitionRegistryService definitionRegistry, boolean callAfterCallback) { // construct the definitionName and Properties map Map<String, Properties> def2PropsMap = new HashMap<>(); for (Properties prop : properties) { // look for the definition associated with the properties Iterable<Definition> allDefs = definitionRegistry.getDefinitionForPropertiesType(prop.getClass()); for (Definition def : allDefs) { def2PropsMap.put(def.getName(), prop); } } resolveReferenceProperties(def2PropsMap, callAfterCallback); }
/** * 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()); }
protected Map<String, ? extends Definition<V>> getPossibleFormatValues() { DefinitionRegistryService registry = getDefinitionRegistry(); if (registry == null) { return Collections.emptyMap(); } return registry.getDefinitionsMapByType(getDefinitionClass()); }
@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)); }
/** * Creates a ui-spec representation of the properties including json-schema, json-ui and json-data * * @param formName name of the wanted form. * @param properties instance of the properties to serialize. * @return json string in ui-specs representation of the data. */ public String toJson(String formName, Properties properties) { Iterable<Definition> definitionForPropertiesType = definitionRegistry .getDefinitionForPropertiesType(properties.getClass()); if (!definitionForPropertiesType.iterator().hasNext()) { // did not find any definition for the given properties throw TalendRuntimeException.build(CommonErrorCodes.UNREGISTERED_DEFINITION).set(properties.getClass().getName()); } // else we got definition so we take the first one. return JsonSchemaUtil.toJson(properties, formName, definitionForPropertiesType.iterator().next().getName()); }
protected Map<String, ? extends Definition<V>> getPossibleFormatValues() { DefinitionRegistryService registry = getDefinitionRegistry(); if (registry == null) { return Collections.emptyMap(); } return registry.getDefinitionsMapByType(getDefinitionClass()); }
/** * check that all Components and Wizards have theirs images properly set. * * @param componentService service to get the components to be checked. * */ public static void assertAllComponentImagesAreSet(DefinitionRegistryService definitionRegistry) { // check components Collection<ComponentDefinition> allComponents = definitionRegistry.getDefinitionsMapByType(ComponentDefinition.class) .values(); for (ComponentDefinition compDef : allComponents) { assertComponentImagesAreSet(compDef); } // check wizards Collection<ComponentWizardDefinition> allWizards = definitionRegistry .getDefinitionsMapByType(ComponentWizardDefinition.class).values(); for (ComponentWizardDefinition wizDef : allWizards) { assertWizardImagesAreSet(wizDef); } }
@Test @Ignore public void listDataStoreDefinitions() throws Exception { ArrayList<DatastoreDefinition> value = new ArrayList<>(); when(defRegistryDelegate.getDefinitionsMapByType(DatastoreDefinition.class).values()).thenReturn(value); //Iterable<DefinitionDTO> datastoreDefinitions = dataStoreController.listDataStoreDefinitions( // DefinitionType.DATA_STORE); // assertEquals(value, datastoreDefinitions); // verify(componentServiceDelegate).getDefinitionsByType(DatastoreDefinition.class); }
/** * check all properties of a component for i18n, check form i18n, check ComponentProperties title is i18n * * @param componentService where to get all the components * @param errorCollector used to collect all errors at once. @see * <a href="http://junit.org/apidocs/org/junit/rules/ErrorCollector.html">ErrorCollector</a> */ static public void assertReturnProperties18nAreSet(DefinitionRegistryService definitionRegistry, ErrorCollector errorCollector) { Collection<ComponentDefinition> allComponents = definitionRegistry.getDefinitionsMapByType(ComponentDefinition.class) .values(); for (ComponentDefinition cd : allComponents) { // check return properties i18n checkAllPropertyI18n(cd.getReturnProperties(), cd, errorCollector); } }
@Test @Ignore public void getDatastoreDefinition() throws Exception { // Given ArrayList<DatastoreDefinition> definitions = new ArrayList<>(); DatastoreDefinition dsd1 = mock(DatastoreDefinition.class); when(dsd1.getName()).thenReturn("toto"); definitions.add(dsd1); DatastoreDefinition dsd2 = mock(DatastoreDefinition.class); String datastoreName = "datastore name"; when(dsd2.getName()).thenReturn(datastoreName); definitions.add(dsd2); when(defRegistryDelegate.getDefinitionsMapByType(DatastoreDefinition.class).values()).thenReturn(definitions); // When // DatastoreDefinition datastoreDefinition = dataStoreController.getDataStoreProperties(datastoreName); // // // Then // assertEquals(dsd2, datastoreDefinition); // verify(componentServiceDelegate, times(1)).getDefinitionsByType(DatastoreDefinition.class); // verify(dsd1, times(1)).getName(); // verify(dsd2, times(1)).getName(); }
@Test public void shouldHaveIconKeyIfPresent() throws Exception { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // then when().get(getVersionPrefix() + "/definitions/components").then() // .statusCode(OK.value()) // .body("iconKey", hasSize(14)) // total including nulls .body("iconKey.findAll { iconKey -> iconKey != null }", hasSize(5)); // total non-null }
public void shouldFilterComponentsByTag(String tag, int expectedResults) throws JsonParseException, JsonMappingException, IOException { Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when().get(getVersionPrefix() + "/definitions/" + COMPONENT + "?tag=" + tag).andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(expectedResults, actual.size()); }
@Test public void shouldNotFilterTypology() throws Exception { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when().get(getVersionPrefix() + "/definitions/components").andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(14, actual.size()); }