private String buildIconUrl(Definition origin, DefinitionImageType imageType) { return "/properties/" + origin.getName() + "/icon/" + imageType; }
@Override public <T extends Definition> Map<String, T> getDefinitionsMapByType(Class<T> cls) { Map<String, T> definitionsAsMap = new HashMap<>(); for (T def : getDefinitionsByType(cls)) { definitionsAsMap.put(def.getName(), def); } return definitionsAsMap; }
@Override public <T extends Definition> Map<String, T> getDefinitionsMapByType(Class<T> cls) { Map<String, T> definitionsAsMap = new HashMap<>(); for (T def : getDefinitionsByType(cls)) { definitionsAsMap.put(def.getName(), def); } return definitionsAsMap; }
@Override public void registerDefinition(Iterable<? extends Definition> defs) { for (Definition def : defs) { String name = def.getName(); if (name == null) { throw TalendRuntimeException .createUnexpectedException("The definition [" + def.getClass().getName() + "] name cannot be null."); } // else we are fine keep going Definition previousValue = definitions.put(name, def); if (previousValue != null) {// we cannot have 2 definiions with the same name throw TalendRuntimeException.createUnexpectedException( "2 definitions have the same name [" + previousValue.getName() + "] but their name must be unique."); } LOGGER.info("Talend Definition registered :" + name); } }
@Override public void registerDefinition(Iterable<? extends Definition> defs) { for (Definition def : defs) { String name = def.getName(); if (name == null) { throw TalendRuntimeException .createUnexpectedException("The definition [" + def.getClass().getName() + "] name cannot be null."); } // else we are fine keep going Definition previousValue = definitions.put(name, def); if (previousValue != null) {// we cannot have 2 definiions with the same name throw TalendRuntimeException.createUnexpectedException( "2 definitions have the same name [" + previousValue.getName() + "] but their name must be unique."); } LOGGER.info("Talend Definition registered :" + name); } }
/** * 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); }
/** * Constructor for the RuntimableDefinition part. * * @param origin the RuntimableDefinition. */ private DefinitionDTO(Definition origin) { this.name = origin.getName(); this.label = origin.getDisplayName(); // Get the first icon URL from the definition. for (DefinitionImageType imageType : DefinitionImageType.values()) { if (origin.getImagePath(imageType) != null) { this.iconURL = buildIconUrl(origin, imageType); break; } } this.iconKey = origin.getIconKey(); }