<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.snomed.datastore.converter;

import java.util.List;

import com.b2international.commons.http.ExtendedLocale;
import com.b2international.commons.options.Options;
import com.b2international.snowowl.core.CoreTerminologyBroker;
import com.b2international.snowowl.core.date.EffectiveTimes;
import com.b2international.snowowl.core.domain.BranchContext;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetImpl;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument;
import com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder;
import com.b2international.snowowl.snomed.datastore.request.SnomedRequests;

/**
 * @since 4.5
 */
final class SnomedReferenceSetConverter extends BaseSnomedComponentConverter<SnomedConceptDocument, SnomedReferenceSet, SnomedReferenceSets> {
	
	protected SnomedReferenceSetConverter(BranchContext context, Options expand, List<ExtendedLocale> locales) {
		super(context, expand, locales);
	}

	@Override
	protected SnomedReferenceSets createCollectionResource(List<SnomedReferenceSet> results, int offset, int limit, int total) {
		return new SnomedReferenceSets(results, offset, limit, total);
	}
	
	@Override
	protected void expand(List<SnomedReferenceSet> results) {
		expandMembers(results);
	}

	private void expandMembers(List<SnomedReferenceSet> results) {
		if (expand().containsKey("members")) {
			Options expandOptions = expand().get("members", Options.class);
			
			for (SnomedReferenceSet refSet : results) {
				SnomedRefSetMemberSearchRequestBuilder req = SnomedRequests.prepareSearchMember()
						.filterByRefSet(refSet.getId())
						.setLocales(locales())
						.setExpand(expandOptions.get("expand", Options.class));
				
				if (expandOptions.containsKey("offset")) {
					req.setOffset(expandOptions.get("offset", Integer.class));
				}
				
				if (expandOptions.containsKey("limit")) {
					req.setLimit(expandOptions.get("limit", Integer.class));
				}

				((SnomedReferenceSetImpl) refSet).setMembers(req.build().execute(context()));
			}
		}
	}
	
	@Override
	public SnomedReferenceSet toResource(SnomedConceptDocument entry) {
		final SnomedReferenceSetImpl refset = new SnomedReferenceSetImpl();
		refset.setStorageKey(entry.getRefSetStorageKey());
		refset.setId(entry.getId());
		refset.setEffectiveTime(EffectiveTimes.toDate(entry.getEffectiveTime()));
		refset.setActive(entry.isActive());
		refset.setReleased(entry.isReleased());
		refset.setModuleId(entry.getModuleId());
		refset.setIconId(entry.getIconId());
		refset.setScore(entry.getScore());
		final int referencedComponentType = entry.getReferencedComponentType();
		if (referencedComponentType > 0) {
			refset.setReferencedComponentType(getReferencedComponentType(referencedComponentType));
		}
		final int mapTargetComponentType = entry.getMapTargetComponentType();
		if (mapTargetComponentType > 0) {
			refset.setMapTargetComponentType(getReferencedComponentType(mapTargetComponentType));
		}
		refset.setType(entry.getRefSetType());
		if (refset.getType() == null) {
			System.err.println();
		}
		return refset;
	}

	private String getReferencedComponentType(final int referencedComponentType) {
		return CoreTerminologyBroker.getInstance().getComponentInformation((short) referencedComponentType).getId();
	}
}<commit_msg>[snomed] Remove empty diagnostic output from SnomedReferenceSetConverter<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.snomed.datastore.converter;

import java.util.List;

import com.b2international.commons.http.ExtendedLocale;
import com.b2international.commons.options.Options;
import com.b2international.snowowl.core.CoreTerminologyBroker;
import com.b2international.snowowl.core.date.EffectiveTimes;
import com.b2international.snowowl.core.domain.BranchContext;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetImpl;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument;
import com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder;
import com.b2international.snowowl.snomed.datastore.request.SnomedRequests;

/**
 * @since 4.5
 */
final class SnomedReferenceSetConverter extends BaseSnomedComponentConverter<SnomedConceptDocument, SnomedReferenceSet, SnomedReferenceSets> {
	
	protected SnomedReferenceSetConverter(BranchContext context, Options expand, List<ExtendedLocale> locales) {
		super(context, expand, locales);
	}

	@Override
	protected SnomedReferenceSets createCollectionResource(List<SnomedReferenceSet> results, int offset, int limit, int total) {
		return new SnomedReferenceSets(results, offset, limit, total);
	}
	
	@Override
	protected void expand(List<SnomedReferenceSet> results) {
		expandMembers(results);
	}

	private void expandMembers(List<SnomedReferenceSet> results) {
		if (expand().containsKey("members")) {
			Options expandOptions = expand().get("members", Options.class);
			
			for (SnomedReferenceSet refSet : results) {
				SnomedRefSetMemberSearchRequestBuilder req = SnomedRequests.prepareSearchMember()
						.filterByRefSet(refSet.getId())
						.setLocales(locales())
						.setExpand(expandOptions.get("expand", Options.class));
				
				if (expandOptions.containsKey("offset")) {
					req.setOffset(expandOptions.get("offset", Integer.class));
				}
				
				if (expandOptions.containsKey("limit")) {
					req.setLimit(expandOptions.get("limit", Integer.class));
				}

				((SnomedReferenceSetImpl) refSet).setMembers(req.build().execute(context()));
			}
		}
	}
	
	@Override
	public SnomedReferenceSet toResource(SnomedConceptDocument entry) {
		final SnomedReferenceSetImpl refset = new SnomedReferenceSetImpl();
		refset.setStorageKey(entry.getRefSetStorageKey());
		refset.setId(entry.getId());
		refset.setEffectiveTime(EffectiveTimes.toDate(entry.getEffectiveTime()));
		refset.setActive(entry.isActive());
		refset.setReleased(entry.isReleased());
		refset.setModuleId(entry.getModuleId());
		refset.setIconId(entry.getIconId());
		refset.setScore(entry.getScore());
		final int referencedComponentType = entry.getReferencedComponentType();
		if (referencedComponentType > 0) {
			refset.setReferencedComponentType(getReferencedComponentType(referencedComponentType));
		}
		final int mapTargetComponentType = entry.getMapTargetComponentType();
		if (mapTargetComponentType > 0) {
			refset.setMapTargetComponentType(getReferencedComponentType(mapTargetComponentType));
		}
		refset.setType(entry.getRefSetType());
		return refset;
	}

	private String getReferencedComponentType(final int referencedComponentType) {
		return CoreTerminologyBroker.getInstance().getComponentInformation((short) referencedComponentType).getId();
	}
}
{'fraction_non_alphanumeric': 0.10329985652797705, 'fraction_numerical': 0.007173601147776184, 'mean_word_length': 5.913223140495868, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '3322977', 'n_tokens_mistral': 2682, 'n_tokens_neox': 2410, 'n_words': 470}