diff --git a/core/com.b2international.snowowl.datastore/src/com/b2international/snowowl/datastore/CodeSystemUtils.java b/core/com.b2international.snowowl.datastore/src/com/b2international/snowowl/datastore/CodeSystemUtils.java
index 47c50cbe150..b83d8631acf 100644
--- a/core/com.b2international.snowowl.datastore/src/com/b2international/snowowl/datastore/CodeSystemUtils.java
+++ b/core/com.b2international.snowowl.datastore/src/com/b2international/snowowl/datastore/CodeSystemUtils.java
@@ -17,6 +17,7 @@
import static com.b2international.snowowl.core.ApplicationContext.getServiceForClass;
import static com.b2international.snowowl.datastore.BranchPathUtils.isMain;
+import static com.b2international.snowowl.datastore.ICodeSystem.TO_BRANCH_PATH_FUNCTION;
import static com.google.common.base.Strings.nullToEmpty;
import java.util.Comparator;
@@ -56,33 +57,6 @@ public class CodeSystemUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(CodeSystemUtils.class);
- /**
- * Predicate for selecting those {@link ICodeSystem}s:
- *
that are residing in the repository denoted by the given repositoryUuid
- * whose branch path matches the active branch's path.
- *
- * Note: if the active branch is a task branch, this predicate will ignore the last segment (task id part) of the active branch path.
- */
- private static final class ActiveCodeSystemPredicate implements Predicate {
-
- private final IBranchPathMap branchPathMap;
- private final String repositoryUuid;
-
- private ActiveCodeSystemPredicate(IBranchPathMap branchPathMap, String repositoryUuid) {
- this.branchPathMap = branchPathMap;
- this.repositoryUuid = repositoryUuid;
- }
-
- @Override
- public boolean apply(ICodeSystem input) {
- IBranchPath activeBranchPath = branchPathMap.getBranchPath(repositoryUuid);
- //ignore last segment if we are on a task branch
- if (getServiceForClass(TaskManager.class).hasActiveTask())
- return activeBranchPath.getParentPath().equals(input.getBranchPath());
-
- return activeBranchPath.getPath().equals(input.getBranchPath());
- }
- }
private static final class SameRepositoryCodeSystemPredicate implements Predicate {
@@ -98,53 +72,7 @@ public boolean apply(ICodeSystem input) {
}
}
- /**
- * Predicate, which selects code systems, that represent the MAIN for its terminology.
- * In other words: Predicate, which doesn't let extension code systems through.
- */
- private static final class MainCodeSystemPredicate implements Predicate {
-
- @Override
- public boolean apply(ICodeSystem input) {
- return BranchPathUtils.isMain(input.getBranchPath());
- }
-
- }
-
- /**
- * Function to turn {@link ICodeSystem} into it's short name.
- */
- public static final class CodeSystemToShortNameFunction implements Function {
-
- @Override
- public String apply(ICodeSystem input) {
- return input.getShortName();
- }
-
- }
- /**
- * Function to turn {@link ICodeSystem} into it's repository Uuid.
- */
- public static final class CodeSystemToRepositoryUuidFunction implements Function {
-
- @Override
- public String apply(ICodeSystem input) {
- return input.getRepositoryUuid();
- }
- }
-
-
- /**
- * Function to turn {@link ICodeSystem} into it's branch path string.
- */
- public static final class CodeSystemToBranchPathFunction implements Function {
-
- @Override
- public String apply(ICodeSystem input) {
- return input.getBranchPath();
- }
- }
@@ -242,7 +170,7 @@ public static ICodeSystem findMatchingCodeSystem(IBranchPath branchPath, String
// branchPath can be: main, task branch, version/tag branch Path, extension branchPath
Iterable codeSystemsInRepositoryUuid = Iterables.filter(getTerminologyRegistryService().getCodeSystems(new UserBranchPathMap()), sameRepositoryCodeSystemPredicate(repositoryUuid));
- Map branchPathToCodeSystemMap = Maps.uniqueIndex(codeSystemsInRepositoryUuid, new CodeSystemToBranchPathFunction());
+ Map branchPathToCodeSystemMap = Maps.uniqueIndex(codeSystemsInRepositoryUuid, TO_BRANCH_PATH_FUNCTION);
// if (branchPathToCodeSystemMap.containsKey(branchPath.getPath()))
// return branchPathToCodeSystemMap.get(branchPath.getPath());
@@ -254,7 +182,7 @@ public static ICodeSystem findMatchingCodeSystem(IBranchPath branchPath, String
}
// falling back to the repositoryUUID's main code system.
- return Iterables.find(codeSystemsInRepositoryUuid, new MainCodeSystemPredicate());
+ return Iterables.find(codeSystemsInRepositoryUuid, ICodeSystem.IS_MAIN_BRANCH_PATH_PREDICATE);
}
/**
@@ -328,26 +256,6 @@ public static Predicate sameRepositoryCodeSystemPredicate(final Str
return new SameRepositoryCodeSystemPredicate(repositoryUUID);
}
- public static Predicate activeCodeSystemPredicate(final IBranchPathMap branchPathMap, final String repositoryUuid) {
- return new ActiveCodeSystemPredicate(branchPathMap, repositoryUuid);
- }
-
- public static Predicate mainCodeSystemPredicate() {
- return new MainCodeSystemPredicate();
- }
-
- public static Function toShortNameFunction() {
- return new CodeSystemToShortNameFunction();
- }
-
- public static Function toRepositoryUuidFunction() {
- return new CodeSystemToRepositoryUuidFunction();
- }
-
- public static Function toBranchPathFunction() {
- return new CodeSystemToBranchPathFunction();
- }
-
/*returns with the connection for the given repository UUID*/
private static ICDOConnection getConnection(final String repositoryUuid) {
return getConnectionManager().getByUuid(repositoryUuid);
diff --git a/core/com.b2international.snowowl.datastore/src/com/b2international/snowowl/datastore/ICodeSystem.java b/core/com.b2international.snowowl.datastore/src/com/b2international/snowowl/datastore/ICodeSystem.java
index 613cbb1643f..2fce10d4385 100644
--- a/core/com.b2international.snowowl.datastore/src/com/b2international/snowowl/datastore/ICodeSystem.java
+++ b/core/com.b2international.snowowl.datastore/src/com/b2international/snowowl/datastore/ICodeSystem.java
@@ -19,6 +19,10 @@
import javax.annotation.Nullable;
+import com.b2international.snowowl.core.api.IBranchPath;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+
/**
* Serializable representation of a code system.
*/
@@ -91,5 +95,65 @@ public interface ICodeSystem extends Serializable {
* @return the path for the code system.
*/
String getBranchPath();
+
+
+ /**
+ * Predicate selecting code systems representing the MAIN of its terminology.
+ * In other words: Predicate, which doesn't let extension
code systems through.
+ */
+ public static final Predicate IS_MAIN_BRANCH_PATH_PREDICATE = new Predicate () {
+
+ @Override
+ public boolean apply(ICodeSystem input) {
+ return BranchPathUtils.isMain(input.getBranchPath());
+ }
+
+ };
+
+ /**
+ * Function to turn a {@link ICodeSystem} into it's short name.
+ */
+ public static final Function TO_SHORTNAME_FUNCTION = new Function () {
+
+ @Override
+ public String apply(ICodeSystem input) {
+ return input.getShortName();
+ }
+
+ };
+ /**
+ * Function to turn a {@link ICodeSystem} into it's repository UUID.
+ */
+ public static final Function TO_REPOSITORY_UUID_FUNCTION = new Function () {
+
+ @Override
+ public String apply(ICodeSystem input) {
+ return input.getRepositoryUuid();
+ }
+ };
+
+
+ /**
+ * Function to turn {@link ICodeSystem} into it's branch path string.
+ */
+ public static final Function TO_BRANCH_PATH_FUNCTION = new Function () {
+
+ @Override
+ public String apply(ICodeSystem input) {
+ return input.getBranchPath();
+ }
+ };
+
+ /**
+ * Function to turn {@link ICodeSystem} into it's {@link IBranchPath}.
+ */
+ public static final Function TO_IBRANCH_PATH_FUNCTION = new Function () {
+
+ @Override
+ public String apply(ICodeSystem input) {
+ return input.getBranchPath();
+ }
+ };
+
}
\ No newline at end of file