package com.hevelian.olastic.core.common;

import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.elasticsearch.index.mapper.BinaryFieldMapper;
import org.elasticsearch.index.mapper.BooleanFieldMapper;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.mapper.TextFieldMapper;

import lombok.extern.log4j.Log4j2;

/**
 * Class for mapping Elasticsearch types to Edm primitive types.
 * 
 * @author yuflyud
 */
@Log4j2
public class PrimitiveTypeMapper {

	public EdmPrimitiveTypeKind map(String elasticType) {
		EdmPrimitiveTypeKind result;
		if (TextFieldMapper.CONTENT_TYPE.equals(elasticType) || KeywordFieldMapper.CONTENT_TYPE.equals(elasticType)) {
			result = EdmPrimitiveTypeKind.String;
		} else if (NumberFieldMapper.NumberType.LONG.typeName().equals(elasticType)) {
			result = EdmPrimitiveTypeKind.Int64;
		} else if (NumberFieldMapper.NumberType.INTEGER.typeName().equals(elasticType)) {
			result = EdmPrimitiveTypeKind.Int32;
		} else if (NumberFieldMapper.NumberType.SHORT.typeName().equals(elasticType)) {
			result = EdmPrimitiveTypeKind.Int16;
		} else if (NumberFieldMapper.NumberType.BYTE.typeName().equals(elasticType)) {
			result = EdmPrimitiveTypeKind.Byte;
		} else if (NumberFieldMapper.NumberType.LONG.typeName().equals(elasticType)) {
			result = EdmPrimitiveTypeKind.Single;
		} else if (NumberFieldMapper.NumberType.DOUBLE.typeName().equals(elasticType)) {
			result = EdmPrimitiveTypeKind.Double;
		} else if (DateFieldMapper.CONTENT_TYPE.equals(elasticType)) {
			result = EdmPrimitiveTypeKind.DateTimeOffset;
		} else if (BooleanFieldMapper.CONTENT_TYPE.equals(elasticType)) {
			result = EdmPrimitiveTypeKind.Boolean;
		} else if (BinaryFieldMapper.CONTENT_TYPE.equals(elasticType)) {
			result = EdmPrimitiveTypeKind.Binary;
		} else {
			log.warn("Type '{}' is not supported. Setting String instead.", elasticType);
			result = EdmPrimitiveTypeKind.String;
		}
		return result;
	}
}

@@ -616,17 +616,20 @@
 pper %7B%0A%0A
-%09
+    
 public E
@@ -674,18 +674,24 @@
 Type) %7B%0A
-%09%09
+        
 EdmPrimi
@@ -711,18 +711,24 @@
 result;%0A
-%09%09
+        
 if (Text
@@ -771,16 +771,32 @@
 ticType)
+%0A               
  %7C%7C Keyw
@@ -838,35 +838,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -896,18 +896,24 @@
 String;%0A
-%09%09
+        
 %7D else i
@@ -975,35 +975,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -1032,18 +1032,24 @@
 .Int64;%0A
-%09%09
+        
 %7D else i
@@ -1114,35 +1114,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -1171,18 +1171,24 @@
 .Int32;%0A
-%09%09
+        
 %7D else i
@@ -1251,35 +1251,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -1308,18 +1308,24 @@
 .Int16;%0A
-%09%09
+        
 %7D else i
@@ -1387,35 +1387,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -1443,18 +1443,24 @@
 d.Byte;%0A
-%09%09
+        
 %7D else i
@@ -1483,36 +1483,37 @@
 pper.NumberType.
+F
 LO
-NG
+AT
 .typeName().equa
@@ -1523,35 +1523,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -1577,26 +1577,32 @@
 ind.Single;%0A
-%09%09
+        
 %7D else if (N
@@ -1662,35 +1662,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -1720,18 +1720,24 @@
 Double;%0A
-%09%09
+        
 %7D else i
@@ -1783,35 +1783,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -1849,18 +1849,24 @@
 Offset;%0A
-%09%09
+        
 %7D else i
@@ -1915,35 +1915,44 @@
 elasticType)) %7B%0A
-%09%09%09
+            
 result = EdmPrim
@@ -1974,18 +1974,24 @@
 oolean;%0A
-%09%09
+        
 %7D else i
@@ -2047,19 +2047,28 @@
 ype)) %7B%0A
-%09%09%09
+            
 result =
@@ -2097,18 +2097,24 @@
 Binary;%0A
-%09%09
+        
 %7D else %7B
@@ -2114,19 +2114,28 @@
  else %7B%0A
-%09%09%09
+            
 log.warn
@@ -2208,11 +2208,20 @@
 e);%0A
-%09%09%09
+            
 resu
@@ -2258,14 +2258,26 @@
 ng;%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 retu
@@ -2291,9 +2291,12 @@
 lt;%0A
-%09
+    
 %7D%0A%7D%0A

Fix for float metadata