<commit_before>/*
 * Copyright 2011-2015 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.index;

import static com.b2international.snowowl.core.date.Dates.getTime;
import static com.b2international.snowowl.datastore.cdo.CDOUtils.check;
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_LATEST_UPDATE_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_VERSION_ID;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.StringField;

import com.b2international.snowowl.core.date.EffectiveTimes;
import com.b2international.snowowl.datastore.cdo.CDOIDUtils;
import com.b2international.snowowl.datastore.index.AbstractIndexMappingStrategy;
import com.b2international.snowowl.datastore.index.mapping.Mappings;
import com.b2international.snowowl.terminologymetadata.CodeSystemVersion;

/**
 * Index mapping strategy for {@link CodeSystemVersion}.
 *
 */
public class CodeSystemVersionIndexMappingStrategy extends AbstractIndexMappingStrategy {

	private final CodeSystemVersion version;
	
	public CodeSystemVersionIndexMappingStrategy(final CodeSystemVersion version) {
		this.version = check(version);
	}
	
	@Override
	public Document createDocument() {
		final Document doc = new Document();
		doc.add(new LongField(VERSION_IMPORT_DATE, getTime(version.getImportDate()), Store.YES));
		doc.add(new LongField(VERSION_EFFECTIVE_DATE, EffectiveTimes.getEffectiveTime(version.getEffectiveDate()), Store.YES));
		addStringFieldIfExists(doc, VERSION_DESCRIPTION, version.getDescription());
		addStringFieldIfExists(doc, VERSION_VERSION_ID, version.getVersionId());
		// XXX using EffectiveTimes here to handle possible null lastUpdateDate values 
		doc.add(new LongField(VERSION_LATEST_UPDATE_DATE, EffectiveTimes.getEffectiveTime(version.getLastUpdateDate()), Store.YES));
		doc.add(new LongField(VERSION_STORAGE_KEY, getStorageKey(), Store.YES));
		Mappings.storageKey().addTo(doc, getStorageKey());
		addStringFieldIfExists(doc, VERSION_REPOSITORY_UUID, version.getCodeSystemVersionGroup().getRepositoryUuid());
		return doc;
	}

	@Override
	protected long getStorageKey() {
		return CDOIDUtils.asLong(version.cdoID());
	}
	
	private void addStringFieldIfExists(final Document doc, final String fieldName, final String value) {
		if (null != value) {
			doc.add(new StringField(fieldName, value, Store.YES));
		}
	}

}<commit_msg>SO-1957: fix references to renamed Mappings class<commit_after>/*
 * Copyright 2011-2015 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.index;

import static com.b2international.snowowl.core.date.Dates.getTime;
import static com.b2international.snowowl.datastore.cdo.CDOUtils.check;
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_LATEST_UPDATE_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_VERSION_ID;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.StringField;

import com.b2international.index.lucene.Fields;
import com.b2international.snowowl.core.date.EffectiveTimes;
import com.b2international.snowowl.datastore.cdo.CDOIDUtils;
import com.b2international.snowowl.datastore.index.AbstractIndexMappingStrategy;
import com.b2international.snowowl.terminologymetadata.CodeSystemVersion;

/**
 * Index mapping strategy for {@link CodeSystemVersion}.
 *
 */
public class CodeSystemVersionIndexMappingStrategy extends AbstractIndexMappingStrategy {

	private final CodeSystemVersion version;
	
	public CodeSystemVersionIndexMappingStrategy(final CodeSystemVersion version) {
		this.version = check(version);
	}
	
	@Override
	public Document createDocument() {
		final Document doc = new Document();
		doc.add(new LongField(VERSION_IMPORT_DATE, getTime(version.getImportDate()), Store.YES));
		doc.add(new LongField(VERSION_EFFECTIVE_DATE, EffectiveTimes.getEffectiveTime(version.getEffectiveDate()), Store.YES));
		addStringFieldIfExists(doc, VERSION_DESCRIPTION, version.getDescription());
		addStringFieldIfExists(doc, VERSION_VERSION_ID, version.getVersionId());
		// XXX using EffectiveTimes here to handle possible null lastUpdateDate values 
		doc.add(new LongField(VERSION_LATEST_UPDATE_DATE, EffectiveTimes.getEffectiveTime(version.getLastUpdateDate()), Store.YES));
		doc.add(new LongField(VERSION_STORAGE_KEY, getStorageKey(), Store.YES));
		Fields.storageKey().addTo(doc, getStorageKey());
		addStringFieldIfExists(doc, VERSION_REPOSITORY_UUID, version.getCodeSystemVersionGroup().getRepositoryUuid());
		return doc;
	}

	@Override
	protected long getStorageKey() {
		return CDOIDUtils.asLong(version.cdoID());
	}
	
	private void addStringFieldIfExists(final Document doc, final String fieldName, final String value) {
		if (null != value) {
			doc.add(new StringField(fieldName, value, Store.YES));
		}
	}

}
{'fraction_non_alphanumeric': 0.08772614863985423, 'fraction_numerical': 0.008069764414942079, 'mean_word_length': 6.714859437751004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6822859', 'n_tokens_mistral': 2337, 'n_tokens_neox': 2192, 'n_words': 458}