@@ -0,0 +1,3267 @@
+/*%0A * Copyright 2020 Netflix, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.netflix.spinnaker.orca.front50.pipeline;%0A%0Aimport com.fasterxml.jackson.core.type.TypeReference;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.netflix.spinnaker.kork.core.RetrySupport;%0Aimport com.netflix.spinnaker.kork.expressions.ExpressionFunctionProvider;%0Aimport com.netflix.spinnaker.kork.expressions.SpelHelperFunctionException;%0Aimport com.netflix.spinnaker.orca.front50.Front50Service;%0Aimport com.netflix.spinnaker.orca.front50.model.Application;%0Aimport java.util.Map;%0Aimport java.util.Optional;%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.annotations.Nullable;%0Aimport org.springframework.stereotype.Component;%0A%0A@Component%0Apublic class ApplicationExpressionFunctionProvider implements ExpressionFunctionProvider %7B%0A  // Static because it's needed during expression eval (which is a static)%0A  private static Front50Service front50Service = null;%0A  private static ObjectMapper objectMapper = null;%0A%0A  ApplicationExpressionFunctionProvider(%0A      ObjectMapper objectMapper, Optional%3CFront50Service%3E front50Service) %7B%0A    front50Service.ifPresent(%0A        service -%3E ApplicationExpressionFunctionProvider.front50Service = service);%0A%0A    ApplicationExpressionFunctionProvider.objectMapper = objectMapper;%0A  %7D%0A%0A  @Nullable%0A  @Override%0A  public String getNamespace() %7B%0A    return null;%0A  %7D%0A%0A  @NotNull%0A  @Override%0A  public Functions getFunctions() %7B%0A    return new Functions(%0A        new FunctionDefinition(%0A            %22applicationMetadata%22,%0A            %22Get application metadata for a specific application%22,%0A            new FunctionParameter(%0A                String.class, %22applicationName%22, %22Application to get metadata for%22)));%0A  %7D%0A%0A  /**%0A   * Function to retrieve application metadata for a specific application%0A   *%0A   * @param applicationName the application name to look up metadata for%0A   * @return returns a map with application metadata%0A   */%0A  public static Map%3CString, Object%3E applicationMetadata(String applicationName) %7B%0A    if (front50Service == null) %7B%0A      throw new SpelHelperFunctionException(%0A          %22front50 service is missing. It's required when using applicationMetadata function%22);%0A    %7D%0A%0A    try %7B%0A      RetrySupport retrySupport = new RetrySupport();%0A      Application application =%0A          retrySupport.retry(() -%3E front50Service.get(applicationName), 3, 1000, true);%0A%0A      return objectMapper.convertValue(application, new TypeReference%3CMap%3CString, Object%3E%3E() %7B%7D);%0A    %7D catch (Exception e) %7B%0A      throw new SpelHelperFunctionException(%0A          String.format(%0A              %22Application metadata for application '%25s' could not be retrieved%22, applicationName),%0A          e);%0A    %7D%0A  %7D%0A%7D%0A

Add applicationMetadata SpEL helper function (#3799)