<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.api.impl;

import static com.b2international.commons.StringUtils.isEmpty;
import static com.b2international.snowowl.snomed.common.ContentSubType.DELTA;
import static com.b2international.snowowl.snomed.common.ContentSubType.FULL;
import static com.b2international.snowowl.snomed.common.ContentSubType.SNAPSHOT;
import static com.b2international.snowowl.snomed.exporter.model.SnomedRf2ExportModel.createExportModelWithAllRefSets;
import static com.google.common.base.Strings.nullToEmpty;

import java.io.File;
import java.util.Map;

import javax.annotation.Resource;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.xtext.util.Strings;

import com.b2international.collections.longs.LongSet;
import com.b2international.commons.StringUtils;
import com.b2international.commons.collect.LongSets;
import com.b2international.snowowl.core.ApplicationContext;
import com.b2international.snowowl.core.api.IBranchPath;
import com.b2international.snowowl.core.api.SnowowlRuntimeException;
import com.b2international.snowowl.core.branch.Branch;
import com.b2international.snowowl.core.date.DateFormats;
import com.b2international.snowowl.core.date.Dates;
import com.b2international.snowowl.core.date.EffectiveTimes;
import com.b2international.snowowl.core.exceptions.BadRequestException;
import com.b2international.snowowl.datastore.server.domain.StorageRef;
import com.b2international.snowowl.eventbus.IEventBus;
import com.b2international.snowowl.snomed.SnomedConstants.Concepts;
import com.b2international.snowowl.snomed.api.ISnomedExportService;
import com.b2international.snowowl.snomed.api.exception.SnomedExportException;
import com.b2international.snowowl.snomed.api.impl.domain.SnomedExportConfiguration;
import com.b2international.snowowl.snomed.common.ContentSubType;
import com.b2international.snowowl.snomed.core.domain.BranchMetadataResolver;
import com.b2international.snowowl.snomed.core.domain.ISnomedExportConfiguration;
import com.b2international.snowowl.snomed.core.domain.Rf2ReleaseType;
import com.b2international.snowowl.snomed.datastore.SnomedDatastoreActivator;
import com.b2international.snowowl.snomed.datastore.SnomedTerminologyBrowser;
import com.b2international.snowowl.snomed.datastore.request.SnomedRequests;
import com.b2international.snowowl.snomed.exporter.model.SnomedRf2ExportModel;
import com.google.common.collect.ImmutableMap;

/**
 * {@link ISnomedExportService export service} implementation for the SNOMED CT ontology.
 */
public class SnomedExportService implements ISnomedExportService {

	@Resource
	private IEventBus bus;

	private static final Map<Rf2ReleaseType, ContentSubType> TYPE_MAPPING = ImmutableMap.of(
			Rf2ReleaseType.DELTA, DELTA, 
			Rf2ReleaseType.SNAPSHOT, SNAPSHOT, 
			Rf2ReleaseType.FULL, FULL
		);
	
	@Override
	public String resolveNamespaceId(String branchPath) {
		String namespace = "INT";
		Branch branch = SnomedRequests.branching().prepareGet(branchPath).executeSync(bus);
		String branchMetaShortname = BranchMetadataResolver.getEffectiveBranchMetadataValue(branch, "shortname");
		String branchMetaDefaultNamespace = BranchMetadataResolver.getEffectiveBranchMetadataValue(branch, "defaultNamespace");
		if (!Strings.isEmpty(branchMetaShortname) && !Strings.isEmpty(branchMetaDefaultNamespace)) {
			namespace = branchMetaShortname + branchMetaDefaultNamespace;
		}
		return namespace;
	}
	
	@Override
	public File export(final ISnomedExportConfiguration configuration) {
		checkNotNull(configuration, "Configuration was missing for the export operation.");
		return tryExport(convertConfiguration(configuration));
	}

	private File tryExport(final SnomedRf2ExportModel model) {
		try {
			return doExport(model);
		} catch (final Exception e) {
			return throwExportException(
					isEmpty(e.getMessage()) 
						? "Error occurred while exporting SNOMED CT." 
						: e.getMessage());
		}
	}

