/* * 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. * * Contributions from 2013-2017 where performed either by US government * employees, or under US Veterans Health Administration contracts. * * US Veterans Health Administration contributions by government employees * are work of the U.S. Government and are not subject to copyright * protection in the United States. Portions contributed by government * employees are USGovWork (17USC ยง105). Not subject to copyright. * * Contribution by contractors to the US Veterans Health Administration * during this period are contractually contributed under the * Apache License, Version 2.0. * * See: https://www.usa.gov/government-works * * Contributions prior to 2013: * * Copyright (C) International Health Terminology Standards Development Organisation. * Licensed under the Apache License, Version 2.0. * */ package sh.isaac.model.concept; //~--- JDK imports ------------------------------------------------------------ import java.nio.file.Path; import java.util.Arrays; import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.IntStream; import java.util.stream.Stream; //~--- non-JDK imports -------------------------------------------------------- import org.jvnet.hk2.annotations.Service; import sh.isaac.api.Get; import sh.isaac.api.collections.ConceptSequenceSet; import sh.isaac.api.component.concept.ConceptChronology; import sh.isaac.api.component.concept.ConceptService; import sh.isaac.api.component.concept.ConceptSnapshotService; import sh.isaac.api.component.concept.ConceptVersion; import sh.isaac.api.coordinate.LanguageCoordinate; import sh.isaac.api.coordinate.StampCoordinate; //~--- classes ---------------------------------------------------------------- /** * Created by kec on 1/3/16. */ @Service public class MockConceptService implements ConceptService { /** The concepts map. */ ConcurrentHashMap<Integer, ConceptChronology<? extends ConceptVersion<?>>> conceptsMap = new ConcurrentHashMap<>(); /** The db id. */ UUID dbId = UUID.randomUUID(); //~--- methods ------------------------------------------------------------- /** * Clear database validity value. */ @Override public void clearDatabaseValidityValue() { // Placeholder as databaseFolderExists always returns true. } /** * Write concept. * * @param concept the concept */ @Override public void writeConcept(ConceptChronology<? extends ConceptVersion<?>> concept) { this.conceptsMap.put(concept.getConceptSequence(), concept); } //~--- get methods --------------------------------------------------------- /** * Gets the concept. * * @param conceptId the concept id * @return the concept */ @Override public ConceptChronology<? extends ConceptVersion<?>> getConcept(int conceptId) { return this.conceptsMap.get(Get.identifierService() .getConceptSequence(conceptId)); } /** * Gets the concept. * * @param conceptUuids the concept uuids * @return the concept */ @Override public ConceptChronology<? extends ConceptVersion<?>> getConcept(UUID... conceptUuids) { final int conceptNid = Get.identifierService() .getNidForUuids(conceptUuids); final int conceptSequence = Get.identifierService() .getConceptSequence(conceptNid); if (this.conceptsMap.containsKey(conceptSequence)) { return this.conceptsMap.get(Get.identifierService() .getConceptSequenceForUuids(conceptUuids)); } final ConceptChronologyImpl concept = new ConceptChronologyImpl(conceptUuids[0], conceptNid, conceptSequence); if (conceptUuids.length > 1) { concept.setAdditionalUuids(Arrays.asList(Arrays.copyOfRange(conceptUuids, 1, conceptUuids.length))); } this.conceptsMap.put(conceptSequence, concept); return concept; } /** * Checks for concept. * * @param conceptId the concept id * @return true, if successful */ @Override public boolean hasConcept(int conceptId) { return this.conceptsMap.containsKey(Get.identifierService() .getConceptSequence(conceptId)); } /** * Checks if concept active. * * @param conceptSequence the concept sequence * @param stampCoordinate the stamp coordinate * @return true, if concept active */ @Override public boolean isConceptActive(int conceptSequence, StampCoordinate stampCoordinate) { return false; } /** * Gets the concept chronology stream. * * @return the concept chronology stream */ @Override public Stream<ConceptChronology<? extends ConceptVersion<?>>> getConceptChronologyStream() { return this.conceptsMap.values() .stream(); } /** * Gets the concept chronology stream. * * @param conceptSequences the concept sequences * @return the concept chronology stream */ @Override public Stream<ConceptChronology<? extends ConceptVersion<?>>> getConceptChronologyStream( ConceptSequenceSet conceptSequences) { throw new UnsupportedOperationException(); } /** * Gets the concept count. * * @return the concept count */ @Override public int getConceptCount() { return this.conceptsMap.size(); } /** * Gets the concept key parallel stream. * * @return the concept key parallel stream */ @Override public IntStream getConceptKeyParallelStream() { return this.conceptsMap.keySet() .parallelStream() .mapToInt(i -> i); } /** * Gets the concept key stream. * * @return the concept key stream */ @Override public IntStream getConceptKeyStream() { return this.conceptsMap.keySet() .stream() .mapToInt(i -> i); } /** * Gets the data store id. * * @return the data store id */ @Override public UUID getDataStoreId() { return this.dbId; } /** * Gets the database folder. * * @return the database folder */ @Override public Path getDatabaseFolder() { return null; } /** * Gets the database validity status. * * @return the database validity status */ @Override public DatabaseValidity getDatabaseValidityStatus() { return null; } /** * Gets the optional concept. * * @param conceptId the concept id * @return the optional concept */ @Override public Optional<? extends ConceptChronology<? extends ConceptVersion<?>>> getOptionalConcept(int conceptId) { return Optional.ofNullable(getConcept(conceptId)); } /** * Gets the optional concept. * * @param conceptUuids the concept uuids * @return the optional concept */ @Override public Optional<? extends ConceptChronology<? extends ConceptVersion<?>>> getOptionalConcept(UUID... conceptUuids) { return Optional.ofNullable(getConcept(conceptUuids)); } /** * Gets the parallel concept chronology stream. * * @return the parallel concept chronology stream */ @Override public Stream<ConceptChronology<? extends ConceptVersion<?>>> getParallelConceptChronologyStream() { return this.conceptsMap.values() .parallelStream(); } /** * Gets the parallel concept chronology stream. * * @param conceptSequences the concept sequences * @return the parallel concept chronology stream */ @Override public Stream<ConceptChronology<? extends ConceptVersion<?>>> getParallelConceptChronologyStream( ConceptSequenceSet conceptSequences) { throw new UnsupportedOperationException(); } /** * Gets the snapshot. * * @param stampCoordinate the stamp coordinate * @param languageCoordinate the language coordinate * @return the snapshot */ @Override public ConceptSnapshotService getSnapshot(StampCoordinate stampCoordinate, LanguageCoordinate languageCoordinate) { throw new UnsupportedOperationException(); } }