-
Notifications
You must be signed in to change notification settings - Fork 7
Rbac
Moon Rbac use DDD Pattern, it support the menu,role,user and permission it provide some base class to do some generic things.
All the Domain should extend from BaseDomain, the BaseDomain provide the domain object save/update/delete operations. All these operations would send correspondence topic message.
For example,for the User domain. if the User domain extend from BaseDomain. the BaseDomain would send follow topic messages:
topic | operation
------------------------------
user/save | save
------------------------------
user/update | update
------------------------------
user/delete | delete
------------------------------
Note:there default use class name (first lower case) and operation as topic
BaseEventHandler would register the handler for the topic what basedomain send(save/update/delete), the EventHandler of domain should extend this class and override the save/update/delete method.
Example: reference the User Domain
BaseService provide two methods:
public T get(Long id);
public T load(Long id);
The get method is for fetch domain object from the domain cache, if not existed in the cache, then would call load to fetch and add into cache with domain model key
This interface use to fetch the domain when not exist in cache. Must implement the loadModel method, In Moon,it can just direct call the BaseService.load() . In Moon, the domain service also can be treated as the domain loader, so the domain service should be implement the ModelLoader interface.
BaseRepository provide some common method for domain repository.contains:
public T get(Long id);
public Long save(T domain);
public Long update(T domain,String...columns);
public Long delete(Long id);
If a doamin repository extend this, there no need anything in java code side. Only need add the correspondence sql statement in the mybatis mapper. In Moon,All the repositories extend from BaseRepository
For one domain,Moon has follow things,which in ddd+cqrs pattern. developer can change to any pattern when use moon ,there just the default pattern in Moon.there should has follow things:
- In this class,should contains the properties which belong to current domain.
- should annotated with @Model, so that the domain container would recognize them
- should extends from
BaseDomain(What we talk above)
- should annotated with
@Introduce("message") - define the event message sender method.which should annotated with
@Send(topic), eg:
@Send("user/get")
public DomainMessage getUser(Long id){
return new DomainMessage(id);
}
- the handler method should be annotated with
@OnEvent(topic), there the topic should be same with the corresponding topic which send by Event/Role with@Send - Event Handler should be a instance which managed by spring container.so should be annotated with
@Component
- In Moon,Domain Service should implement the
ModelLoader. so that the service can be treated as domain loader - Domain Service should extend from the BaseService. and make the
get(id)method with annation@OnEvent(xxx/get).(sometimes,one domain object may need get another domain object, so send an event to get,each domain service should handle this topic message)
- Mapper contains a serious of sql statement that used by repository to persistent data
- Each sql block should has a id property,which should be same with the caller method name. For More about MyBatis,look here