// Path: src/main/java/com/epam/reportportal/auth/integration/AuthIntegrationType.java
// public enum AuthIntegrationType {
// 
// 	ACTIVE_DIRECTORY("ad") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, ActiveDirectoryResource> getToResourceMapper() {
// 			return ActiveDirectoryConverter.TO_RESOURCE;
// 		}
// 	},
// 	LDAP("ldap") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, LdapResource> getToResourceMapper() {
// 			return LdapConverter.TO_RESOURCE;
// 		}
// 	},
// 	SAML("saml") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, SamlResource> getToResourceMapper() {
// 			return SamlConverter.TO_RESOURCE;
// 		}
// 	};
// 
// 	private String name;
// 
// 	AuthIntegrationType(String name) {
// 		this.name = name;
// 	}
// 
// 	public abstract Optional<Integration> get(Integration entity);
// 
// 	public abstract Function<Integration, ? extends AbstractAuthResource> getToResourceMapper();
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public static Optional<AuthIntegrationType> fromId(String id) {
// 		return Arrays.stream(values()).filter(it -> it.name.equalsIgnoreCase(id)).findAny();
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return this.name;
// 	}
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/handler/GetAuthIntegrationStrategy.java
// public interface GetAuthIntegrationStrategy {
// 
// 	AbstractAuthResource getIntegration();
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/converter/SamlConverter.java
// public final static Function<List<Integration>, SamlProvidersResource> TO_PROVIDERS_RESOURCE = integrations -> {
// 	if (CollectionUtils.isEmpty(integrations)) {
// 		SamlProvidersResource emptyResource = new SamlProvidersResource();
// 		emptyResource.setProviders(Collections.emptyList());
// 		return emptyResource;
// 	}
// 	SamlProvidersResource resource = new SamlProvidersResource();
// 	resource.setProviders(integrations.stream().map(TO_RESOURCE).collect(Collectors.toList()));
// 	return resource;
// };


import com.epam.reportportal.auth.integration.AuthIntegrationType;
import com.epam.reportportal.auth.integration.handler.GetAuthIntegrationStrategy;
import com.epam.ta.reportportal.dao.IntegrationRepository;
import com.epam.ta.reportportal.dao.IntegrationTypeRepository;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.entity.integration.IntegrationType;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.epam.ta.reportportal.ws.model.integration.auth.AbstractAuthResource;
import com.epam.ta.reportportal.ws.model.integration.auth.SamlProvidersResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import static com.epam.reportportal.auth.integration.converter.SamlConverter.TO_PROVIDERS_RESOURCE;
package com.epam.reportportal.auth.integration.handler.impl;




/**
 * @author <a href="mailto:ihar_kahadouski@epam.com">Ihar Kahadouski</a>
 */
@Service
public class GetSamlIntegrationsStrategy implements GetAuthIntegrationStrategy {

	private IntegrationTypeRepository integrationTypeRepository;

	private IntegrationRepository integrationRepository;

	@Autowired
	public GetSamlIntegrationsStrategy(IntegrationTypeRepository integrationTypeRepository, IntegrationRepository integrationRepository) {
		this.integrationTypeRepository = integrationTypeRepository;
		this.integrationRepository = integrationRepository;
	}

	@Override
	public AbstractAuthResource getIntegration() {
		IntegrationType samlIntegrationType = integrationTypeRepository.findByName(AuthIntegrationType.SAML.getName())
				.orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, AuthIntegrationType.SAML.getName()));
		List<Integration> providers = integrationRepository.findAllGlobalByType(samlIntegrationType);
		SamlProvidersResource resource = TO_PROVIDERS_RESOURCE.apply(providers);
// Path: src/main/java/com/epam/reportportal/auth/integration/AuthIntegrationType.java
// public enum AuthIntegrationType {
// 
// 	ACTIVE_DIRECTORY("ad") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, ActiveDirectoryResource> getToResourceMapper() {
// 			return ActiveDirectoryConverter.TO_RESOURCE;
// 		}
// 	},
// 	LDAP("ldap") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, LdapResource> getToResourceMapper() {
// 			return LdapConverter.TO_RESOURCE;
// 		}
// 	},
// 	SAML("saml") {
// 		@Override
// 		public Optional<Integration> get(Integration entity) {
// 			return ofNullable(entity);
// 		}
// 
// 		@Override
// 		public Function<Integration, SamlResource> getToResourceMapper() {
// 			return SamlConverter.TO_RESOURCE;
// 		}
// 	};
// 
// 	private String name;
// 
// 	AuthIntegrationType(String name) {
// 		this.name = name;
// 	}
// 
// 	public abstract Optional<Integration> get(Integration entity);
// 
// 	public abstract Function<Integration, ? extends AbstractAuthResource> getToResourceMapper();
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public static Optional<AuthIntegrationType> fromId(String id) {
// 		return Arrays.stream(values()).filter(it -> it.name.equalsIgnoreCase(id)).findAny();
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return this.name;
// 	}
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/handler/GetAuthIntegrationStrategy.java
// public interface GetAuthIntegrationStrategy {
// 
// 	AbstractAuthResource getIntegration();
// }
// 
// Path: src/main/java/com/epam/reportportal/auth/integration/converter/SamlConverter.java
// public final static Function<List<Integration>, SamlProvidersResource> TO_PROVIDERS_RESOURCE = integrations -> {
// 	if (CollectionUtils.isEmpty(integrations)) {
// 		SamlProvidersResource emptyResource = new SamlProvidersResource();
// 		emptyResource.setProviders(Collections.emptyList());
// 		return emptyResource;
// 	}
// 	SamlProvidersResource resource = new SamlProvidersResource();
// 	resource.setProviders(integrations.stream().map(TO_RESOURCE).collect(Collectors.toList()));
// 	return resource;
// };


// Path: src/main/java/com/epam/reportportal/auth/integration/handler/impl/GetSamlIntegrationsStrategy.java
import com.epam.reportportal.auth.integration.AuthIntegrationType;
import com.epam.reportportal.auth.integration.handler.GetAuthIntegrationStrategy;
import com.epam.ta.reportportal.dao.IntegrationRepository;
import com.epam.ta.reportportal.dao.IntegrationTypeRepository;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.entity.integration.IntegrationType;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.epam.ta.reportportal.ws.model.integration.auth.AbstractAuthResource;
import com.epam.ta.reportportal.ws.model.integration.auth.SamlProvidersResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import static com.epam.reportportal.auth.integration.converter.SamlConverter.TO_PROVIDERS_RESOURCE;

package com.epam.reportportal.auth.integration.handler.impl;




/**
 * @author <a href="mailto:ihar_kahadouski@epam.com">Ihar Kahadouski</a>
 */
@Service
public class GetSamlIntegrationsStrategy implements GetAuthIntegrationStrategy {

	private IntegrationTypeRepository integrationTypeRepository;

	private IntegrationRepository integrationRepository;

	@Autowired
	public GetSamlIntegrationsStrategy(IntegrationTypeRepository integrationTypeRepository, IntegrationRepository integrationRepository) {
		this.integrationTypeRepository = integrationTypeRepository;
		this.integrationRepository = integrationRepository;
	}

	@Override
	public AbstractAuthResource getIntegration() {
		IntegrationType samlIntegrationType = integrationTypeRepository.findByName(AuthIntegrationType.SAML.getName())
				.orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, AuthIntegrationType.SAML.getName()));
		List<Integration> providers = integrationRepository.findAllGlobalByType(samlIntegrationType);
		SamlProvidersResource resource = TO_PROVIDERS_RESOURCE.apply(providers);
		resource.setType(samlIntegrationType.getName());