package eu.dzhw.fdz.metadatamanagement.searchmanagement.config;

import java.time.LocalDate;
import java.time.LocalDateTime;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory;

import eu.dzhw.fdz.metadatamanagement.analysispackagemanagement.domain.AbstractAnalysisDataPackage;
import eu.dzhw.fdz.metadatamanagement.analysispackagemanagement.domain.DataPackage;
import eu.dzhw.fdz.metadatamanagement.analysispackagemanagement.domain.ExternalDataPackage;
import eu.dzhw.fdz.metadatamanagement.searchmanagement.documents.RelatedQuestionSubDocumentProjectionAdapter;
import eu.dzhw.fdz.metadatamanagement.variablemanagement.domain.projections.RelatedQuestionSubDocumentProjection;

/**
 * Spring Configuration which instantiates the Jest Elasticsearch Client.
 * 
 * @author René Reitmann
 */
@Configuration
public class ElasticsearchClientConfiguration {
  /**
   * Configure elasticsearch json serialization / deserialization.
   * 
   * @return the configured gson mapper
   */
  @Bean
  public Gson gson() {
    RuntimeTypeAdapterFactory<AbstractAnalysisDataPackage> adapterFactory =
        RuntimeTypeAdapterFactory.of(AbstractAnalysisDataPackage.class, "type")
            .registerSubtype(ExternalDataPackage.class, "externalData")
            .registerSubtype(DataPackage.class, "dataPackage");
    Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, new LocalDateConverter())
        .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeConverter())
        .registerTypeAdapter(RelatedQuestionSubDocumentProjection.class,
            new RelatedQuestionSubDocumentProjectionAdapter())
        .registerTypeAdapterFactory(adapterFactory).create();
    return gson;
  }
}

@@ -454,32 +454,122 @@
 sisDataPackage;%0A
+import eu.dzhw.fdz.metadatamanagement.analysispackagemanagement.domain.CustomDataPackage;%0A
 import eu.dzhw.f
@@ -1573,16 +1573,91 @@
 ackage%22)
+%0A            .registerSubtype(CustomDataPackage.class, %22customDataPackage%22)
 ;%0A    Gs

add custom data package to elasticsearch mapper (#2978 )