// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/model/Commodity.java
// @Document
// public class Commodity {
// 
//     @Id @Field("_id") private String code;
//     @Field private String name;
// 
//     public Commodity(String code, String name) {
//         this.code = code;
//         this.name = name;
//     }
// 
//     public String getCode() {
//         return code;
//     }
// 
//     public void setCode(String code) {
//         this.code = code;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
// }
// 
// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/repository/CommodityRepository.java
// @Repository
// public interface CommodityRepository extends MongoRepository<Commodity, String> {
// 
// }
// 
// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/util/CommonUtil.java
// public interface CommonUtil {
// 
//     static boolean isEmpty(String obj) {
//         return obj == null || obj.isEmpty();
//     }
// 
//     static boolean notEmpty(String obj) {
//         return !isEmpty(obj);
//     }
// 
// }
// 
// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/constants/Constants.java
// public interface Constants {
// 
//     String REF_DATA_EXCHANGE = "rpc.refdata.exchange";
// 
//     String COMMODITY_DATA_QUEUE = "commodity.data.queue";
//     String COUNTER_PARTY_DATA_QUEUE = "counterparty.data.queue";
//     String LOCATION_DATA_QUEUE = "location.data.queue";
// 
// }


import org.sapient.metalica.referencedataservice.model.Commodity;
import org.sapient.metalica.referencedataservice.repository.CommodityRepository;
import org.sapient.metalica.referencedataservice.util.CommonUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import static org.sapient.metalica.referencedataservice.constants.Constants.*;
package org.sapient.metalica.referencedataservice.controller;




public class CommodityListener {

    @Resource
    CommodityRepository commodityRepository;

    @RabbitListener(queues = COMMODITY_DATA_QUEUE)
    public Collection<Commodity> getCommodities(String code) {
        if (CommonUtil.isEmpty(code)) {
            return commodityRepository.findAll();
        }
// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/model/Commodity.java
// @Document
// public class Commodity {
// 
//     @Id @Field("_id") private String code;
//     @Field private String name;
// 
//     public Commodity(String code, String name) {
//         this.code = code;
//         this.name = name;
//     }
// 
//     public String getCode() {
//         return code;
//     }
// 
//     public void setCode(String code) {
//         this.code = code;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
// }
// 
// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/repository/CommodityRepository.java
// @Repository
// public interface CommodityRepository extends MongoRepository<Commodity, String> {
// 
// }
// 
// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/util/CommonUtil.java
// public interface CommonUtil {
// 
//     static boolean isEmpty(String obj) {
//         return obj == null || obj.isEmpty();
//     }
// 
//     static boolean notEmpty(String obj) {
//         return !isEmpty(obj);
//     }
// 
// }
// 
// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/constants/Constants.java
// public interface Constants {
// 
//     String REF_DATA_EXCHANGE = "rpc.refdata.exchange";
// 
//     String COMMODITY_DATA_QUEUE = "commodity.data.queue";
//     String COUNTER_PARTY_DATA_QUEUE = "counterparty.data.queue";
//     String LOCATION_DATA_QUEUE = "location.data.queue";
// 
// }


// Path: multiple-microservices-example/reference-data-service/src/main/java/org/sapient/metalica/referencedataservice/controller/CommodityListener.java
import org.sapient.metalica.referencedataservice.model.Commodity;
import org.sapient.metalica.referencedataservice.repository.CommodityRepository;
import org.sapient.metalica.referencedataservice.util.CommonUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import static org.sapient.metalica.referencedataservice.constants.Constants.*;

package org.sapient.metalica.referencedataservice.controller;




public class CommodityListener {

    @Resource
    CommodityRepository commodityRepository;

    @RabbitListener(queues = COMMODITY_DATA_QUEUE)
    public Collection<Commodity> getCommodities(String code) {
        if (CommonUtil.isEmpty(code)) {
            return commodityRepository.findAll();
        }
        return Collections.singletonList(commodityRepository.findOne(code));