// Path: src/main/java/act/aaa/model/UserLinked.java
// public interface UserLinked {
// 
//     boolean isLinkedTo(Principal user);
// 
//     class DynamicPermissionChecker extends DynamicPermissionCheckHelperBase<UserLinked> {
//         @Override
//         public boolean isAssociated(UserLinked target, Principal user) {
//             return target.isLinkedTo(user);
//         }
//     }
// 
// }
// 
// Path: testapps/jpa_model_id/src/main/java/jpa_test/endpoint/CustomerLinked.java
// public interface CustomerLinked {
// 
//     boolean isLinkedToCustomer(Principal principal);
// 
//     class DynamicPermissionChecker extends DynamicPermissionCheckHelperBase<CustomerLinked> {
//         @Override
//         public boolean isAssociated(CustomerLinked target, Principal user) {
//             return target.isLinkedToCustomer(user);
//         }
// 
//         @Override
//         protected List<String> permissionNames() {
//             return C.list("view-my-order");
//         }
//     }
// 
// }


import act.aaa.model.UserLinked;
import act.db.jpa.JPADao;
import act.util.SimpleBean;
import act.util.Stateless;
import org.osgl.aaa.Principal;
import org.osgl.util.S;
import jpa_test.endpoint.CustomerLinked;
import javax.persistence.*;
package jpa_test.model;



@Entity(name = "orders")
public class Order implements SimpleBean, UserLinked, CustomerLinked {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "agent_id")
    public User agent;

    @ManyToOne(optional = false)
    @JoinColumn(name = "cust_id", nullable = false)
    public User customer;

    public String product;

    public int quantity;

    @Override
    public boolean isLinkedTo(Principal user) {
        String agentName = null == agent ? null : agent.email;
        String username = user.getName();
        return S.eq(username, agentName);
    }

// Path: src/main/java/act/aaa/model/UserLinked.java
// public interface UserLinked {
// 
//     boolean isLinkedTo(Principal user);
// 
//     class DynamicPermissionChecker extends DynamicPermissionCheckHelperBase<UserLinked> {
//         @Override
//         public boolean isAssociated(UserLinked target, Principal user) {
//             return target.isLinkedTo(user);
//         }
//     }
// 
// }
// 
// Path: testapps/jpa_model_id/src/main/java/jpa_test/endpoint/CustomerLinked.java
// public interface CustomerLinked {
// 
//     boolean isLinkedToCustomer(Principal principal);
// 
//     class DynamicPermissionChecker extends DynamicPermissionCheckHelperBase<CustomerLinked> {
//         @Override
//         public boolean isAssociated(CustomerLinked target, Principal user) {
//             return target.isLinkedToCustomer(user);
//         }
// 
//         @Override
//         protected List<String> permissionNames() {
//             return C.list("view-my-order");
//         }
//     }
// 
// }


// Path: testapps/jpa_model_id/src/main/java/jpa_test/model/Order.java
import act.aaa.model.UserLinked;
import act.db.jpa.JPADao;
import act.util.SimpleBean;
import act.util.Stateless;
import org.osgl.aaa.Principal;
import org.osgl.util.S;
import jpa_test.endpoint.CustomerLinked;
import javax.persistence.*;

package jpa_test.model;



@Entity(name = "orders")
public class Order implements SimpleBean, UserLinked, CustomerLinked {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "agent_id")
    public User agent;

    @ManyToOne(optional = false)
    @JoinColumn(name = "cust_id", nullable = false)
    public User customer;

    public String product;

    public int quantity;

    @Override
    public boolean isLinkedTo(Principal user) {
        String agentName = null == agent ? null : agent.email;
        String username = user.getName();
        return S.eq(username, agentName);
    }

    @Override