/*
 * Copyright 2018 Amazon.com, Inc. or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.spinnaker.clouddriver.lambda.cache.client;

import static com.netflix.spinnaker.clouddriver.lambda.cache.Keys.Namespace.LAMBDA_FUNCTIONS;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.awsobjectmapper.AmazonObjectMapperConfigurer;
import com.netflix.spinnaker.cats.cache.Cache;
import com.netflix.spinnaker.cats.cache.CacheData;
import com.netflix.spinnaker.clouddriver.lambda.cache.model.LambdaFunction;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class LambdaCacheClient extends AbstractCacheClient<LambdaFunction> {
  private final ObjectMapper objectMapper = AmazonObjectMapperConfigurer.createConfigured();

  @Autowired
  public LambdaCacheClient(Cache cacheView) {
    super(cacheView, LAMBDA_FUNCTIONS.ns);
  }

  @Override
  protected LambdaFunction convert(CacheData cacheData) {
    Map<String, Object> attributes = cacheData.getAttributes();
    return objectMapper.convertValue(attributes, LambdaFunction.class);
  }
}

@@ -1077,19 +1077,17 @@
 va.util.
-Map
+*
 ;%0Aimport
@@ -1624,14 +1624,39 @@
     
-return
+LambdaFunction lambdaFunction =
  obj
@@ -1709,18 +1709,741 @@
 ion.class);%0A
+    // Fix broken translation of uuid fields. Perhaps this is better fixed by configuring the%0A    // objectMapper right%0A    List%3CMap%3E eventSourceMappings = (List%3CMap%3E) attributes.get(%22eventSourceMappings%22);%0A    if (eventSourceMappings == null) %7B%0A      return lambdaFunction;%0A    %7D%0A    Map%3CString, String%3E arnUuidMap = new HashMap%3C%3E();%0A    eventSourceMappings.stream()%0A        .forEach(%0A            xx -%3E %7B%0A              arnUuidMap.put((String) xx.get(%22eventSourceArn%22), (String) xx.get(%22uuid%22));%0A            %7D);%0A    lambdaFunction%0A        .getEventSourceMappings()%0A        .forEach(%0A            currMapping -%3E %7B%0A              currMapping.setUUID((String) arnUuidMap.get(%22uuid%22));%0A            %7D);%0A    return lambdaFunction;%0A
   %7D%0A%7D%0A

fix (aws/lambda): patch broken translation of uuid fields by object mapper (#4892)