// Path: osgi.enroute.examples.plugin.application/src/osgi/enroute/examples/plugin/api/Product.java
// public class Product extends DTO {
// 	public String	supplier;
// 	public String	id;
// 	public String	name;
// 	public String	description;
// 	public long		price;
// 	public int		inStock;
// 	public int		deliveryTimeInDays;
// }
// 
// Path: osgi.enroute.examples.plugin.application/src/osgi/enroute/examples/plugin/api/SupplierPlugin.java
// public interface SupplierPlugin {
//     Set<Product> findProducts( String query );
//     boolean buy( String id);
//     String getSupplierId();
// }


import java.io.InputStream;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.examples.plugin.api.Product;
import osgi.enroute.examples.plugin.api.SupplierPlugin;
package osgi.enroute.examples.plugin.test.provider;




@Component
public class TestSupplier implements SupplierPlugin {

	@Reference
	DTOs dtos;

	Product[] products;

	@Activate
	void activate() throws Exception {
		try {
			InputStream in = TestSupplier.class.getResourceAsStream("products.json");
			products = dtos.decoder(Product[].class).get(in);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public Set<Product> findProducts(String query) {
		return Stream.of(products)//
				.filter(p -> p.description.toLowerCase().contains(query.toLowerCase()))//
				.collect(Collectors.toSet());
	}

	@Override
	public boolean buy(String id) {
// Path: osgi.enroute.examples.plugin.application/src/osgi/enroute/examples/plugin/api/Product.java
// public class Product extends DTO {
// 	public String	supplier;
// 	public String	id;
// 	public String	name;
// 	public String	description;
// 	public long		price;
// 	public int		inStock;
// 	public int		deliveryTimeInDays;
// }
// 
// Path: osgi.enroute.examples.plugin.application/src/osgi/enroute/examples/plugin/api/SupplierPlugin.java
// public interface SupplierPlugin {
//     Set<Product> findProducts( String query );
//     boolean buy( String id);
//     String getSupplierId();
// }


// Path: osgi.enroute.examples.plugin.application/src/osgi/enroute/examples/plugin/test/provider/TestSupplier.java
import java.io.InputStream;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.examples.plugin.api.Product;
import osgi.enroute.examples.plugin.api.SupplierPlugin;

package osgi.enroute.examples.plugin.test.provider;




@Component
public class TestSupplier implements SupplierPlugin {

	@Reference
	DTOs dtos;

	Product[] products;

	@Activate
	void activate() throws Exception {
		try {
			InputStream in = TestSupplier.class.getResourceAsStream("products.json");
			products = dtos.decoder(Product[].class).get(in);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public Set<Product> findProducts(String query) {
		return Stream.of(products)//
				.filter(p -> p.description.toLowerCase().contains(query.toLowerCase()))//
				.collect(Collectors.toSet());
	}

	@Override
	public boolean buy(String id) {
		Optional<Product> product = Stream.of(products).filter(p -> p.id.equals(id)).findFirst();