<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.core.domain;

import com.b2international.snowowl.core.SnowOwlApplication;
import com.b2international.snowowl.core.domain.BranchContext;
import com.b2international.snowowl.core.terminology.ComponentCategory;
import com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration;
import com.b2international.snowowl.snomed.datastore.id.ISnomedIdentifierService;
import com.google.common.base.Objects;

/**
 * @since 4.5
 */
public class ReservingIdStrategy implements IdGenerationStrategy {

	private final ComponentCategory category;
	private final String namespaceId;

	public ReservingIdStrategy(final ComponentCategory category) {
		this(category, null);
	}
	
	public ReservingIdStrategy(final ComponentCategory category, final String namespaceId) {
		this.category = category;
		this.namespaceId = namespaceId;
	}

	@Override
	public String generate(BranchContext context) {
		// XXX: Does not add an IdAction to SnomedIdentifiers
		final ISnomedIdentifierService identifierService = context.service(ISnomedIdentifierService.class);
		final String componentId = identifierService.reserve(getNamespaceIdOrDefault(), category);
		return componentId;
	}

	private String getNamespaceIdOrDefault() {
		// XXX: an empty namespace string for INT component IDs must be supported here
		return (null == namespaceId) 
				? SnowOwlApplication.INSTANCE.getConfiguration().getModuleConfig(SnomedCoreConfiguration.class).getDefaultNamespace()
				: namespaceId;
	}

	@Override
	public String toString() {
		return Objects.toStringHelper(this)
				.add("category", category)
				.add("namespaceId", namespaceId)
				.toString();
	}
}
<commit_msg>SO-2124: Expose namespace of ReservingIdStrategy<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.core.domain;

import com.b2international.snowowl.core.SnowOwlApplication;
import com.b2international.snowowl.core.domain.BranchContext;
import com.b2international.snowowl.core.terminology.ComponentCategory;
import com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration;
import com.b2international.snowowl.snomed.datastore.id.ISnomedIdentifierService;
import com.google.common.base.Objects;

/**
 * @since 4.5
 */
public class ReservingIdStrategy implements IdGenerationStrategy {

	private final ComponentCategory category;
	private final String namespaceId;

	public ReservingIdStrategy(final ComponentCategory category) {
		this(category, null);
	}
	
	public ReservingIdStrategy(final ComponentCategory category, final String namespaceId) {
		this.category = category;
		this.namespaceId = namespaceId;
	}

	@Override
	public String generate(BranchContext context) {
		// XXX: Does not add an IdAction to SnomedIdentifiers
		final ISnomedIdentifierService identifierService = context.service(ISnomedIdentifierService.class);
		final String componentId = identifierService.reserve(getNamespaceIdOrDefault(), category);
		return componentId;
	}

	private String getNamespaceIdOrDefault() {
		// XXX: an empty namespace string for INT component IDs must be supported here
		return (null == namespaceId) 
				? SnowOwlApplication.INSTANCE.getConfiguration().getModuleConfig(SnomedCoreConfiguration.class).getDefaultNamespace()
				: namespaceId;
	}

	public String getNamespaceId() {
		return namespaceId;
	}
	
	@Override
	public String toString() {
		return Objects.toStringHelper(this)
				.add("category", category)
				.add("namespaceId", namespaceId)
				.toString();
	}
}

{'fraction_non_alphanumeric': 0.08333333333333333, 'fraction_numerical': 0.010075566750629723, 'mean_word_length': 5.024020227560051, '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': '3235028', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1282, 'n_words': 385}