/*
 * Copyright 2022 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.fhir.core.request.codesystem;

import static com.google.common.base.Preconditions.checkArgument;

import org.elasticsearch.common.Strings;

import com.b2international.snowowl.core.RepositoryManager;
import com.b2international.snowowl.core.domain.RepositoryContext;
import com.b2international.snowowl.core.events.Request;
import com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem;

/**
 * @since 8.2.0
 */
final class FhirCodeSystemPutRequest implements Request<RepositoryContext, Boolean> {

	private static final long serialVersionUID = 1L;
	
	private final CodeSystem codeSystem;
	
	public FhirCodeSystemPutRequest(CodeSystem codeSystem) {
		this.codeSystem = codeSystem;
	}

	@Override
	public Boolean execute(RepositoryContext context) {
		checkArgument(!Strings.isNullOrEmpty(codeSystem.getToolingId()), "Cannot create/update code system without tooling id.");

		FhirCodeSystemCUDSupport cudSupport = context.service(RepositoryManager.class).get(codeSystem.getToolingId())
				.optionalService(FhirCodeSystemCUDSupport.class)
				.orElse(FhirCodeSystemCUDSupport.DEFAULT);

		cudSupport.updateOrCreateCodeSystem(context, codeSystem);
		return Boolean.TRUE;
	}
	
}

@@ -694,168 +694,28 @@
 ort 
-static com.google.common.base.Preconditions.checkArgument;%0A%0Aimport org.elasticsearch.common.Strings;%0A%0Aimport com.b2international.snowowl.core.RepositoryManager;
+java.util.Optional;%0A
 %0Aimp
@@ -833,16 +833,81 @@
 equest;%0A
+import com.b2international.snowowl.core.plugin.ClassPathScanner;%0A
 import c
@@ -1340,133 +1340,20 @@
 %7B%0A%09%09
-checkArgument(!Strings.isNullOrEmpty(codeSystem.getToolingId()), %22Cannot create/update code system without tooling id.%22);%0A%0A%09%09
+%0A%09%09Optional%3C
 Fhir
@@ -1372,16 +1372,17 @@
 DSupport
+%3E
  cudSupp
@@ -1407,165 +1407,162 @@
 ice(
-RepositoryManager.class).get(codeSystem.getToolingId())%0A%09%09%09%09.optionalService(FhirCodeSystemCUDSupport.class)%0A%09%09%09%09.orElse(FhirCodeSystemCUDSupport.DEFAULT);%0A%0A
+ClassPathScanner.class)%0A%09%09%09%09.getComponentsByInterface(FhirCodeSystemCUDSupport.class)%0A%09%09%09%09.stream()%0A%09%09%09%09.findFirst();%0A%09%09%0A%09%09if (cudSupport.isPresent()) %7B%0A%09
 %09%09cu
@@ -1570,16 +1570,22 @@
 Support.
+get().
 updateOr
@@ -1625,16 +1625,17 @@
 tem);%0A%09%09
+%09
 return B
@@ -1646,16 +1646,50 @@
 an.TRUE;
+%09%09%09%0A%09%09%7D%0A%09%09%0A%09%09return Boolean.FALSE;
 %0A%09%7D%0A%09%0A%7D%0A

Remove tooling id based filtering of implementing classes