Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
logwire-bo-persistence
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
薛涛 Toby Xue
logwire-bo-persistence
Commits
c3f628bb
Commit
c3f628bb
authored
Nov 30, 2020
by
薛涛 Toby Xue
🆒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
load handler
parent
657d18ca
Pipeline
#4022
canceled with stages
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
51 deletions
+122
-51
BoRelationDefinition.java
src/main/java/logwire/web/bo/BoRelationDefinition.java
+47
-10
BoRelationBeanDefinitionLoader.java
...logwire/web/bo/loader/BoRelationBeanDefinitionLoader.java
+41
-23
LoaderUtil.java
src/main/java/logwire/web/bo/loader/LoaderUtil.java
+5
-0
TypeOperationInterceptor.java
...n/java/logwire/web/bo/proxy/TypeOperationInterceptor.java
+29
-18
No files found.
src/main/java/logwire/web/bo/BoRelationDefinition.java
View file @
c3f628bb
package
logwire
.
web
.
bo
;
import
logwire.core.bo.handler.OperationHandler
;
import
logwire.core.bo.eventhandler.ListOperationEventHandler
;
import
logwire.core.bo.eventhandler.ObjectOperationEventHandler
;
import
logwire.core.bo.eventhandler.TypeOperationEventHandler
;
import
logwire.core.bo.handler.ListOperationHandler
;
import
logwire.core.bo.handler.ObjectOperationHandler
;
import
logwire.core.bo.handler.TypeOperationHandler
;
import
logwire.core.bo.object.BizObject
;
import
logwire.core.meta.Config
;
import
logwire.core.resource.bean.BeanAdapter
;
...
...
@@ -31,14 +36,22 @@ public class BoRelationDefinition extends BeanAdapter {
private
List
<
Class
>
listOperationProviders
=
new
ArrayList
<>();
@Config
private
List
<
OperationHandler
>
typeOperationHandlers
=
new
ArrayList
<>();
private
List
<
Type
OperationHandler
>
typeOperationHandlers
=
new
ArrayList
<>();
@Config
private
List
<
Class
>
objectOperationHandlers
=
new
ArrayList
<>();
private
List
<
ObjectOperationHandler
>
objectOperationHandlers
=
new
ArrayList
<>();
@Config
private
List
<
Class
>
listOperationHandlers
=
new
ArrayList
<>();
private
List
<
ListOperationHandler
>
listOperationHandlers
=
new
ArrayList
<>();
@Config
private
List
<
TypeOperationEventHandler
>
typeOperationEventHandlers
=
new
ArrayList
<>();
@Config
private
List
<
ObjectOperationEventHandler
>
objectOperationEventHandlers
=
new
ArrayList
<>();
@Config
private
List
<
ListOperationEventHandler
>
listOperationEventHandlers
=
new
ArrayList
<>();
public
List
<
Class
>
getTypeOperationProviders
()
{
return
typeOperationProviders
;
...
...
@@ -77,27 +90,27 @@ public class BoRelationDefinition extends BeanAdapter {
this
.
listOperationProviders
.
add
(
listOperationProvider
);
}
public
List
<
OperationHandler
>
getTypeOperationHandlers
()
{
public
List
<
Type
OperationHandler
>
getTypeOperationHandlers
()
{
return
typeOperationHandlers
;
}
public
void
setTypeOperationHandlers
(
List
<
OperationHandler
>
typeOperationHandlers
)
{
public
void
setTypeOperationHandlers
(
List
<
Type
OperationHandler
>
typeOperationHandlers
)
{
this
.
typeOperationHandlers
=
typeOperationHandlers
;
}
public
List
<
Class
>
getObjectOperationHandlers
()
{
public
List
<
ObjectOperationHandler
>
getObjectOperationHandlers
()
{
return
objectOperationHandlers
;
}
public
void
setObjectOperationHandlers
(
List
<
Class
>
objectOperationHandlers
)
{
public
void
setObjectOperationHandlers
(
List
<
ObjectOperationHandler
>
objectOperationHandlers
)
{
this
.
objectOperationHandlers
=
objectOperationHandlers
;
}
public
List
<
Class
>
getListOperationHandlers
()
{
public
List
<
ListOperationHandler
>
getListOperationHandlers
()
{
return
listOperationHandlers
;
}
public
void
setListOperationHandlers
(
List
<
Class
>
listOperationHandlers
)
{
public
void
setListOperationHandlers
(
List
<
ListOperationHandler
>
listOperationHandlers
)
{
this
.
listOperationHandlers
=
listOperationHandlers
;
}
...
...
@@ -126,4 +139,28 @@ public class BoRelationDefinition extends BeanAdapter {
public
void
setBoServiceInitialized
(
boolean
boServiceInitialized
)
{
this
.
boServiceInitialized
=
boServiceInitialized
;
}
public
List
<
TypeOperationEventHandler
>
getTypeOperationEventHandlers
()
{
return
typeOperationEventHandlers
;
}
public
void
setTypeOperationEventHandlers
(
List
<
TypeOperationEventHandler
>
typeOperationEventHandlers
)
{
this
.
typeOperationEventHandlers
=
typeOperationEventHandlers
;
}
public
List
<
ObjectOperationEventHandler
>
getObjectOperationEventHandlers
()
{
return
objectOperationEventHandlers
;
}
public
void
setObjectOperationEventHandlers
(
List
<
ObjectOperationEventHandler
>
objectOperationEventHandlers
)
{
this
.
objectOperationEventHandlers
=
objectOperationEventHandlers
;
}
public
List
<
ListOperationEventHandler
>
getListOperationEventHandlers
()
{
return
listOperationEventHandlers
;
}
public
void
setListOperationEventHandlers
(
List
<
ListOperationEventHandler
>
listOperationEventHandlers
)
{
this
.
listOperationEventHandlers
=
listOperationEventHandlers
;
}
}
src/main/java/logwire/web/bo/loader/BoRelationBeanDefinitionLoader.java
View file @
c3f628bb
...
...
@@ -5,7 +5,12 @@ import logwire.core.bo.annotation.BizModel;
import
logwire.core.bo.annotation.ListOperationProvider
;
import
logwire.core.bo.annotation.ObjectOperationProvider
;
import
logwire.core.bo.annotation.TypeOperationProvider
;
import
logwire.core.bo.eventhandler.ListOperationEventHandler
;
import
logwire.core.bo.eventhandler.ObjectOperationEventHandler
;
import
logwire.core.bo.eventhandler.OperationEventHandler
;
import
logwire.core.bo.eventhandler.TypeOperationEventHandler
;
import
logwire.core.bo.handler.ListOperationHandler
;
import
logwire.core.bo.handler.ObjectOperationHandler
;
import
logwire.core.bo.handler.OperationHandler
;
import
logwire.core.bo.handler.TypeOperationHandler
;
import
logwire.core.bo.object.BizObject
;
...
...
@@ -69,14 +74,18 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
field
.
set
(
null
,
o
);
boRelationDefinition
.
setBoServiceInitialized
(
true
);
}
catch
(
NoSuchFieldException
|
IllegalAccessException
|
InstantiationException
e
)
{
//TODO
e
.
printStackTrace
();
}
}
}
private
Map
<
String
,
BoRelationDefinition
>
loadBeanDefinition
(
TenantProject
project
)
throws
ClassNotFoundException
{
/**
* @param project
* @return
* @throws Exception
*/
private
Map
<
String
,
BoRelationDefinition
>
loadBeanDefinition
(
TenantProject
project
)
throws
Exception
{
Map
<
String
,
BoRelationDefinition
>
boRelationBeanDefinitions
=
Maps
.
newHashMap
();
TenantClassLoader
classLoader
=
project
.
getTenantBeanContext
().
getTenantClassLoader
();
ClassPathScanningCandidateComponentProvider
provider
=
loaderUtil
.
getScanningBeanProvider
();
...
...
@@ -93,14 +102,12 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
//handler
if
(
loaderUtil
.
isOperationHandler
(
clazz
))
{
if
(!
isConcrete
((
ScannedGenericBeanDefinition
)
boClassDefinition
))
continue
;
addOperationHandlerBeanDefinition
(
boRelationBeanDefinitions
,
(
Class
<
OperationHandler
>)
clazz
);
addOperationHandler
(
boRelationBeanDefinitions
,
(
Class
<
OperationHandler
>)
clazz
);
}
//event_handler
else
if
(
OperationEventHandler
.
class
.
isAssignableFrom
(
clazz
))
{
else
if
(
loaderUtil
.
isOperationEventHandler
(
clazz
))
{
if
(!
isConcrete
((
ScannedGenericBeanDefinition
)
boClassDefinition
))
continue
;
//TODO
addOperationEventHandler
(
boRelationBeanDefinitions
,
clazz
);
addOperationEventHandler
(
boRelationBeanDefinitions
,
(
Class
<
OperationEventHandler
>)
clazz
);
}
//operation
else
if
(
clazz
.
getAnnotation
(
TypeOperationProvider
.
class
)
!=
null
)
{
...
...
@@ -114,8 +121,6 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
boRelationBeanDefinitions
.
get
(
type
.
getSimpleName
()).
addListOperationProvider
(
clazz
);
}
}
}
return
boRelationBeanDefinitions
;
}
...
...
@@ -140,23 +145,36 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
provider
.
addIncludeFilter
(
new
AnnotationTypeFilter
(
ListOperationProvider
.
class
));
}
private
void
addOperationEventHandler
(
Map
<
String
,
BoRelationDefinition
>
bizObjectBeanMap
,
Class
<?>
beanClass
)
{
//TODO
private
void
addOperationEventHandler
(
Map
<
String
,
BoRelationDefinition
>
bizObjectBeanMap
,
Class
<
OperationEventHandler
>
clazz
)
throws
IllegalAccessException
,
InstantiationException
{
//get BizObject from genericInterface
Class
<?
extends
BizObject
>
bizObject
=
(
Class
<?
extends
BizObject
>)
((
ParameterizedType
)
clazz
.
getGenericInterfaces
()[
0
]).
getActualTypeArguments
()[
0
];
BoRelationDefinition
boRelationDefinition
=
bizObjectBeanMap
.
get
(
bizObject
.
getSimpleName
());
OperationEventHandler
opEventHandler
=
clazz
.
newInstance
();
if
(
opEventHandler
.
isEnabled
())
{
if
(
TypeOperationEventHandler
.
class
.
isAssignableFrom
(
clazz
))
{
boRelationDefinition
.
getTypeOperationEventHandlers
().
add
((
TypeOperationEventHandler
)
opEventHandler
);
}
else
if
(
TypeOperationHandler
.
class
.
isAssignableFrom
(
clazz
))
{
boRelationDefinition
.
getObjectOperationEventHandlers
().
add
((
ObjectOperationEventHandler
)
opEventHandler
);
}
else
{
boRelationDefinition
.
getListOperationEventHandlers
().
add
((
ListOperationEventHandler
)
opEventHandler
);
}
}
}
private
void
addOperationHandler
BeanDefinition
(
Map
<
String
,
BoRelationDefinition
>
bizObjectBeanMap
,
Class
<
OperationHandler
>
clazz
)
{
if
(
TypeOperationHandler
.
class
.
isAssignableFrom
(
clazz
))
{
private
void
addOperationHandler
(
Map
<
String
,
BoRelationDefinition
>
bizObjectBeanMap
,
Class
<
OperationHandler
>
clazz
)
throws
IllegalAccessException
,
InstantiationException
{
//get BizObject from genericInterface
Class
<?
extends
BizObject
>
bizObject
=
(
Class
<?
extends
BizObject
>)
((
ParameterizedType
)
clazz
.
getGenericInterfaces
()[
0
]).
getActualTypeArguments
()[
0
];
BoRelationDefinition
boRelationDefinition
=
bizObjectBeanMap
.
get
(
bizObject
.
getSimpleName
());
try
{
boRelationDefinition
.
getTypeOperationHandlers
().
add
(
clazz
.
newInstance
());
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
OperationHandler
opHandler
=
clazz
.
newInstance
();
if
(
opHandler
.
isEnabled
())
{
if
(
TypeOperationHandler
.
class
.
isAssignableFrom
(
clazz
))
{
boRelationDefinition
.
getTypeOperationHandlers
().
add
((
TypeOperationHandler
)
opHandler
);
}
else
if
(
ObjectOperationHandler
.
class
.
isAssignableFrom
(
clazz
))
{
boRelationDefinition
.
getObjectOperationHandlers
().
add
((
ObjectOperationHandler
)
opHandler
);
}
else
if
(
ListOperationHandler
.
class
.
isAssignableFrom
(
clazz
))
{
boRelationDefinition
.
getListOperationHandlers
().
add
((
ListOperationHandler
)
opHandler
);
}
}
}
private
boolean
isConcrete
(
ScannedGenericBeanDefinition
beanDefinition
)
{
...
...
src/main/java/logwire/web/bo/loader/LoaderUtil.java
View file @
c3f628bb
package
logwire
.
web
.
bo
.
loader
;
import
logwire.core.bo.eventhandler.OperationEventHandler
;
import
logwire.core.bo.handler.OperationHandler
;
import
logwire.core.bo.object.BizObject
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
...
...
@@ -33,6 +34,10 @@ public class LoaderUtil {
return
OperationHandler
.
class
.
isAssignableFrom
(
beanClass
);
}
public
boolean
isOperationEventHandler
(
Class
<?>
beanClass
)
{
return
OperationEventHandler
.
class
.
isAssignableFrom
(
beanClass
);
}
private
class
AbstractTypeFilter
extends
AssignableTypeFilter
{
public
AbstractTypeFilter
(
Class
<?>
targetType
)
{
super
(
targetType
);
...
...
src/main/java/logwire/web/bo/proxy/TypeOperationInterceptor.java
View file @
c3f628bb
package
logwire
.
web
.
bo
.
proxy
;
import
logwire.core.bo.handler.
Operation
Handler
;
import
logwire.core.bo.
handler.TypeOperationHandler
;
import
logwire.core.bo.handler.Handler
;
import
logwire.core.bo.
object.BizObject
;
import
logwire.web.bo.BoRelationDefinition
;
import
logwire.web.security.SecurityUtil
;
import
logwire.web.security.TenantUser
;
import
net.bytebuddy.implementation.bind.annotation.AllArguments
;
import
net.bytebuddy.implementation.bind.annotation.Origin
;
import
net.bytebuddy.implementation.bind.annotation.SuperMethod
;
import
net.bytebuddy.implementation.bind.annotation.This
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.lang.reflect.Method
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.function.Function
;
public
class
TypeOperationInterceptor
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
TypeOperationInterceptor
.
class
);
private
BoRelationDefinition
boRelationDefinition
;
public
TypeOperationInterceptor
(
BoRelationDefinition
boRelationDefinition
)
{
...
...
@@ -35,23 +38,31 @@ public class TypeOperationInterceptor {
}
/**
* 根据methodName
找到
对应的handler
* 根据methodName
执行
对应的handler
*/
private
Object
doHandler
(
Method
method
,
Object
[]
args
)
{
List
<
OperationHandler
>
typeOperationHandlers
=
boRelationDefinition
.
getTypeOperationHandlers
();
OperationHandler
operationHandler
=
typeOperationHandlers
.
stream
()
.
filter
(
typeOperationHandler
->
{
return
method
.
getName
().
equals
(
typeOperationHandler
.
getOperation
());
})
.
max
(
Comparator
.
comparing
(
OperationHandler:
:
getOrder
)).
get
();
TenantUser
currentUser
=
SecurityUtil
.
currentUser
();
/* logger.debug("Execute operation {} start", new Object[]{operationName});
String namespace = logwire.core.resource.Util.operationName(thisOperable.getOperableName(), operationName);
actionContext.emit(namespace, BuiltinEventNames.OPERATION_BEFORE.name(), currentUser.getDomain(), new OperationEventData(thisOperable, inputArgs, null));
*/
return
((
TypeOperationHandler
)
operationHandler
).
execute
(
boRelationDefinition
.
getBoClass
(),
args
);
Class
<?
extends
BizObject
>
bizClazz
=
boRelationDefinition
.
getBoClass
();
String
operationName
=
method
.
getName
();
logger
.
debug
(
"Execute operation {} start"
,
new
Object
[]{
operationName
});
getHandler
(
operationName
,
boRelationDefinition
.
getTypeOperationEventHandlers
(),
typeOperationEventHandler
->
!
typeOperationEventHandler
.
isAfter
())
.
doBefore
(
bizClazz
,
args
);
Object
result
=
getHandler
(
operationName
,
boRelationDefinition
.
getTypeOperationHandlers
(),
typeOperationHandler
->
typeOperationHandler
.
accept
(
bizClazz
,
args
))
.
execute
(
bizClazz
,
args
);
getHandler
(
operationName
,
boRelationDefinition
.
getTypeOperationEventHandlers
(),
typeOperationEventHandler
->
typeOperationEventHandler
.
isAfter
())
.
doAfter
(
bizClazz
,
result
,
args
);
return
result
;
}
private
<
T
extends
Handler
>
T
getHandler
(
String
operation
,
List
<
T
>
handlers
,
Function
<
T
,
Boolean
>
function
)
{
return
handlers
.
stream
()
.
filter
(
handler
->
operation
.
equals
(
handler
.
getOperation
())
&&
function
.
apply
(
handler
))
.
max
(
Comparator
.
comparing
(
T:
:
getOrder
)).
get
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment