// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/data/GroupInfo.java
// @Document
// @Data
// @EqualsAndHashCode(of = "groupName")
// public class GroupInfo {
// 	@Id
// 	@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
// 	private String id;
// 
// 	@NotNull
// 	@Field
// 	private String groupName;
// 
// 	@NotNull
// 	@Field
// 	private UserInfo groupOwner;
// 
// 	public GroupInfo() {
// 		super();
// 	}
// 
// 	public GroupInfo(String groupName, UserInfo groupOwner) {
// 		super();
// 		this.groupName = groupName;
// 		this.groupOwner = groupOwner;
// 	}
// }
// 
// Path: spring-data-plain-demo/src/main/java/org/springframework/data/demo/data/GroupMember.java
// @Entity
// @org.springframework.data.mongodb.core.mapping.Document
// @Data
// @EqualsAndHashCode(of = {"member", "memberOfgroup"})
// public class GroupMember {
//     @NotNull
//     private Boolean enabled;
//     // Using a string id for use in both MongoDB and JPA.
//     @Id
//     @com.couchbase.client.java.repository.annotation.Id
//     @GeneratedValue(generator = "system-uuid")
//     @GenericGenerator(name = "system-uuid", strategy = "uuid2")
//     private String id;
//     @NotNull
//     @ManyToOne
//     @DBRef
//     private UserInfo member;
//     @NotNull
//     @ManyToOne
//     @DBRef
//     private GroupInfo memberOfgroup;
// 
//     public GroupMember() {
//         super();
//     }
// 
//     public GroupMember(GroupInfo memberOfgroup, UserInfo member, Boolean enabled) {
//         super();
//         this.memberOfgroup = memberOfgroup;
//         this.member = member;
//         this.enabled = enabled;
//     }
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/data/UserInfo.java
// @Document
// @Data
// @EqualsAndHashCode(of = "userId")
// public class UserInfo {
// 	@Id
// 	@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
// 	private String id;
// 
// 	@Field
// 	private Date dateOfBirth;
// 
// 	@Field
// 	private String emailAddress;
// 
// 	@NotNull
// 	@Field
// 	private String fullName;
// 
// 	@NotNull
// 	@Field
// 	private String userId;
// 
// 	public UserInfo() {
// 		super();
// 	}
// 
// 	public UserInfo(String userId, String fullName) {
// 		this.userId = userId;
// 		this.fullName = fullName;
// 	}
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/GroupMemberRepository.java
// @N1qlPrimaryIndexed
// @ViewIndexed(designDoc = "groupMember")
// public interface GroupMemberRepository extends CouchbaseRepository<GroupMember, String> {
// 	List<GroupMember> findByMemberOfgroup(GroupInfo group);
// 	List<GroupMember> findByMemberOfgroupAndEnabledTrue(GroupInfo group);
// 	List<GroupMember> findByMemberUserIdAndEnabledTrue(String userId);
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/GroupInfoRepository.java
// @ViewIndexed(designDoc = "groupInfo")
// public interface GroupInfoRepository extends CouchbaseRepository<GroupInfo, String> {
// 	GroupInfo findByGroupName(String name);
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/UserInfoRepository.java
// @N1qlPrimaryIndexed
// @ViewIndexed(designDoc = "userInfo")
// public interface UserInfoRepository extends CouchbaseRepository<UserInfo, String> {
// 	UserInfo findByUserId(String userId);
// }


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.demo.data.GroupInfo;
import org.springframework.data.demo.data.GroupMember;
import org.springframework.data.demo.data.UserInfo;
import org.springframework.data.demo.repository.GroupMemberRepository;
import org.springframework.data.demo.repository.GroupInfoRepository;
import org.springframework.data.demo.repository.UserInfoRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
    }

    @Override
    @Transactional
    public void deleteUserInfo(UserInfo userInfo) {
        logger.info("deleteUserInfo:" + userInfo);
        userInfoRepository.delete(userInfo);
    }

    @Override
    @Transactional(readOnly = true)
    public GroupInfo findGroup(String name) {
        logger.info("findGroup:" + name);
        return groupInfoRepository.findByGroupName(name);
    }

    @Override
    @Transactional(readOnly = true)
    public UserInfo findUser(String userId) {
        logger.info("findUser:" + userId);
        return userInfoRepository.findByUserId(userId);
    }

    @Override
    @Transactional(readOnly = true)
    public List<UserInfo> listActiveUsersInGroup(String groupName) {
        logger.info("listActiveUsersInGroup:" + groupName);
        List<UserInfo> userList = new ArrayList<UserInfo>();
        GroupInfo group = groupInfoRepository.findByGroupName(groupName);
        List<GroupMember> members = memberRepository.findByMemberOfgroupAndEnabledTrue(group);
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/data/GroupInfo.java
// @Document
// @Data
// @EqualsAndHashCode(of = "groupName")
// public class GroupInfo {
// 	@Id
// 	@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
// 	private String id;
// 
// 	@NotNull
// 	@Field
// 	private String groupName;
// 
// 	@NotNull
// 	@Field
// 	private UserInfo groupOwner;
// 
// 	public GroupInfo() {
// 		super();
// 	}
// 
// 	public GroupInfo(String groupName, UserInfo groupOwner) {
// 		super();
// 		this.groupName = groupName;
// 		this.groupOwner = groupOwner;
// 	}
// }
// 
// Path: spring-data-plain-demo/src/main/java/org/springframework/data/demo/data/GroupMember.java
// @Entity
// @org.springframework.data.mongodb.core.mapping.Document
// @Data
// @EqualsAndHashCode(of = {"member", "memberOfgroup"})
// public class GroupMember {
//     @NotNull
//     private Boolean enabled;
//     // Using a string id for use in both MongoDB and JPA.
//     @Id
//     @com.couchbase.client.java.repository.annotation.Id
//     @GeneratedValue(generator = "system-uuid")
//     @GenericGenerator(name = "system-uuid", strategy = "uuid2")
//     private String id;
//     @NotNull
//     @ManyToOne
//     @DBRef
//     private UserInfo member;
//     @NotNull
//     @ManyToOne
//     @DBRef
//     private GroupInfo memberOfgroup;
// 
//     public GroupMember() {
//         super();
//     }
// 
//     public GroupMember(GroupInfo memberOfgroup, UserInfo member, Boolean enabled) {
//         super();
//         this.memberOfgroup = memberOfgroup;
//         this.member = member;
//         this.enabled = enabled;
//     }
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/data/UserInfo.java
// @Document
// @Data
// @EqualsAndHashCode(of = "userId")
// public class UserInfo {
// 	@Id
// 	@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
// 	private String id;
// 
// 	@Field
// 	private Date dateOfBirth;
// 
// 	@Field
// 	private String emailAddress;
// 
// 	@NotNull
// 	@Field
// 	private String fullName;
// 
// 	@NotNull
// 	@Field
// 	private String userId;
// 
// 	public UserInfo() {
// 		super();
// 	}
// 
// 	public UserInfo(String userId, String fullName) {
// 		this.userId = userId;
// 		this.fullName = fullName;
// 	}
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/GroupMemberRepository.java
// @N1qlPrimaryIndexed
// @ViewIndexed(designDoc = "groupMember")
// public interface GroupMemberRepository extends CouchbaseRepository<GroupMember, String> {
// 	List<GroupMember> findByMemberOfgroup(GroupInfo group);
// 	List<GroupMember> findByMemberOfgroupAndEnabledTrue(GroupInfo group);
// 	List<GroupMember> findByMemberUserIdAndEnabledTrue(String userId);
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/GroupInfoRepository.java
// @ViewIndexed(designDoc = "groupInfo")
// public interface GroupInfoRepository extends CouchbaseRepository<GroupInfo, String> {
// 	GroupInfo findByGroupName(String name);
// }
// 
// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/repository/UserInfoRepository.java
// @N1qlPrimaryIndexed
// @ViewIndexed(designDoc = "userInfo")
// public interface UserInfoRepository extends CouchbaseRepository<UserInfo, String> {
// 	UserInfo findByUserId(String userId);
// }


// Path: spring-data-couchbase-demo/src/main/java/org/springframework/data/demo/service/UserGroupDataServiceImpl.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.demo.data.GroupInfo;
import org.springframework.data.demo.data.GroupMember;
import org.springframework.data.demo.data.UserInfo;
import org.springframework.data.demo.repository.GroupMemberRepository;
import org.springframework.data.demo.repository.GroupInfoRepository;
import org.springframework.data.demo.repository.UserInfoRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

    }

    @Override
    @Transactional
    public void deleteUserInfo(UserInfo userInfo) {
        logger.info("deleteUserInfo:" + userInfo);
        userInfoRepository.delete(userInfo);
    }

    @Override
    @Transactional(readOnly = true)
    public GroupInfo findGroup(String name) {
        logger.info("findGroup:" + name);
        return groupInfoRepository.findByGroupName(name);
    }

    @Override
    @Transactional(readOnly = true)
    public UserInfo findUser(String userId) {
        logger.info("findUser:" + userId);
        return userInfoRepository.findByUserId(userId);
    }

    @Override
    @Transactional(readOnly = true)
    public List<UserInfo> listActiveUsersInGroup(String groupName) {
        logger.info("listActiveUsersInGroup:" + groupName);
        List<UserInfo> userList = new ArrayList<UserInfo>();
        GroupInfo group = groupInfoRepository.findByGroupName(groupName);
        List<GroupMember> members = memberRepository.findByMemberOfgroupAndEnabledTrue(group);
        for (GroupMember member : members) {