/*
 * Copyright 2011-2016 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * 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.b2international.snowowl.terminologyregistry.core.builder;

import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_DESCRIPTION;
import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_EFFECTIVE_DATE;
import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_IMPORT_DATE;
import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_REPOSITORY_UUID;
import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_STORAGE_KEY;
import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_SYSTEM_SHORT_NAME;
import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_VERSION_ID;
import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_LATEST_UPDATE_DATE;

import org.apache.lucene.document.Document;

import com.b2international.snowowl.datastore.CodeSystemVersionEntry;
import com.b2international.snowowl.datastore.index.mapping.Mappings;
import com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants;

/**
 * @since 4.7
 */
public class CodeSystemVersionEntryBuilder {

	public CodeSystemVersionEntry build(final Document doc) {
		return new CodeSystemVersionEntry(
				Mappings.longDocValuesField(VERSION_IMPORT_DATE).getValue(doc),
				Mappings.longDocValuesField(VERSION_EFFECTIVE_DATE).getValue(doc),
				Mappings.longDocValuesField(VERSION_LATEST_UPDATE_DATE).getValue(doc),
				Mappings.stringDocValuesField(VERSION_DESCRIPTION).getValue(doc),
				doc.get(VERSION_VERSION_ID), 
				doc.get(TerminologyRegistryIndexConstants.VERSION_PARENT_BRANCH_PATH) != null
					? doc.get(TerminologyRegistryIndexConstants.VERSION_PARENT_BRANCH_PATH): "MAIN",
				Mappings.longDocValuesField(VERSION_STORAGE_KEY).getValue(doc),
				doc.get(VERSION_REPOSITORY_UUID),
				doc.get(VERSION_SYSTEM_SHORT_NAME));
	}

}

@@ -1075,24 +1075,159 @@
 MPORT_DATE;%0A
+import static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_LATEST_UPDATE_DATE;%0A
 import stati
@@ -1342,24 +1342,24 @@
 ITORY_UUID;%0A
-
 import stati
@@ -1738,143 +1738,8 @@
 _ID;
-%0Aimport static com.b2international.snowowl.terminologyregistry.core.index.TerminologyRegistryIndexConstants.VERSION_LATEST_UPDATE_DATE;
 %0A%0Aim
@@ -2198,33 +2198,24 @@
 appings.long
-DocValues
 Field(VERSIO
@@ -2257,33 +2257,24 @@
 appings.long
-DocValues
 Field(VERSIO
@@ -2319,33 +2319,24 @@
 appings.long
-DocValues
 Field(VERSIO
@@ -2380,37 +2380,15 @@
 %09%09%09%09
-Mappings.stringDocValuesField
+doc.get
 (VER
@@ -2404,30 +2404,16 @@
 RIPTION)
-.getValue(doc)
 ,%0A%09%09%09%09do

Use proper field getters.