<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.server.internal.refset;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import com.b2international.snowowl.core.CoreTerminologyBroker;
import com.b2international.snowowl.core.api.IBranchPath;
import com.b2international.snowowl.core.domain.IComponentInput;
import com.b2international.snowowl.core.domain.IComponentRef;
import com.b2international.snowowl.core.exceptions.AlreadyExistsException;
import com.b2international.snowowl.core.terminology.ComponentCategory;
import com.b2international.snowowl.datastore.server.components.AbstractComponentServiceImpl;
import com.b2international.snowowl.snomed.core.refset.SnomedReferenceSet;
import com.b2international.snowowl.snomed.core.refset.SnomedReferenceSetService;
import com.b2international.snowowl.snomed.datastore.SnomedDatastoreActivator;
import com.b2international.snowowl.snomed.datastore.SnomedEditingContext;
import com.b2international.snowowl.snomed.datastore.SnomedRefSetBrowser;
import com.b2international.snowowl.snomed.datastore.SnomedRefSetEditingContext;
import com.b2international.snowowl.snomed.datastore.index.refset.SnomedRefSetIndexEntry;
import com.b2international.snowowl.snomed.snomedrefset.SnomedRefSet;
import com.google.common.collect.ImmutableList;
import com.google.inject.Provider;

/**
 * @since 4.5
 */
public class SnomedReferenceSetServiceImpl extends AbstractComponentServiceImpl<IComponentInput, SnomedReferenceSet, IComponentInput, SnomedRefSetEditingContext, SnomedRefSet> implements SnomedReferenceSetService {

	private Provider<SnomedRefSetBrowser> refSetBrowser;

	public SnomedReferenceSetServiceImpl(Provider<SnomedRefSetBrowser> refSetBrowser) {
		super(SnomedDatastoreActivator.REPOSITORY_UUID, ComponentCategory.SET);
		this.refSetBrowser = refSetBrowser;
	}

	@Override
	public List<SnomedReferenceSet> getReferenceSets(String path) {
		final IBranchPath branchPath = createStorageRef("SNOMEDCT", path).getBranch().branchPath();
		final ImmutableList.Builder<SnomedReferenceSet> result = ImmutableList.builder();
		final Collection<SnomedRefSetIndexEntry> referenceSets = refSetBrowser.get().getAllReferenceSets(branchPath);
		for (SnomedRefSetIndexEntry entry : referenceSets) {
			final SnomedReferenceSetImpl refset = new SnomedReferenceSetImpl();
			refset.setId(entry.getId());
			refset.setEffectiveTime(new Date(entry.getEffectiveTimeAsLong()));
			// refset.setActive(entry.isActive()); TODO fix index entry
			// refset.setReleased(entry.isReleased()); TODO fix index entry
			refset.setModuleId(entry.getModuleId());
			refset.setReferencedComponent(CoreTerminologyBroker.getInstance().getComponentInformation(entry.getReferencedComponentType()).getName());
			refset.setType(entry.getType());
			result.add(refset);
		}
		return result.build();
	}

	@Override
	protected boolean componentExists(IComponentInput input) {
		throw new UnsupportedOperationException();
	}

	@Override
	protected boolean componentExists(IComponentRef ref) {
		throw new UnsupportedOperationException();
	}

	@Override
	protected AlreadyExistsException createDuplicateComponentException(IComponentInput input) {
		return null;
	}

	@Override
	protected SnomedRefSetEditingContext createEditingContext(IComponentRef ref) {<commit_msg>SO-1710: include released and active flag in RefSet representation<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.server.internal.refset;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import com.b2international.snowowl.core.CoreTerminologyBroker;
import com.b2international.snowowl.core.api.IBranchPath;
import com.b2international.snowowl.core.domain.IComponentInput;
import com.b2international.snowowl.core.domain.IComponentRef;
import com.b2international.snowowl.core.exceptions.AlreadyExistsException;
import com.b2international.snowowl.core.terminology.ComponentCategory;
import com.b2international.snowowl.datastore.server.components.AbstractComponentServiceImpl;
import com.b2international.snowowl.snomed.core.refset.SnomedReferenceSet;
import com.b2international.snowowl.snomed.core.refset.SnomedReferenceSetService;
import com.b2international.snowowl.snomed.datastore.SnomedDatastoreActivator;
import com.b2international.snowowl.snomed.datastore.SnomedEditingContext;
import com.b2international.snowowl.snomed.datastore.SnomedRefSetBrowser;
import com.b2international.snowowl.snomed.datastore.SnomedRefSetEditingContext;
import com.b2international.snowowl.snomed.datastore.index.refset.SnomedRefSetIndexEntry;
import com.b2international.snowowl.snomed.snomedrefset.SnomedRefSet;
import com.google.common.collect.ImmutableList;
import com.google.inject.Provider;

/**
 * @since 4.5
 */
public class SnomedReferenceSetServiceImpl extends AbstractComponentServiceImpl<IComponentInput, SnomedReferenceSet, IComponentInput, SnomedRefSetEditingContext, SnomedRefSet> implements SnomedReferenceSetService {

	private Provider<SnomedRefSetBrowser> refSetBrowser;

	public SnomedReferenceSetServiceImpl(Provider<SnomedRefSetBrowser> refSetBrowser) {
		super(SnomedDatastoreActivator.REPOSITORY_UUID, ComponentCategory.SET);
		this.refSetBrowser = refSetBrowser;
	}

	@Override
	public List<SnomedReferenceSet> getReferenceSets(String path) {
		final IBranchPath branchPath = createStorageRef("SNOMEDCT", path).getBranch().branchPath();
		final ImmutableList.Builder<SnomedReferenceSet> result = ImmutableList.builder();
		final Collection<SnomedRefSetIndexEntry> referenceSets = refSetBrowser.get().getAllReferenceSets(branchPath);
		for (SnomedRefSetIndexEntry entry : referenceSets) {
			final SnomedReferenceSetImpl refset = new SnomedReferenceSetImpl();
			refset.setId(entry.getId());
			refset.setEffectiveTime(new Date(entry.getEffectiveTimeAsLong()));
			refset.setActive(entry.isActive());
			refset.setReleased(entry.isReleased());
			refset.setModuleId(entry.getModuleId());
			refset.setReferencedComponent(CoreTerminologyBroker.getInstance().getComponentInformation(entry.getReferencedComponentType()).getName());
			refset.setType(entry.getType());
			result.add(refset);
		}
		return result.build();
	}

	@Override
	protected boolean componentExists(IComponentInput input) {
		throw new UnsupportedOperationException();
	}

	@Override
	protected boolean componentExists(IComponentRef ref) {
		throw new UnsupportedOperationException();
	}

	@Override
	protected AlreadyExistsException createDuplicateComponentException(IComponentInput input) {
		return null;
	}

	@Override
	protected SnomedRefSetEditingContext createEditingContext(IComponentRef ref) {
{'fraction_non_alphanumeric': 0.0880152187698161, 'fraction_numerical': 0.008623969562460369, 'mean_word_length': 6.716242661448141, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7256362', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2297, 'n_words': 450}