use of com.microsoft.azure.toolkit.lib.legacy.function.bindings.Binding in project azure-tools-for-java by Microsoft.
the class FunctionUtils method generateConfiguration.
private static FunctionConfiguration generateConfiguration(PsiMethod method) throws AzureExecutionException {
final FunctionConfiguration config = new FunctionConfiguration();
final List<Binding> bindings = new ArrayList<>();
processParameterAnnotations(method, bindings);
processMethodAnnotations(method, bindings);
patchStorageBinding(method, bindings);
config.setEntryPoint(method.getContainingClass().getQualifiedName() + "." + method.getName());
// Todo: add set bindings method in tools-common
config.setBindings(bindings);
return config;
}
use of com.microsoft.azure.toolkit.lib.legacy.function.bindings.Binding in project azure-tools-for-java by Microsoft.
the class FunctionUtils method getHTTPOutBinding.
private static Binding getHTTPOutBinding() {
final Binding result = new Binding(BindingEnum.HttpOutput);
result.setName(HTTP_OUTPUT_DEFAULT_NAME);
return result;
}
use of com.microsoft.azure.toolkit.lib.legacy.function.bindings.Binding in project azure-tools-for-java by Microsoft.
the class FunctionUtils method getUserDefinedBinding.
private static Binding getUserDefinedBinding(final Project project, PsiAnnotation annotation) throws AzureExecutionException {
final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
if (referenceElement == null) {
return null;
}
final PsiAnnotation customBindingAnnotation = AnnotationUtil.findAnnotation((PsiModifierListOwner) referenceElement.resolve(), AZURE_FUNCTION_CUSTOM_BINDING_CLASS);
if (customBindingAnnotation == null) {
return null;
}
final Map<String, Object> annotationProperties = AnnotationHelper.evaluateAnnotationProperties(project, annotation, CUSTOM_BINDING_RESERVED_PROPERTIES);
final Map<String, Object> customBindingProperties = AnnotationHelper.evaluateAnnotationProperties(project, customBindingAnnotation, null);
final Map<String, Object> mergedMap = new HashMap<>(annotationProperties);
customBindingProperties.forEach(mergedMap::putIfAbsent);
final Binding extendBinding = new Binding(BindingEnum.CustomBinding) {
public String getName() {
return (String) mergedMap.get("name");
}
public String getDirection() {
return (String) mergedMap.get("direction");
}
public String getType() {
return (String) mergedMap.get("type");
}
};
annotationProperties.forEach((name, value) -> {
if (!CUSTOM_BINDING_RESERVED_PROPERTIES.contains(name)) {
extendBinding.setAttribute(name, value);
}
});
return extendBinding;
}
use of com.microsoft.azure.toolkit.lib.legacy.function.bindings.Binding in project azure-tools-for-java by Microsoft.
the class FunctionUtils method writeFunctionJsonFile.
private static void writeFunctionJsonFile(File file, FunctionConfiguration config) throws IOException {
final Map<String, Object> json = new LinkedHashMap<>();
json.put("scriptFile", config.getScriptFile());
json.put("entryPoint", config.getEntryPoint());
final List<Map<String, Object>> lists = new ArrayList<>();
if (config.getBindings() != null) {
for (final Binding binding : config.getBindings()) {
final Map<String, Object> bindingJson = new LinkedHashMap<>();
bindingJson.put("type", binding.getType());
bindingJson.put("direction", binding.getDirection());
bindingJson.put("name", binding.getName());
final Map<String, Object> attributes = binding.getBindingAttributes();
for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
// Skip 'name' property since we have serialized before the for-loop
if (bindingJson.containsKey(entry.getKey())) {
continue;
}
bindingJson.put(entry.getKey(), entry.getValue());
}
lists.add(bindingJson);
}
json.put("bindings", lists.toArray());
}
file.getParentFile().mkdirs();
JsonUtils.writeJsonToFile(file, json);
}
use of com.microsoft.azure.toolkit.lib.legacy.function.bindings.Binding in project azure-tools-for-java by Microsoft.
the class FunctionUtils method patchStorageBinding.
private static void patchStorageBinding(final PsiMethod method, final List<Binding> bindings) {
final PsiAnnotation storageAccount = AnnotationUtil.findAnnotation(method, StorageAccount.class.getCanonicalName());
if (storageAccount != null) {
// todo: Remove System.out.println
System.out.println(message("function.binding.storage.found"));
final String connectionString = AnnotationUtil.getDeclaredStringAttributeValue(storageAccount, "value");
// Replace empty connection string
bindings.stream().filter(binding -> binding.getBindingEnum().isStorage()).filter(binding -> StringUtils.isEmpty((String) binding.getAttribute("connection"))).forEach(binding -> binding.setAttribute("connection", connectionString));
} else {
// todo: Remove System.out.println
System.out.println(message("function.binding.storage.notFound"));
}
}
Aggregations