public Definition<?> getDefinition(String definitionName) { return definitionServiceDelegate.getDefinitionsMapByType(Definition.class).get(definitionName); }
public <T extends Definition> T getDefinition(Class<T> clazz, String definitionName) { return definitionServiceDelegate.getDefinitionsMapByType(clazz).get(definitionName); }
protected Map<String, ? extends Definition<V>> getPossibleFormatValues() { DefinitionRegistryService registry = getDefinitionRegistry(); if (registry == null) { return Collections.emptyMap(); } return registry.getDefinitionsMapByType(getDefinitionClass()); }
protected Map<String, ? extends Definition<V>> getPossibleFormatValues() { DefinitionRegistryService registry = getDefinitionRegistry(); if (registry == null) { return Collections.emptyMap(); } return registry.getDefinitionsMapByType(getDefinitionClass()); }
/** * Return components that match the given typology and/or execution engine. * * @param typology the wanted typology. * @param executionEngine the wanted execution engine. * @return the list of all definitions that match the wanted typology. * @returnWrapped java.lang.Iterable<org.talend.components.service.rest.dto.DefinitionDTO> */ @Override public List<DefinitionDTO> listComponentDefinitions(ConnectorTypology typology, ExecutionEngine executionEngine) { final Collection<ComponentDefinition> definitions = // definitionServiceDelegate.getDefinitionsMapByType(ComponentDefinition.class).values(); Stream<ComponentDefinition> stream = definitions.stream(); if (typology != null) { stream = stream.filter(c -> c.getSupportedConnectorTopologies().contains(typology.getTopology())); } if (executionEngine != null) { stream = stream.filter(c -> c.isSupportingExecutionEngines(executionEngine)); } final List<DefinitionDTO> result = stream // .map(DefinitionDTO::new) // .collect(Collectors.toList()); logger.debug("found {} component definitions for typology {}", result.size(), typology); return result; }
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; }
@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); }
/** * 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()); }
/** * 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 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(); }
/** * 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); } }
when(delegate.getDefinitionsMapByType(DatastoreDefinition.class)) // .thenReturn(datastoresMap); when(delegate.getDefinitionsMapByType(DatasetDefinition.class)) // .thenReturn(datasetMap); runtimablesMap.putAll(datastoresMap); runtimablesMap.putAll(datasetMap); when(delegate.getDefinitionsMapByType(Definition.class)) // .thenReturn(runtimablesMap); when(delegate.getDefinitionsMapByType(Definition.class)) // .thenReturn(runtimablesMap);
public void shouldListDefinitions(List<String> names, // Class clazz, // Function<List<String>, Map<String, ? extends Definition>> provider, // DefinitionType wantedType, // String expectedType) throws IOException { // given BDDMockito.given(delegate.getDefinitionsMapByType(clazz)) // .willReturn(provider.apply(names)); // when final Response response = when().get(getVersionPrefix() + "/definitions/" + wantedType).andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(names.size(), actual.size()); actual.forEach(d -> { assertEquals(expectedType, d.getType()); assertTrue(names.contains(d.getName().substring("mock ".length()))); // it's expected }); }
@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 shouldFilterComponentsByTypologyAndExecutionEngine(ConnectorTypology wantedTypology, ExecutionEngine executionEngine, int expectedResults) throws IOException { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when().get(getVersionPrefix() + "/definitions/components?typology=" + wantedTypology + "&executionEngine=" + executionEngine.name()).andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(expectedResults, actual.size()); assertEquals(expectedResults, actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.name())) .filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count()); }
public void shouldFilterComponentsByExecutionEngine(ExecutionEngine executionEngine, int expectedResults) throws IOException { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when() .get(getVersionPrefix() + "/definitions/components?executionEngine=" + executionEngine.name()).andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(expectedResults, actual.size()); assertEquals(expectedResults, actual.stream().filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count()); }
public void shouldFilterComponentsByTypology(ConnectorTypology wantedTypology, int expectedResults) throws IOException { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when().get(getVersionPrefix() + "/definitions/components?typology=" + wantedTypology.name()) .andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(expectedResults, actual.size()); assertEquals(expectedResults, actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.name())) // it's // a // source .count()); }
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()); }