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; }
/** * 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()); }
/** * 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); }
when(delegate.getDefinitionForPropertiesType(MockDatasetProperties.class)).thenReturn(singletonList(datasetDefinition)); when(delegate.getDefinitionForPropertiesType(MockDatastoreProperties.class)) .thenReturn(singletonList(datastoreDefinition));