}
public static SecurityModel generateModel() {
// This is creates base package
SecurityModel pack = UamFactory.eINSTANCE.createSecurityModel();
pack.setId("com.jresearchsoft.flexess.examples.orders.test"); //$NON-NLS-1$
pack.setName("orders"); //$NON-NLS-1$
pack.setNsPrefix("ord"); //$NON-NLS-1$
pack.setNsURI("http://www.jresearchsoft.com/schemas/orders"); //$NON-NLS-1$
EcoreUtil.setAnnotation(pack, UamPackage.eNS_URI, "#description", "test application"); //$NON-NLS-1$ //$NON-NLS-2$
PObject order = UamFactory.eINSTANCE.createPObject();
order.setId("order_pobject"); //$NON-NLS-1$
order.setName("order"); //$NON-NLS-1$
EcoreUtil.setAnnotation(order, UamPackage.eNS_URI, "#class_name", "com.jresearchsoft.uam.client.tests.Order"); //$NON-NLS-1$ //$NON-NLS-2$
EcoreUtil.setAnnotation(order, UamPackage.eNS_URI, "#mapper_name", "com.jresearchsoft.uam.client.mappers.impl.JavaInstanceMapper"); //$NON-NLS-1$ //$NON-NLS-2$
EcoreUtil.setAnnotation(order, UamPackage.eNS_URI, "#description", "customer order"); //$NON-NLS-1$ //$NON-NLS-2$
pack.getEClassifiers().add(order);
// region is an attribute for pObject and
EAttribute region = EcoreFactory.eINSTANCE.createEAttribute();
region.setName("region"); //$NON-NLS-1$
EcoreUtil.setAnnotation(region, UamPackage.eNS_URI, "#description", "region where the order comes"); //$NON-NLS-1$ //$NON-NLS-2$
region.setEType(EcorePackage.eINSTANCE.getEString());
order.getEStructuralFeatures().add(region);
// user id is an attribute - id of the current user
EAttribute userID = EcoreFactory.eINSTANCE.createEAttribute();
EcoreUtil.setAnnotation(userID, UamPackage.eNS_URI, IAttributeConstant.ANNOTATION_KEY_RUNTIME, "true"); //$NON-NLS-1$
userID.setName("userId"); //$NON-NLS-1$
userID.setEType(EcorePackage.eINSTANCE.getEString());
order.getEStructuralFeatures().add(userID);
// Now we create basic operations and add them to order
POperation createOp = UamFactory.eINSTANCE.createPOperation();
createOp.setId("create_operation"); //$NON-NLS-1$
createOp.setName("create"); //$NON-NLS-1$
POperation viewOp = UamFactory.eINSTANCE.createPOperation();
viewOp.setId("view_operation"); //$NON-NLS-1$
viewOp.setName("view"); //$NON-NLS-1$
POperation deleteOp = UamFactory.eINSTANCE.createPOperation();
deleteOp.setId("delete_operation"); //$NON-NLS-1$
deleteOp.setName("delete"); //$NON-NLS-1$
POperation updateOp = UamFactory.eINSTANCE.createPOperation();
updateOp.setId("update_operation"); //$NON-NLS-1$
updateOp.setName("update"); //$NON-NLS-1$
order.getEOperations().add(createOp);
order.getEOperations().add(viewOp);
order.getEOperations().add(deleteOp);
order.getEOperations().add(updateOp);
final String USER_EXPRESSION = "context orders::user_permission inv: login=object.userId"; //$NON-NLS-1$
final String REGION_EXPRESSION = "context orders::regional_permission inv: region=object.region"; //$NON-NLS-1$
Permission regionalPermission = UamFactory.eINSTANCE.createPermission();
regionalPermission.setId("regional_permission"); //$NON-NLS-1$
regionalPermission.setName("regional_permission"); //$NON-NLS-1$
Constraint constraint = UamFactory.eINSTANCE.createConstraint();
regionalPermission.setConstraint(constraint);
constraint.setExpession(REGION_EXPRESSION);
region = EcoreFactory.eINSTANCE.createEAttribute();
region.setName("region"); //$NON-NLS-1$
EcoreUtil.setAnnotation(region, UamPackage.eNS_URI, "#description", "region where the order comes"); //$NON-NLS-1$ //$NON-NLS-2$
region.setEType(EcorePackage.eINSTANCE.getEString());
regionalPermission.getEStructuralFeatures().add(region);
regionalPermission.setPObject(order);
// EMFUtil.addPobject(regionalPermission, order);
pack.getEClassifiers().add(regionalPermission);
// viewOp.getPermission().add(regionalPermission);
// createOp.getPermission().add(regionalPermission);
// deleteOp.getPermission().add(regionalPermission);
// updateOp.getPermission().add(regionalPermission);
Permission userPermission = UamFactory.eINSTANCE.createPermission();
userPermission.setId("user_permission"); //$NON-NLS-1$
userPermission.setName("user_permission"); //$NON-NLS-1$
Constraint userConstraint = UamFactory.eINSTANCE.createConstraint();
userPermission.setConstraint(userConstraint);
userConstraint.setExpession(USER_EXPRESSION);
userID = EcoreFactory.eINSTANCE.createEAttribute();
EcoreUtil.setAnnotation(userID, UamPackage.eNS_URI, IAttributeConstant.ANNOTATION_KEY_RUNTIME, "true"); //$NON-NLS-1$
userID.setName("login"); //$NON-NLS-1$
userID.setEType(EcorePackage.eINSTANCE.getEString());
userPermission.getEStructuralFeatures().add(userID);
pack.getEClassifiers().add(userPermission);
Role manager = UamFactory.eINSTANCE.createRole();
manager.setId("manager_role"); //$NON-NLS-1$
manager.setName("regional manager"); //$NON-NLS-1$
EcoreUtil.setAnnotation(manager, UamPackage.eNS_URI, "#description", "orders manager"); //$NON-NLS-1$ //$NON-NLS-2$
pack.getEClassifiers().add(manager);
EMFUtil.addPermission(manager, regionalPermission);
Role customer = UamFactory.eINSTANCE.createRole();
customer.setId("customer_role"); //$NON-NLS-1$
customer.setName("customer"); //$NON-NLS-1$
EcoreUtil.setAnnotation(customer, UamPackage.eNS_URI, "#description", "orders customer"); //$NON-NLS-1$ //$NON-NLS-2$
pack.getEClassifiers().add(customer);
userPermission.setPObject(order);
// EMFUtil.addPobject(userPermission, order);
// order.getPermission().add(userPermission);
EMFUtil.addPermission(customer, userPermission);
return pack;