	private File doExport(final SnomedRf2ExportModel model) throws Exception {
		return getDelegateService().export(model, new NullProgressMonitor());<commit_msg>WRP-3035 Uppercase extension code in RF2 export filenames.<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.api.impl;

import static com.b2international.commons.StringUtils.isEmpty;
import static com.b2international.snowowl.snomed.common.ContentSubType.DELTA;
import static com.b2international.snowowl.snomed.common.ContentSubType.FULL;
import static com.b2international.snowowl.snomed.common.ContentSubType.SNAPSHOT;
import static com.b2international.snowowl.snomed.exporter.model.SnomedRf2ExportModel.createExportModelWithAllRefSets;
import static com.google.common.base.Strings.nullToEmpty;

import java.io.File;
import java.util.Map;

import javax.annotation.Resource;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.xtext.util.Strings;

import com.b2international.collections.longs.LongSet;
import com.b2international.commons.StringUtils;
import com.b2international.commons.collect.LongSets;
import com.b2international.snowowl.core.ApplicationContext;
import com.b2international.snowowl.core.api.IBranchPath;
import com.b2international.snowowl.core.api.SnowowlRuntimeException;
import com.b2international.snowowl.core.branch.Branch;
import com.b2international.snowowl.core.date.DateFormats;
import com.b2international.snowowl.core.date.Dates;
import com.b2international.snowowl.core.date.EffectiveTimes;
import com.b2international.snowowl.core.exceptions.BadRequestException;
import com.b2international.snowowl.datastore.server.domain.StorageRef;
import com.b2international.snowowl.eventbus.IEventBus;
import com.b2international.snowowl.snomed.SnomedConstants.Concepts;
import com.b2international.snowowl.snomed.api.ISnomedExportService;
import com.b2international.snowowl.snomed.api.exception.SnomedExportException;
import com.b2international.snowowl.snomed.api.impl.domain.SnomedExportConfiguration;
import com.b2international.snowowl.snomed.common.ContentSubType;
import com.b2international.snowowl.snomed.core.domain.BranchMetadataResolver;
import com.b2international.snowowl.snomed.core.domain.ISnomedExportConfiguration;
import com.b2international.snowowl.snomed.core.domain.Rf2ReleaseType;
import com.b2international.snowowl.snomed.datastore.SnomedDatastoreActivator;
import com.b2international.snowowl.snomed.datastore.SnomedTerminologyBrowser;
import com.b2international.snowowl.snomed.datastore.request.SnomedRequests;
import com.b2international.snowowl.snomed.exporter.model.SnomedRf2ExportModel;
import com.google.common.collect.ImmutableMap;

/**
 * {@link ISnomedExportService export service} implementation for the SNOMED CT ontology.
 */
public class SnomedExportService implements ISnomedExportService {

	@Resource
	private IEventBus bus;

	private static final Map<Rf2ReleaseType, ContentSubType> TYPE_MAPPING = ImmutableMap.of(
			Rf2ReleaseType.DELTA, DELTA, 
			Rf2ReleaseType.SNAPSHOT, SNAPSHOT, 
			Rf2ReleaseType.FULL, FULL
		);
	
	@Override
	public String resolveNamespaceId(String branchPath) {
		String namespace = "INT";
		Branch branch = SnomedRequests.branching().prepareGet(branchPath).executeSync(bus);
		String branchMetaShortname = BranchMetadataResolver.getEffectiveBranchMetadataValue(branch, "shortname");
		String branchMetaDefaultNamespace = BranchMetadataResolver.getEffectiveBranchMetadataValue(branch, "defaultNamespace");
		if (!Strings.isEmpty(branchMetaShortname) && !Strings.isEmpty(branchMetaDefaultNamespace)) {
			namespace = branchMetaShortname.toUpperCase() + branchMetaDefaultNamespace;
		}
		return namespace;
	}
	
	@Override
	public File export(final ISnomedExportConfiguration configuration) {
		checkNotNull(configuration, "Configuration was missing for the export operation.");
		return tryExport(convertConfiguration(configuration));
	}

	private File tryExport(final SnomedRf2ExportModel model) {
		try {
			return doExport(model);
		} catch (final Exception e) {
			return throwExportException(
					isEmpty(e.getMessage()) 
						? "Error occurred while exporting SNOMED CT." 
						: e.getMessage());
		}
	}

	private File doExport(final SnomedRf2ExportModel model) throws Exception {
		return getDelegateService().export(model, new NullProgressMonitor());
{'fraction_non_alphanumeric': 0.08760121989693974, 'fraction_numerical': 0.01188347880954885, 'mean_word_length': 6.210007581501137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3147326', 'n_tokens_mistral': 3037, 'n_tokens_neox': 2813, 'n_words': 558}