use of alien4cloud.model.components.IncompatiblePropertyDefinitionException in project alien4cloud by alien4cloud.
the class EditorInputHelperService method getInputCandidates.
/**
* Utility method to get the list of inputs (ids) that are compatible with the given property definition (no constraint conflicts)..
*
* @param topologyId The id of the topology for which to find input candidates.
* @param nodeTemplateName The name of the node template for which to get input candidates.
* @param propertyDefinitionGetter Implementation on how to get the property definition (from node properties, capabilities properties, relationships
* properties).
* @return A list of input candidates that are compatible with the requested property definition.
*/
public List<String> getInputCandidates(String topologyId, String nodeTemplateName, IPropertyDefinitionGetter propertyDefinitionGetter) {
try {
editionContextManager.init(topologyId);
// check authorization to update a topology
topologyService.checkEditionAuthorizations(EditionContextManager.getTopology());
Topology topology = EditionContextManager.getTopology();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateName);
PropertyDefinition pd = propertyDefinitionGetter.get(nodeTemplate);
if (pd == null) {
throw new NotFoundException("Unexpected error, property definition cannot be found for node <" + nodeTemplateName + ">");
}
Map<String, PropertyDefinition> inputs = topology.getInputs();
List<String> inputIds = new ArrayList<String>();
if (inputs != null && !inputs.isEmpty()) {
// iterate overs existing inputs and filter them by checking constraint compatibility
for (Map.Entry<String, PropertyDefinition> inputEntry : inputs.entrySet()) {
try {
inputEntry.getValue().checkIfCompatibleOrFail(pd);
inputIds.add(inputEntry.getKey());
} catch (IncompatiblePropertyDefinitionException e) {
// Nothing to do here, the id won't be added to the list
}
}
}
return inputIds;
} finally {
editionContextManager.destroy();
}
}
Aggregations