From 07e34ad18e1d17e17e5d2ed0581115bab85b1366 Mon Sep 17 00:00:00 2001 From: "fulan.zjf" Date: Fri, 4 Jan 2019 15:08:27 +0800 Subject: [PATCH] change sofa to cola --- README.md | 105 ++---------------- {sofa-archetype => cola-archetype}/.gitignore | 0 {sofa-archetype => cola-archetype}/pom.xml | 8 +- .../META-INF/maven/archetype-metadata.xml | 18 +-- .../__rootArtifactId__-app/pom.xml | 7 +- .../main/java/command/CustomerAddCmdExe.java | 29 +++-- .../src/main/java/command/package-info.java | 0 .../query/CustomerFindByCriteriaQueryExe.java | 22 ++-- .../main/java/command/query/package-info.java | 0 .../java/convertor/CustomerConvertor.java | 37 ++++++ .../extension/CustomerBizOneConvertorExt.java | 28 +++++ .../extension/CustomerBizTwoConvertorExt.java | 28 +++++ .../CustomerConvertorExtPt.java | 11 +- .../CustomerCreatedSyncSearchHandler.java | 27 +++++ .../handler/CustomerCreatedSysLogHandler.java | 27 +++++ .../java/interceptor/ContextInterceptor.java | 30 +++++ .../interceptor/LoggerPostInterceptor.java | 20 ++-- .../interceptor/LoggerPreInterceptor.java | 16 +-- .../interceptor/ValidationInterceptor.java | 12 +- .../main/java/interceptor/package-info.java | 0 .../java/service/CustomerServiceImpl.java | 14 +-- .../src/main/java/service/package-info.java | 0 .../java/validator/CustomerAddValidator.java | 12 +- .../CustomerAddBizOneValidatorExt.java | 39 +++++++ .../CustomerAddBizTwoValidatorExt.java | 38 +++++++ .../validator/extension/package-info.java | 0 .../CustomerAddValidatorExtPt.java | 16 +++ .../extensionpoint/package-info.java | 0 .../src/main/java/validator/package-info.java | 0 .../test/java/app/CustomerConvertorTest.java | 62 +++++++++++ .../test/java/app/CustomerValidatorTest.java | 21 ++++ .../src/test/java/app/TestConfig.java | 29 +++++ .../__rootArtifactId__-client/pom.xml | 5 +- .../src/main/java/api/CustomerServiceI.java | 9 +- .../src/main/java/context/DemoContent.java | 39 +++++++ .../src/main/java/dto/CustomerAddCmd.java | 4 +- .../java/dto/CustomerFindByCriteriaQry.java | 2 +- .../main/java/dto/CustomerFindByNameQry.java | 2 +- .../src/main/java/dto/CustomerUpdateCmd.java | 2 +- .../java/dto/clientobject/CustomerCO.java | 9 +- .../java/dto/clientobject/CustomerType.java | 0 .../main/java/dto/clientobject/LeadCO.java | 2 +- .../java/dto/clientobject/OppertunityCO.java | 2 +- .../java/dto/clientobject/QueryCriteria.java | 2 +- .../dto/domainevent/CustomerCreatedEvent.java | 25 +++++ .../__rootArtifactId__-domain/pom.xml | 5 +- .../convertor/CustomerDomainConvertor.java | 32 ++++++ .../customer/convertor/package-info.java | 0 .../java/domain/customer/entity/ContactE.java | 12 ++ .../domain/customer/entity/CustomerE.java | 39 ++++--- .../repository/ContactRepository.java | 11 +- .../repository/CustomerRepository.java | 30 +++++ .../domain/customer/valueobject/AddressV.java | 2 +- .../customer/valueobject/CompanyType.java | 0 .../customer/valueobject/SourceType.java | 5 +- .../src/main/java/domain/package-info.java | 0 .../src/main/resources/sample.properties | 0 .../test/java/domain/CustomerEntityTest.java | 0 .../src/test/resources/sample.properties | 0 .../__rootArtifactId__-infrastructure/pom.xml | 9 +- .../src/main/java/common/BizCode.java | 11 ++ .../main/java/common/exception/ErrorCode.java | 35 ++++++ .../common/util/DomainEventPublisher.java | 30 +++++ .../src/main/java/config/ColaConfig.java | 27 +++++ .../src/main/java/config/DiamondConfig.java | 0 .../tunnel/database}/CustomerDBTunnel.java | 23 +--- .../database}/dataobject/CustomerDO.java | 9 +- .../java/tunnel/rpc/AccountRpcTunnel.java | 12 ++ .../java/tunnel/rpc/dataobject/AccountDO.java | 13 +++ .../tunnel/search/CustomerSearchTunnel.java | 12 ++ .../dataobject/CustomerSearchResultDO.java | 13 +++ .../src/main/resources/logback-spring.xml | 0 .../resources/mybatis/customer-mapper.xml | 6 +- .../main/resources/mybatis/mybatis-config.xml | 0 .../test/java/tunnel/CustomerTunnelTest.java | 0 .../src/test/resources/sample.properties | 0 .../resources/archetype-resources/pom.xml | 20 ++-- .../archetype-resources/start/pom.xml | 5 +- .../start/src/main/java/Application.java | 7 +- .../src/main/resources/application.properties | 0 .../src/test/java/CustomerServiceTest.java | 74 ++++++++++++ .../start/src/test/java/TestConfig.java | 27 +++++ .../start/src/test/resources/logback-test.xml | 38 +++++++ .../start/src/test/resources/test.properties | 2 +- .../projects/basic/archetype.properties | 0 .../test/resources/projects/basic/goal.txt | 0 .../cola-common}/pom.xml | 8 +- .../com/alibaba/cola/context/Context.java | 48 ++++++++ .../com/alibaba/cola}/dto/ClientObject.java | 8 +- .../java/com/alibaba/cola}/dto/Command.java | 20 ++-- .../main/java/com/alibaba/cola}/dto/DTO.java | 4 +- .../com/alibaba/cola}/dto/MultiResponse.java | 2 +- .../java/com/alibaba/cola}/dto/OrderDesc.java | 2 +- .../java/com/alibaba/cola}/dto/PageQuery.java | 2 +- .../java/com/alibaba/cola}/dto/Query.java | 2 +- .../java/com/alibaba/cola}/dto/Response.java | 2 +- .../com/alibaba/cola}/dto/SingleResponse.java | 2 +- .../alibaba/cola/dto/event/DomainEvent.java | 18 +++ .../com/alibaba/cola}/dto/event/Event.java | 21 +++- .../cola-core}/pom.xml | 14 +-- .../alibaba/cola}/assembler/AssemblerI.java | 2 +- .../alibaba/cola}/assembler/package-info.java | 2 +- .../com/alibaba/cola}/boot/Bootstrap.java | 6 +- .../cola}/boot/ClassInterfaceChecker.java | 2 +- .../cola}/boot/ClassNameComparator.java | 2 +- .../cola}/boot/ClassPathScanHandler.java | 6 +- .../alibaba/cola}/boot/CommandRegister.java | 46 +++++--- .../com/alibaba/cola/boot/EventRegister.java | 69 ++++++++++++ .../alibaba/cola}/boot/ExtensionRegister.java | 28 ++--- .../cola}/boot/PostInterceptorRegister.java | 10 +- .../cola}/boot/PreInterceptorRegister.java | 10 +- .../alibaba/cola}/boot/RegisterFactory.java | 45 +------- .../com/alibaba/cola}/boot/RegisterI.java | 2 +- .../com/alibaba/cola}/boot/package-info.java | 2 +- .../com/alibaba/cola}/command/Command.java | 2 +- .../com/alibaba/cola/command/CommandBus.java | 93 ++++++++++++++++ .../alibaba/cola}/command/CommandBusI.java | 6 +- .../cola}/command/CommandExecutorI.java | 6 +- .../com/alibaba/cola}/command/CommandHub.java | 9 +- .../cola}/command/CommandInterceptorI.java | 6 +- .../cola}/command/CommandInvocation.java | 6 +- .../cola}/command/PostInterceptor.java | 4 +- .../alibaba/cola}/command/PreInterceptor.java | 4 +- .../alibaba/cola/command/QueryExecutorI.java | 8 ++ .../alibaba/cola}/command/package-info.java | 4 +- .../cola/common/ApplicationContextHelper.java | 45 ++++++++ .../com/alibaba/cola/common/ColaConstant.java | 10 +- .../alibaba/cola}/convertor/ConvertorI.java | 14 ++- .../alibaba/cola}/convertor/package-info.java | 2 +- .../alibaba/cola}/domain/AggregateRootI.java | 2 +- .../cola/domain/DomainEventServiceI.java | 22 ++++ .../alibaba/cola/domain/DomainFactory.java | 16 +++ .../alibaba/cola/domain/DomainServiceI.java | 10 ++ .../java/com/alibaba/cola/domain/Entity.java | 22 ++++ .../com/alibaba/cola/domain/EntityObject.java | 44 +++----- .../com/alibaba/cola}/domain/ValueObject.java | 2 +- .../alibaba/cola}/domain/package-info.java | 2 +- .../java/com/alibaba/cola/event/EventBus.java | 51 +++++++++ .../com/alibaba/cola/event/EventBusI.java | 30 +++++ .../com/alibaba/cola}/event/EventHandler.java | 2 +- .../com/alibaba/cola/event/EventHandlerI.java | 15 +++ .../java/com/alibaba/cola/event/EventHub.java | 52 +++++++++ .../alibaba/cola/exception/AppException.java | 10 +- .../cola/exception/BasicErrorCode.java | 60 ++++++++++ .../alibaba/cola}/exception/BizException.java | 8 +- .../alibaba/cola/exception/ColaException.java | 22 ++++ .../alibaba/cola}/exception/ErrorCodeI.java | 3 +- .../cola/exception/ExceptionHandlerI.java | 15 +++ .../cola}/exception/ParamException.java | 8 +- .../cola}/exception/Preconditions.java | 2 +- .../alibaba/cola/exception/SysException.java | 27 +++++ .../alibaba/cola}/exception/package-info.java | 2 +- .../extension/AbstractExecutorFacade.java | 46 ++++++++ .../alibaba/cola}/extension/Extension.java | 7 +- .../cola}/extension/ExtensionCoordinate.java | 18 +-- .../cola/extension/ExtensionExecutor.java | 105 ++++++++++++++++++ .../cola}/extension/ExtensionPointI.java | 2 +- .../cola}/extension/ExtensionRepository.java | 2 +- .../alibaba/cola}/extension/package-info.java | 2 +- .../java/com/alibaba/cola}/logger/Logger.java | 2 +- .../alibaba/cola/logger/LoggerFactory.java | 32 ++++++ .../com/alibaba/cola}/logger/SLFJLogger.java | 4 +- .../com/alibaba/cola/logger/SysLogger.java | 46 ++++++++ .../alibaba/cola}/logger/package-info.java | 2 +- .../alibaba/cola}/repository/RepositoryI.java | 2 +- .../cola}/repository/package-info.java | 2 +- .../com/alibaba/cola/tunnel/DataObject.java | 25 +++++ .../com/alibaba/cola/tunnel/DataTunnelI.java | 14 +++ .../com/alibaba/cola/tunnel/package-info.java | 6 + .../validator/ColaMessageInterpolator.java | 4 +- .../cola}/validator/ValidatorCompoiste.java | 2 +- .../alibaba/cola}/validator/ValidatorI.java | 2 +- .../alibaba/cola/validator/package-info.java | 6 + .../src/main/resources/sample.properties | 0 .../java/com/alibaba/cola}/TestConfig.java | 9 +- .../cola}/test/CustomerCommandTest.java | 36 +++--- .../cola}/test/EntityPrototypeTest.java | 12 +- .../alibaba/cola}/test/SpringConfigTest.java | 8 +- .../alibaba/cola/test/SysLoggerStarter.java | 24 ++++ .../cola}/test/customer/AddCustomerCmd.java | 4 +- .../cola/test/customer/AddCustomerCmdExe.java | 44 ++++++++ .../cola}/test/customer/Constants.java | 6 +- .../cola}/test/customer/CustomerCO.java | 6 +- .../cola}/test/customer/CustomerDO.java | 6 +- .../cola}/test/customer/CustomerServiceI.java | 6 +- .../test/customer/CustomerServiceImpl.java | 8 +- .../cola}/test/customer/CustomerType.java | 2 +- .../alibaba/cola/test/customer/ErrorCode.java | 33 ++++++ .../test/customer/GetOneCustomerQry.java | 4 +- .../extension/CustomerBizOneConvertorExt.java | 37 ++++++ .../extension/CustomerBizTwoConvertorExt.java | 35 ++++++ .../CustomerDefaultConvertorExt.java | 26 +++++ .../CustomerConvertorExtPt.java | 18 +++ .../cola/test/customer/entity/CustomerE.java | 27 +++-- .../test/customer/entity/SourceType.java | 2 +- .../extension/CustomerBizOneCheckExt.java | 26 +++++ .../extension/CustomerBizTwoCheckExt.java | 27 +++++ .../extensionpoint/CustomerCheckExtPt.java | 17 +++ .../interceptor/ContextInterceptor.java | 12 +- .../interceptor/ExceptionHandler.java | 50 +++++++++ .../interceptor/ValidationInterceptor.java | 14 +-- .../repository/CustomerRepository.java | 8 +- .../extension/AddCustomerBizOneValidator.java | 16 +-- .../extension/AddCustomerBizTwoValidator.java | 14 +-- .../AddCustomerDefaultValidator.java | 19 ++++ .../AddCustomerValidatorExtPt.java | 6 +- .../cola/test/extension/AnimalExtPt.java | 13 +++ .../cola/test/extension/BizCodeTest.java | 27 +++++ .../cola/test/extension/CommonAnimalExt.java | 18 +++ .../cola/test/extension/DefaultAnimalExt.java | 18 +++ .../alibaba/cola/test/extension/DogExt.java | 20 ++++ .../test/extension/LocateExtensionTest.java | 60 ++++++++++ .../src/test/resources/sample.properties | 0 .../cola-test}/pom.xml | 8 +- .../alibaba/cola/container}/TestExecutor.java | 2 +- .../cola/container}/TestsContainer.java | 14 +-- {sofa-framework => cola-framework}/pom.xml | 30 ++--- .../java/assembler/CustomerAssembler.java | 18 --- .../src/main/java/assembler/package-info.java | 9 -- .../command/CustomerCheckConflictCmdExe.java | 33 ------ .../CustomerSearchConditionCGSExt.java | 18 --- .../CustomerSearchConditionTPExt.java | 18 --- .../java/command/extension/package-info.java | 9 -- ...omerCheckConflictSearchConditionExtPt.java | 11 -- .../command/extensionpoint/package-info.java | 9 -- .../handler/CustomerChangeEventHandler.java | 24 ---- .../java/interceptor/ContextInterceptor.java | 19 ---- .../extension/CustomerAddCGSValidator.java | 52 --------- .../extension/CustomerAddDDValidator.java | 57 ---------- .../CustomerAddValidatorExtPt.java | 22 ---- .../src/main/resources/applicationContext.xml | 20 ---- .../src/test/java/service/AppTestSuite.java | 22 ---- .../test/java/service/AppTestsContainer.java | 21 ---- .../java/service/CustomerServiceTest.java | 94 ---------------- .../resources/applicationContext-test.xml | 30 ----- .../src/test/resources/localConfig.properties | 7 -- .../java/dto/CustomerCheckConflictCmd.java | 10 -- .../customer/convertor/CustomerConvertor.java | 41 ------- .../extension/CustomerCGSConvertorExt.java | 43 ------- .../extension/CustomerDDConvertorExt.java | 46 -------- .../java/domain/customer/entity/ContactE.java | 8 -- .../domain/customer/entity/OpportunityE.java | 8 -- .../factory/CustomerDomainFactory.java | 23 ---- .../repository/CustomerRepository.java | 38 ------- .../rule/extension/CustomerCGSRuleExt.java | 22 ---- .../rule/extension/CustomerDDRuleExt.java | 29 ----- .../extensionpoint/CustomerRuleExtPt.java | 25 ----- .../src/main/java/common/AppConstants.java | 18 --- .../src/main/java/common/BizCode.java | 17 --- .../tunnel/datatunnel/CustomerTunnelI.java | 15 --- .../src/main/resources/app-boot-start.xml | 20 ---- .../src/main/resources/app.properties | 3 - .../start/src/test/java/TestApplication.java | 23 ---- .../test/java/app/CustomerServiceTest.java | 24 ---- .../test/java/tunnel/CustomerTunnelTest.java | 10 -- .../alibaba/sofa/dto/event/MetaqEvent.java | 12 -- .../com/alibaba/sofa/enums/EventType.java | 12 -- .../alibaba/sofa/boot/ComponentExecutor.java | 20 ---- .../com/alibaba/sofa/boot/EventRegister.java | 66 ----------- .../alibaba/sofa/boot/PlainRuleRegister.java | 34 ------ .../sofa/boot/PlainValidatorRegister.java | 34 ------ .../com/alibaba/sofa/command/CommandBus.java | 63 ----------- .../alibaba/sofa/command/QueryExecutorI.java | 8 -- .../sofa/common/ApplicationContextHelper.java | 27 ----- .../com/alibaba/sofa/common/CoreConstant.java | 28 ----- .../com/alibaba/sofa/context/PvgContext.java | 63 ----------- .../alibaba/sofa/context/TenantContext.java | 42 ------- .../alibaba/sofa/context/package-info.java | 6 - .../alibaba/sofa/domain/DomainFactoryI.java | 12 -- .../com/alibaba/sofa/domain/ServiceI.java | 10 -- .../java/com/alibaba/sofa/event/EventBus.java | 58 ---------- .../com/alibaba/sofa/event/EventBusI.java | 21 ---- .../com/alibaba/sofa/event/EventHandlerI.java | 15 --- .../java/com/alibaba/sofa/event/EventHub.java | 51 --------- .../sofa/exception/BasicErrorCode.java | 42 ------- .../sofa/exception/InfraException.java | 22 ---- .../sofa/extension/ExtensionExecutor.java | 72 ------------ .../MetaqEventConsumerExtPt.java | 13 --- .../alibaba/sofa/logger/LoggerFactory.java | 24 ---- .../com/alibaba/sofa/logger/SysLogger.java | 33 ------ .../alibaba/sofa/repository/DataObject.java | 11 -- .../alibaba/sofa/repository/DataTunnel.java | 21 ---- .../sofa/rule/PlainRuleRepository.java | 18 --- .../com/alibaba/sofa/rule/RuleExecutor.java | 37 ------ .../java/com/alibaba/sofa/rule/RuleI.java | 24 ---- .../com/alibaba/sofa/rule/package-info.java | 7 -- .../sofa/rule/ruleengine/AbstractRule.java | 24 ---- .../alibaba/sofa/rule/ruleengine/AndRule.java | 24 ---- .../alibaba/sofa/rule/ruleengine/NotRule.java | 22 ---- .../alibaba/sofa/rule/ruleengine/OrRule.java | 24 ---- .../validator/PlainValidatorRepository.java | 18 --- .../sofa/validator/ValidatorExecutor.java | 36 ------ .../alibaba/sofa/validator/package-info.java | 6 - .../sofa/test/customer/AddCustomerCmdExe.java | 47 -------- .../convertor/CustomerBizOneConvertorExt.java | 35 ------ .../convertor/CustomerBizTwoConvertorExt.java | 33 ------ .../customer/convertor/CustomerConvertor.java | 31 ------ .../convertor/CustomerConvertorExtPt.java | 17 --- .../entity/rule/CustomerBizOneRuleExt.java | 25 ----- .../entity/rule/CustomerBizTwoRuleExt.java | 21 ---- .../entity/rule/CustomerRuleExtPt.java | 22 ---- 301 files changed, 2748 insertions(+), 2861 deletions(-) rename {sofa-archetype => cola-archetype}/.gitignore (100%) rename {sofa-archetype => cola-archetype}/pom.xml (66%) rename {sofa-archetype => cola-archetype}/src/main/resources/META-INF/maven/archetype-metadata.xml (92%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/pom.xml (93%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerAddCmdExe.java (51%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/package-info.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/CustomerFindByCriteriaQueryExe.java (62%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/package-info.java (100%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/CustomerConvertor.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extension/CustomerBizOneConvertorExt.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extension/CustomerBizTwoConvertorExt.java rename {sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer => cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java}/convertor/extensionpoint/CustomerConvertorExtPt.java (57%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerCreatedSyncSearchHandler.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerCreatedSysLogHandler.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ContextInterceptor.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPostInterceptor.java (50%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPreInterceptor.java (54%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ValidationInterceptor.java (77%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/package-info.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/CustomerServiceImpl.java (73%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/package-info.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/CustomerAddValidator.java (60%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddBizOneValidatorExt.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddBizTwoValidatorExt.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/package-info.java (100%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/CustomerAddValidatorExtPt.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/package-info.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/package-info.java (100%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/CustomerConvertorTest.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/CustomerValidatorTest.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/TestConfig.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml (86%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/api/CustomerServiceI.java (65%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/context/DemoContent.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerAddCmd.java (76%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByCriteriaQry.java (82%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByNameQry.java (82%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerUpdateCmd.java (81%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerCO.java (73%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerType.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/LeadCO.java (80%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/OppertunityCO.java (80%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/QueryCriteria.java (80%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/domainevent/CustomerCreatedEvent.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/pom.xml (90%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/CustomerDomainConvertor.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/package-info.java (100%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/ContactE.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/CustomerE.java (57%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/ContactRepository.java (56%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/CustomerRepository.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/AddressV.java (85%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/CompanyType.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/SourceType.java (71%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/package-info.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/resources/sample.properties (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/java/domain/CustomerEntityTest.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/resources/sample.properties (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/pom.xml (83%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/BizCode.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/exception/ErrorCode.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/util/DomainEventPublisher.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/ColaConfig.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/DiamondConfig.java (100%) rename {sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/datatunnel/impl => cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/database}/CustomerDBTunnel.java (62%) rename {sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel => cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/database}/dataobject/CustomerDO.java (59%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/rpc/AccountRpcTunnel.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/rpc/dataobject/AccountDO.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/search/CustomerSearchTunnel.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/search/dataobject/CustomerSearchResultDO.java rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/logback-spring.xml (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/customer-mapper.xml (66%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/mybatis-config.xml (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/java/tunnel/CustomerTunnelTest.java (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/resources/sample.properties (100%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/pom.xml (94%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/start/pom.xml (91%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/start/src/main/java/Application.java (72%) rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/start/src/main/resources/application.properties (100%) create mode 100644 cola-archetype/src/main/resources/archetype-resources/start/src/test/java/CustomerServiceTest.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/start/src/test/java/TestConfig.java create mode 100644 cola-archetype/src/main/resources/archetype-resources/start/src/test/resources/logback-test.xml rename {sofa-archetype => cola-archetype}/src/main/resources/archetype-resources/start/src/test/resources/test.properties (96%) rename {sofa-archetype => cola-archetype}/src/test/resources/projects/basic/archetype.properties (100%) rename {sofa-archetype => cola-archetype}/src/test/resources/projects/basic/goal.txt (100%) rename {sofa-framework/sofa-common => cola-framework/cola-common}/pom.xml (87%) create mode 100644 cola-framework/cola-common/src/main/java/com/alibaba/cola/context/Context.java rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/ClientObject.java (81%) rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/Command.java (59%) rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/DTO.java (76%) rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/MultiResponse.java (97%) rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/OrderDesc.java (92%) rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/PageQuery.java (97%) rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/Query.java (89%) rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/Response.java (97%) rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/SingleResponse.java (97%) create mode 100644 cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/event/DomainEvent.java rename {sofa-framework/sofa-common/src/main/java/com/alibaba/sofa => cola-framework/cola-common/src/main/java/com/alibaba/cola}/dto/event/Event.java (55%) rename {sofa-framework/sofa-core => cola-framework/cola-core}/pom.xml (91%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/assembler/AssemblerI.java (94%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/assembler/package-info.java (77%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/Bootstrap.java (91%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/ClassInterfaceChecker.java (95%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/ClassNameComparator.java (91%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/ClassPathScanHandler.java (98%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/CommandRegister.java (67%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/EventRegister.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/ExtensionRegister.java (68%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/PostInterceptorRegister.java (90%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/PreInterceptorRegister.java (90%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/RegisterFactory.java (55%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/RegisterI.java (94%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/boot/package-info.java (75%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/Command.java (91%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandBus.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/CommandBusI.java (74%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/CommandExecutorI.java (64%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/CommandHub.java (83%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/CommandInterceptorI.java (83%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/CommandInvocation.java (93%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/PostInterceptor.java (69%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/PreInterceptor.java (69%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/command/QueryExecutorI.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/command/package-info.java (51%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/common/ApplicationContextHelper.java rename sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/DefaultBizCode.java => cola-framework/cola-core/src/main/java/com/alibaba/cola/common/ColaConstant.java (64%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/convertor/ConvertorI.java (66%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/convertor/package-info.java (78%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/domain/AggregateRootI.java (72%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainEventServiceI.java create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactory.java create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainServiceI.java create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/Entity.java rename sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/Entity.java => cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/EntityObject.java (52%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/domain/ValueObject.java (74%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/domain/package-info.java (66%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBus.java create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBusI.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/event/EventHandler.java (88%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHandlerI.java create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHub.java rename sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/CrmException.java => cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/AppException.java (64%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/BasicErrorCode.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/exception/BizException.java (64%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ColaException.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/exception/ErrorCodeI.java (75%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ExceptionHandlerI.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/exception/ParamException.java (65%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/exception/Preconditions.java (95%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/SysException.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/exception/package-info.java (73%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/AbstractExecutorFacade.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/extension/Extension.java (74%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/extension/ExtensionCoordinate.java (76%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionExecutor.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/extension/ExtensionPointI.java (89%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/extension/ExtensionRepository.java (94%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/extension/package-info.java (81%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/logger/Logger.java (98%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/LoggerFactory.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/logger/SLFJLogger.java (86%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/SysLogger.java rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/logger/package-info.java (80%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/repository/RepositoryI.java (83%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/repository/package-info.java (76%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/DataObject.java create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/DataTunnelI.java create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/package-info.java rename sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/SofaMessageInterpolator.java => cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ColaMessageInterpolator.java (80%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/validator/ValidatorCompoiste.java (97%) rename {sofa-framework/sofa-core/src/main/java/com/alibaba/sofa => cola-framework/cola-core/src/main/java/com/alibaba/cola}/validator/ValidatorI.java (94%) create mode 100644 cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/package-info.java rename {sofa-framework/sofa-core => cola-framework/cola-core}/src/main/resources/sample.properties (100%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/TestConfig.java (71%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/CustomerCommandTest.java (77%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/EntityPrototypeTest.java (63%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/SpringConfigTest.java (78%) create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/SysLoggerStarter.java rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/AddCustomerCmd.java (78%) create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/AddCustomerCmdExe.java rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/Constants.java (76%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/CustomerCO.java (72%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/CustomerDO.java (72%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/CustomerServiceI.java (68%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/CustomerServiceImpl.java (77%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/CustomerType.java (79%) create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/ErrorCode.java rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/GetOneCustomerQry.java (73%) create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerBizOneConvertorExt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerBizTwoConvertorExt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerDefaultConvertorExt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extensionpoint/CustomerConvertorExtPt.java rename sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/CustomerEntity.java => cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/CustomerE.java (52%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/entity/SourceType.java (80%) create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extension/CustomerBizOneCheckExt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extension/CustomerBizTwoCheckExt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extensionpoint/CustomerCheckExtPt.java rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/interceptor/ContextInterceptor.java (51%) create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ExceptionHandler.java rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/interceptor/ValidationInterceptor.java (72%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/repository/CustomerRepository.java (57%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/validator/extension/AddCustomerBizOneValidator.java (57%) rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/validator/extension/AddCustomerBizTwoValidator.java (59%) create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerDefaultValidator.java rename {sofa-framework/sofa-core/src/test/java/com/alibaba/sofa => cola-framework/cola-core/src/test/java/com/alibaba/cola}/test/customer/validator/extensionpoint/AddCustomerValidatorExtPt.java (52%) create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/AnimalExtPt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/BizCodeTest.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/CommonAnimalExt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/DefaultAnimalExt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/DogExt.java create mode 100644 cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/LocateExtensionTest.java rename {sofa-framework/sofa-core => cola-framework/cola-core}/src/test/resources/sample.properties (100%) rename {sofa-framework/sofa-test => cola-framework/cola-test}/pom.xml (91%) rename {sofa-framework/sofa-test/src/main/java/com/alibaba/sofa/pandora/test => cola-framework/cola-test/src/main/java/com/alibaba/cola/container}/TestExecutor.java (99%) rename {sofa-framework/sofa-test/src/main/java/com/alibaba/sofa/pandora/test => cola-framework/cola-test/src/main/java/com/alibaba/cola/container}/TestsContainer.java (93%) rename {sofa-framework => cola-framework}/pom.xml (90%) delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/assembler/CustomerAssembler.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/assembler/package-info.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerCheckConflictCmdExe.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/CustomerSearchConditionCGSExt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/CustomerSearchConditionTPExt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/package-info.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extensionpoint/CustomerCheckConflictSearchConditionExtPt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extensionpoint/package-info.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerChangeEventHandler.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ContextInterceptor.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddCGSValidator.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddDDValidator.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/CustomerAddValidatorExtPt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/resources/applicationContext.xml delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/AppTestSuite.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/AppTestsContainer.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/CustomerServiceTest.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/resources/applicationContext-test.xml delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/resources/localConfig.properties delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerCheckConflictCmd.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/CustomerConvertor.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extension/CustomerCGSConvertorExt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extension/CustomerDDConvertorExt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/ContactE.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/OpportunityE.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/factory/CustomerDomainFactory.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/CustomerRepository.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extension/CustomerCGSRuleExt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extension/CustomerDDRuleExt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extensionpoint/CustomerRuleExtPt.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/AppConstants.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/BizCode.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/datatunnel/CustomerTunnelI.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/app-boot-start.xml delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/app.properties delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/TestApplication.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/app/CustomerServiceTest.java delete mode 100644 sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/tunnel/CustomerTunnelTest.java delete mode 100644 sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/event/MetaqEvent.java delete mode 100644 sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/enums/EventType.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ComponentExecutor.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/EventRegister.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PlainRuleRegister.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PlainValidatorRegister.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandBus.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/QueryExecutorI.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/ApplicationContextHelper.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/CoreConstant.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/PvgContext.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/TenantContext.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/package-info.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/DomainFactoryI.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/ServiceI.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventBus.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventBusI.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHandlerI.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHub.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/BasicErrorCode.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/InfraException.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionExecutor.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extensionpoint/MetaqEventConsumerExtPt.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/LoggerFactory.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/SysLogger.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/DataObject.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/DataTunnel.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/PlainRuleRepository.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/RuleExecutor.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/RuleI.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/package-info.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/AbstractRule.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/AndRule.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/NotRule.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/OrRule.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/PlainValidatorRepository.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorExecutor.java delete mode 100644 sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/package-info.java delete mode 100644 sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/AddCustomerCmdExe.java delete mode 100644 sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerBizOneConvertorExt.java delete mode 100644 sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerBizTwoConvertorExt.java delete mode 100644 sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerConvertor.java delete mode 100644 sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerConvertorExtPt.java delete mode 100644 sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerBizOneRuleExt.java delete mode 100644 sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerBizTwoRuleExt.java delete mode 100644 sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerRuleExtPt.java diff --git a/README.md b/README.md index 24969da33..d883e90b7 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -# SOFA -> SOFA是Simple Object-Oriented and Flexible Architecture的缩写,是轻量级的企业应用框架,可以有效的降低业务系统复杂度。 +# COLA +> COLA是Clean Object-oriented & Layered Architecture的缩写,是轻量级的企业应用框架,可以有效的降低业务系统复杂度。 ![image.png](http://ata2-img.cn-hangzhou.img-pub.aliyun-inc.com/26321403c9123efc269cb6013c55555f.png) 关于架构和设计的详细内容,请查看:https://www.atatech.org/articles/96063 # 项目说明 -SOFA框架包括两个Project,一个是sofa-framework里面是框架的核心代码,另一个是sofa-archetype是用来生成新应用的Maven Archetype源码。 -## sofa-framework Project -该Project包含3个Module,sofa-core, sofa-common, sofa-test -### sofa-core +COLA框架包括两个Project,一个是cola-framework里面是框架的核心代码,另一个是cola-archetype是用来生成新应用的Maven Archetype源码。 +## cola-framework Project +该Project包含3个Module,cola-core, cola-common, cola-test +### cola-core 该Module是整个框架的核心,里面的主要功能和Package如下: ``` com └── alibaba - └── sofa + └── cola ├── assembler \\提供Assembler标准 ├── boot \\这是框架的核心启动包,负责框架组件的注册、发现 ├── command \\提供Command标准 @@ -31,95 +31,14 @@ com │   └── ruleengine └── validator \\提供Validator标准和执行 ``` -### sofa-common +### cola-common 该Module提供了框架中Client Object, Entity Object和Data Object的定义,二方库会依赖该Module。 -### sofa-test +### cola-test 该Module主要是提供一些开发测试的工具,可以使用TDD来进行开发。 -## sofa-archetype Project +## cola-archetype Project 该Project下面是Archetype的源码,先执行`mvn install`,然后就可以用下面的命令来创建新应用了: ``` -mvn archetype:generate -DgroupId=com.alibaba.crm -DartifactId=demo -Dversion=1.0.0-SNAPSHOT -Dpackage=com.alibaba.crm.demo -DarchetypeArtifactId=sofa-framework-archetype -DarchetypeGroupId=com.alibaba.sofa -DarchetypeVersion=1.0.0-SNAPSHOT -``` -生成的应用主要包括demo-app, demo-domain, demo-tunnel, demo-config, demo-client和Start五个Module,分别代表不同层次(Tier)和用途。 -``` -├── demo-app \\这个是Application层 -│   └── src -│   └── main -│   └── java -│   └── com -│   └── alibaba -│   └── crm -│   └── demo -│   ├── assembler -│   ├── command -│   │   ├── extension -│   │   ├── extensionpoint -│   │   └── query -│   ├── event -│   │   └── handler -│   ├── interceptor -│   ├── service -│   └── validator -│   ├── extension -│   └── extensionpoint -├── demo-client \\这个是二方库,提供给Consumer做RPC调用用的 -│   └── src -│   └── main -│   └── java -│   └── com -│   └── alibaba -│   └── crm -│   └── demo -│   ├── api -│   └── dto -│   └── clientobject -├── demo-config \\这个是应用的配置 -│   └── src -│   └── main -│   └── java -│   └── com -│   └── alibaba -│   └── crm -│   └── demo -│   └── config -├── demo-domain \\这个是Domain层,所有的业务逻辑都应该在这个Module里面 -│   └── src -│   └── main -│   └── java -│   └── com -│   └── alibaba -│   └── crm -│   └── demo -│   └── domain -│   └── customer -│   ├── convertor -│   │   ├── extension -│   │   └── extensionpoint -│   ├── entity -│   ├── factory -│   ├── repository -│   ├── rule -│   │   ├── extension -│   │   └── extensionpoint -│   └── valueobject -├── demo-tunnel \\这个是Tunnel层,也就是仓储层,所有和DB或者其它通道的数据交互都在这一层处理 -│   └── src -│   └── main -│   └── java -│   └── com -│   └── alibaba -│   └── crm -│   └── demo -│   ├── dataobject -│   └── datatunnel -│   └── impl -└── start \\这个是应用的启动Module,通常是用SpringBoot,如果是阿里系的话,通常是PandoraBoot - └── src - └── main - └── java - └── com - └── alibaba - └── crm - └── demo +mvn archetype:generate -DgroupId=com.alibaba.demo -DartifactId=sample -Dversion=1.0.0-SNAPSHOT -Dpackage=com.alibaba.demo -DarchetypeArtifactId=cola-framework-archetype -DarchetypeGroupId=com.alibaba.cola -DarchetypeVersion=1.0.0-SNAPSHOT ``` +生成的应用主要包括demo-app, demo-domain, demo-tunnel, demo-config, demo-client和Start五个Module,分别代表不同层次(layer)和用途。 diff --git a/sofa-archetype/.gitignore b/cola-archetype/.gitignore similarity index 100% rename from sofa-archetype/.gitignore rename to cola-archetype/.gitignore diff --git a/sofa-archetype/pom.xml b/cola-archetype/pom.xml similarity index 66% rename from sofa-archetype/pom.xml rename to cola-archetype/pom.xml index 5567c6dff..8028b1b02 100644 --- a/sofa-archetype/pom.xml +++ b/cola-archetype/pom.xml @@ -2,11 +2,11 @@ 4.0.0 - com.alibaba.sofa - sofa-framework-archetype + com.alibaba.cola + cola-framework-archetype 1.0.0-SNAPSHOT jar - sofa framework archetype - sofa framework archetype + cola framework archetype + cola framework archetype diff --git a/sofa-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/cola-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml similarity index 92% rename from sofa-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml rename to cola-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml index 421dae936..833d976d4 100644 --- a/sofa-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/cola-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -11,19 +11,6 @@ **/*.java - - bin - - **/*.xml - **/*.project - - - - bin/src - - **/*.class - - @@ -38,6 +25,7 @@ src/main/resources **/*.xml + **/*.properties @@ -94,6 +82,7 @@ src/main/resources + **/*.xml **/*.properties @@ -106,6 +95,7 @@ src/test/resources + **/*.xml **/*.properties @@ -122,6 +112,7 @@ src/main/resources + **/*.xml **/*.properties @@ -134,6 +125,7 @@ src/test/resources + **/*.xml **/*.properties diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/pom.xml b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/pom.xml similarity index 93% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/pom.xml rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/pom.xml index f5768b1f6..40d093f67 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/pom.xml +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/pom.xml @@ -5,6 +5,7 @@ ${groupId} ${rootArtifactId}.all ${version} + ../pom.xml ${artifactId} ${version} @@ -34,8 +35,8 @@ - com.alibaba.sofa - sofa-test + com.alibaba.cola + cola-test org.mockito @@ -63,5 +64,5 @@ - + diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerAddCmdExe.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerAddCmdExe.java similarity index 51% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerAddCmdExe.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerAddCmdExe.java index 19e45b876..9962a02a2 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerAddCmdExe.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerAddCmdExe.java @@ -3,23 +3,22 @@ #set( $symbol_escape = '\' ) package ${package}.command; -import ${package}.domain.customer.convertor.extensionpoint.CustomerConvertorExtPt; -import ${package}.domain.customer.entity.CustomerE; -import com.alibaba.sofa.extension.ExtensionExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import com.alibaba.sofa.command.Command; -import com.alibaba.sofa.command.CommandExecutorI; -import com.alibaba.sofa.dto.Response; +import com.alibaba.cola.extension.ExtensionExecutor; +import com.alibaba.cola.command.Command; +import com.alibaba.cola.command.CommandExecutorI; +import com.alibaba.cola.dto.Response; + import ${package}.dto.CustomerAddCmd; import ${package}.validator.extensionpoint.CustomerAddValidatorExtPt; -import com.alibaba.sofa.validator.ValidatorExecutor; +import ${package}.convertor.extensionpoint.CustomerConvertorExtPt; +import ${package}.domain.customer.entity.CustomerE; +import org.springframework.beans.factory.annotation.Autowired; + @Command public class CustomerAddCmdExe implements CommandExecutorI{ - @Autowired - private ValidatorExecutor validatorExecutor; @Autowired private ExtensionExecutor extensionExecutor; @@ -27,13 +26,13 @@ public class CustomerAddCmdExe implements CommandExecutorI validator.validate(cmd)); + //2, invoke domain service or directly operate domain to do business logic process - CustomerE customerEntity = extensionExecutor.execute(CustomerConvertorExtPt.class, extension -> extension.clientToEntity(cmd.getCustomer())); - customerEntity.addNewCustomer(); + CustomerE customerE = extensionExecutor.execute(CustomerConvertorExtPt.class, cmd.getContext(), convertor -> convertor.clientToEntity(cmd.getCustomerCO(), cmd.getContext())); + customerE.addNewCustomer(); - //3, notify by sending message out + //3, response return Response.buildSuccess(); } diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/package-info.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/CustomerFindByCriteriaQueryExe.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/CustomerFindByCriteriaQueryExe.java similarity index 62% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/CustomerFindByCriteriaQueryExe.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/CustomerFindByCriteriaQueryExe.java index 3950ab055..70750c467 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/CustomerFindByCriteriaQueryExe.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/CustomerFindByCriteriaQueryExe.java @@ -3,14 +3,14 @@ #set( $symbol_escape = '\' ) package ${package}.command.query; -import ${package}.domain.customer.convertor.CustomerConvertor; -import ${package}.tunnel.dataobject.CustomerDO; -import ${package}.tunnel.datatunnel.CustomerTunnelI; +import ${package}.convertor.CustomerConvertor; +import ${package}.tunnel.database.dataobject.CustomerDO; +import ${package}.tunnel.database.CustomerDBTunnel; import ${package}.dto.CustomerFindByCriteriaQry; import ${package}.dto.clientobject.CustomerCO; -import com.alibaba.sofa.command.Command; -import com.alibaba.sofa.command.QueryExecutorI; -import com.alibaba.sofa.dto.MultiResponse; +import com.alibaba.cola.command.Command; +import com.alibaba.cola.command.QueryExecutorI; +import com.alibaba.cola.dto.MultiResponse; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; @@ -20,10 +20,10 @@ public class CustomerFindByCriteriaQueryExe implements QueryExecutorI, CustomerFindByCriteriaQry> { @Autowired - CustomerTunnelI customerDBTunnel; + private CustomerDBTunnel customerDBTunnel; @Autowired - CustomerConvertor customerConvertor; + private CustomerConvertor customerConvertor; @Override public MultiResponse execute(CustomerFindByCriteriaQry cmd) { @@ -32,10 +32,4 @@ public MultiResponse execute(CustomerFindByCriteriaQry cmd) { customerCos.add(customerConvertor.dataToClient(customerDO)); return MultiResponse.of(customerCos, customerCos.size()); } - - - public CustomerDO get(String id) { - CustomerDO customerDO = customerDBTunnel.get("123"); - return customerDO; - } } diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/query/package-info.java diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/CustomerConvertor.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/CustomerConvertor.java new file mode 100644 index 000000000..2643368eb --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/CustomerConvertor.java @@ -0,0 +1,37 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.convertor; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.domain.DomainFactory; +import com.alibaba.cola.convertor.ConvertorI; +import ${package}.dto.clientobject.CustomerCO; +import ${package}.domain.customer.entity.CustomerE; +import ${package}.tunnel.database.dataobject.CustomerDO; +import org.springframework.stereotype.Component; +/** + * General CustomerConvertor, the difference is implemented by Extension mechanism + * + * @author Frank Zhang + * @date 2018-01-07 3:08 AM + */ +@Component +public class CustomerConvertor implements ConvertorI { + + public CustomerE clientToEntity(CustomerCO customerCO, Context context){ + CustomerE customerE = DomainFactory.create(CustomerE.class); + customerE.setCompanyName(customerCO.getCompanyName()); + customerE.setContext(context); + return customerE; + } + + public CustomerCO dataToClient(CustomerDO dataObject) { + CustomerCO customerCO = new CustomerCO(); + customerCO.setCustomerName(dataObject.getCompanyName()); + customerCO.setCustomerType(dataObject.getCompanyType()); + customerCO.setMemberId(dataObject.getMemberId()); + customerCO.setCustomerId(dataObject.getCustomerId()); + return customerCO; + } +} diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extension/CustomerBizOneConvertorExt.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extension/CustomerBizOneConvertorExt.java new file mode 100644 index 000000000..664de9577 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extension/CustomerBizOneConvertorExt.java @@ -0,0 +1,28 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.convertor.extension; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.extension.Extension; +import ${package}.common.BizCode; +import ${package}.convertor.CustomerConvertor; +import ${package}.convertor.extensionpoint.CustomerConvertorExtPt; +import ${package}.domain.customer.entity.CustomerE; +import ${package}.domain.customer.valueobject.SourceType; +import ${package}.dto.clientobject.CustomerCO; +import org.springframework.beans.factory.annotation.Autowired; + +@Extension(bizCode = BizCode.BIZ_ONE) +public class CustomerBizOneConvertorExt implements CustomerConvertorExtPt{ + + @Autowired + private CustomerConvertor customerConvertor; + + @Override + public CustomerE clientToEntity(CustomerCO customerCO, Context context) { + CustomerE customerE = customerConvertor.clientToEntity(customerCO, context); + customerE.setSourceType(SourceType.BIZ_ONE); + return customerE; + } +} \ No newline at end of file diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extension/CustomerBizTwoConvertorExt.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extension/CustomerBizTwoConvertorExt.java new file mode 100644 index 000000000..387e6d221 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extension/CustomerBizTwoConvertorExt.java @@ -0,0 +1,28 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.convertor.extension; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.extension.Extension; +import ${package}.common.BizCode; +import ${package}.convertor.CustomerConvertor; +import ${package}.convertor.extensionpoint.CustomerConvertorExtPt; +import ${package}.domain.customer.entity.CustomerE; +import ${package}.domain.customer.valueobject.SourceType; +import ${package}.dto.clientobject.CustomerCO; +import org.springframework.beans.factory.annotation.Autowired; + +@Extension(bizCode = BizCode.BIZ_TWO) +public class CustomerBizTwoConvertorExt implements CustomerConvertorExtPt{ + + @Autowired + private CustomerConvertor customerConvertor; + + @Override + public CustomerE clientToEntity(CustomerCO customerCO, Context context) { + CustomerE customerE = customerConvertor.clientToEntity(customerCO, context); + customerE.setSourceType(SourceType.BIZ_TWO); + return customerE; + } +} \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extensionpoint/CustomerConvertorExtPt.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extensionpoint/CustomerConvertorExtPt.java similarity index 57% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extensionpoint/CustomerConvertorExtPt.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extensionpoint/CustomerConvertorExtPt.java index c1e4ce3a5..81bccdc1d 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extensionpoint/CustomerConvertorExtPt.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/convertor/extensionpoint/CustomerConvertorExtPt.java @@ -1,12 +1,13 @@ #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) -package ${package}.domain.customer.convertor.extensionpoint; +package ${package}.convertor.extensionpoint; -import ${package}.domain.customer.entity.CustomerE; +import com.alibaba.cola.context.Context; +import com.alibaba.cola.convertor.ConvertorI; +import com.alibaba.cola.extension.ExtensionPointI; import ${package}.dto.clientobject.CustomerCO; -import com.alibaba.sofa.convertor.ConvertorI; -import com.alibaba.sofa.extension.ExtensionPointI; +import ${package}.domain.customer.entity.CustomerE; /** * CustomerConvertorExtPt @@ -16,5 +17,5 @@ */ public interface CustomerConvertorExtPt extends ConvertorI, ExtensionPointI { - public CustomerE clientToEntity(CustomerCO customerCO); + public CustomerE clientToEntity(CustomerCO customerCO, Context context); } diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerCreatedSyncSearchHandler.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerCreatedSyncSearchHandler.java new file mode 100644 index 000000000..1f57be4e1 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerCreatedSyncSearchHandler.java @@ -0,0 +1,27 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.event.handler; + +import com.alibaba.cola.event.EventHandler; +import com.alibaba.cola.event.EventHandlerI; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import ${package}.dto.domainevent.CustomerCreatedEvent; + +/** + * 同步搜索器的handler + * + * @author frankzhang + * @date 2017/11/30 + */ +@EventHandler +public class CustomerCreatedSyncSearchHandler implements EventHandlerI { + + private Logger logger = LoggerFactory.getLogger(CustomerCreatedSyncSearchHandler.class); + + @Override + public void execute(CustomerCreatedEvent event) { + logger.debug("Sync new customer to Search"); + } +} diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerCreatedSysLogHandler.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerCreatedSysLogHandler.java new file mode 100644 index 000000000..c4bdd3aa3 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerCreatedSysLogHandler.java @@ -0,0 +1,27 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.event.handler; + +import com.alibaba.cola.event.EventHandler; +import com.alibaba.cola.event.EventHandlerI; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import ${package}.dto.domainevent.CustomerCreatedEvent; + +/** + * 记录系统日志的handler + * + * @author Frank Zhang + * @date 2019-01-04 11:24 AM + */ +@EventHandler +public class CustomerCreatedSysLogHandler implements EventHandlerI { + + private Logger logger = LoggerFactory.getLogger(CustomerCreatedSysLogHandler.class); + + @Override + public void execute(CustomerCreatedEvent event) { + logger.debug("Logging system operation for new customer"); + } +} \ No newline at end of file diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ContextInterceptor.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ContextInterceptor.java new file mode 100644 index 000000000..2c78960e0 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ContextInterceptor.java @@ -0,0 +1,30 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.interceptor; + +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.PreInterceptor; +import com.alibaba.cola.context.Context; +import com.alibaba.cola.dto.Command; +import ${package}.context.DemoContent; + +@PreInterceptor +public class ContextInterceptor implements CommandInterceptorI{ + + @Override + public void preIntercept(Command command) { + Context context = new Context(); + DemoContent content = new DemoContent(); + content.setUserId("testUserId"); + context.setContent(content); + + if(command.getContext() != null){ + context.setBizCode(command.getContext().getBizCode()); + } + + command.setContext(context); + + } + +} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPostInterceptor.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPostInterceptor.java similarity index 50% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPostInterceptor.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPostInterceptor.java index 4fb04d42d..a6e1a31ef 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPostInterceptor.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPostInterceptor.java @@ -3,21 +3,21 @@ #set( $symbol_escape = '\' ) package ${package}.interceptor; -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.PostInterceptor; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.PostInterceptor; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; @PostInterceptor public class LoggerPostInterceptor implements CommandInterceptorI{ - + Logger logger = LoggerFactory.getLogger(LoggerPostInterceptor.class); - + @Override public void postIntercept(Command command, Response response) { - logger.debug("Finished processing "+ command.getClass()+" Response:"+response); + logger.debug("End processing "+ command.getClass()+" Response:"+response); } -} \ No newline at end of file +} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPreInterceptor.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPreInterceptor.java similarity index 54% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPreInterceptor.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPreInterceptor.java index d20c20c15..7837bf9b5 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPreInterceptor.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/LoggerPreInterceptor.java @@ -3,20 +3,20 @@ #set( $symbol_escape = '\' ) package ${package}.interceptor; -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.PreInterceptor; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.PreInterceptor; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; @PreInterceptor public class LoggerPreInterceptor implements CommandInterceptorI{ - + Logger logger = LoggerFactory.getLogger(LoggerPreInterceptor.class); - + @Override public void preIntercept(Command command) { - logger.debug("Begin to process "+ command); + logger.debug("Start processing "+ command); } } diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ValidationInterceptor.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ValidationInterceptor.java similarity index 77% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ValidationInterceptor.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ValidationInterceptor.java index 171628bad..c36f3b115 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ValidationInterceptor.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ValidationInterceptor.java @@ -3,11 +3,11 @@ #set( $symbol_escape = '\' ) package ${package}.interceptor; -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.PreInterceptor; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.exception.ParamException; -import com.alibaba.sofa.validator.SofaMessageInterpolator; +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.PreInterceptor; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.exception.ParamException; +import com.alibaba.cola.validator.ColaMessageInterpolator; import org.hibernate.validator.HibernateValidator; import javax.validation.ConstraintViolation; @@ -26,7 +26,7 @@ public class ValidationInterceptor implements CommandInterceptorI { //Enable fail fast, which will improve performance private ValidatorFactory factory = Validation.byProvider(HibernateValidator.class).configure().failFast(true) - .messageInterpolator(new SofaMessageInterpolator()).buildValidatorFactory(); + .messageInterpolator(new ColaMessageInterpolator()).buildValidatorFactory(); @Override public void preIntercept(Command command) { diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/package-info.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/CustomerServiceImpl.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/CustomerServiceImpl.java similarity index 73% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/CustomerServiceImpl.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/CustomerServiceImpl.java index 990b23df8..6fc3fcdc3 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/CustomerServiceImpl.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/CustomerServiceImpl.java @@ -3,11 +3,10 @@ #set( $symbol_escape = '\' ) package ${package}.service; -import ${package}.dto.CustomerCheckConflictCmd; import ${package}.dto.CustomerFindByCriteriaQry; -import com.alibaba.sofa.command.CommandBusI; -import com.alibaba.sofa.dto.MultiResponse; -import com.alibaba.sofa.dto.Response; +import com.alibaba.cola.command.CommandBusI; +import com.alibaba.cola.dto.MultiResponse; +import com.alibaba.cola.dto.Response; import ${package}.api.CustomerServiceI; import ${package}.dto.CustomerAddCmd; import ${package}.dto.clientobject.CustomerCO; @@ -24,17 +23,12 @@ public class CustomerServiceImpl implements CustomerServiceI { @Autowired private CommandBusI commandBus; - + @Override public Response addCustomer(CustomerAddCmd customerAddCmd) { return (Response)commandBus.send(customerAddCmd); } - @Override - public MultiResponse checkConflict(CustomerCheckConflictCmd customerCheckConflictCmd) { - return (MultiResponse)commandBus.send(customerCheckConflictCmd); - } - @Override public MultiResponse findByCriteria(CustomerFindByCriteriaQry CustomerFindByCriteriaQry) { return (MultiResponse)commandBus.send(CustomerFindByCriteriaQry); diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/service/package-info.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/CustomerAddValidator.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/CustomerAddValidator.java similarity index 60% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/CustomerAddValidator.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/CustomerAddValidator.java index 0e59f2c25..a739f087c 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/CustomerAddValidator.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/CustomerAddValidator.java @@ -3,21 +3,21 @@ #set( $symbol_escape = '\' ) package ${package}.validator; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import com.alibaba.cola.validator.ValidatorI; +import ${package}.dto.CustomerAddCmd; import org.springframework.stereotype.Component; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; -import ${package}.dto.CustomerAddCmd; -import ${package}.validator.extensionpoint.CustomerAddValidatorExtPt; @Component -public class CustomerAddValidator implements CustomerAddValidatorExtPt { +public class CustomerAddValidator implements ValidatorI { private Logger logger = LoggerFactory.getLogger(CustomerAddValidator.class); @Override public void validate(Object candidate) { - logger.debug("Do common validation"); + logger.debug("General validation"); CustomerAddCmd addCmd = (CustomerAddCmd)candidate; } } diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddBizOneValidatorExt.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddBizOneValidatorExt.java new file mode 100644 index 000000000..216134c49 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddBizOneValidatorExt.java @@ -0,0 +1,39 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + +package ${package}.validator.extension; + +import ${package}.common.BizCode; +import ${package}.dto.CustomerAddCmd; +import ${package}.dto.clientobject.CustomerType; +import ${package}.validator.CustomerAddValidator; +import ${package}.validator.extensionpoint.CustomerAddValidatorExtPt; + +import com.alibaba.cola.exception.BizException; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; + +import org.springframework.beans.factory.annotation.Autowired; + +/** + * CustomerAddBizOneValidatorExt + * + * @author fulan.zjf 2017-11-04 + */ +@Extension(bizCode = BizCode.BIZ_ONE) +public class CustomerAddBizOneValidatorExt implements CustomerAddValidatorExtPt { + + private Logger logger = LoggerFactory.getLogger(CustomerAddBizOneValidatorExt.class); + + @Autowired + private CustomerAddValidator customerAddValidator; + + @Override + public void validate(Object candidate) { + customerAddValidator.validate(candidate); + logger.debug("Biz One validation"); + } + +} diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddBizTwoValidatorExt.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddBizTwoValidatorExt.java new file mode 100644 index 000000000..56eb6cf0e --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddBizTwoValidatorExt.java @@ -0,0 +1,38 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + +package ${package}.validator.extension; + +import ${package}.common.BizCode; +import ${package}.dto.CustomerAddCmd; +import ${package}.validator.CustomerAddValidator; +import com.alibaba.cola.exception.ParamException; +import org.springframework.beans.factory.annotation.Autowired; + +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import ${package}.validator.extensionpoint.CustomerAddValidatorExtPt; +import com.alibaba.cola.validator.ValidatorCompoiste; + +/** + * CustomerAddDDValidator + * + * @author fulan.zjf 2017-11-04 + */ +@Extension(bizCode = BizCode.BIZ_TWO) +public class CustomerAddBizTwoValidatorExt implements CustomerAddValidatorExtPt{ + + private Logger logger = LoggerFactory.getLogger(CustomerAddBizTwoValidatorExt.class); + + @Autowired + private CustomerAddValidator customerAddValidator; + + @Override + public void validate(Object candidate) { + customerAddValidator.validate(candidate); + logger.debug("Biz Two validation"); + } + +} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/package-info.java diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/CustomerAddValidatorExtPt.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/CustomerAddValidatorExtPt.java new file mode 100644 index 000000000..549f10fd5 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/CustomerAddValidatorExtPt.java @@ -0,0 +1,16 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + +package ${package}.validator.extensionpoint; + +import com.alibaba.cola.extension.ExtensionPointI; +import com.alibaba.cola.validator.ValidatorI; + +/** + * CustomerAdd Validation Point + * @author fulan.zjf 2017-11-05 + */ +public interface CustomerAddValidatorExtPt extends ValidatorI, ExtensionPointI{ + +} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/package-info.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/package-info.java diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/CustomerConvertorTest.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/CustomerConvertorTest.java new file mode 100644 index 000000000..df9a67cf4 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/CustomerConvertorTest.java @@ -0,0 +1,62 @@ +#set($symbol_pound='#') +#set($symbol_dollar='$') +#set($symbol_escape='\' ) +package ${package}.app; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.extension.ExtensionExecutor; +import ${package}.common.BizCode; +import ${package}.convertor.extensionpoint.CustomerConvertorExtPt; +import ${package}.domain.customer.entity.CustomerE; +import ${package}.domain.customer.valueobject.SourceType; +import ${package}.dto.clientobject.CustomerCO; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {TestConfig.class}) +public class CustomerConvertorTest { + + @Autowired + private ExtensionExecutor extensionExecutor; + + private CustomerCO customerCO; + + @Before + public void setup(){ + customerCO = new CustomerCO(); + customerCO.setCompanyName("TestCompany"); + } + + @Test + public void testBizOneConvert(){ + //1. prepare + Context context = new Context(); + context.setBizCode(BizCode.BIZ_ONE); + + //2. execute + CustomerE customerE = extensionExecutor.execute(CustomerConvertorExtPt.class, context, extension -> extension.clientToEntity(customerCO, context)); + + //3. assert + Assert.assertEquals(SourceType.BIZ_ONE, customerE.getSourceType()); + } + + @Test + public void testBizTwoConvert(){ + //1. prepare + Context context = new Context(); + context.setBizCode(BizCode.BIZ_TWO); + + //2. execute + CustomerE customerE = extensionExecutor.execute(CustomerConvertorExtPt.class, context, extension -> extension.clientToEntity(customerCO, context)); + + //3. assert + Assert.assertEquals(SourceType.BIZ_TWO, customerE.getSourceType()); + } +} \ No newline at end of file diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/CustomerValidatorTest.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/CustomerValidatorTest.java new file mode 100644 index 000000000..8e04226c8 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/CustomerValidatorTest.java @@ -0,0 +1,21 @@ +#set($symbol_pound='#') +#set($symbol_dollar='$') +#set($symbol_escape='\' ) +package ${package}.app; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {TestConfig.class}) +public class CustomerValidatorTest { + + @Test + public void testValidation(){ + + } +} \ No newline at end of file diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/TestConfig.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/TestConfig.java new file mode 100644 index 000000000..fcee03474 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/app/TestConfig.java @@ -0,0 +1,29 @@ +#set($symbol_pound='#') +#set($symbol_dollar='$') +#set($symbol_escape='\' ) +package ${package}.app; + +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ComponentScan; + +/** + * TestConfig, use @Configuration to replace xml + * + * COLA framework initialization is configured in {@link ${package}.config.ColaConfig} + * + * @author Frank Zhang + * @date 2018-08-08 12:33 PM + */ +@Configuration +@ComponentScan(basePackages = {"com.alibaba.cola", "${package}"}) +public class TestConfig { + + public TestConfig() { + LoggerFactory.activateSysLogger(); + Logger logger = LoggerFactory.getLogger(TestConfig.class); + logger.debug("Spring container is booting"); + } + +} \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml similarity index 86% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml index 4805b988d..371e5e683 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml @@ -5,14 +5,15 @@ ${groupId} ${rootArtifactId}.all ${version} + ../pom.xml ${artifactId} ${version} ${artifactId} - com.alibaba.sofa - sofa-common + com.alibaba.cola + cola-common org.projectlombok diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/api/CustomerServiceI.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/api/CustomerServiceI.java similarity index 65% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/api/CustomerServiceI.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/api/CustomerServiceI.java index ee27fb052..5944ee744 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/api/CustomerServiceI.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/api/CustomerServiceI.java @@ -4,17 +4,14 @@ package ${package}.api; import ${package}.dto.CustomerAddCmd; -import ${package}.dto.CustomerCheckConflictCmd; import ${package}.dto.CustomerFindByCriteriaQry; -import com.alibaba.sofa.dto.MultiResponse; -import com.alibaba.sofa.dto.Response; +import com.alibaba.cola.dto.MultiResponse; +import com.alibaba.cola.dto.Response; import ${package}.dto.clientobject.CustomerCO; public interface CustomerServiceI { public Response addCustomer(CustomerAddCmd customerAddCmd); - - public MultiResponse checkConflict(CustomerCheckConflictCmd customerCheckConflictCmd); - + public MultiResponse findByCriteria(CustomerFindByCriteriaQry CustomerFindByCriteriaQry); } diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/context/DemoContent.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/context/DemoContent.java new file mode 100644 index 000000000..434d5e6bb --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/context/DemoContent.java @@ -0,0 +1,39 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.context; +/** + * DemoContent + * + * @author Frank Zhang + * @date 2019-01-04 10:29 AM + */ +public class DemoContent { + private String userId; + private String roleName; + private String orgId; + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getRoleName() { + return roleName; + } + + public void setRoleName(String roleName) { + this.roleName = roleName; + } + + public String getOrgId() { + return orgId; + } + + public void setOrgId(String orgId) { + this.orgId = orgId; + } +} \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerAddCmd.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerAddCmd.java similarity index 76% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerAddCmd.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerAddCmd.java index dd1279305..0c54a469b 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerAddCmd.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerAddCmd.java @@ -4,12 +4,12 @@ package ${package}.dto; import ${package}.dto.clientobject.CustomerCO; -import com.alibaba.sofa.dto.Command; +import com.alibaba.cola.dto.Command; import lombok.Data; @Data public class CustomerAddCmd extends Command{ - private CustomerCO customer; + private CustomerCO customerCO; } diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByCriteriaQry.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByCriteriaQry.java similarity index 82% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByCriteriaQry.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByCriteriaQry.java index 7e3f9d51d..a22c6543f 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByCriteriaQry.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByCriteriaQry.java @@ -3,7 +3,7 @@ #set( $symbol_escape = '\' ) package ${package}.dto; -import com.alibaba.sofa.dto.Query; +import com.alibaba.cola.dto.Query; public class CustomerFindByCriteriaQry extends Query{ diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByNameQry.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByNameQry.java similarity index 82% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByNameQry.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByNameQry.java index c583e51d1..1911066fa 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByNameQry.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerFindByNameQry.java @@ -3,7 +3,7 @@ #set( $symbol_escape = '\' ) package ${package}.dto; -import com.alibaba.sofa.dto.Query; +import com.alibaba.cola.dto.Query; public class CustomerFindByNameQry extends Query{ diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerUpdateCmd.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerUpdateCmd.java similarity index 81% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerUpdateCmd.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerUpdateCmd.java index 6c8a04496..46e244346 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerUpdateCmd.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerUpdateCmd.java @@ -3,7 +3,7 @@ #set( $symbol_escape = '\' ) package ${package}.dto; -import com.alibaba.sofa.dto.Command; +import com.alibaba.cola.dto.Command; public class CustomerUpdateCmd extends Command{ diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerCO.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerCO.java similarity index 73% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerCO.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerCO.java index 1ac84d076..e638611bf 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerCO.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerCO.java @@ -3,7 +3,7 @@ #set( $symbol_escape = '\' ) package ${package}.dto.clientobject; -import com.alibaba.sofa.dto.ClientObject; +import com.alibaba.cola.dto.ClientObject; import lombok.Data; import javax.validation.constraints.NotEmpty; @@ -13,13 +13,12 @@ public class CustomerCO extends ClientObject { private String customerId; private String memberId; private String customerName; - private CustomerType customerType; - + private String customerType; @NotEmpty private String companyName; @NotEmpty - private String source; //advertisement, p4p, RFQ, ATM + private String source; + - } diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerType.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerType.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerType.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/CustomerType.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/LeadCO.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/LeadCO.java similarity index 80% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/LeadCO.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/LeadCO.java index 9f99aafb6..d6f75e4c3 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/LeadCO.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/LeadCO.java @@ -3,7 +3,7 @@ #set( $symbol_escape = '\' ) package ${package}.dto.clientobject; -import com.alibaba.sofa.dto.ClientObject; +import com.alibaba.cola.dto.ClientObject; public class LeadCO extends ClientObject{ diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/OppertunityCO.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/OppertunityCO.java similarity index 80% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/OppertunityCO.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/OppertunityCO.java index 052ca82d1..bc2ca27d9 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/OppertunityCO.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/OppertunityCO.java @@ -3,7 +3,7 @@ #set( $symbol_escape = '\' ) package ${package}.dto.clientobject; -import com.alibaba.sofa.dto.ClientObject; +import com.alibaba.cola.dto.ClientObject; public class OppertunityCO extends ClientObject{ diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/QueryCriteria.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/QueryCriteria.java similarity index 80% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/QueryCriteria.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/QueryCriteria.java index a9fe96a9f..fca56b185 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/QueryCriteria.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/clientobject/QueryCriteria.java @@ -3,7 +3,7 @@ #set( $symbol_escape = '\' ) package ${package}.dto.clientobject; -import com.alibaba.sofa.dto.ClientObject; +import com.alibaba.cola.dto.ClientObject; public class QueryCriteria extends ClientObject{ diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/domainevent/CustomerCreatedEvent.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/domainevent/CustomerCreatedEvent.java new file mode 100644 index 000000000..1153bcd88 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/domainevent/CustomerCreatedEvent.java @@ -0,0 +1,25 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.dto.domainevent; + +import com.alibaba.cola.dto.event.DomainEvent; + +/** + * CustomerCreatedEvent + * + * @author Frank Zhang + * @date 2019-01-04 10:32 AM + */ +public class CustomerCreatedEvent extends DomainEvent{ + + private String customerId; + + public String getCustomerId() { + return customerId; + } + + public void setCustomerId(String customerId) { + this.customerId = customerId; + } +} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/pom.xml b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/pom.xml similarity index 90% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/pom.xml rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/pom.xml index 4d8b20bf8..a84eb2773 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/pom.xml +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/pom.xml @@ -5,6 +5,7 @@ ${groupId} ${rootArtifactId}.all ${version} + ../pom.xml ${artifactId} ${version} @@ -19,8 +20,8 @@ ${rootArtifactId}-client - com.alibaba.sofa - sofa-test + com.alibaba.cola + cola-test junit diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/CustomerDomainConvertor.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/CustomerDomainConvertor.java new file mode 100644 index 000000000..3026b3922 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/CustomerDomainConvertor.java @@ -0,0 +1,32 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.domain.customer.convertor; + +import com.alibaba.cola.convertor.ConvertorI; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import ${package}.context.DemoContent; +import ${package}.domain.customer.entity.CustomerE; +import ${package}.tunnel.database.dataobject.CustomerDO; +import org.springframework.stereotype.Component; + +/** + * CustomerConvertor + * + * @author Frank Zhang + * @date 2018-01-07 3:08 AM + */ +@Component +public class CustomerDomainConvertor implements ConvertorI { + private Logger logger = LoggerFactory.getLogger(CustomerDomainConvertor.class); + + public CustomerDO entityToData(CustomerE customerE){ + CustomerDO customerDO = new CustomerDO(); + customerDO.setCompanyName(customerE.getCompanyName()); + DemoContent demoContent = (DemoContent) customerE.getContext().getContent(); + logger.debug("The userId from context is:"+demoContent.getUserId()); + customerDO.setCreator(demoContent.getUserId()); + return customerDO; + } +} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/package-info.java diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/ContactE.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/ContactE.java new file mode 100644 index 000000000..b6051b4f2 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/ContactE.java @@ -0,0 +1,12 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.domain.customer.entity; + +import com.alibaba.cola.domain.EntityObject; +import com.alibaba.cola.domain.Entity; + +@Entity +public class ContactE extends EntityObject { + +} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/CustomerE.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/CustomerE.java similarity index 57% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/CustomerE.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/CustomerE.java index af5bda84d..675a72349 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/CustomerE.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/CustomerE.java @@ -3,33 +3,31 @@ #set( $symbol_escape = '\' ) package ${package}.domain.customer.entity; +import com.alibaba.cola.domain.Entity; +import com.alibaba.cola.domain.EntityObject; +import com.alibaba.cola.exception.BizException; +import ${package}.common.exception.ErrorCode; +import ${package}.common.util.DomainEventPublisher; import ${package}.domain.customer.repository.ContactRepository; import ${package}.domain.customer.repository.CustomerRepository; -import ${package}.domain.customer.rule.extensionpoint.CustomerRuleExtPt; import ${package}.domain.customer.valueobject.CompanyType; import ${package}.domain.customer.valueobject.SourceType; -import com.alibaba.sofa.domain.Entity; -import com.alibaba.sofa.extension.ExtensionExecutor; -import com.alibaba.sofa.rule.RuleExecutor; +import ${package}.dto.domainevent.CustomerCreatedEvent; import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; import java.util.List; @Data -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class CustomerE extends Entity { +@Entity +public class CustomerE extends EntityObject { private String customerId; private String memberId; private String globalId; - private ContactE kp; // Key Person + private ContactE contact; // contact Person private List contactList; - private long registeredCapital; // + private long registeredCapital; private String companyName; private SourceType sourceType; private CompanyType companyType; @@ -39,7 +37,7 @@ public class CustomerE extends Entity { @Autowired private CustomerRepository customerRepository; @Autowired - private RuleExecutor ruleExecutor; + private DomainEventPublisher domainEventPublisher; public CustomerE() { } @@ -53,11 +51,22 @@ public boolean isSME() { } public void addNewCustomer() { - //Add customer policy - ruleExecutor.execute(CustomerRuleExtPt.class, extension -> extension.addCustomerCheck(this)); + //check conflict + checkConfilict(); //Persist customer customerRepository.persist(this); + + //Send domain event + domainEventPublisher.publish(new CustomerCreatedEvent()); + } + public void checkConfilict(){ + //Per different biz, the check policy could be different, if so, use ExtensionPoint + if("ConflictCompanyName".equals(this.companyName)){ + throw new BizException(ErrorCode.B_CUSTOMER_companyNameConflict, this.companyName+" has already existed, you can not add it"); + } + + } } diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/ContactRepository.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/ContactRepository.java similarity index 56% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/ContactRepository.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/ContactRepository.java index 887b60d34..1446f7e09 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/ContactRepository.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/ContactRepository.java @@ -4,20 +4,11 @@ package ${package}.domain.customer.repository; import java.util.Set; - import org.springframework.stereotype.Repository; - -import com.alibaba.sofa.context.TenantContext; -import com.alibaba.sofa.repository.RepositoryI; +import com.alibaba.cola.repository.RepositoryI; import ${package}.domain.customer.entity.ContactE; @Repository public class ContactRepository implements RepositoryI { - public Set queryContactByGlobalId(String globalId, String type){ - TenantContext.getTenantId(); - TenantContext.getBizCode(); - return null; - } - } diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/CustomerRepository.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/CustomerRepository.java new file mode 100644 index 000000000..57222d444 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/CustomerRepository.java @@ -0,0 +1,30 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.domain.customer.repository; + +import java.util.ArrayList; +import java.util.List; + +import ${package}.tunnel.database.dataobject.CustomerDO; +import ${package}.tunnel.database.CustomerDBTunnel; +import ${package}.domain.customer.convertor.CustomerDomainConvertor; +import ${package}.domain.customer.entity.CustomerE; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; +import com.alibaba.cola.repository.RepositoryI; + +@Repository +public class CustomerRepository implements RepositoryI{ + + @Autowired + private CustomerDBTunnel customerDBTunnel; + + @Autowired + private CustomerDomainConvertor customerDomainConvertor; + + public void persist(CustomerE customer) { + customerDBTunnel.create(customerDomainConvertor.entityToData(customer)); + } + +} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/AddressV.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/AddressV.java similarity index 85% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/AddressV.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/AddressV.java index e0b775c5d..e23aa73c9 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/AddressV.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/AddressV.java @@ -3,7 +3,7 @@ #set( $symbol_escape = '\' ) package ${package}.domain.customer.valueobject; -import com.alibaba.sofa.domain.ValueObject; +import com.alibaba.cola.domain.ValueObject; /** * Address Value Object diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/CompanyType.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/CompanyType.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/CompanyType.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/CompanyType.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/SourceType.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/SourceType.java similarity index 71% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/SourceType.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/SourceType.java index 1fbd5e3f7..23f3ce5b6 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/SourceType.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/valueobject/SourceType.java @@ -10,7 +10,6 @@ * @date 2018-01-08 11:09 AM */ public enum SourceType { - AD, //Advertisement 广告 - WB, // Web site 网站 - RFQ; // Request For Quota 询盘 + BIZ_ONE, //From biz one + BIZ_TWO; //From biz two } diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/package-info.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/package-info.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/package-info.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/package-info.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/resources/sample.properties b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/resources/sample.properties similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/resources/sample.properties rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/resources/sample.properties diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/java/domain/CustomerEntityTest.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/java/domain/CustomerEntityTest.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/java/domain/CustomerEntityTest.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/java/domain/CustomerEntityTest.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/resources/sample.properties b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/resources/sample.properties similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/resources/sample.properties rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/test/resources/sample.properties diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/pom.xml b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/pom.xml similarity index 83% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/pom.xml rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/pom.xml index 490113bb9..409414be5 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/pom.xml +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/pom.xml @@ -5,6 +5,7 @@ ${groupId} ${rootArtifactId}.all ${version} + ../pom.xml ${artifactId} ${version} @@ -12,12 +13,12 @@ - com.alibaba.sofa - sofa-core + com.alibaba.cola + cola-core - com.alibaba.sofa - sofa-test + com.alibaba.cola + cola-test diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/BizCode.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/BizCode.java new file mode 100644 index 000000000..957185632 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/BizCode.java @@ -0,0 +1,11 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.common; + +public class BizCode { + + public final static String BIZ_ONE = "ali.cola.demo.bizOne"; //biz one + + public final static String BIZ_TWO = "ali.cola.demo.bizTwo"; //biz two +} diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/exception/ErrorCode.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/exception/ErrorCode.java new file mode 100644 index 000000000..b6dcb70cd --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/exception/ErrorCode.java @@ -0,0 +1,35 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.common.exception; + +import com.alibaba.cola.exception.ErrorCodeI; + +/** + * ErrorCode + * + * @author Frank Zhang + * @date 2019-01-04 11:00 AM + */ +public enum ErrorCode implements ErrorCodeI { + + B_CUSTOMER_companyNameConflict("B_CUSTOMER_companyNameConflict", "客户公司名冲突"); + + private final String errCode; + private final String errDesc; + + private ErrorCode(String errCode, String errDesc) { + this.errCode = errCode; + this.errDesc = errDesc; + } + + @Override + public String getErrCode() { + return errCode; + } + + @Override + public String getErrDesc() { + return errDesc; + } +} \ No newline at end of file diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/util/DomainEventPublisher.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/util/DomainEventPublisher.java new file mode 100644 index 000000000..a7b1f3f05 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/util/DomainEventPublisher.java @@ -0,0 +1,30 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.common.util; + +import com.alibaba.cola.domain.DomainEventServiceI; +import com.alibaba.cola.dto.event.DomainEvent; +import com.alibaba.cola.event.EventBusI; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * DomainEventPublisher, this is for demo purpose, the Event is sent to EventBus + * + * Normally DomainEvent should be sent to Messaging Middleware + * + * @author Frank Zhang + * @date 2019-01-04 11:05 AM + */ +@Component +public class DomainEventPublisher implements DomainEventServiceI{ + + @Autowired + private EventBusI eventBus; + + @Override + public void publish(DomainEvent domainEvent) { + eventBus.fire(domainEvent); + } +} \ No newline at end of file diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/ColaConfig.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/ColaConfig.java new file mode 100644 index 000000000..b86b3a6c8 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/ColaConfig.java @@ -0,0 +1,27 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.alibaba.cola.boot.Bootstrap; +import java.util.ArrayList; +import java.util.List; + +/** + * Configuration for COLA framework + */ +@Configuration +public class ColaConfig { + + @Bean(initMethod = "init") + public Bootstrap bootstrap() { + Bootstrap bootstrap = new Bootstrap(); + List packagesToScan = new ArrayList<>(); + packagesToScan.add("${package}"); + bootstrap.setPackages(packagesToScan); + return bootstrap; + } +} \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/DiamondConfig.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/DiamondConfig.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/DiamondConfig.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/config/DiamondConfig.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/datatunnel/impl/CustomerDBTunnel.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/database/CustomerDBTunnel.java similarity index 62% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/datatunnel/impl/CustomerDBTunnel.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/database/CustomerDBTunnel.java index 55fbb1566..5c8df9c92 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/datatunnel/impl/CustomerDBTunnel.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/database/CustomerDBTunnel.java @@ -1,43 +1,32 @@ #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) -package ${package}.tunnel.datatunnel.impl; +package ${package}.tunnel.database; -import ${package}.tunnel.dataobject.CustomerDO; -import ${package}.tunnel.datatunnel.CustomerTunnelI; +import ${package}.tunnel.database.dataobject.CustomerDO; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Component; - +import com.alibaba.cola.tunnel.DataTunnelI; import java.util.List; @Component @Mapper -public class CustomerDBTunnel implements CustomerTunnelI { +public class CustomerDBTunnel implements DataTunnelI { - @Override public CustomerDO create(CustomerDO customerDo) { return new CustomerDO(); } - - @Override + public void update(CustomerDO customerDo) { - } - - @Override + public CustomerDO get(String id) { CustomerDO customerDo = new CustomerDO();//just for demo return customerDo; } - @Override public List findByCriteria(String... params) { return null; } - @Override - public List getByEntity(CustomerDO arg0) { - return null; - } - } diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/dataobject/CustomerDO.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/database/dataobject/CustomerDO.java similarity index 59% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/dataobject/CustomerDO.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/database/dataobject/CustomerDO.java index d2ff60617..5adbbe3fb 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/dataobject/CustomerDO.java +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/database/dataobject/CustomerDO.java @@ -1,16 +1,13 @@ #set( $symbol_pound = '#' ) #set( $symbol_dollar = '$' ) #set( $symbol_escape = '\' ) -package ${package}.tunnel.dataobject; - -import com.alibaba.sofa.repository.DataObject; +package ${package}.tunnel.database.dataobject; +import com.alibaba.cola.tunnel.DataObject; import lombok.Data; -import lombok.EqualsAndHashCode; @Data -@EqualsAndHashCode(callSuper = false) -public class CustomerDO implements DataObject { +public class CustomerDO extends DataObject { private String customerId; private String memberId; private String globalId; diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/rpc/AccountRpcTunnel.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/rpc/AccountRpcTunnel.java new file mode 100644 index 000000000..879f0d128 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/rpc/AccountRpcTunnel.java @@ -0,0 +1,12 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.tunnel.rpc; + +import org.springframework.stereotype.Component; +import com.alibaba.cola.tunnel.DataTunnelI; + +@Component +public class AccountRpcTunnel implements DataTunnelI { + +} diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/rpc/dataobject/AccountDO.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/rpc/dataobject/AccountDO.java new file mode 100644 index 000000000..3faaf2850 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/rpc/dataobject/AccountDO.java @@ -0,0 +1,13 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.tunnel.rpc.dataobject; + +import com.alibaba.cola.tunnel.DataObject; +import lombok.Data; + +@Data +public class AccountDO extends DataObject { + +} + diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/search/CustomerSearchTunnel.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/search/CustomerSearchTunnel.java new file mode 100644 index 000000000..674b6622d --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/search/CustomerSearchTunnel.java @@ -0,0 +1,12 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.tunnel.search; + +import org.springframework.stereotype.Component; +import com.alibaba.cola.tunnel.DataTunnelI; + +@Component +public class CustomerSearchTunnel implements DataTunnelI { + +} diff --git a/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/search/dataobject/CustomerSearchResultDO.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/search/dataobject/CustomerSearchResultDO.java new file mode 100644 index 000000000..0c49c3867 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/search/dataobject/CustomerSearchResultDO.java @@ -0,0 +1,13 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.tunnel.search.dataobject; + +import com.alibaba.cola.tunnel.DataObject; +import lombok.Data; + +@Data +public class CustomerSearchResultDO extends DataObject { + +} + diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/logback-spring.xml b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/logback-spring.xml similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/logback-spring.xml rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/logback-spring.xml diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/customer-mapper.xml b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/customer-mapper.xml similarity index 66% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/customer-mapper.xml rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/customer-mapper.xml index d650b72ef..998be37e2 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/customer-mapper.xml +++ b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/customer-mapper.xml @@ -6,10 +6,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + select * from customer where customer_id = ${symbol_pound}{id} - + diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/mybatis-config.xml b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/mybatis-config.xml similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/mybatis-config.xml rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/mybatis/mybatis-config.xml diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/java/tunnel/CustomerTunnelTest.java b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/java/tunnel/CustomerTunnelTest.java similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/java/tunnel/CustomerTunnelTest.java rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/java/tunnel/CustomerTunnelTest.java diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/resources/sample.properties b/cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/resources/sample.properties similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/resources/sample.properties rename to cola-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/test/resources/sample.properties diff --git a/sofa-archetype/src/main/resources/archetype-resources/pom.xml b/cola-archetype/src/main/resources/archetype-resources/pom.xml similarity index 94% rename from sofa-archetype/src/main/resources/archetype-resources/pom.xml rename to cola-archetype/src/main/resources/archetype-resources/pom.xml index 77081e0d8..1e569e45f 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/pom.xml +++ b/cola-archetype/src/main/resources/archetype-resources/pom.xml @@ -23,7 +23,7 @@ 4.12 1.2.3.5-struct 1.7.22 - 1.0.0-SNAPSHOT + 1.0.0-SNAPSHOT @@ -38,19 +38,19 @@ - com.alibaba.sofa - sofa-common - ${sofa.framework.version} + com.alibaba.cola + cola-common + ${cola.framework.version} - com.alibaba.sofa - sofa-core - ${sofa.framework.version} + com.alibaba.cola + cola-core + ${cola.framework.version} - com.alibaba.sofa - sofa-test - ${sofa.framework.version} + com.alibaba.cola + cola-test + ${cola.framework.version} test diff --git a/sofa-archetype/src/main/resources/archetype-resources/start/pom.xml b/cola-archetype/src/main/resources/archetype-resources/start/pom.xml similarity index 91% rename from sofa-archetype/src/main/resources/archetype-resources/start/pom.xml rename to cola-archetype/src/main/resources/archetype-resources/start/pom.xml index 83ff836cd..d25d08b42 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/start/pom.xml +++ b/cola-archetype/src/main/resources/archetype-resources/start/pom.xml @@ -5,6 +5,7 @@ ${groupId} ${rootArtifactId}.all ${version} + ../pom.xml 4.0.0 @@ -36,8 +37,8 @@ junit - com.alibaba.sofa - sofa-test + com.alibaba.cola + cola-test org.springframework.boot diff --git a/sofa-archetype/src/main/resources/archetype-resources/start/src/main/java/Application.java b/cola-archetype/src/main/resources/archetype-resources/start/src/main/java/Application.java similarity index 72% rename from sofa-archetype/src/main/resources/archetype-resources/start/src/main/java/Application.java rename to cola-archetype/src/main/resources/archetype-resources/start/src/main/java/Application.java index 27bacc32e..e6b04c507 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/start/src/main/java/Application.java +++ b/cola-archetype/src/main/resources/archetype-resources/start/src/main/java/Application.java @@ -8,12 +8,13 @@ import org.springframework.context.annotation.ImportResource; /** - * Spring Boot应用的入口类 + * Spring Boot Starter + * + * COLA framework initialization is configured in {@link ${package}.config.ColaConfig} * * @author Frank Zhang */ -@ImportResource(locations = {"classpath*:app-boot-start.xml"}) -@SpringBootApplication(scanBasePackages = {"${groupId}"}) +@SpringBootApplication(scanBasePackages = {"${package}"}) public class Application { public static void main(String[] args) { diff --git a/sofa-archetype/src/main/resources/archetype-resources/start/src/main/resources/application.properties b/cola-archetype/src/main/resources/archetype-resources/start/src/main/resources/application.properties similarity index 100% rename from sofa-archetype/src/main/resources/archetype-resources/start/src/main/resources/application.properties rename to cola-archetype/src/main/resources/archetype-resources/start/src/main/resources/application.properties diff --git a/cola-archetype/src/main/resources/archetype-resources/start/src/test/java/CustomerServiceTest.java b/cola-archetype/src/main/resources/archetype-resources/start/src/test/java/CustomerServiceTest.java new file mode 100644 index 000000000..075bf35e5 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/start/src/test/java/CustomerServiceTest.java @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.dto.Response; +import ${package}.api.CustomerServiceI; +import ${package}.common.BizCode; +import ${package}.common.exception.ErrorCode; +import ${package}.context.DemoContent; +import ${package}.dto.CustomerAddCmd; +import ${package}.dto.clientobject.CustomerCO; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * This is for integration test. + * + * Created by fulan.zjf on 2017/11/29. + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {TestConfig.class}) +public class CustomerServiceTest { + + @Autowired + private CustomerServiceI customerService; + + private Context context; + + @Before + public void setUp() { + context = new Context<>(); + } + @Test + public void testCustomerAddSuccess(){ + //1.prepare + CustomerAddCmd customerAddCmd = new CustomerAddCmd(); + context.setBizCode(BizCode.BIZ_ONE); + customerAddCmd.setContext(context); + CustomerCO customerCO = new CustomerCO(); + customerCO.setCompanyName("NormalName"); + customerAddCmd.setCustomerCO(customerCO); + + //2.execute + Response response = customerService.addCustomer(customerAddCmd); + + //3.assert + Assert.assertTrue(response.isSuccess()); + } + + @Test + public void testCustomerAddCompanyNameConflict(){ + //1.prepare + CustomerAddCmd customerAddCmd = new CustomerAddCmd(); + context.setBizCode(BizCode.BIZ_ONE); + customerAddCmd.setContext(context); + CustomerCO customerCO = new CustomerCO(); + customerCO.setCompanyName("ConflictCompanyName"); + customerAddCmd.setCustomerCO(customerCO); + + //2.execute + Response response = customerService.addCustomer(customerAddCmd); + + //3.assert + Assert.assertEquals(ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode(), response.getErrCode()); + + } +} diff --git a/cola-archetype/src/main/resources/archetype-resources/start/src/test/java/TestConfig.java b/cola-archetype/src/main/resources/archetype-resources/start/src/test/java/TestConfig.java new file mode 100644 index 000000000..bcc5f423a --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/start/src/test/java/TestConfig.java @@ -0,0 +1,27 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * TestConfig, {@link com.alibaba.demo.config.ColaConfig} + * + * @author Frank Zhang + * @date 2018-08-08 12:33 PM + */ +@Configuration +@ComponentScan(basePackages = {"com.alibaba.cola", "com.alibaba.demo"}) +public class TestConfig { + + public TestConfig() { + LoggerFactory.activateSysLogger(); + Logger logger = LoggerFactory.getLogger(TestConfig.class); + logger.debug("Spring container is booting"); + } + +} \ No newline at end of file diff --git a/cola-archetype/src/main/resources/archetype-resources/start/src/test/resources/logback-test.xml b/cola-archetype/src/main/resources/archetype-resources/start/src/test/resources/logback-test.xml new file mode 100644 index 000000000..b58b89ff1 --- /dev/null +++ b/cola-archetype/src/main/resources/archetype-resources/start/src/test/resources/logback-test.xml @@ -0,0 +1,38 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + ${symbol_dollar}{LOG_FILE} + + ${symbol_dollar}{FILE_LOG_PATTERN} + + + ${symbol_dollar}{LOG_FILE}.%d{yyyy-MM-dd}.%i.log + 7 + 50MB + 20GB + + + + + + ${symbol_dollar}{CONSOLE_LOG_PATTERN} + utf8 + + + + + + + + \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/start/src/test/resources/test.properties b/cola-archetype/src/main/resources/archetype-resources/start/src/test/resources/test.properties similarity index 96% rename from sofa-archetype/src/main/resources/archetype-resources/start/src/test/resources/test.properties rename to cola-archetype/src/main/resources/archetype-resources/start/src/test/resources/test.properties index f7e214397..695eb4a3f 100644 --- a/sofa-archetype/src/main/resources/archetype-resources/start/src/test/resources/test.properties +++ b/cola-archetype/src/main/resources/archetype-resources/start/src/test/resources/test.properties @@ -4,7 +4,7 @@ ${symbol_pound}tddl -spring.tddl.app=TDDL5_APP +spring.tddl.app=TDDL6_APP spring.tddl.sharding=false mybatis.config-location=classpath:mybatis/mybatis-config.xml diff --git a/sofa-archetype/src/test/resources/projects/basic/archetype.properties b/cola-archetype/src/test/resources/projects/basic/archetype.properties similarity index 100% rename from sofa-archetype/src/test/resources/projects/basic/archetype.properties rename to cola-archetype/src/test/resources/projects/basic/archetype.properties diff --git a/sofa-archetype/src/test/resources/projects/basic/goal.txt b/cola-archetype/src/test/resources/projects/basic/goal.txt similarity index 100% rename from sofa-archetype/src/test/resources/projects/basic/goal.txt rename to cola-archetype/src/test/resources/projects/basic/goal.txt diff --git a/sofa-framework/sofa-common/pom.xml b/cola-framework/cola-common/pom.xml similarity index 87% rename from sofa-framework/sofa-common/pom.xml rename to cola-framework/cola-common/pom.xml index 7c959ff0a..dc6a67ba9 100644 --- a/sofa-framework/sofa-common/pom.xml +++ b/cola-framework/cola-common/pom.xml @@ -2,14 +2,14 @@ 4.0.0 - com.alibaba.sofa + com.alibaba.cola all 1.0.0-SNAPSHOT ../pom.xml - sofa-common + cola-common 1.0.0-SNAPSHOT - sofa-common + cola-common @@ -26,5 +26,5 @@ - + diff --git a/cola-framework/cola-common/src/main/java/com/alibaba/cola/context/Context.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/context/Context.java new file mode 100644 index 000000000..6995881a6 --- /dev/null +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/context/Context.java @@ -0,0 +1,48 @@ +package com.alibaba.cola.context; + +/** + * Context is initialized before request processing, usually it should be in Interceptor, + * and will be used through in all layers in one request, that is why it's composited in Command and Entity + * + * Note that the Context is stateless and thread safe + * + * @author Frank Zhang + * @date 2019-01-02 10:14 AM + */ +public class Context { + + /** + * bizCode is used for Extension, the naming should follow Java namespace. + * + * For example: "ali.tmall.supermarket" means it is "天猫超市的业务编码" + */ + private String bizCode; + + /** + * This is the content for application customization, different application would have different Context content. + * + * For example: in a typical application, the content might contain before info + * + * String userId; + * String roleName; + * String orgId; + * String operatorId; + */ + private T content; + + public String getBizCode() { + return bizCode; + } + + public void setBizCode(String bizCode) { + this.bizCode = bizCode; + } + + public T getContent() { + return content; + } + + public void setContent(T content) { + this.content = content; + } +} diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/ClientObject.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/ClientObject.java similarity index 81% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/ClientObject.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/ClientObject.java index 895b12ae7..cf96a7d6c 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/ClientObject.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/ClientObject.java @@ -1,12 +1,14 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; import java.io.Serializable; import java.util.HashMap; import java.util.Map; /** - * This is the object communicate with Client. - * The clients could be view layer or other HSF Consumers + * This is the simple data object used to transfer data between application and caller. + * + * Typical caller includes controller, RPC, MTop and so on. + * * @author fulan.zjf 2017-10-27 PM 12:19:15 */ public abstract class ClientObject implements Serializable{ diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Command.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Command.java similarity index 59% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Command.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Command.java index 252e14265..0193523e4 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Command.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Command.java @@ -1,4 +1,6 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; + +import com.alibaba.cola.context.Context; /** * Command stands for a request from Client. @@ -10,19 +12,13 @@ public abstract class Command extends DTO{ private static final long serialVersionUID = 1L; - /** - * command的操作人 - */ - private String operater; + private Context context; - public String getOperater() { - return operater; + public Context getContext() { + return context; } - public void setOperater(String operater) { - this.operater = operater; + public void setContext(Context context) { + this.context = context; } - - - } diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/DTO.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/DTO.java similarity index 76% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/DTO.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/DTO.java index 22e9443ae..915db72ea 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/DTO.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/DTO.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; import java.io.Serializable; @@ -9,7 +9,7 @@ * * @author fulan.zjf 2017年10月21日 下午8:53:55 */ -public class DTO implements Serializable{ +public abstract class DTO implements Serializable{ private static final long serialVersionUID = 1L; diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/MultiResponse.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/MultiResponse.java similarity index 97% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/MultiResponse.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/MultiResponse.java index d3cfc8434..d9ff4f474 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/MultiResponse.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/MultiResponse.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; import java.util.Collection; diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/OrderDesc.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/OrderDesc.java similarity index 92% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/OrderDesc.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/OrderDesc.java index fec9cf1b6..bd43371f3 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/OrderDesc.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/OrderDesc.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; /** * Order Description diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/PageQuery.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/PageQuery.java similarity index 97% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/PageQuery.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/PageQuery.java index 316955f9a..b773c945f 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/PageQuery.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/PageQuery.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; import java.util.ArrayList; import java.util.Collection; diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Query.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Query.java similarity index 89% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Query.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Query.java index bd8e331da..20f987b6e 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Query.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Query.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; /** * diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Response.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Response.java similarity index 97% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Response.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Response.java index a0c58a432..ecd619426 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/Response.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/Response.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; /** * Response to caller diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/SingleResponse.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/SingleResponse.java similarity index 97% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/SingleResponse.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/SingleResponse.java index 6eb936fba..ebcd04622 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/SingleResponse.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/SingleResponse.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.dto; +package com.alibaba.cola.dto; /** * Response with single record to return diff --git a/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/event/DomainEvent.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/event/DomainEvent.java new file mode 100644 index 000000000..fe9b8296e --- /dev/null +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/event/DomainEvent.java @@ -0,0 +1,18 @@ +package com.alibaba.cola.dto.event; + +import com.alibaba.cola.dto.event.Event; + +/** + * Domain Event (领域事件) + * + * 命名规则:实体名+动词的过去时态+Event + * + * 比如CustomerCreatedEvent 表示创建完客户发送出来的领域事件 + * 比如ContactAddedEvent 表示添加完联系人发送出来的领域事件 + * 比如OpportunityTransferredEvent 表示机会转移完发送出来的领域事件 + * + * @author Frank Zhang + * @date 2019-01-03 12:24 PM + */ +public abstract class DomainEvent extends Event{ +} diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/event/Event.java b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/event/Event.java similarity index 55% rename from sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/event/Event.java rename to cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/event/Event.java index 4d315d6a9..99cb1da94 100644 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/event/Event.java +++ b/cola-framework/cola-common/src/main/java/com/alibaba/cola/dto/event/Event.java @@ -1,6 +1,6 @@ -package com.alibaba.sofa.dto.event; +package com.alibaba.cola.dto.event; -import com.alibaba.sofa.dto.DTO; +import com.alibaba.cola.dto.DTO; /** * @author shawnzhan.zxy @@ -8,13 +8,14 @@ */ public class Event extends DTO{ private static final long serialVersionUID = 5740150436439366761L; - protected String eventId; - protected String eventType; /** - * event type,for example "CREATE"/"UPDATE"... - * @return + * Optional fields, mainly used for Messaging Middleware */ + private String eventId; + private String eventType; + private String eventTopic; + public String getEventType(){ return eventType; } @@ -30,4 +31,12 @@ public void setEventId(String eventId) { public void setEventType(String eventType) { this.eventType = eventType; } + + public String getEventTopic() { + return eventTopic; + } + + public void setEventTopic(String eventTopic) { + this.eventTopic = eventTopic; + } } diff --git a/sofa-framework/sofa-core/pom.xml b/cola-framework/cola-core/pom.xml similarity index 91% rename from sofa-framework/sofa-core/pom.xml rename to cola-framework/cola-core/pom.xml index 4eab3bb9a..2ef180adc 100644 --- a/sofa-framework/sofa-core/pom.xml +++ b/cola-framework/cola-core/pom.xml @@ -3,18 +3,18 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - com.alibaba.sofa + com.alibaba.cola all 1.0.0-SNAPSHOT ../pom.xml - sofa-core + cola-core 1.0.0-SNAPSHOT - sofa-core - + cola-core + - com.alibaba.sofa - sofa-common + com.alibaba.cola + cola-common org.projectlombok @@ -88,5 +88,5 @@ - + diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/assembler/AssemblerI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/assembler/AssemblerI.java similarity index 94% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/assembler/AssemblerI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/assembler/AssemblerI.java index 538c5b930..e02957094 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/assembler/AssemblerI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/assembler/AssemblerI.java @@ -5,7 +5,7 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.assembler; +package com.alibaba.cola.assembler; /** diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/assembler/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/assembler/package-info.java similarity index 77% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/assembler/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/assembler/package-info.java index 4d2c628c8..6f4184ba7 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/assembler/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/assembler/package-info.java @@ -3,4 +3,4 @@ * * @author fulan.zjf */ -package com.alibaba.sofa.assembler; \ No newline at end of file +package com.alibaba.cola.assembler; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/Bootstrap.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/Bootstrap.java similarity index 91% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/Bootstrap.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/Bootstrap.java index 7b30ea92e..be4bdc182 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/Bootstrap.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/Bootstrap.java @@ -5,7 +5,7 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; import java.util.List; import java.util.Set; @@ -13,7 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; -import com.alibaba.sofa.exception.InfraException; +import com.alibaba.cola.exception.ColaException; import lombok.Getter; import lombok.Setter; @@ -60,7 +60,7 @@ private void registerBeans(Set> classSet) { * @return */ private Set> scanConfiguredPackages() { - if (packages == null) throw new InfraException("Command packages is not specified"); + if (packages == null) throw new ColaException("Command packages is not specified"); String[] pkgs = new String[packages.size()]; handler = new ClassPathScanHandler(packages.toArray(pkgs)); diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassInterfaceChecker.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassInterfaceChecker.java similarity index 95% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassInterfaceChecker.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassInterfaceChecker.java index 7dd3fa5aa..d5da9ef39 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassInterfaceChecker.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassInterfaceChecker.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassNameComparator.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassNameComparator.java similarity index 91% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassNameComparator.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassNameComparator.java index 59e2825d7..f599b6e90 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassNameComparator.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassNameComparator.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; import java.util.Comparator; diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassPathScanHandler.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassPathScanHandler.java similarity index 98% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassPathScanHandler.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassPathScanHandler.java index 2c41fdcac..15d0d61ab 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ClassPathScanHandler.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ClassPathScanHandler.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; import java.io.File; import java.io.FileFilter; @@ -24,8 +24,8 @@ import org.reflections.scanners.TypeAnnotationsScanner; import org.reflections.util.ConfigurationBuilder; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; import lombok.Getter; import lombok.Setter; diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/CommandRegister.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/CommandRegister.java similarity index 67% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/CommandRegister.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/CommandRegister.java index 0a7bab38f..09300f86e 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/CommandRegister.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/CommandRegister.java @@ -5,15 +5,15 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; -import com.alibaba.sofa.command.CommandExecutorI; -import com.alibaba.sofa.command.CommandHub; -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.CommandInvocation; -import com.alibaba.sofa.common.CoreConstant; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.exception.InfraException; +import com.alibaba.cola.command.CommandExecutorI; +import com.alibaba.cola.command.CommandHub; +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.CommandInvocation; +import com.alibaba.cola.common.ColaConstant; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.exception.ColaException; import com.google.common.collect.Iterables; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; @@ -51,18 +51,28 @@ public void doRegistration(Class targetClz) { private Class getCommandFromExecutor(Class commandExecutorClz) { Method[] methods = commandExecutorClz.getDeclaredMethods(); for (Method method : methods) { - Class[] exeParams = method.getParameterTypes(); - /** - * This is for return right response type on exception scenarios - */ - if (CoreConstant.EXE_METHOD.equals(method.getName()) && exeParams.length == 1 - && Command.class.isAssignableFrom(exeParams[0]) && !method.isBridge()) { - commandHub.getResponseRepository().put(exeParams[0], method.getReturnType()); - return (Class) exeParams[0]; + if (isExecuteMethod(method)){ + Class commandClz = checkAndGetCommandParamType(method); + commandHub.getResponseRepository().put(commandClz, method.getReturnType()); + return (Class) commandClz; } } - throw new InfraException("Command param in " + commandExecutorClz + " " + CoreConstant.EXE_METHOD - + "() is not detected"); + throw new ColaException(" There is no " + ColaConstant.EXE_METHOD + "() in "+ commandExecutorClz); + } + + private boolean isExecuteMethod(Method method ){ + return ColaConstant.EXE_METHOD.equals(method.getName()) && !method.isBridge(); + } + + private Class checkAndGetCommandParamType(Method method){ + Class[] exeParams = method.getParameterTypes(); + if (exeParams.length == 0){ + throw new ColaException("Execute method in "+method.getDeclaringClass()+" should at least have one parameter"); + } + if(!Command.class.isAssignableFrom(exeParams[0]) ){ + throw new ColaException("Execute method in "+method.getDeclaringClass()+" should be the subClass of Command"); + } + return exeParams[0]; } private Iterable collectInterceptors(Class commandClass, boolean pre) { diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/EventRegister.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/EventRegister.java new file mode 100644 index 000000000..48025af52 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/EventRegister.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Alibaba.com All right reserved. This software is the + * confidential and proprietary information of Alibaba.com ("Confidential + * Information"). You shall not disclose such Confidential Information and shall + * use it only in accordance with the terms of the license agreement you entered + * into with Alibaba.com. + */ +package com.alibaba.cola.boot; + +import com.alibaba.cola.common.ApplicationContextHelper; +import com.alibaba.cola.common.ColaConstant; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.event.Event; +import com.alibaba.cola.event.EventHandlerI; +import com.alibaba.cola.event.EventHub; +import com.alibaba.cola.exception.ColaException; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Method; + +/** + * EventRegister + * + * @author shawnzhan.zxy + * @date 2017/11/20 + */ +@Component +public class EventRegister implements RegisterI { + + @Autowired + private EventHub eventHub; + + @Override + public void doRegistration(Class targetClz) { + Class eventClz = getEventFromExecutor(targetClz); + EventHandlerI executor = (EventHandlerI) ApplicationContextHelper.getBean(targetClz); + eventHub.register(eventClz, executor); + } + + private Class getEventFromExecutor(Class eventExecutorClz) { + Method[] methods = eventExecutorClz.getDeclaredMethods(); + for (Method method : methods) { + if (isExecuteMethod(method)){ + return checkAndGetEventParamType(method); + } + } + throw new ColaException("Event param in " + eventExecutorClz + " " + ColaConstant.EXE_METHOD + + "() is not detected"); + } + + private boolean isExecuteMethod(Method method){ + return ColaConstant.EXE_METHOD.equals(method.getName()) && !method.isBridge(); + } + + private Class checkAndGetEventParamType(Method method){ + Class[] exeParams = method.getParameterTypes(); + if (exeParams.length == 0){ + throw new ColaException("Execute method in "+method.getDeclaringClass()+" should at least have one parameter"); + } + if(!Event.class.isAssignableFrom(exeParams[0]) ){ + throw new ColaException("Execute method in "+method.getDeclaringClass()+" should be the subClass of Event"); + } + return exeParams[0]; + } +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ExtensionRegister.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ExtensionRegister.java similarity index 68% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ExtensionRegister.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ExtensionRegister.java index ee4191c7e..0dde60e9c 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ExtensionRegister.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/ExtensionRegister.java @@ -5,14 +5,14 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; -import com.alibaba.sofa.common.CoreConstant; -import com.alibaba.sofa.exception.InfraException; -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.extension.ExtensionCoordinate; -import com.alibaba.sofa.extension.ExtensionPointI; -import com.alibaba.sofa.extension.ExtensionRepository; +import com.alibaba.cola.common.ColaConstant; +import com.alibaba.cola.exception.ColaException; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.extension.ExtensionCoordinate; +import com.alibaba.cola.extension.ExtensionPointI; +import com.alibaba.cola.extension.ExtensionRepository; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeansException; @@ -37,11 +37,11 @@ public class ExtensionRegister implements RegisterI, ApplicationContextAware{ public void doRegistration(Class targetClz) { ExtensionPointI extension = (ExtensionPointI) applicationContext.getBean(targetClz); Extension extensionAnn = targetClz.getDeclaredAnnotation(Extension.class); - String extensionPoint = calculateExtensionPoint(targetClz); - ExtensionCoordinate extensionCoordinate = new ExtensionCoordinate(extensionPoint, extensionAnn.bizCode(), extensionAnn.tenantId()); + String extPtClassName = calculateExtensionPoint(targetClz); + ExtensionCoordinate extensionCoordinate = new ExtensionCoordinate(extPtClassName, extensionAnn.bizCode()); ExtensionPointI preVal = extensionRepository.getExtensionRepo().put(extensionCoordinate, extension); if (preVal != null) { - throw new InfraException("Duplicate registration is not allowed for :"+extensionCoordinate); + throw new ColaException("Duplicate registration is not allowed for :" + extensionCoordinate); } } @@ -52,13 +52,13 @@ public void doRegistration(Class targetClz) { private String calculateExtensionPoint(Class targetClz) { Class[] interfaces = targetClz.getInterfaces(); if (ArrayUtils.isEmpty(interfaces)) - throw new InfraException("Please assign a extension point interface for "+targetClz); + throw new ColaException("Please assign a extension point interface for "+targetClz); for (Class intf : interfaces) { String extensionPoint = intf.getSimpleName(); - if (StringUtils.contains(extensionPoint, CoreConstant.EXTENSION_EXTPT_NAMING)) - return extensionPoint; + if (StringUtils.contains(extensionPoint, ColaConstant.EXTENSION_EXTPT_NAMING)) + return intf.getName(); } - throw new InfraException("Your name of ExtensionPoint for "+targetClz+" is not valid, must be end of "+CoreConstant.EXTENSION_EXTPT_NAMING); + throw new ColaException("Your name of ExtensionPoint for "+targetClz+" is not valid, must be end of "+ ColaConstant.EXTENSION_EXTPT_NAMING); } diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PostInterceptorRegister.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/PostInterceptorRegister.java similarity index 90% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PostInterceptorRegister.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/PostInterceptorRegister.java index 85dc8ab7d..0d6ccb66b 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PostInterceptorRegister.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/PostInterceptorRegister.java @@ -5,7 +5,7 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; @@ -13,10 +13,10 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; -import com.alibaba.sofa.command.CommandHub; -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.PostInterceptor; -import com.alibaba.sofa.dto.Command; +import com.alibaba.cola.command.CommandHub; +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.PostInterceptor; +import com.alibaba.cola.dto.Command; /** * PostInterceptorRegister diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PreInterceptorRegister.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/PreInterceptorRegister.java similarity index 90% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PreInterceptorRegister.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/PreInterceptorRegister.java index 99b1597b9..bb2d40009 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PreInterceptorRegister.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/PreInterceptorRegister.java @@ -5,7 +5,7 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; import java.lang.annotation.Annotation; @@ -15,10 +15,10 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; -import com.alibaba.sofa.command.CommandHub; -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.PreInterceptor; -import com.alibaba.sofa.dto.Command; +import com.alibaba.cola.command.CommandHub; +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.PreInterceptor; +import com.alibaba.cola.dto.Command; /** * PreInterceptorRegister diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/RegisterFactory.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/RegisterFactory.java similarity index 55% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/RegisterFactory.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/RegisterFactory.java index 050db67df..133382b4a 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/RegisterFactory.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/RegisterFactory.java @@ -5,15 +5,13 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; -import com.alibaba.sofa.command.Command; -import com.alibaba.sofa.command.PostInterceptor; -import com.alibaba.sofa.command.PreInterceptor; -import com.alibaba.sofa.common.CoreConstant; -import com.alibaba.sofa.event.EventHandler; -import com.alibaba.sofa.exception.InfraException; -import com.alibaba.sofa.extension.Extension; +import com.alibaba.cola.command.Command; +import com.alibaba.cola.command.PostInterceptor; +import com.alibaba.cola.command.PreInterceptor; +import com.alibaba.cola.event.EventHandler; +import com.alibaba.cola.extension.Extension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -35,10 +33,6 @@ public class RegisterFactory{ private ExtensionRegister extensionRegister; @Autowired private EventRegister eventRegister; - @Autowired - private PlainValidatorRegister plainValidatorRegister; - @Autowired - private PlainRuleRegister plainRuleRegister; public RegisterI getRegister(Class targetClz) { PreInterceptor preInterceptorAnn = targetClz.getDeclaredAnnotation(PreInterceptor.class); @@ -57,12 +51,6 @@ public RegisterI getRegister(Class targetClz) { if (extensionAnn != null) { return extensionRegister; } - if (isPlainValidator(targetClz)) { - return plainValidatorRegister; - } - if (isPlainRule(targetClz)) { - return plainRuleRegister; - } EventHandler eventHandlerAnn = targetClz.getDeclaredAnnotation(EventHandler.class); if (eventHandlerAnn != null) { return eventRegister; @@ -70,25 +58,4 @@ public RegisterI getRegister(Class targetClz) { return null; } - private boolean isPlainRule(Class targetClz) { - if (ClassInterfaceChecker.check(targetClz, CoreConstant.RULEI_CLASS) && makeSureItsNotExtensionPoint(targetClz)) { - return true; - } - return false; - } - - private boolean isPlainValidator(Class targetClz) { - if (ClassInterfaceChecker.check(targetClz, CoreConstant.VALIDATORI_CLASS) && makeSureItsNotExtensionPoint(targetClz)) { - return true; - } - return false; - } - - private boolean makeSureItsNotExtensionPoint(Class targetClz) { - if (ClassInterfaceChecker.check(targetClz, CoreConstant.EXTENSIONPOINT_CLASS)) { - throw new InfraException( - "Please add @Extension for " + targetClz.getSimpleName() + " since it's a ExtensionPoint"); - } - return true; - } } diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/RegisterI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/RegisterI.java similarity index 94% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/RegisterI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/RegisterI.java index 9e55df3d6..0313f8beb 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/RegisterI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/RegisterI.java @@ -5,7 +5,7 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.boot; +package com.alibaba.cola.boot; import java.lang.annotation.Annotation; diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/package-info.java similarity index 75% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/package-info.java index 6fc14e107..296568603 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/boot/package-info.java @@ -3,4 +3,4 @@ * * @author fulan.zjf */ -package com.alibaba.sofa.boot; \ No newline at end of file +package com.alibaba.cola.boot; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/Command.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/Command.java similarity index 91% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/Command.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/Command.java index 19b5f30a9..016dc5ec5 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/Command.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/Command.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; import org.springframework.stereotype.Component; diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandBus.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandBus.java new file mode 100644 index 000000000..a91dd8082 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandBus.java @@ -0,0 +1,93 @@ +package com.alibaba.cola.command; + +import com.alibaba.cola.exception.*; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +/** + * Just send Command to CommandBus, + * + * @author fulan.zjf 2017年10月24日 上午12:47:18 + */ +@Component +public class CommandBus implements CommandBusI, ApplicationContextAware{ + + Logger logger = LoggerFactory.getLogger(CommandBus.class); + + @Autowired + private CommandHub commandHub; + + private ApplicationContext applicationContext; + + @SuppressWarnings("unchecked") + @Override + public Response send(Command cmd) { + Response response = null; + try { + response = commandHub.getCommandInvocation(cmd.getClass()).invoke(cmd); + } + catch (Exception exception) { + response = handleException(cmd, exception); + } + return response; + } + + private Response handleException(Command cmd, Exception exception) { + Response response = getResponseInstance(cmd); + + ExceptionHandlerI exceptionHandler = getCustomerizedExceptionHandler(); + if (exceptionHandler != null){ + exceptionHandler.handleException(cmd, response, exception); + return response; + } + + defaultHandleException(cmd, response, exception); + return response; + } + + private Response getResponseInstance(Command cmd) { + Class responseClz = commandHub.getResponseRepository().get(cmd.getClass()); + try { + return (Response) responseClz.newInstance(); + } catch (Exception e) { + logger.error("Process "+cmd+" error: "+e.getMessage(), e); + throw new ColaException(e.getMessage()); + } + } + + private void defaultHandleException(Command cmd, Response response, Exception exception) { + if (exception instanceof AppException) { + ErrorCodeI errCode = ((AppException) exception).getErrCode(); + response.setErrCode(errCode.getErrCode()); + } + else { + response.setErrCode(BasicErrorCode.S_UNKNOWN.getErrCode()); + } + response.setErrMessage(exception.getMessage()); + logger.error("Process ["+cmd+"] error, errorCode: " + + response.getErrCode() + " errorMsg:" + + response.getErrMessage(), exception); + } + + private ExceptionHandlerI getCustomerizedExceptionHandler() { + try { + return applicationContext.getBean(ExceptionHandlerI.class); + } + catch (NoSuchBeanDefinitionException ex){ + return null; + } + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandBusI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandBusI.java similarity index 74% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandBusI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandBusI.java index f166a3aea..57a206fb6 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandBusI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandBusI.java @@ -1,7 +1,7 @@ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.dto.Response; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; /** * diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandExecutorI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandExecutorI.java similarity index 64% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandExecutorI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandExecutorI.java index bb1eaaa1c..88a613f94 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandExecutorI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandExecutorI.java @@ -1,7 +1,7 @@ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.dto.Response; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; /** * diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandHub.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandHub.java similarity index 83% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandHub.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandHub.java index 6d5a0c136..f62bdd2ef 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandHub.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandHub.java @@ -1,6 +1,6 @@ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; -import com.alibaba.sofa.exception.InfraException; +import com.alibaba.cola.exception.ColaException; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; import lombok.Getter; @@ -38,12 +38,15 @@ public class CommandHub{ private Map commandRepository = new HashMap<>(); @Getter + /** + * This Repository is used for return right response type on exception scenarios + */ private Map responseRepository = new HashMap<>(); public CommandInvocation getCommandInvocation(Class cmdClass) { CommandInvocation commandInvocation = commandRepository.get(cmdClass); if (commandRepository.get(cmdClass) == null) - throw new InfraException(cmdClass + " is not registered in CommandHub, please register first"); + throw new ColaException(cmdClass + " is not registered in CommandHub, please register first"); return commandInvocation; } } diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandInterceptorI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandInterceptorI.java similarity index 83% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandInterceptorI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandInterceptorI.java index fab52cbd9..d1edd94b3 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandInterceptorI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandInterceptorI.java @@ -1,7 +1,7 @@ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.dto.Response; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; /** * Interceptor will do AOP processing before or after Command Execution diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandInvocation.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandInvocation.java similarity index 93% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandInvocation.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandInvocation.java index 7343af8c9..17a3973af 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandInvocation.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/CommandInvocation.java @@ -1,7 +1,7 @@ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.dto.Response; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; import com.google.common.collect.FluentIterable; import lombok.Setter; diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/PostInterceptor.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/PostInterceptor.java similarity index 69% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/PostInterceptor.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/PostInterceptor.java index 8b92914b0..6ff211b3c 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/PostInterceptor.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/PostInterceptor.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; import org.springframework.stereotype.Component; @@ -10,6 +10,6 @@ @Retention(RetentionPolicy.RUNTIME) public @interface PostInterceptor { - Class[] commands() default {}; + Class[] commands() default {}; } diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/PreInterceptor.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/PreInterceptor.java similarity index 69% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/PreInterceptor.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/PreInterceptor.java index c0f49ff8a..e6dcaa656 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/PreInterceptor.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/PreInterceptor.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; import org.springframework.stereotype.Component; @@ -10,6 +10,6 @@ @Retention(RetentionPolicy.RUNTIME) public @interface PreInterceptor { - Class[] commands() default {}; + Class[] commands() default {}; } diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/QueryExecutorI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/QueryExecutorI.java new file mode 100644 index 000000000..0e7bbbd9d --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/QueryExecutorI.java @@ -0,0 +1,8 @@ +package com.alibaba.cola.command; + +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; + +public interface QueryExecutorI extends CommandExecutorI{ + +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/package-info.java similarity index 51% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/command/package-info.java index 672b3a059..8704c5758 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/command/package-info.java @@ -1,6 +1,6 @@ /** - * This package contains {@link CommandExecutorI} and {@link QueryExecutorI} to process {@link com.alibaba.sofa.dto.Command} from client. + * This package contains {@link CommandExecutorI} and {@link QueryExecutorI} to process {@link com.alibaba.cola.dto.Command} from client. * * @author fulan.zjf */ -package com.alibaba.sofa.command; +package com.alibaba.cola.command; diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/common/ApplicationContextHelper.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/common/ApplicationContextHelper.java new file mode 100644 index 000000000..26dfa22cc --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/common/ApplicationContextHelper.java @@ -0,0 +1,45 @@ +package com.alibaba.cola.common; + +import com.alibaba.cola.exception.BasicErrorCode; +import com.alibaba.cola.exception.SysException; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * ApplicationContextHelper + * + * @author Frank Zhang + * @date 2018-01-07 12:30 PM + */ +@Component +public class ApplicationContextHelper implements ApplicationContextAware{ + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + ApplicationContextHelper.applicationContext = applicationContext; + } + + public static T getBean(Class targetClz){ + T beanInstance = null; + //优先按type查 + try { + beanInstance = (T) applicationContext.getBean(targetClz); + }catch (Exception e){ + } + //按name查 + if(beanInstance == null){ + String simpleName = targetClz.getSimpleName(); + //首字母小写 + simpleName = Character.toLowerCase(simpleName.charAt(0)) + simpleName.substring(1); + beanInstance = (T) applicationContext.getBean(simpleName); + } + if(beanInstance == null){ + new SysException(BasicErrorCode.S_COLA_ERROR, "Component " + targetClz + " can not be found in Spring Container"); + } + return beanInstance; + } +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/DefaultBizCode.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/common/ColaConstant.java similarity index 64% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/DefaultBizCode.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/common/ColaConstant.java index 0863e07b5..8bd36151a 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/DefaultBizCode.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/common/ColaConstant.java @@ -5,15 +5,19 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.common; +package com.alibaba.cola.common; /** - * For App BizCode, please define it in your own App, this is for Framework only + * ColaConstant * @author fulan.zjf 2017-11-04 */ -public class DefaultBizCode { +public class ColaConstant { public final static String DEFAULT_BIZ_CODE = "$defaultBizCode$"; + public final static String BIZ_CODE_SEPARATOR = "."; + public final static String EXTENSION_EXTPT_NAMING = "ExtPt"; + + public final static String EXE_METHOD = "execute"; } diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/convertor/ConvertorI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/convertor/ConvertorI.java similarity index 66% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/convertor/ConvertorI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/convertor/ConvertorI.java index ed0972bf9..505a1f719 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/convertor/ConvertorI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/convertor/ConvertorI.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.convertor; +package com.alibaba.cola.convertor; /** * Convertor are used to convert Objects among Client Object, Domain Object and Data Object. @@ -7,15 +7,19 @@ */ public interface ConvertorI { + //Convert entity object to client object default public C entityToClient(E entityObject){return null;} - default public C dataToClient(D dataObject){return null;} + //Convert entity object to data object + default public D entityToData(E entityObject){return null;} - default public E clientToEntity(C clientObject){return null;} + //Convert data object to client object + default public C dataToClient(D dataObject){return null;} + //Convert data object to entity object default public E dataToEntity(D dataObject){return null;} - default public D entityToData(E entityObject){return null;} - + //Convert client object to entity object + default public E clientToEntity(C clientObject){return null;} } diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/convertor/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/convertor/package-info.java similarity index 78% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/convertor/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/convertor/package-info.java index d01bd5a47..626de6676 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/convertor/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/convertor/package-info.java @@ -3,4 +3,4 @@ * * @author fulan.zjf */ -package com.alibaba.sofa.convertor; \ No newline at end of file +package com.alibaba.cola.convertor; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/AggregateRootI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/AggregateRootI.java similarity index 72% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/AggregateRootI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/AggregateRootI.java index f519d357e..972f78150 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/AggregateRootI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/AggregateRootI.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.domain; +package com.alibaba.cola.domain; /** * 聚合根 diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainEventServiceI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainEventServiceI.java new file mode 100644 index 000000000..f69ddd4dc --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainEventServiceI.java @@ -0,0 +1,22 @@ +package com.alibaba.cola.domain; + +import com.alibaba.cola.dto.event.DomainEvent; + +/** + * DomainEventServiceI + * + * @author Frank Zhang + * @date 2019-01-03 12:25 PM + */ +public interface DomainEventServiceI { + + /** + * Publish Domain Event + * + * The implementation should be provided by application, depends on what kind of Messaging mechanism you are using + * + * It could be RocketMQ, ActiveMQ, Kafka etc. + * @param domainEvent + */ + public void publish(DomainEvent domainEvent); +} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactory.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactory.java new file mode 100644 index 000000000..d19f36642 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactory.java @@ -0,0 +1,16 @@ +package com.alibaba.cola.domain; + +import com.alibaba.cola.common.ApplicationContextHelper; + +/** + * DomainFactory + * + * @author Frank Zhang + * @date 2019-01-03 2:41 PM + */ +public class DomainFactory { + + public static T create(Class entityClz){ + return ApplicationContextHelper.getBean(entityClz); + } +} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainServiceI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainServiceI.java new file mode 100644 index 000000000..f5c4b04b4 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainServiceI.java @@ -0,0 +1,10 @@ +package com.alibaba.cola.domain; + +/** + * 领域服务 + * @author xueliang.sxl + * + */ +public interface DomainServiceI { + +} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/Entity.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/Entity.java new file mode 100644 index 000000000..0ab2264e1 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/Entity.java @@ -0,0 +1,22 @@ +package com.alibaba.cola.domain; + +import lombok.Data; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.lang.annotation.*; + +/** + * Entity, Entity Object is prototype and is not thread-safe + * + * @author Frank Zhang + * @date 2019-01-03 2:53 PM + */ +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public @interface Entity { +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/Entity.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/EntityObject.java similarity index 52% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/Entity.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/EntityObject.java index 954237109..aa53e16d8 100755 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/Entity.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/EntityObject.java @@ -1,38 +1,28 @@ -package com.alibaba.sofa.domain; - -import java.util.Date; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +package com.alibaba.cola.domain; +import com.alibaba.cola.context.Context; import lombok.Getter; import lombok.Setter; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** - * 聚合内的实体 + * Entity Object + * * This is the parent object of all domain objects * @author fulan.zjf 2017年10月27日 上午10:16:10 */ -public abstract class Entity { - - /* - * Entity 包含所有表都有的6个基础字段. - */ - @Getter @Setter - protected String id; - @Getter @Setter - protected Date gmtCreate; - @Getter @Setter - protected Date gmtModified; - @Getter @Setter - protected String creator; - @Getter @Setter - protected String modifier; - @Getter @Setter - protected String isDeleted; - @Getter @Setter - protected String tenantId;//租户ID - @Getter @Setter - protected String bizCode;//业务代码 +public abstract class EntityObject { + + private Context context; + + public Context getContext() { + return context; + } + + public void setContext(Context context) { + this.context = context; + } /* * 扩展字段 diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/ValueObject.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/ValueObject.java similarity index 74% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/ValueObject.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/ValueObject.java index ef259f3bb..dd092d47f 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/ValueObject.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/ValueObject.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.domain; +package com.alibaba.cola.domain; /** * 领域值对象 diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/package-info.java similarity index 66% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/package-info.java index 4a47acfb8..b128568f3 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/package-info.java @@ -3,4 +3,4 @@ * * @author fulan.zjf */ -package com.alibaba.sofa.domain; \ No newline at end of file +package com.alibaba.cola.domain; \ No newline at end of file diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBus.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBus.java new file mode 100644 index 000000000..35d69d61d --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBus.java @@ -0,0 +1,51 @@ +package com.alibaba.cola.event; + +import com.alibaba.cola.dto.Response; +import com.alibaba.cola.dto.event.Event; +import com.alibaba.cola.exception.BasicErrorCode; +import com.alibaba.cola.exception.AppException; +import com.alibaba.cola.exception.ErrorCodeI; +import com.alibaba.cola.exception.ColaException; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.stream.Collector; +import java.util.stream.Collectors; + +/** + * Event Bus + * + * @author shawnzhan.zxy + * @date 2017/11/20 + */ +@Component +public class EventBus implements EventBusI { + Logger logger = LoggerFactory.getLogger(EventBus.class); + + @Autowired + private EventHub eventHub; + + @Override + public void fire(Event event) { + eventHub.getEventHandler(event.getClass()).stream().forEach(p -> { + p.execute(event); + }); + } + + @Override + public void asyncFire(Event event) { + eventHub.getEventHandler(event.getClass()).parallelStream().forEach(p -> { + p.execute(event); + }); + } + +/* + Exception will be thrown out + + private void handleException(EventHandlerI handler, Event event, Exception exception) { + logger.error("Process event error, EventHandler:["+handler.getClass()+"] Event:"+event+" ErrorMessage:"+exception.getMessage(), exception); + } + */ +} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBusI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBusI.java new file mode 100644 index 000000000..6f2374644 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBusI.java @@ -0,0 +1,30 @@ +package com.alibaba.cola.event; + +import com.alibaba.cola.dto.event.Event; +import com.alibaba.cola.dto.Response; + + +/** + * EventBus interface + * @author shawnzhan.zxy + * @date 2017/11/20 + */ +public interface EventBusI { + + /** + * Send event to EventBus + * + * @param event + * @return Response + */ + public void fire(Event event); + + /** + * Send event to EventBus + * + * @param event + * @return Response + */ + public void asyncFire(Event event); + +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHandler.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHandler.java similarity index 88% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHandler.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHandler.java index ce982d101..f367d31d4 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHandler.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHandler.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.event; +package com.alibaba.cola.event; import org.springframework.stereotype.Component; diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHandlerI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHandlerI.java new file mode 100644 index 000000000..cf7e6f8c4 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHandlerI.java @@ -0,0 +1,15 @@ +package com.alibaba.cola.event; + +import com.alibaba.cola.dto.event.Event; +import com.alibaba.cola.dto.Response; + +/** + * event handler + * + * @author shawnzhan.zxy + * @date 2017/11/20 + */ +public interface EventHandlerI { + + public void execute(E e); +} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHub.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHub.java new file mode 100644 index 000000000..a6538f47a --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventHub.java @@ -0,0 +1,52 @@ +package com.alibaba.cola.event; + +import com.alibaba.cola.dto.event.Event; +import com.alibaba.cola.exception.ColaException; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 事件控制中枢 + * @author shawnzhan.zxy + * @date 2017/11/20 + */ +@SuppressWarnings("rawtypes") +@Component +@Data +public class EventHub { + + /** + * one event could have multiple event handlers + */ + private ListMultimap eventRepository = ArrayListMultimap.create(); + + public List getEventHandler(Class eventClass) { + List eventHandlerIList = findHandler(eventClass); + if (eventHandlerIList == null || eventHandlerIList.size() == 0) { + throw new ColaException(eventClass + "is not registered in eventHub, please register first"); + } + return eventHandlerIList; + } + + /** + * 注册事件 + * @param eventClz + * @param executor + */ + public void register(Class eventClz, EventHandlerI executor){ + eventRepository.put(eventClz, executor); + } + + private List findHandler(Class eventClass){ + return eventRepository.get(eventClass); + } + +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/CrmException.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/AppException.java similarity index 64% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/CrmException.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/AppException.java index 00e3a938a..e5ec12110 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/CrmException.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/AppException.java @@ -1,22 +1,22 @@ -package com.alibaba.sofa.exception; +package com.alibaba.cola.exception; /** * - * CRM Exception + * Application Exception * * @author fulan.zjf 2017年10月22日 上午12:00:39 */ -public abstract class CrmException extends RuntimeException{ +public abstract class AppException extends RuntimeException{ private static final long serialVersionUID = 1L; private ErrorCodeI errCode; - public CrmException(String errMessage){ + public AppException(String errMessage){ super(errMessage); } - public CrmException(String errMessage, Throwable e) { + public AppException(String errMessage, Throwable e) { super(errMessage, e); } diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/BasicErrorCode.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/BasicErrorCode.java new file mode 100644 index 000000000..b91f2ed6f --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/BasicErrorCode.java @@ -0,0 +1,60 @@ +package com.alibaba.cola.exception; + +/** + * Application Exceptions can be divided into Biz Exception and Sys Exception. + * + * BizException (including ParamException) is not retry-able, while Sys Exception could be instantaneous and retry-able. + * + * So i suggest to define 3 types of ErrorCode, the format is TYPE_SCENARIO_REASON + * + * TYPE: P_ Stands for Parameter + * TYPE: B_ Stands for Business + * TYPE: S_ Stands for System + * + * Created by fulan.zjf on 2017/12/18. + */ +public enum BasicErrorCode implements ErrorCodeI{ + + /** + * Parameter Exception + * + * You can extend it by implementing ErrorCodeI in your Application + * For example: P_CUSTOMER_NameIsNull("P_CUSTOMER_NameIsNull","客户姓名不能为空") + */ + P_COMMON_ERROR("P_COMMON_ERROR" , "通用的参数校验错误"), + + /** + * Business Exception + * + * You can extend it by implementing ErrorCodeI in your Application + * For example: B_CUSTOMER_NameAlreadyExist("B_CUSTOMER_NameAlreadyExist","客户姓名已经存在") + */ + B_COMMON_ERROR("B_COMMON_ERROR" , "通用的业务逻辑错误"), + + /** + * System Exception + * You can extend it by implementing ErrorCodeI in your Application + */ + S_COLA_ERROR("S_COLA_ERROR" , "COLA框架错误"), + S_DB_ERROR("S_DB_ERROR", "数据库错误"), + S_RPC_ERROR("S_RPC_ERROR", "远程方法调用错误"), + S_UNKNOWN("S_UNKNOWN" , "未知的系统错误" ); + + private String errCode; + private String errDesc; + + private BasicErrorCode(String errCode, String errDesc){ + this.errCode = errCode; + this.errDesc = errDesc; + } + + @Override + public String getErrCode() { + return errCode; + } + + @Override + public String getErrDesc() { + return errDesc; + } +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/BizException.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/BizException.java similarity index 64% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/BizException.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/BizException.java index 4669bffb8..91fa6e8f6 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/BizException.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/BizException.java @@ -1,12 +1,12 @@ -package com.alibaba.sofa.exception; +package com.alibaba.cola.exception; -public class BizException extends CrmException{ +public class BizException extends AppException { private static final long serialVersionUID = 1L; public BizException(String errMessage){ super(errMessage); - this.setErrCode(BasicErrorCode.BIZ_ERROR); + this.setErrCode(BasicErrorCode.B_COMMON_ERROR); } public BizException(ErrorCodeI errCode, String errMessage){ @@ -16,6 +16,6 @@ public BizException(ErrorCodeI errCode, String errMessage){ public BizException(String errMessage, Throwable e) { super(errMessage, e); - this.setErrCode(BasicErrorCode.BIZ_ERROR); + this.setErrCode(BasicErrorCode.B_COMMON_ERROR); } } \ No newline at end of file diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ColaException.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ColaException.java new file mode 100644 index 000000000..ae6d50653 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ColaException.java @@ -0,0 +1,22 @@ +package com.alibaba.cola.exception; + +/** + * + * COLA framework Exception + * + * @author fulan.zjf 2017年10月22日 下午5:56:57 + */ +public class ColaException extends AppException { + + private static final long serialVersionUID = 1L; + + public ColaException(String errMessage){ + super(errMessage); + this.setErrCode(BasicErrorCode.S_COLA_ERROR); + } + + public ColaException(String errMessage, Throwable e) { + super(errMessage, e); + this.setErrCode(BasicErrorCode.S_COLA_ERROR); + } +} \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/ErrorCodeI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ErrorCodeI.java similarity index 75% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/ErrorCodeI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ErrorCodeI.java index cae29adc5..56744443a 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/ErrorCodeI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ErrorCodeI.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.exception; +package com.alibaba.cola.exception; /** * Extends your error codes in your App by implements this Interface. @@ -11,5 +11,4 @@ public interface ErrorCodeI { public String getErrDesc(); - public boolean isRetriable(); } diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ExceptionHandlerI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ExceptionHandlerI.java new file mode 100644 index 000000000..04130290b --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ExceptionHandlerI.java @@ -0,0 +1,15 @@ +package com.alibaba.cola.exception; + +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; + +/** + * ExceptionHandlerI provide a backdoor that Application can override the default Exception handling + * + * @author Frank Zhang + * @date 2019-01-02 11:25 PM + */ +public interface ExceptionHandlerI { + + public void handleException(Command cmd, Response response, Exception exception); +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/ParamException.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ParamException.java similarity index 65% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/ParamException.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ParamException.java index 216bbb353..a56cb46c4 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/ParamException.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ParamException.java @@ -1,12 +1,12 @@ -package com.alibaba.sofa.exception; +package com.alibaba.cola.exception; -public class ParamException extends CrmException{ +public class ParamException extends AppException { private static final long serialVersionUID = 1L; public ParamException(String errMessage){ super(errMessage); - this.setErrCode(BasicErrorCode.PARAM_ERROR); + this.setErrCode(BasicErrorCode.P_COMMON_ERROR); } public ParamException(ErrorCodeI errCode, String errMessage){ @@ -16,6 +16,6 @@ public ParamException(ErrorCodeI errCode, String errMessage){ public ParamException(String errMessage, Throwable e) { super(errMessage, e); - this.setErrCode(BasicErrorCode.PARAM_ERROR); + this.setErrCode(BasicErrorCode.P_COMMON_ERROR); } } diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/Preconditions.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/Preconditions.java similarity index 95% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/Preconditions.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/Preconditions.java index e0639cb81..e7d61ee7e 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/Preconditions.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/Preconditions.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.exception; +package com.alibaba.cola.exception; /** * Created by Danny.Lee on 2017/11/1. diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/SysException.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/SysException.java new file mode 100644 index 000000000..6155542fa --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/SysException.java @@ -0,0 +1,27 @@ +package com.alibaba.cola.exception; + +/** + * SysException + * + * @author Frank Zhang + * @date 2018-12-29 4:38 PM + */ +public class SysException extends AppException { + + private static final long serialVersionUID = 1L; + + public SysException(String errMessage){ + super(errMessage); + this.setErrCode(BasicErrorCode.S_UNKNOWN); + } + + public SysException(ErrorCodeI errCode, String errMessage){ + super(errMessage); + this.setErrCode(errCode); + } + + public SysException(String errMessage, Throwable e) { + super(errMessage, e); + this.setErrCode(BasicErrorCode.S_UNKNOWN); + } +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/package-info.java similarity index 73% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/package-info.java index fa0be9738..1f8451e8b 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/package-info.java @@ -3,4 +3,4 @@ * * @author fulan.zjf */ -package com.alibaba.sofa.exception; \ No newline at end of file +package com.alibaba.cola.exception; \ No newline at end of file diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/AbstractExecutorFacade.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/AbstractExecutorFacade.java new file mode 100644 index 000000000..5e781d643 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/AbstractExecutorFacade.java @@ -0,0 +1,46 @@ +package com.alibaba.cola.extension; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; + +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * @author fulan.zjf + * @date 2017/12/21 + */ +public abstract class AbstractExecutorFacade { + + /** + * Execute extension with Response + * + * @param targetClz + * @param context + * @param exeFunction + * @param Response Type + * @param Parameter Type + * @return + */ + public R execute(Class targetClz, Context context, Function exeFunction) { + T component = locateComponent(targetClz, context); + return exeFunction.apply(component); + } + + /** + * Execute extension without Response + * + * @param targetClz + * @param context + * @param exeFunction + * @param Parameter Type + */ + public void executeVoid(Class targetClz, Context context, Consumer exeFunction) { + T component = locateComponent(targetClz, context); + exeFunction.accept(component); + } + + + protected abstract C locateComponent(Class targetClz, Context context); +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/Extension.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/Extension.java similarity index 74% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/Extension.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/Extension.java index 4360012c1..ba97f50a4 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/Extension.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/Extension.java @@ -5,9 +5,9 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.extension; +package com.alibaba.cola.extension; -import com.alibaba.sofa.common.CoreConstant; +import com.alibaba.cola.common.ColaConstant; import org.springframework.stereotype.Component; import java.lang.annotation.*; @@ -21,6 +21,5 @@ @Target({ElementType.TYPE}) @Component public @interface Extension { - String bizCode() default CoreConstant.DEFAULT_BIZ_CODE; - String tenantId() default CoreConstant.DEFAULT_TENANT_ID; + String bizCode() default ColaConstant.DEFAULT_BIZ_CODE; } diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionCoordinate.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionCoordinate.java similarity index 76% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionCoordinate.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionCoordinate.java index 78d4aa231..abd904ddb 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionCoordinate.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionCoordinate.java @@ -5,12 +5,12 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.extension; +package com.alibaba.cola.extension; import lombok.Data; /** - * Extension Coordinate(扩展点坐标) used to uniquely position a Extension + * Extension Coordinate(扩展点坐标) is used to uniquely position a Extension * @author fulan.zjf 2017-11-05 */ @Data @@ -18,18 +18,15 @@ public class ExtensionCoordinate { private String extensionPoint; private String bizCode; - private String tenantId; - + /** * @param extensionPoint * @param bizCode - * @param tenantId */ - public ExtensionCoordinate(String extensionPoint, String bizCode, String tenantId){ + public ExtensionCoordinate(String extensionPoint, String bizCode){ super(); this.extensionPoint = extensionPoint; this.bizCode = bizCode; - this.tenantId = tenantId; } @Override @@ -38,7 +35,6 @@ public int hashCode() { int result = 1; result = prime * result + ((bizCode == null) ? 0 : bizCode.hashCode()); result = prime * result + ((extensionPoint == null) ? 0 : extensionPoint.hashCode()); - result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); return result; } @Override @@ -53,16 +49,12 @@ public boolean equals(Object obj) { if (extensionPoint == null) { if (other.extensionPoint != null) return false; } else if (!extensionPoint.equals(other.extensionPoint)) return false; - if (tenantId == null) { - if (other.tenantId != null) return false; - } else if (!tenantId.equals(other.tenantId)) return false; return true; } @Override public String toString() { - return "ExtensionCoordinate [extensionPoint=" + extensionPoint + ", bizCode=" + bizCode + ", tenantId=" - + tenantId + "]"; + return "ExtensionCoordinate [extensionPoint=" + extensionPoint + ", bizCode=" + bizCode + "]"; } } diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionExecutor.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionExecutor.java new file mode 100644 index 000000000..68b4796f5 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionExecutor.java @@ -0,0 +1,105 @@ +/* + * Copyright 2017 Alibaba.com All right reserved. This software is the + * confidential and proprietary information of Alibaba.com ("Confidential + * Information"). You shall not disclose such Confidential Information and shall + * use it only in accordance with the terms of the license agreement you entered + * into with Alibaba.com. + */ +package com.alibaba.cola.extension; + +import com.alibaba.cola.common.ColaConstant; +import com.alibaba.cola.context.Context; +import com.alibaba.cola.exception.ColaException; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * ExtensionExecutor + * @author fulan.zjf 2017-11-05 + */ +@Component +public class ExtensionExecutor extends AbstractExecutorFacade { + + private Logger logger = LoggerFactory.getLogger(ExtensionExecutor.class); + + @Autowired + private ExtensionRepository extensionRepository; + + @Override + protected C locateComponent(Class targetClz, Context context) { + C extension = locateExtension(targetClz, context); + logger.debug("[Located Extension]: "+extension.getClass().getSimpleName()); + return extension; + } + + /** + * if the bizCode is "ali.tmall.supermarket" + * + * the search path is as below: + * 1、first try to get extension by "ali.tmall.supermarket", if get, return it. + * 2、loop try to get extension by "ali.tmall", if get, return it. + * 3、loop try to get extension by "ali", if get, return it. + * 4、if not found, try the default extension + * @param targetClz + */ + protected Ext locateExtension(Class targetClz, Context context) { + Ext extension; + checkNull(context); + String bizCode = context.getBizCode(); + logger.debug("Biz Code in locateExtension is : " + bizCode); + + // first try + extension = firstTry(targetClz, bizCode); + if (extension != null) { + return extension; + } + + // loop try + extension = loopTry(targetClz, bizCode); + if (extension != null) { + return extension; + } + + // last try + extension = tryDefault(targetClz); + if (extension != null) { + return extension; + } + + throw new ColaException("Can not find extension with ExtensionPoint: "+targetClz+" BizCode:"+bizCode); + } + + private Ext firstTry(Class targetClz, String bizCode) { + return (Ext)extensionRepository.getExtensionRepo().get(new ExtensionCoordinate(targetClz.getName(), bizCode)); + } + + private Ext loopTry(Class targetClz, String bizCode){ + Ext extension; + if (bizCode == null){ + return null; + } + int lastDotIndex = bizCode.lastIndexOf(ColaConstant.BIZ_CODE_SEPARATOR); + while(lastDotIndex != -1){ + bizCode = bizCode.substring(0, lastDotIndex); + extension =(Ext)extensionRepository.getExtensionRepo().get(new ExtensionCoordinate(targetClz.getName(), bizCode)); + if (extension != null) { + return extension; + } + } + return null; + } + + private Ext tryDefault(Class targetClz) { + return (Ext)extensionRepository.getExtensionRepo().get(new ExtensionCoordinate(targetClz.getName(), ColaConstant.DEFAULT_BIZ_CODE)); + } + + + private void checkNull(Context context){ + if(context == null){ + throw new ColaException("Context can not be null for extension"); + } + } + +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionPointI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionPointI.java similarity index 89% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionPointI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionPointI.java index 9275a05e1..1bd51a70d 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionPointI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionPointI.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.extension; +package com.alibaba.cola.extension; /** * ExtensionPointI is the parent interface of all ExtensionPoints diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionRepository.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionRepository.java similarity index 94% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionRepository.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionRepository.java index ac4366551..0258b438c 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionRepository.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/ExtensionRepository.java @@ -5,7 +5,7 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.extension; +package com.alibaba.cola.extension; import java.util.HashMap; import java.util.Map; diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/package-info.java similarity index 81% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/package-info.java index 12a9d86a8..0a93d236d 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/extension/package-info.java @@ -3,4 +3,4 @@ * * @author fulan.zjf */ -package com.alibaba.sofa.extension; \ No newline at end of file +package com.alibaba.cola.extension; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/Logger.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/Logger.java similarity index 98% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/Logger.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/Logger.java index f289f5097..65f4b515d 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/Logger.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/Logger.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.logger; +package com.alibaba.cola.logger; /** * This is a typical DIP, by depending on ourselves logger, we can change the underline logger vendor easily diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/LoggerFactory.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/LoggerFactory.java new file mode 100644 index 000000000..a0f38d0ac --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/LoggerFactory.java @@ -0,0 +1,32 @@ +package com.alibaba.cola.logger; + +public class LoggerFactory { + + private static boolean useSysLogger = false; + + public static Logger getLogger(Class clazz) { + if(useSysLogger) + return SysLogger.getLogger(clazz); + org.slf4j.Logger slfjLogger = org.slf4j.LoggerFactory.getLogger(clazz); + return new SLFJLogger(slfjLogger); + } + + public static Logger getLogger(String loggerName) { + if(useSysLogger) { + return SysLogger.getLogger(loggerName); + } + org.slf4j.Logger slfjLogger = org.slf4j.LoggerFactory.getLogger(loggerName); + return new SLFJLogger(slfjLogger); + } + + /** + * This is just for testing purpose, don't use it on product! + */ + public static void activateSysLogger() { + useSysLogger = true; + } + + public static void deactivateSysLogger() { + useSysLogger = false; + } +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/SLFJLogger.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/SLFJLogger.java similarity index 86% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/SLFJLogger.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/SLFJLogger.java index c05cab75a..6748f1718 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/SLFJLogger.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/SLFJLogger.java @@ -1,6 +1,6 @@ -package com.alibaba.sofa.logger; +package com.alibaba.cola.logger; -public class SLFJLogger implements com.alibaba.sofa.logger.Logger{ +public class SLFJLogger implements com.alibaba.cola.logger.Logger{ private org.slf4j.Logger slfjLogger; diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/SysLogger.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/SysLogger.java new file mode 100644 index 000000000..bdf70f906 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/SysLogger.java @@ -0,0 +1,46 @@ +package com.alibaba.cola.logger; + +public class SysLogger implements Logger{ + + private String loggerName; + + private SysLogger(String loggerName){ + this.loggerName = loggerName; + } + + public static Logger getLogger(Class clz){ + return new SysLogger(clz.getName()); + } + + + public static Logger getLogger(String loggerName){ + return new SysLogger(loggerName); + } + + @Override + public void debug(String msg) { + System.out.println("["+loggerName+"] DEBUG: "+msg); + } + + @Override + public void info(String msg) { + System.out.println("["+loggerName+"] INFO: "+msg); + } + + @Override + public void warn(String msg) { + System.out.println("["+loggerName+"] WARN: "+msg); + } + + @Override + public void error(String msg) { + System.err.println("["+loggerName+"] ERROR: "+msg); + } + + @Override + public void error(String msg, Throwable t) { + System.err.println("["+loggerName+"] ERROR: "+msg); + t.printStackTrace(); + } + +} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/package-info.java similarity index 80% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/package-info.java index 1ffaed84e..461ceb8f3 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/logger/package-info.java @@ -3,4 +3,4 @@ * * @author fulan.zjf */ -package com.alibaba.sofa.logger; \ No newline at end of file +package com.alibaba.cola.logger; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/RepositoryI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/repository/RepositoryI.java similarity index 83% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/RepositoryI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/repository/RepositoryI.java index e5a5c30e0..cd504c138 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/RepositoryI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/repository/RepositoryI.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.repository; +package com.alibaba.cola.repository; /** * This is Repository pattern which decouples the data access from concrete data tunnels. diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/repository/package-info.java similarity index 76% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/package-info.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/repository/package-info.java index 9394994ef..ec28bfc2e 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/package-info.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/repository/package-info.java @@ -3,4 +3,4 @@ * * @author fulan.zjf */ -package com.alibaba.sofa.repository; \ No newline at end of file +package com.alibaba.cola.repository; \ No newline at end of file diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/DataObject.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/DataObject.java new file mode 100644 index 000000000..3ae7c0f26 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/DataObject.java @@ -0,0 +1,25 @@ +package com.alibaba.cola.tunnel; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + +/** + * This is the parent of all Data Objects. + * Data object only has fields and according getters and setters, it's used to do CRUD operations + * + * @author fulan.zjf 2017年10月27日 上午10:21:01 + */ +@Data +public abstract class DataObject { + + private String id; + private String creator; + private String modifier; + private Date gmtCreate; + private Date gmtModified; + +} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/DataTunnelI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/DataTunnelI.java new file mode 100644 index 000000000..9e1cc706d --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/DataTunnelI.java @@ -0,0 +1,14 @@ +package com.alibaba.cola.tunnel; + +import java.util.List; + +/** + * Data Tunnel is used to provide data to Domain + * + * The data could come from different tunnel, such as database, rpc, search etc. + * + * @author fulan.zjf 2017年10月27日 上午10:34:17 + */ +public interface DataTunnelI { + +} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/package-info.java new file mode 100644 index 000000000..aacf88e8a --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/tunnel/package-info.java @@ -0,0 +1,6 @@ +/** + * Tunnel is composed by Repository to persist and provide data to Domain layer + * + * @author fulan.zjf + */ +package com.alibaba.cola.tunnel; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/SofaMessageInterpolator.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ColaMessageInterpolator.java similarity index 80% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/SofaMessageInterpolator.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ColaMessageInterpolator.java index 62f864c26..433956840 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/SofaMessageInterpolator.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ColaMessageInterpolator.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.validator; +package com.alibaba.cola.validator; import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; @@ -8,7 +8,7 @@ * @author fulan.zjf * @date 2017/12/25 */ -public class SofaMessageInterpolator extends ResourceBundleMessageInterpolator{ +public class ColaMessageInterpolator extends ResourceBundleMessageInterpolator{ @Override public String interpolate(String message, Context context) { diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorCompoiste.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ValidatorCompoiste.java similarity index 97% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorCompoiste.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ValidatorCompoiste.java index 99e348fd6..1fd39eb30 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorCompoiste.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ValidatorCompoiste.java @@ -5,7 +5,7 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.validator; +package com.alibaba.cola.validator; import com.google.common.collect.Lists; import org.springframework.beans.factory.InitializingBean; diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ValidatorI.java similarity index 94% rename from sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorI.java rename to cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ValidatorI.java index f3c8545bf..d40a459e1 100644 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorI.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/ValidatorI.java @@ -5,7 +5,7 @@ * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ -package com.alibaba.sofa.validator; +package com.alibaba.cola.validator; /** * Validator Interface diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/package-info.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/package-info.java new file mode 100644 index 000000000..e27d71f59 --- /dev/null +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/validator/package-info.java @@ -0,0 +1,6 @@ +/** + * Use {@link com.alibaba.cola.validator.ValidatorI} to declare Validator, and use {@link com.alibaba.cola.extension.Extension} if this Validator needs Extension. + * + * @author fulan.zjf + */ +package com.alibaba.cola.validator; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/resources/sample.properties b/cola-framework/cola-core/src/main/resources/sample.properties similarity index 100% rename from sofa-framework/sofa-core/src/main/resources/sample.properties rename to cola-framework/cola-core/src/main/resources/sample.properties diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/TestConfig.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/TestConfig.java similarity index 71% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/TestConfig.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/TestConfig.java index 2aee36f0c..0b09fce78 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/TestConfig.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/TestConfig.java @@ -1,6 +1,7 @@ -package com.alibaba.sofa; +package com.alibaba.cola; -import com.alibaba.sofa.boot.Bootstrap; +import com.alibaba.cola.boot.Bootstrap; +import com.alibaba.cola.logger.LoggerFactory; import org.springframework.context.annotation.*; import java.util.ArrayList; @@ -12,7 +13,7 @@ * @author Frank Zhang 2018-01-06 7:57 AM */ @Configuration -@ComponentScan("com.alibaba.sofa") +@ComponentScan("com.alibaba.cola") @PropertySource(value = {"/sample.properties"}) public class TestConfig { @@ -20,7 +21,7 @@ public class TestConfig { public Bootstrap bootstrap() { Bootstrap bootstrap = new Bootstrap(); List packagesToScan = new ArrayList<>(); - packagesToScan.add("com.alibaba.sofa.test"); + packagesToScan.add("com.alibaba.cola.test"); bootstrap.setPackages(packagesToScan); return bootstrap; } diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/CustomerCommandTest.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/CustomerCommandTest.java similarity index 77% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/CustomerCommandTest.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/CustomerCommandTest.java index 5c88c2b28..5b1dade66 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/CustomerCommandTest.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/CustomerCommandTest.java @@ -1,10 +1,10 @@ -package com.alibaba.sofa.test; +package com.alibaba.cola.test; -import com.alibaba.sofa.TestConfig; -import com.alibaba.sofa.context.TenantContext; -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.exception.BasicErrorCode; -import com.alibaba.sofa.test.customer.*; +import com.alibaba.cola.TestConfig; +import com.alibaba.cola.context.Context; +import com.alibaba.cola.dto.Response; +import com.alibaba.cola.exception.BasicErrorCode; +import com.alibaba.cola.test.customer.*; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -34,16 +34,19 @@ public class CustomerCommandTest { @Value("${bizCode}") private String bizCode; + private Context context; + @Before public void setUp() { - TenantContext.set(Constants.TENANT_ID, bizCode); + context = new Context(); } @Test public void testBizOneAddCustomerSuccess(){ //1. Prepare - TenantContext.set(Constants.TENANT_ID, Constants.BIZ_1); AddCustomerCmd addCustomerCmd = new AddCustomerCmd(); + context.setBizCode(Constants.BIZ_ONE); + addCustomerCmd.setContext(context); CustomerCO customerCO = new CustomerCO(); customerCO.setCompanyName("alibaba"); customerCO.setSource(Constants.SOURCE_RFQ); @@ -60,8 +63,9 @@ public void testBizOneAddCustomerSuccess(){ @Test public void testBizOneAddCustomerFailure(){ //1. Prepare - TenantContext.set(Constants.TENANT_ID, Constants.BIZ_1); AddCustomerCmd addCustomerCmd = new AddCustomerCmd(); + context.setBizCode(Constants.BIZ_ONE); + addCustomerCmd.setContext(context); CustomerCO customerCO = new CustomerCO(); customerCO.setCompanyName("alibaba"); customerCO.setSource(Constants.SOURCE_AD); @@ -73,14 +77,15 @@ public void testBizOneAddCustomerFailure(){ //3. Expect exception Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getErrCode(), BasicErrorCode.BIZ_ERROR.getErrCode()); + Assert.assertEquals(response.getErrCode(),ErrorCode.B_CUSTOMER_advNotAllowed.getErrCode()); } @Test public void testBizTwoAddCustomer(){ //1. Prepare - TenantContext.set(Constants.TENANT_ID, Constants.BIZ_2); AddCustomerCmd addCustomerCmd = new AddCustomerCmd(); + context.setBizCode(Constants.BIZ_TWO); + addCustomerCmd.setContext(context); CustomerCO customerCO = new CustomerCO(); customerCO.setCompanyName("alibaba"); customerCO.setSource(Constants.SOURCE_AD); @@ -95,8 +100,10 @@ public void testBizTwoAddCustomer(){ } @Test - public void testCompanyTypeViolation(){ + public void testBizTwoAddCustomerFailure(){ AddCustomerCmd addCustomerCmd = new AddCustomerCmd(); + addCustomerCmd.setContext(context); + context.setBizCode(Constants.BIZ_TWO); CustomerCO customerCO = new CustomerCO(); customerCO.setCompanyName("alibaba"); customerCO.setSource("p4p"); @@ -106,16 +113,17 @@ public void testCompanyTypeViolation(){ //Expect biz exception Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getErrCode(), BasicErrorCode.BIZ_ERROR.getErrCode()); + Assert.assertEquals(response.getErrCode(), ErrorCode.B_CUSTOMER_vipNeedApproval.getErrCode()); } @Test public void testParamValidationFail(){ AddCustomerCmd addCustomerCmd = new AddCustomerCmd(); + addCustomerCmd.setContext(context); Response response = customerService.addCustomer(addCustomerCmd); //Expect parameter validation error Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getErrCode(), BasicErrorCode.PARAM_ERROR.getErrCode()); + Assert.assertEquals(response.getErrCode(), BasicErrorCode.P_COMMON_ERROR.getErrCode()); } } diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/EntityPrototypeTest.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/EntityPrototypeTest.java similarity index 63% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/EntityPrototypeTest.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/EntityPrototypeTest.java index f2f832aa8..e002d3063 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/EntityPrototypeTest.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/EntityPrototypeTest.java @@ -1,8 +1,8 @@ -package com.alibaba.sofa.test; +package com.alibaba.cola.test; -import com.alibaba.sofa.TestConfig; -import com.alibaba.sofa.common.ApplicationContextHelper; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; +import com.alibaba.cola.TestConfig; +import com.alibaba.cola.domain.DomainFactory; +import com.alibaba.cola.test.customer.entity.CustomerE; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,9 +22,9 @@ public class EntityPrototypeTest { @Test public void testPrototype(){ - CustomerEntity customerEntity1 = (CustomerEntity)ApplicationContextHelper.getBean(CustomerEntity.class); + CustomerE customerEntity1 = DomainFactory.create(CustomerE.class); System.out.println(customerEntity1); - CustomerEntity customerEntity2 = (CustomerEntity)ApplicationContextHelper.getBean(CustomerEntity.class); + CustomerE customerEntity2 = DomainFactory.create(CustomerE.class); System.out.println(customerEntity2); Assert.assertEquals(customerEntity1, customerEntity2); diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/SpringConfigTest.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/SpringConfigTest.java similarity index 78% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/SpringConfigTest.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/SpringConfigTest.java index f0e8dba42..61e6a9507 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/SpringConfigTest.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/SpringConfigTest.java @@ -1,8 +1,8 @@ -package com.alibaba.sofa.test; +package com.alibaba.cola.test; -import com.alibaba.sofa.TestConfig; -import com.alibaba.sofa.boot.Bootstrap; -import com.alibaba.sofa.boot.RegisterFactory; +import com.alibaba.cola.TestConfig; +import com.alibaba.cola.boot.Bootstrap; +import com.alibaba.cola.boot.RegisterFactory; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class SpringConfigTest { diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/SysLoggerStarter.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/SysLoggerStarter.java new file mode 100644 index 000000000..4f9a0ddee --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/SysLoggerStarter.java @@ -0,0 +1,24 @@ +package com.alibaba.cola.test; + +import com.alibaba.cola.logger.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.stereotype.Component; + +/** + * SysLoggerStarter + * + * For testing purpose, make sure SysLogger is activated before any bean creation + * + * @author Frank Zhang + * @date 2019-01-03 10:21 AM + */ +@Component +public class SysLoggerStarter implements BeanFactoryPostProcessor { + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + //if you want to use sysLogger, it should be activated before bean creation + LoggerFactory.activateSysLogger(); + } +} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/AddCustomerCmd.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/AddCustomerCmd.java similarity index 78% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/AddCustomerCmd.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/AddCustomerCmd.java index 8db2cef3f..67ddd4b7d 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/AddCustomerCmd.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/AddCustomerCmd.java @@ -1,7 +1,7 @@ -package com.alibaba.sofa.test.customer; +package com.alibaba.cola.test.customer; -import com.alibaba.sofa.dto.Command; +import com.alibaba.cola.dto.Command; import lombok.Data; import javax.validation.Valid; diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/AddCustomerCmdExe.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/AddCustomerCmdExe.java new file mode 100644 index 000000000..25479f207 --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/AddCustomerCmdExe.java @@ -0,0 +1,44 @@ +package com.alibaba.cola.test.customer; + +import com.alibaba.cola.command.Command; +import com.alibaba.cola.command.CommandExecutorI; +import com.alibaba.cola.dto.Response; +import com.alibaba.cola.extension.ExtensionExecutor; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import com.alibaba.cola.test.customer.convertor.extensionpoint.CustomerConvertorExtPt; +import com.alibaba.cola.test.customer.entity.CustomerE; +import com.alibaba.cola.test.customer.validator.extensionpoint.AddCustomerValidatorExtPt; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * AddCustomerCmdExe + * + * @author Frank Zhang 2018-01-06 7:48 PM + */ +@Command +public class AddCustomerCmdExe implements CommandExecutorI { + + private Logger logger = LoggerFactory.getLogger(AddCustomerCmd.class); + + @Autowired + private ExtensionExecutor extensionExecutor; + + + @Override + public Response execute(AddCustomerCmd cmd) { + logger.info("Start processing command:" + cmd); + //Do validation + extensionExecutor.executeVoid(AddCustomerValidatorExtPt.class, cmd.getContext(), validator -> validator.validate(cmd)); + + //Convert CO to EntityObject + CustomerE customerE = extensionExecutor.execute(CustomerConvertorExtPt.class, cmd.getContext(), convertor -> convertor.clientToEntity(cmd.getCustomerCO(), cmd.getContext())); + + //Call Domain EntityObject for business logic processing + logger.info("Call Domain EntityObject for business logic processing..."+customerE); + customerE.addNewCustomer(); + + logger.info("End processing command:" + cmd); + return Response.buildSuccess(); + } +} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/Constants.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/Constants.java similarity index 76% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/Constants.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/Constants.java index d768a186e..6e5fd354b 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/Constants.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/Constants.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.test.customer; +package com.alibaba.cola.test.customer; /** * Constants @@ -8,8 +8,8 @@ */ public class Constants { - public static final String BIZ_1 = "BIZ_ONE"; - public static final String BIZ_2 = "BIZ_TWO"; + public static final String BIZ_ONE = "BIZ_ONE"; + public static final String BIZ_TWO = "BIZ_TWO"; public static final String TENANT_ID = "122344"; diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerCO.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerCO.java similarity index 72% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerCO.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerCO.java index 2af3c25d2..8bc0a1a2c 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerCO.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerCO.java @@ -1,6 +1,6 @@ -package com.alibaba.sofa.test.customer; +package com.alibaba.cola.test.customer; -import com.alibaba.sofa.dto.ClientObject; +import com.alibaba.cola.dto.ClientObject; import lombok.Data; import javax.validation.constraints.NotEmpty; @@ -11,7 +11,7 @@ * @author Frank Zhang 2018-01-06 7:30 PM */ @Data -public class CustomerCO extends ClientObject{ +public class CustomerCO extends ClientObject { @NotEmpty private String companyName; diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerDO.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerDO.java similarity index 72% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerDO.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerDO.java index 14f4cdb10..e80edd292 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerDO.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerDO.java @@ -1,6 +1,6 @@ -package com.alibaba.sofa.test.customer; +package com.alibaba.cola.test.customer; -import com.alibaba.sofa.repository.DataObject; +import com.alibaba.cola.tunnel.DataObject; import lombok.Data; import lombok.EqualsAndHashCode; @@ -12,7 +12,7 @@ */ @Data @EqualsAndHashCode(callSuper = false) -public class CustomerDO implements DataObject { +public class CustomerDO extends DataObject { private String customerId; private String memberId; private String globalId; diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerServiceI.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerServiceI.java similarity index 68% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerServiceI.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerServiceI.java index 3c199d0e0..313cd1dff 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerServiceI.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerServiceI.java @@ -1,7 +1,7 @@ -package com.alibaba.sofa.test.customer; +package com.alibaba.cola.test.customer; -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.dto.SingleResponse; +import com.alibaba.cola.dto.Response; +import com.alibaba.cola.dto.SingleResponse; /** * CustomerServiceI diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerServiceImpl.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerServiceImpl.java similarity index 77% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerServiceImpl.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerServiceImpl.java index 1cffc8717..abe543aee 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerServiceImpl.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerServiceImpl.java @@ -1,8 +1,8 @@ -package com.alibaba.sofa.test.customer; +package com.alibaba.cola.test.customer; -import com.alibaba.sofa.command.CommandBusI; -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.dto.SingleResponse; +import com.alibaba.cola.command.CommandBusI; +import com.alibaba.cola.dto.Response; +import com.alibaba.cola.dto.SingleResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerType.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerType.java similarity index 79% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerType.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerType.java index c7229e09e..67f0669e4 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/CustomerType.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/CustomerType.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.test.customer; +package com.alibaba.cola.test.customer; /** * CustomerType diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/ErrorCode.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/ErrorCode.java new file mode 100644 index 000000000..87b0c08c9 --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/ErrorCode.java @@ -0,0 +1,33 @@ +package com.alibaba.cola.test.customer; + +import com.alibaba.cola.exception.ErrorCodeI; + +/** + * ErrorCode + * + * @author Frank Zhang + * @date 2019-01-03 11:24 AM + */ +public enum ErrorCode implements ErrorCodeI{ + + B_CUSTOMER_advNotAllowed("B_CUSTOMER_advNotAllowed", "不允许添加广告客户"), + B_CUSTOMER_vipNeedApproval("B_CUSTOMER_vipNeedApproval", "VIP客户需要审批"); + + private String errCode; + private String errDesc; + + private ErrorCode(String errCode, String errDesc){ + this.errCode = errCode; + this.errDesc = errDesc; + } + + @Override + public String getErrCode() { + return errCode; + } + + @Override + public String getErrDesc() { + return errDesc; + } +} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/GetOneCustomerQry.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/GetOneCustomerQry.java similarity index 73% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/GetOneCustomerQry.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/GetOneCustomerQry.java index 5e063c27a..814b00d76 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/GetOneCustomerQry.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/GetOneCustomerQry.java @@ -1,6 +1,6 @@ -package com.alibaba.sofa.test.customer; +package com.alibaba.cola.test.customer; -import com.alibaba.sofa.dto.Query; +import com.alibaba.cola.dto.Query; import lombok.Data; /** diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerBizOneConvertorExt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerBizOneConvertorExt.java new file mode 100644 index 000000000..08dc2623c --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerBizOneConvertorExt.java @@ -0,0 +1,37 @@ +package com.alibaba.cola.test.customer.convertor.extension; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.Constants; +import com.alibaba.cola.test.customer.CustomerCO; +import com.alibaba.cola.test.customer.convertor.extensionpoint.CustomerConvertorExtPt; +import com.alibaba.cola.test.customer.entity.CustomerE; +import com.alibaba.cola.test.customer.entity.SourceType; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * CustomerBizOneConvertorExt + * + * @author Frank Zhang + * @date 2018-01-07 3:05 AM + */ +@Extension(bizCode = Constants.BIZ_ONE) +public class CustomerBizOneConvertorExt implements CustomerConvertorExtPt { + + @Autowired + private CustomerDefaultConvertorExt customerConvertor;//Composite basic convertor to do basic conversion + + @Override + public CustomerE clientToEntity(CustomerCO customerCO, Context context){ + CustomerE customerE = customerConvertor.clientToEntity(customerCO, context); + //In this business, AD and RFQ are regarded as different source + if(Constants.SOURCE_AD.equals(customerCO.getSource())) + { + customerE.setSourceType(SourceType.AD); + } + if (Constants.SOURCE_RFQ.equals(customerCO.getSource())){ + customerE.setSourceType(SourceType.RFQ); + } + return customerE; + } +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerBizTwoConvertorExt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerBizTwoConvertorExt.java new file mode 100644 index 000000000..76747974a --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerBizTwoConvertorExt.java @@ -0,0 +1,35 @@ +package com.alibaba.cola.test.customer.convertor.extension; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.Constants; +import com.alibaba.cola.test.customer.CustomerCO; +import com.alibaba.cola.test.customer.convertor.extensionpoint.CustomerConvertorExtPt; +import com.alibaba.cola.test.customer.entity.CustomerE; +import com.alibaba.cola.test.customer.entity.SourceType; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * CustomerBizTwoConvertorExt + * + * @author Frank Zhang + * @date 2018-01-07 3:05 AM + */ +@Extension(bizCode = Constants.BIZ_TWO) +public class CustomerBizTwoConvertorExt implements CustomerConvertorExtPt { + + @Autowired + private CustomerDefaultConvertorExt customerConvertor;//Composite basic convertor to do basic conversion + + @Override + public CustomerE clientToEntity(CustomerCO customerCO, Context context){ + CustomerE customerE = customerConvertor.clientToEntity(customerCO, context); + //In this business, if customers from RFQ and Advertisement are both regarded as Advertisement + if(Constants.SOURCE_AD.equals(customerCO.getSource()) || Constants.SOURCE_RFQ.equals(customerCO.getSource())) + { + customerE.setSourceType(SourceType.AD); + } + return customerE; + } + +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerDefaultConvertorExt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerDefaultConvertorExt.java new file mode 100644 index 000000000..a1a2ee441 --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extension/CustomerDefaultConvertorExt.java @@ -0,0 +1,26 @@ +package com.alibaba.cola.test.customer.convertor.extension; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.domain.DomainFactory; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.CustomerCO; +import com.alibaba.cola.test.customer.convertor.extensionpoint.CustomerConvertorExtPt; +import com.alibaba.cola.test.customer.entity.CustomerE; + +/** + * CustomerDefaultConvertorExt + * + * @author Frank Zhang + * @date 2018-01-07 3:08 AM + */ +@Extension +public class CustomerDefaultConvertorExt implements CustomerConvertorExtPt { + + public CustomerE clientToEntity(CustomerCO customerCO, Context context){ + CustomerE customerE = DomainFactory.create(CustomerE.class); + customerE.setCompanyName(customerCO.getCompanyName()); + customerE.setCustomerType(customerCO.getCustomerType()); + customerE.setContext(context); + return customerE; + } +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extensionpoint/CustomerConvertorExtPt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extensionpoint/CustomerConvertorExtPt.java new file mode 100644 index 000000000..9a40704ac --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/convertor/extensionpoint/CustomerConvertorExtPt.java @@ -0,0 +1,18 @@ +package com.alibaba.cola.test.customer.convertor.extensionpoint; + +import com.alibaba.cola.context.Context; +import com.alibaba.cola.convertor.ConvertorI; +import com.alibaba.cola.extension.ExtensionPointI; +import com.alibaba.cola.test.customer.CustomerCO; +import com.alibaba.cola.test.customer.entity.CustomerE; + +/** + * CustomerConvertorExtPt + * + * @author Frank Zhang + * @date 2018-01-07 2:37 AM + */ +public interface CustomerConvertorExtPt extends ConvertorI, ExtensionPointI { + + public CustomerE clientToEntity(CustomerCO customerCO, Context context); +} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/CustomerEntity.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/CustomerE.java similarity index 52% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/CustomerEntity.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/CustomerE.java index 7f8842f94..8a4b748ba 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/CustomerEntity.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/CustomerE.java @@ -1,11 +1,11 @@ -package com.alibaba.sofa.test.customer.entity; - -import com.alibaba.sofa.domain.Entity; -import com.alibaba.sofa.extension.ExtensionExecutor; -import com.alibaba.sofa.test.customer.CustomerType; -import com.alibaba.sofa.test.customer.convertor.CustomerConvertorExtPt; -import com.alibaba.sofa.test.customer.entity.rule.CustomerRuleExtPt; -import com.alibaba.sofa.test.customer.repository.CustomerRepository; +package com.alibaba.cola.test.customer.entity; + +import com.alibaba.cola.domain.Entity; +import com.alibaba.cola.domain.EntityObject; +import com.alibaba.cola.extension.ExtensionExecutor; +import com.alibaba.cola.test.customer.CustomerType; +import com.alibaba.cola.test.customer.entity.extensionpoint.CustomerCheckExtPt; +import com.alibaba.cola.test.customer.repository.CustomerRepository; import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -13,15 +13,14 @@ import org.springframework.stereotype.Component; /** - * Customer Entity + * Customer EntityObject * * @author Frank Zhang * @date 2018-01-07 2:38 AM */ @Data -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class CustomerEntity extends Entity { +@Entity +public class CustomerE extends EntityObject { private String companyName; private SourceType sourceType; @@ -32,13 +31,13 @@ public class CustomerEntity extends Entity { @Autowired private ExtensionExecutor extensionExecutor; - public CustomerEntity() { + public CustomerE() { } public void addNewCustomer() { //Add customer policy - extensionExecutor.execute(CustomerRuleExtPt.class, extension -> extension.addCustomerCheck(this)); + extensionExecutor.executeVoid(CustomerCheckExtPt.class, this.getContext(), extension -> extension.addCustomerCheck(this)); //Persist customer customerRepository.persist(this); diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/SourceType.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/SourceType.java similarity index 80% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/SourceType.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/SourceType.java index 593a9d462..8b4062dfb 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/SourceType.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/SourceType.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.test.customer.entity; +package com.alibaba.cola.test.customer.entity; /** * SourceType diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extension/CustomerBizOneCheckExt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extension/CustomerBizOneCheckExt.java new file mode 100644 index 000000000..a33fd551b --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extension/CustomerBizOneCheckExt.java @@ -0,0 +1,26 @@ +package com.alibaba.cola.test.customer.entity.extension; + +import com.alibaba.cola.exception.BizException; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.Constants; +import com.alibaba.cola.test.customer.ErrorCode; +import com.alibaba.cola.test.customer.entity.CustomerE; +import com.alibaba.cola.test.customer.entity.SourceType; +import com.alibaba.cola.test.customer.entity.extensionpoint.CustomerCheckExtPt; + +/** + * CustomerBizOneCheckExt + * + * @author Frank Zhang + * @date 2018-01-07 12:10 PM + */ +@Extension(bizCode = Constants.BIZ_ONE) +public class CustomerBizOneCheckExt implements CustomerCheckExtPt { + + @Override + public void addCustomerCheck(CustomerE customerEntity) { + if(SourceType.AD == customerEntity.getSourceType()){ + throw new BizException(ErrorCode.B_CUSTOMER_advNotAllowed, "Sorry, Customer from advertisement can not be added in this period"); + } + } +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extension/CustomerBizTwoCheckExt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extension/CustomerBizTwoCheckExt.java new file mode 100644 index 000000000..ff8b26356 --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extension/CustomerBizTwoCheckExt.java @@ -0,0 +1,27 @@ +package com.alibaba.cola.test.customer.entity.extension; + +import com.alibaba.cola.exception.BizException; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.Constants; +import com.alibaba.cola.test.customer.CustomerType; +import com.alibaba.cola.test.customer.ErrorCode; +import com.alibaba.cola.test.customer.entity.CustomerE; +import com.alibaba.cola.test.customer.entity.extensionpoint.CustomerCheckExtPt; + +/** + * CustomerBizTwoCheckExt + * + * @author Frank Zhang + * @date 2018-01-07 12:10 PM + */ +@Extension(bizCode = Constants.BIZ_TWO) +public class CustomerBizTwoCheckExt implements CustomerCheckExtPt { + + @Override + public void addCustomerCheck(CustomerE customerEntity) { + //Any Customer can be added + if(CustomerType.VIP == customerEntity.getCustomerType()){ + throw new BizException(ErrorCode.B_CUSTOMER_vipNeedApproval, "Sorry, you don't have privilege to add VIP customer"); + } + } +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extensionpoint/CustomerCheckExtPt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extensionpoint/CustomerCheckExtPt.java new file mode 100644 index 000000000..3d404c4bb --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/entity/extensionpoint/CustomerCheckExtPt.java @@ -0,0 +1,17 @@ +package com.alibaba.cola.test.customer.entity.extensionpoint; + +import com.alibaba.cola.extension.ExtensionPointI; +import com.alibaba.cola.test.customer.entity.CustomerE; + +/** + * CustomerCheckExtPt + * + * @author Frank Zhang + * @date 2018-01-07 12:03 PM + */ +public interface CustomerCheckExtPt extends ExtensionPointI{ + + //Different business check for different biz + public void addCustomerCheck(CustomerE customerEntity); + +} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/interceptor/ContextInterceptor.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ContextInterceptor.java similarity index 51% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/interceptor/ContextInterceptor.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ContextInterceptor.java index 55eee55e3..bc89bb87f 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/interceptor/ContextInterceptor.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ContextInterceptor.java @@ -1,10 +1,8 @@ -package com.alibaba.sofa.test.customer.interceptor; +package com.alibaba.cola.test.customer.interceptor; -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.PreInterceptor; -import com.alibaba.sofa.context.TenantContext; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.test.customer.Constants; +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.PreInterceptor; +import com.alibaba.cola.dto.Command; /** * ContextInterceptor @@ -17,6 +15,6 @@ public class ContextInterceptor implements CommandInterceptorI { @Override public void preIntercept(Command command) { - // TenantContext.set(Constants.TENANT_ID, Constants.BIZ_1); + // TenantContext.set(Constants.TENANT_ID, Constants.BIZ_ONE); } } diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ExceptionHandler.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ExceptionHandler.java new file mode 100644 index 000000000..ea97f183d --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ExceptionHandler.java @@ -0,0 +1,50 @@ +package com.alibaba.cola.test.customer.interceptor; + +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.dto.Response; +import com.alibaba.cola.exception.*; +import com.alibaba.cola.logger.Logger; +import com.alibaba.cola.logger.LoggerFactory; +import com.alibaba.cola.test.customer.AddCustomerCmd; +import org.springframework.stereotype.Component; + +/** + * ExceptionHandler + * + * @author Frank Zhang + * @date 2019-01-03 12:05 AM + */ +@Component +public class ExceptionHandler implements ExceptionHandlerI{ + private Logger logger = LoggerFactory.getLogger(ExceptionHandler.class); + + @Override + public void handleException(Command cmd, Response response, Exception exception) { + assembleResponse(response, exception); + printLog(cmd, response, exception); + } + + private void assembleResponse(Response response, Exception exception) { + if (exception instanceof AppException) { + ErrorCodeI errCode = ((AppException) exception).getErrCode(); + response.setErrCode(errCode.getErrCode()); + } + else { + response.setErrCode(BasicErrorCode.S_UNKNOWN.getErrCode()); + } + response.setErrMessage(exception.getMessage()); + } + + private void printLog(Command cmd, Response response, Exception exception) { + if(exception instanceof BizException || exception instanceof ParamException){ + logger.warn(formErrorMessage(cmd, response), exception); + } + else{ + logger.error(formErrorMessage(cmd, response), exception); + } + } + + private String formErrorMessage(Command cmd, Response response){ + return "Execute ["+cmd+"] error, errorCode: "+ response.getErrCode() + " errorMsg:"+ response.getErrMessage(); + } +} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/interceptor/ValidationInterceptor.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ValidationInterceptor.java similarity index 72% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/interceptor/ValidationInterceptor.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ValidationInterceptor.java index bee37ec13..4605a65c8 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/interceptor/ValidationInterceptor.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/interceptor/ValidationInterceptor.java @@ -1,10 +1,10 @@ -package com.alibaba.sofa.test.customer.interceptor; +package com.alibaba.cola.test.customer.interceptor; -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.PreInterceptor; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.exception.ParamException; -import com.alibaba.sofa.validator.SofaMessageInterpolator; +import com.alibaba.cola.command.CommandInterceptorI; +import com.alibaba.cola.command.PreInterceptor; +import com.alibaba.cola.dto.Command; +import com.alibaba.cola.exception.ParamException; +import com.alibaba.cola.validator.ColaMessageInterpolator; import org.hibernate.validator.HibernateValidator; import javax.validation.ConstraintViolation; @@ -23,7 +23,7 @@ public class ValidationInterceptor implements CommandInterceptorI { //Enable fail fast, which will improve performance private ValidatorFactory factory = Validation.byProvider(HibernateValidator.class).configure().failFast(true) - .messageInterpolator(new SofaMessageInterpolator()).buildValidatorFactory(); + .messageInterpolator(new ColaMessageInterpolator()).buildValidatorFactory(); @Override public void preIntercept(Command command) { diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/repository/CustomerRepository.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/repository/CustomerRepository.java similarity index 57% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/repository/CustomerRepository.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/repository/CustomerRepository.java index f5a4d171c..29c7b6fa4 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/repository/CustomerRepository.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/repository/CustomerRepository.java @@ -1,7 +1,7 @@ -package com.alibaba.sofa.test.customer.repository; +package com.alibaba.cola.test.customer.repository; -import com.alibaba.sofa.repository.RepositoryI; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; +import com.alibaba.cola.repository.RepositoryI; +import com.alibaba.cola.test.customer.entity.CustomerE; import org.springframework.stereotype.Repository; /** @@ -13,7 +13,7 @@ @Repository public class CustomerRepository implements RepositoryI { - public void persist(CustomerEntity customerEntity){ + public void persist(CustomerE customerEntity){ System.out.println("Persist customer to DB : "+ customerEntity); } } diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extension/AddCustomerBizOneValidator.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerBizOneValidator.java similarity index 57% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extension/AddCustomerBizOneValidator.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerBizOneValidator.java index d72d6ecd1..e97ba685d 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extension/AddCustomerBizOneValidator.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerBizOneValidator.java @@ -1,11 +1,11 @@ -package com.alibaba.sofa.test.customer.validator.extension; +package com.alibaba.cola.test.customer.validator.extension; -import com.alibaba.sofa.exception.BizException; -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.test.customer.AddCustomerCmd; -import com.alibaba.sofa.test.customer.Constants; -import com.alibaba.sofa.test.customer.CustomerType; -import com.alibaba.sofa.test.customer.validator.extensionpoint.AddCustomerValidatorExtPt; +import com.alibaba.cola.exception.BizException; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.AddCustomerCmd; +import com.alibaba.cola.test.customer.Constants; +import com.alibaba.cola.test.customer.CustomerType; +import com.alibaba.cola.test.customer.validator.extensionpoint.AddCustomerValidatorExtPt; /** * AddCustomerBizOneValidator @@ -13,7 +13,7 @@ * @author Frank Zhang * @date 2018-01-07 1:31 AM */ -@Extension(bizCode = Constants.BIZ_1) +@Extension(bizCode = Constants.BIZ_ONE) public class AddCustomerBizOneValidator implements AddCustomerValidatorExtPt{ @Override diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extension/AddCustomerBizTwoValidator.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerBizTwoValidator.java similarity index 59% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extension/AddCustomerBizTwoValidator.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerBizTwoValidator.java index 3eedcac67..cae12c751 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extension/AddCustomerBizTwoValidator.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerBizTwoValidator.java @@ -1,10 +1,10 @@ -package com.alibaba.sofa.test.customer.validator.extension; +package com.alibaba.cola.test.customer.validator.extension; -import com.alibaba.sofa.exception.ParamException; -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.test.customer.AddCustomerCmd; -import com.alibaba.sofa.test.customer.Constants; -import com.alibaba.sofa.test.customer.validator.extensionpoint.AddCustomerValidatorExtPt; +import com.alibaba.cola.exception.ParamException; +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.AddCustomerCmd; +import com.alibaba.cola.test.customer.Constants; +import com.alibaba.cola.test.customer.validator.extensionpoint.AddCustomerValidatorExtPt; /** * AddCustomerBizTwoValidator @@ -12,7 +12,7 @@ * @author Frank Zhang * @date 2018-01-07 1:31 AM */ -@Extension(bizCode = Constants.BIZ_2) +@Extension(bizCode = Constants.BIZ_TWO) public class AddCustomerBizTwoValidator implements AddCustomerValidatorExtPt{ @Override diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerDefaultValidator.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerDefaultValidator.java new file mode 100644 index 000000000..7977af5de --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extension/AddCustomerDefaultValidator.java @@ -0,0 +1,19 @@ +package com.alibaba.cola.test.customer.validator.extension; + +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.validator.extensionpoint.AddCustomerValidatorExtPt; + +/** + * AddCustomerDefaultValidator + * + * @author Frank Zhang + * @date 2019-01-03 11:14 AM + */ +@Extension +public class AddCustomerDefaultValidator implements AddCustomerValidatorExtPt { + + @Override + public void validate(Object candidate) { + //do nothing + } +} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extensionpoint/AddCustomerValidatorExtPt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extensionpoint/AddCustomerValidatorExtPt.java similarity index 52% rename from sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extensionpoint/AddCustomerValidatorExtPt.java rename to cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extensionpoint/AddCustomerValidatorExtPt.java index 1381fb98e..0d03294c5 100644 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/validator/extensionpoint/AddCustomerValidatorExtPt.java +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/customer/validator/extensionpoint/AddCustomerValidatorExtPt.java @@ -1,7 +1,7 @@ -package com.alibaba.sofa.test.customer.validator.extensionpoint; +package com.alibaba.cola.test.customer.validator.extensionpoint; -import com.alibaba.sofa.extension.ExtensionPointI; -import com.alibaba.sofa.validator.ValidatorI; +import com.alibaba.cola.extension.ExtensionPointI; +import com.alibaba.cola.validator.ValidatorI; /** * AddCustomerValidatorExtPt diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/AnimalExtPt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/AnimalExtPt.java new file mode 100644 index 000000000..623ee5daf --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/AnimalExtPt.java @@ -0,0 +1,13 @@ +package com.alibaba.cola.test.extension; + +import com.alibaba.cola.extension.ExtensionPointI; + +/** + * AnimalExtPt + * + * @author Frank Zhang + * @date 2019-01-02 9:40 PM + */ +public interface AnimalExtPt extends ExtensionPointI { + public String eat(); +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/BizCodeTest.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/BizCodeTest.java new file mode 100644 index 000000000..b91c689f1 --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/BizCodeTest.java @@ -0,0 +1,27 @@ +package com.alibaba.cola.test.extension; + +/** + * BizCodeTest + * + * @author Frank Zhang + * @date 2019-01-02 12:09 PM + */ +public class BizCodeTest { + + public static void main(String[] args) { + String bizCode = "ali.tmall.supermarket"; + bizCode.lastIndexOf("."); + //System.out.println(bizCode.substring(0, bizCode.lastIndexOf("."))); + + parseBizCode(bizCode); + System.out.println(BizCodeTest.class.getSimpleName()+" "+BizCodeTest.class.getName()); + } + + public static void parseBizCode(String bizCode){ + System.out.println(bizCode); + while(bizCode.lastIndexOf(".") != -1){ + bizCode = bizCode.substring(0, bizCode.lastIndexOf(".")); + System.out.println(bizCode); + } + } +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/CommonAnimalExt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/CommonAnimalExt.java new file mode 100644 index 000000000..85d44c480 --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/CommonAnimalExt.java @@ -0,0 +1,18 @@ +package com.alibaba.cola.test.extension; + +import com.alibaba.cola.extension.Extension; + +/** + * CommonAnimalExt + * + * @author Frank Zhang + * @date 2019-01-02 10:05 PM + */ +@Extension(bizCode = "ali.animal") +public class CommonAnimalExt implements AnimalExtPt{ + @Override + public String eat() { + System.out.println("Common Animal Eat, Terrific"); + return "CommonAnimal"; + } +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/DefaultAnimalExt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/DefaultAnimalExt.java new file mode 100644 index 000000000..0ce0e005d --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/DefaultAnimalExt.java @@ -0,0 +1,18 @@ +package com.alibaba.cola.test.extension; + +import com.alibaba.cola.extension.Extension; + +/** + * DefaultAnimalExt + * + * @author Frank Zhang + * @date 2019-01-02 9:59 PM + */ +@Extension +public class DefaultAnimalExt implements AnimalExtPt{ + @Override + public String eat() { + System.out.println("Default Animal Eat, Cool"); + return "DefaultAnimal"; + } +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/DogExt.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/DogExt.java new file mode 100644 index 000000000..791db875e --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/DogExt.java @@ -0,0 +1,20 @@ +package com.alibaba.cola.test.extension; + +import com.alibaba.cola.extension.Extension; +import com.alibaba.cola.test.customer.Constants; + +/** + * DogExt + * + * @author Frank Zhang + * @date 2019-01-02 9:42 PM + */ +@Extension(bizCode = "ali.animal.dog") +public class DogExt implements AnimalExtPt{ + + @Override + public String eat() { + System.out.println("Dog Eat, Wow"); + return "Dog"; + } +} diff --git a/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/LocateExtensionTest.java b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/LocateExtensionTest.java new file mode 100644 index 000000000..5c43d558e --- /dev/null +++ b/cola-framework/cola-core/src/test/java/com/alibaba/cola/test/extension/LocateExtensionTest.java @@ -0,0 +1,60 @@ +package com.alibaba.cola.test.extension; + +import com.alibaba.cola.TestConfig; +import com.alibaba.cola.context.Context; +import com.alibaba.cola.exception.ColaException; +import com.alibaba.cola.extension.ExtensionExecutor; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * LocateExtensionTest + * + * @author Frank Zhang + * @date 2019-01-02 9:33 PM + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {TestConfig.class}) +public class LocateExtensionTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Autowired + private ExtensionExecutor extensionExecutor; + + @Test + public void testFullMatch() { + Context context = new Context(); + context.setBizCode("ali.animal.dog"); + String dog = extensionExecutor.execute(AnimalExtPt.class, context, extension -> extension.eat()); + Assert.assertEquals(dog, "Dog"); + } + + @Test + public void testPartMatch() { + Context context = new Context(); + context.setBizCode("ali.animal"); + String dog = extensionExecutor.execute(AnimalExtPt.class, context, extension -> extension.eat()); + Assert.assertEquals(dog, "CommonAnimal"); + } + + @Test + public void testDefault() { + Context context = new Context(); + String dog = extensionExecutor.execute(AnimalExtPt.class, context, extension -> extension.eat()); + Assert.assertEquals(dog, "DefaultAnimal"); + } + + @Test(expected= ColaException.class) + public void testContextNull() throws ColaException{ + extensionExecutor.execute(AnimalExtPt.class, null, extension -> extension.eat()); + thrown.expect(ColaException.class); + } +} diff --git a/sofa-framework/sofa-core/src/test/resources/sample.properties b/cola-framework/cola-core/src/test/resources/sample.properties similarity index 100% rename from sofa-framework/sofa-core/src/test/resources/sample.properties rename to cola-framework/cola-core/src/test/resources/sample.properties diff --git a/sofa-framework/sofa-test/pom.xml b/cola-framework/cola-test/pom.xml similarity index 91% rename from sofa-framework/sofa-test/pom.xml rename to cola-framework/cola-test/pom.xml index 060a7da77..1ad50b278 100644 --- a/sofa-framework/sofa-test/pom.xml +++ b/cola-framework/cola-test/pom.xml @@ -2,14 +2,14 @@ 4.0.0 - com.alibaba.sofa + com.alibaba.cola all 1.0.0-SNAPSHOT ../pom.xml - sofa-test + cola-test 1.0.0-SNAPSHOT - sofa-test + cola-test junit @@ -43,5 +43,5 @@ - + diff --git a/sofa-framework/sofa-test/src/main/java/com/alibaba/sofa/pandora/test/TestExecutor.java b/cola-framework/cola-test/src/main/java/com/alibaba/cola/container/TestExecutor.java similarity index 99% rename from sofa-framework/sofa-test/src/main/java/com/alibaba/sofa/pandora/test/TestExecutor.java rename to cola-framework/cola-test/src/main/java/com/alibaba/cola/container/TestExecutor.java index a0d7bd4cd..1eea8972f 100644 --- a/sofa-framework/sofa-test/src/main/java/com/alibaba/sofa/pandora/test/TestExecutor.java +++ b/cola-framework/cola-test/src/main/java/com/alibaba/cola/container/TestExecutor.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.pandora.test; +package com.alibaba.cola.container; import java.lang.annotation.Annotation; import java.lang.reflect.Field; diff --git a/sofa-framework/sofa-test/src/main/java/com/alibaba/sofa/pandora/test/TestsContainer.java b/cola-framework/cola-test/src/main/java/com/alibaba/cola/container/TestsContainer.java similarity index 93% rename from sofa-framework/sofa-test/src/main/java/com/alibaba/sofa/pandora/test/TestsContainer.java rename to cola-framework/cola-test/src/main/java/com/alibaba/cola/container/TestsContainer.java index 1fdf035f8..e4d5c29ed 100644 --- a/sofa-framework/sofa-test/src/main/java/com/alibaba/sofa/pandora/test/TestsContainer.java +++ b/cola-framework/cola-test/src/main/java/com/alibaba/cola/container/TestsContainer.java @@ -1,4 +1,4 @@ -package com.alibaba.sofa.pandora.test; +package com.alibaba.cola.container; import java.io.BufferedReader; import java.io.IOException; @@ -12,9 +12,9 @@ /** * 这是一个轻量级的TDD测试工具,可以敏捷的在开发过程中,运行测试,功能如下: * 1.测试单个方法,请在控制台输入方法全称 - * 例如:com.alibaba.sofa.sales.service.test.CustomerServiceTest.testCheckConflict() + * 例如:com.alibaba.cola.sales.service.test.CustomerServiceTest.testCheckConflict() * 2.测试整个测试类,请在控制台输入类全称 - * 例如:com.alibaba.sofa.sales.service.test.CustomerServiceTest + * 例如:com.alibaba.cola.sales.service.test.CustomerServiceTest * 3.重复上一次测试,只需在控制台输入字母 - ‘r’ * * @author fulan.zjf @@ -23,9 +23,9 @@ /** * 这是一个轻量级的TDD测试工具,可以敏捷的在开发过程中,运行测试,功能如下: * 1.测试单个方法,请在控制台输入方法全称 - * 例如:com.alibaba.sofa.sales.service.test.CustomerServiceTest.testCheckConflict() + * 例如:com.alibaba.cola.sales.service.test.CustomerServiceTest.testCheckConflict() * 2.测试整个测试类,请在控制台输入类全称 - * 例如:com.alibaba.sofa.sales.service.test.CustomerServiceTest + * 例如:com.alibaba.cola.sales.service.test.CustomerServiceTest * 3.重复上一次测试,只需在控制台输入字母 - ‘r’ * * @author fulan.zjf @@ -99,9 +99,9 @@ private static void execute(String input) throws Exception{ if (WELCOME_INPUT.equals(input)){ System.out.println("************** 欢迎使用轻量级TDD测试工具 ***************************"); System.out.println("**** 1.测试单个方法,请在控制台输入方法全称"); - System.out.println("**** 例如:com.alibaba.sofa.sales.service.test.CustomerServiceTest.testCheckConflict()"); + System.out.println("**** 例如:com.alibaba.cola.sales.service.test.CustomerServiceTest.testCheckConflict()"); System.out.println("**** 2.测试整个测试类,请在控制台输入类全称"); - System.out.println("**** 例如:com.alibaba.sofa.sales.service.test.CustomerServiceTest"); + System.out.println("**** 例如:com.alibaba.cola.sales.service.test.CustomerServiceTest"); System.out.println("**** 3.重复上一次测试,只需在控制台输入字母 - ‘r’"); System.out.println("***********************************************************************************"); return; diff --git a/sofa-framework/pom.xml b/cola-framework/pom.xml similarity index 90% rename from sofa-framework/pom.xml rename to cola-framework/pom.xml index e214c3665..2fc6413ba 100644 --- a/sofa-framework/pom.xml +++ b/cola-framework/pom.xml @@ -6,9 +6,9 @@ parent 2.0.0 - + 4.0.0 - com.alibaba.sofa + com.alibaba.cola all pom 1.0.0-SNAPSHOT @@ -28,35 +28,35 @@ 4.12 1.2.3.5-struct 1.7.22 - 1.0.0-SNAPSHOT + 1.0.0-SNAPSHOT 1.0 1.8.3 - sofa-test - sofa-common - sofa-core + cola-test + cola-common + cola-core - com.alibaba.sofa - sofa-test - ${sofa.framework.version} + com.alibaba.cola + cola-test + ${cola.framework.version} test - com.alibaba.sofa - sofa-common - ${sofa.framework.version} + com.alibaba.cola + cola-common + ${cola.framework.version} - com.alibaba.sofa - sofa-core - ${sofa.framework.version} + com.alibaba.cola + cola-core + ${cola.framework.version} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/assembler/CustomerAssembler.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/assembler/CustomerAssembler.java deleted file mode 100644 index 39dde466e..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/assembler/CustomerAssembler.java +++ /dev/null @@ -1,18 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.assembler; - -import java.util.HashMap; -import java.util.Map; - -import com.alibaba.sofa.assembler.AssemblerI; -import ${package}.dto.clientobject.CustomerCO; - -public class CustomerAssembler implements AssemblerI{ - - public Map assembleQueryParam(CustomerCO customerCO) { - - return new HashMap<>(); - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/assembler/package-info.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/assembler/package-info.java deleted file mode 100644 index 3148a27a7..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/assembler/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/** - * Assembler classes used to assemble parameters to invoke other layers or other services. - * - * @author fulan.zjf - */ -package ${package}.assembler; \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerCheckConflictCmdExe.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerCheckConflictCmdExe.java deleted file mode 100644 index dbe57ee1c..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/CustomerCheckConflictCmdExe.java +++ /dev/null @@ -1,33 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.command; - -import ${package}.dto.CustomerCheckConflictCmd; -import org.springframework.beans.factory.annotation.Autowired; - -import com.alibaba.sofa.command.Command; -import com.alibaba.sofa.command.CommandExecutorI; -import com.alibaba.sofa.dto.MultiResponse; -import com.alibaba.sofa.extension.ExtensionExecutor; -import ${package}.command.extensionpoint.CustomerCheckConflictSearchConditionExtPt; -import ${package}.dto.clientobject.CustomerCO; -import ${package}.dto.CustomerCheckConflictCmd; - -@Command -public class CustomerCheckConflictCmdExe implements CommandExecutorI, CustomerCheckConflictCmd>{ - - @Autowired - private ExtensionExecutor extensionExecutor; - - @Override - public MultiResponse execute(CustomerCheckConflictCmd cmd) { - System.out.println("Shared logic"); - String searchCondition = extensionExecutor.execute( - CustomerCheckConflictSearchConditionExtPt.class, - extension -> extension.getSearchCondition("condition")); - System.out.println("Shared logic with "+ searchCondition); - return MultiResponse.of(null, 0); - } - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/CustomerSearchConditionCGSExt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/CustomerSearchConditionCGSExt.java deleted file mode 100644 index cde41b09b..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/CustomerSearchConditionCGSExt.java +++ /dev/null @@ -1,18 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.command.extension; - -import ${package}.command.extensionpoint.CustomerCheckConflictSearchConditionExtPt; -import ${package}.common.BizCode; -import com.alibaba.sofa.extension.Extension; - -@Extension(bizCode = BizCode.CGS) -public class CustomerSearchConditionCGSExt implements CustomerCheckConflictSearchConditionExtPt { - - @Override - public String getSearchCondition(String condition) { - return "CGS Search Condition"; - } - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/CustomerSearchConditionTPExt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/CustomerSearchConditionTPExt.java deleted file mode 100644 index e9dfac4c7..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/CustomerSearchConditionTPExt.java +++ /dev/null @@ -1,18 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.command.extension; - -import ${package}.command.extensionpoint.CustomerCheckConflictSearchConditionExtPt; -import ${package}.common.BizCode; -import com.alibaba.sofa.extension.Extension; - -@Extension(bizCode = BizCode.TP) -public class CustomerSearchConditionTPExt implements CustomerCheckConflictSearchConditionExtPt { - - @Override - public String getSearchCondition(String condition) { - return "Trust Pass Search Condition"; - } - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/package-info.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/package-info.java deleted file mode 100644 index 16d6699d4..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extension/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/** - * Command Extensions are used when there are different logic per different tenant. - * - * @author fulan.zjf - */ -package ${package}.command.extension; \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extensionpoint/CustomerCheckConflictSearchConditionExtPt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extensionpoint/CustomerCheckConflictSearchConditionExtPt.java deleted file mode 100644 index d61649a53..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extensionpoint/CustomerCheckConflictSearchConditionExtPt.java +++ /dev/null @@ -1,11 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.command.extensionpoint; - -import com.alibaba.sofa.extension.ExtensionPointI; - -public interface CustomerCheckConflictSearchConditionExtPt extends ExtensionPointI{ - - public String getSearchCondition(String condition); -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extensionpoint/package-info.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extensionpoint/package-info.java deleted file mode 100644 index 188084dcf..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/command/extensionpoint/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/** - * Command Extension Point declare the point need to be extended. - * - * @author fulan.zjf - */ -package ${package}.command.extensionpoint; \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerChangeEventHandler.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerChangeEventHandler.java deleted file mode 100644 index 105ae065f..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/event/handler/CustomerChangeEventHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.event.handler; - -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.dto.event.Event; -import com.alibaba.sofa.event.EventHandler; -import com.alibaba.sofa.event.EventHandlerI; - -/** - * @author shawnzhan.zxy - * @date 2017/11/30 - */ -@EventHandler -public class CustomerChangeEventHandler implements EventHandlerI { - - - @Override - public Response execute(Event event) { - System.out.println("Add your own other logic here"); - return Response.buildSuccess(); - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ContextInterceptor.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ContextInterceptor.java deleted file mode 100644 index bd6c9ea33..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/interceptor/ContextInterceptor.java +++ /dev/null @@ -1,19 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.interceptor; - -import com.alibaba.sofa.command.CommandInterceptorI; -import com.alibaba.sofa.command.PreInterceptor; -import com.alibaba.sofa.dto.Command; - -@PreInterceptor -public class ContextInterceptor implements CommandInterceptorI{ - - @Override - public void preIntercept(Command command) { - //Set Tenant Context here - //TenantContext.set("1", "CGS"); - } - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddCGSValidator.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddCGSValidator.java deleted file mode 100644 index 9a8572ffd..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddCGSValidator.java +++ /dev/null @@ -1,52 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/* - * Copyright 2017 Alibaba.com All right reserved. This software is the - * confidential and proprietary information of Alibaba.com ("Confidential - * Information"). You shdemo not disclose such Confidential Information and shdemo - * use it only in accordance with the terms of the license agreement you entered - * into with Alibaba.com. - */ -package ${package}.validator.extension; - -import ${package}.common.BizCode; -import ${package}.dto.CustomerAddCmd; -import ${package}.dto.clientobject.CustomerType; -import ${package}.validator.CustomerAddValidator; -import com.alibaba.sofa.exception.BizException; -import org.springframework.beans.factory.annotation.Autowired; -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; -import ${package}.validator.extensionpoint.CustomerAddValidatorExtPt; -import com.alibaba.sofa.validator.ValidatorCompoiste; - -/** - * CustomerAddCGSValidator - * - * @author fulan.zjf 2017-11-04 - */ -@Extension(bizCode = BizCode.CGS) -public class CustomerAddCGSValidator extends ValidatorCompoiste implements CustomerAddValidatorExtPt { - - private Logger logger = LoggerFactory.getLogger(CustomerAddCGSValidator.class); - - @Autowired - private CustomerAddValidator customerAddValidator; - - @Override - protected void addOtherValidators() { - add(customerAddValidator); - } - - @Override - protected void doValidate(Object candidate) { - logger.debug("This is CGS validation"); - CustomerAddCmd addCustomerCmd = (CustomerAddCmd) candidate; - //For CGS BIZ CustomerTYpe could not be VIP - if(CustomerType.VIP == addCustomerCmd.getCustomer().getCustomerType()) - throw new BizException("VIP Customer can not be added by CGS"); - } - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddDDValidator.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddDDValidator.java deleted file mode 100644 index 700aba63c..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extension/CustomerAddDDValidator.java +++ /dev/null @@ -1,57 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/* - * Copyright 2017 Alibaba.com All right reserved. This software is the - * confidential and proprietary information of Alibaba.com ("Confidential - * Information"). You shdemo not disclose such Confidential Information and shdemo - * use it only in accordance with the terms of the license agreement you entered - * into with Alibaba.com. - */ -package ${package}.validator.extension; - -import ${package}.common.BizCode; -import ${package}.dto.CustomerAddCmd; -import ${package}.validator.CustomerAddValidator; -import com.alibaba.sofa.exception.ParamException; -import org.springframework.beans.factory.annotation.Autowired; - -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; -import ${package}.validator.extensionpoint.CustomerAddValidatorExtPt; -import com.alibaba.sofa.validator.ValidatorCompoiste; - -/** - * CustomerAddDDValidator - * - * @author fulan.zjf 2017-11-04 - */ -@Extension(bizCode = BizCode.DD) -public class CustomerAddDDValidator extends ValidatorCompoiste implements CustomerAddValidatorExtPt{ - - private Logger logger = LoggerFactory.getLogger(CustomerAddDDValidator.class); - - @Autowired - private CustomerAddValidator customerAddValidator; - - @Autowired - private CustomerAddCGSValidator customerAddCGSValidator; - - @Override - protected void addOtherValidators() { - // just for demo, 假设钉钉的校验逻辑是在common和CGS的基础上,还有自己额外的校验 - add(customerAddValidator); - } - - @Override - protected void doValidate(Object candidate) { - logger.debug("Do DingDing validation"); - CustomerAddCmd addCustomerCmd = (CustomerAddCmd) candidate; - //For DD Biz CustomerType could not be null - if (addCustomerCmd.getCustomer().getCustomerType() == null) - throw new ParamException("CustomerType could not be null"); - - } - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/CustomerAddValidatorExtPt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/CustomerAddValidatorExtPt.java deleted file mode 100644 index e1079cd1f..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/validator/extensionpoint/CustomerAddValidatorExtPt.java +++ /dev/null @@ -1,22 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/* - * Copyright 2017 Alibaba.com All right reserved. This software is the - * confidential and proprietary information of Alibaba.com ("Confidential - * Information"). You shdemo not disclose such Confidential Information and shdemo - * use it only in accordance with the terms of the license agreement you entered - * into with Alibaba.com. - */ -package ${package}.validator.extensionpoint; - -import com.alibaba.sofa.extension.ExtensionPointI; -import com.alibaba.sofa.validator.ValidatorI; - -/** - * CustomerAdd Validation Point - * @author fulan.zjf 2017-11-05 - */ -public interface CustomerAddValidatorExtPt extends ValidatorI, ExtensionPointI{ - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/resources/applicationContext.xml b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/resources/applicationContext.xml deleted file mode 100644 index 53c9a6796..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/resources/applicationContext.xml +++ /dev/null @@ -1,20 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) - - - - - - - - - ${package} - - - - \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/AppTestSuite.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/AppTestSuite.java deleted file mode 100644 index aeff44611..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/AppTestSuite.java +++ /dev/null @@ -1,22 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.service; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * AppTestSuite - * - * @author Frank Zhang - * @date 2018-01-08 9:49 AM - */ -@RunWith(Suite.class) - -@Suite.SuiteClasses({ - CustomerServiceTest.class, -}) -public class AppTestSuite { - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/AppTestsContainer.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/AppTestsContainer.java deleted file mode 100644 index f992f7ca9..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/AppTestsContainer.java +++ /dev/null @@ -1,21 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.service; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.alibaba.sofa.logger.LoggerFactory; -import com.alibaba.sofa.pandora.test.TestsContainer; - -public class AppTestsContainer { - - public static void main(String[] args) { - LoggerFactory.activateSysLogger(); - ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-test.xml"); - ((AbstractApplicationContext) context).start(); - TestsContainer.start(context); - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/CustomerServiceTest.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/CustomerServiceTest.java deleted file mode 100644 index 5a43efabc..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/java/service/CustomerServiceTest.java +++ /dev/null @@ -1,94 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.service; - -import ${package}.common.AppConstants; -import ${package}.common.BizCode; -import ${package}.dto.CustomerCheckConflictCmd; -import ${package}.dto.CustomerFindByCriteriaQry; -import ${package}.dto.clientobject.CustomerType; -import com.alibaba.sofa.context.TenantContext; -import com.alibaba.sofa.dto.MultiResponse; -import ${package}.api.CustomerServiceI; -import ${package}.dto.CustomerAddCmd; -import ${package}.dto.clientobject.CustomerCO; -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.exception.BasicErrorCode; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.junit.Assert.assertEquals; - - -/** - * For TDD development, Recommend use {@link AppTestsContainer} to make test agile - * - * @author fulan.zjf 2017年10月27日 下午3:26:11 - */ -@RunWith(SpringRunner.class) -@ContextConfiguration(locations={"classpath:applicationContext.xml"}) -public class CustomerServiceTest { - - @Autowired - private CustomerServiceI customerService; - - @Test - public void testCustomerAddSuccess( ) { - //1.Prepare - TenantContext.set("10001", BizCode.DD); - CustomerAddCmd cmd = new CustomerAddCmd(); - CustomerCO customerCO = new CustomerCO(); - customerCO.setCustomerName("alibaba"); - customerCO.setCustomerType(CustomerType.VIP); - cmd.setCustomer(customerCO); - - //2.Execute - Response response = customerService.addCustomer(cmd); - - //3.Expect - Assert.assertTrue(response.isSuccess()); - } - - @Test - public void testCustomerAddValidationFail( ) { - //1.Prepare - TenantContext.set("10001", BizCode.CGS); - CustomerAddCmd cmd = new CustomerAddCmd(); - CustomerCO customerCO = new CustomerCO(); - customerCO.setCustomerName("alibaba"); - customerCO.setCustomerType(CustomerType.VIP); - cmd.setCustomer(customerCO); - - //2.Execute - Response response = customerService.addCustomer(cmd); - - //3.Expect - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getErrCode(), BasicErrorCode.BIZ_ERROR.getErrCode()); - } - - @Test - public void testCustomerAddRuleVoilation( ){ - //1.Prepare - TenantContext.set("10001", BizCode.DD); - CustomerAddCmd cmd = new CustomerAddCmd(); - CustomerCO customerCO = new CustomerCO(); - customerCO.setCustomerName("alibaba"); - customerCO.setCustomerType(CustomerType.VIP); - customerCO.setSource(AppConstants.SOURCE_AD); - cmd.setCustomer(customerCO); - - //2.Execute - Response response = customerService.addCustomer(cmd); - - //3.Expect - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getErrCode(), BasicErrorCode.BIZ_ERROR.getErrCode()); - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/resources/applicationContext-test.xml b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/resources/applicationContext-test.xml deleted file mode 100644 index e51cc2009..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/resources/applicationContext-test.xml +++ /dev/null @@ -1,30 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) - - - - - - - - - - ${package} - - - - - - - - classpath:localConfig.properties - - - - \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/resources/localConfig.properties b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/resources/localConfig.properties deleted file mode 100644 index a1442551a..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-app/src/test/resources/localConfig.properties +++ /dev/null @@ -1,7 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -${symbol_pound}This is a workaround for local start without pandora -string=This is a wonderful day -number=12332 -boolean=true \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerCheckConflictCmd.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerCheckConflictCmd.java deleted file mode 100644 index 699913f4d..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/dto/CustomerCheckConflictCmd.java +++ /dev/null @@ -1,10 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.dto; - -import com.alibaba.sofa.dto.Command; - -public class CustomerCheckConflictCmd extends Command{ - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/CustomerConvertor.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/CustomerConvertor.java deleted file mode 100644 index 25899d27b..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/CustomerConvertor.java +++ /dev/null @@ -1,41 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.convertor; - -import ${package}.tunnel.dataobject.CustomerDO; -import ${package}.domain.customer.entity.CustomerE; -import ${package}.domain.customer.valueobject.CompanyType; -import ${package}.dto.clientobject.CustomerCO; -import ${package}.dto.clientobject.CustomerType; -import com.alibaba.sofa.common.ApplicationContextHelper; -import com.alibaba.sofa.convertor.ConvertorI; -import org.springframework.stereotype.Component; - -/** - * CustomerConvertor - * - * @author Frank Zhang - * @date 2018-01-07 3:08 AM - */ -@Component -public class CustomerConvertor implements ConvertorI { - - @Override - public CustomerE clientToEntity(CustomerCO customerCO){ - CustomerE customerEntity = (CustomerE) ApplicationContextHelper.getBean(CustomerE.class); - customerEntity.setCompanyName(customerCO.getCompanyName()); - customerEntity.setCompanyType(CompanyType.valueOf(customerCO.getCustomerType().name())); - return customerEntity; - } - - @Override - public CustomerCO dataToClient(CustomerDO dataObject) { - CustomerCO customerCO = new CustomerCO(); - customerCO.setCustomerName(dataObject.getCompanyName()); - customerCO.setCustomerType(CustomerType.valueOf(dataObject.getCompanyType())); - customerCO.setMemberId(dataObject.getMemberId()); - customerCO.setCustomerId(dataObject.getCustomerId()); - return customerCO; - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extension/CustomerCGSConvertorExt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extension/CustomerCGSConvertorExt.java deleted file mode 100644 index d38b9e12c..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extension/CustomerCGSConvertorExt.java +++ /dev/null @@ -1,43 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.convertor.extension; - -import ${package}.common.AppConstants; -import ${package}.common.BizCode; -import ${package}.tunnel.dataobject.CustomerDO; -import ${package}.domain.customer.convertor.CustomerConvertor; -import ${package}.domain.customer.convertor.extensionpoint.CustomerConvertorExtPt; -import ${package}.domain.customer.entity.CustomerE; -import ${package}.domain.customer.valueobject.SourceType; -import ${package}.dto.clientobject.CustomerCO; -import com.alibaba.sofa.extension.Extension; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * CustomerCGSConvertorExt - * - * @author Frank Zhang - * @date 2018-01-07 3:05 AM - */ -@Extension(bizCode = BizCode.CGS) -public class CustomerCGSConvertorExt implements CustomerConvertorExtPt { - - @Autowired - private CustomerConvertor customerConvertor;//Composite basic convertor to do basic conversion - - @Override - public CustomerE clientToEntity(CustomerCO customerCO){ - CustomerE customerEntity = customerConvertor.clientToEntity(customerCO); - //In this business, if customers from RFQ and Advertisement are both regarded as Advertisement - if(AppConstants.SOURCE_AD.equals(customerCO.getSource()) || AppConstants.SOURCE_RFQ.equals(customerCO.getSource())) - { - customerEntity.setSourceType(SourceType.AD); - } - return customerEntity; - } - - public CustomerCO dataToClient(CustomerDO customerDO){ - return customerConvertor.dataToClient(customerDO); - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extension/CustomerDDConvertorExt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extension/CustomerDDConvertorExt.java deleted file mode 100644 index 7397dd7cc..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/convertor/extension/CustomerDDConvertorExt.java +++ /dev/null @@ -1,46 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.convertor.extension; - -import ${package}.common.AppConstants; -import ${package}.common.BizCode; -import ${package}.tunnel.dataobject.CustomerDO; -import ${package}.domain.customer.convertor.CustomerConvertor; -import ${package}.domain.customer.convertor.extensionpoint.CustomerConvertorExtPt; -import ${package}.domain.customer.entity.CustomerE; -import ${package}.domain.customer.valueobject.SourceType; -import ${package}.dto.clientobject.CustomerCO; -import com.alibaba.sofa.extension.Extension; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * CustomerDDConvertorExt - * - * @author Frank Zhang - * @date 2018-01-08 1:57 PM - */ -@Extension(bizCode = BizCode.DD) -public class CustomerDDConvertorExt implements CustomerConvertorExtPt { - - @Autowired - private CustomerConvertor customerConvertor;//Composite basic convertor to do basic conversion - - @Override - public CustomerE clientToEntity(CustomerCO customerCO) { - CustomerE customerEntity = customerConvertor.clientToEntity(customerCO); - //In this business, AD and RFQ are regarded as different source - if(AppConstants.SOURCE_AD.equals(customerCO.getSource())) - { - customerEntity.setSourceType(SourceType.AD); - } - if (AppConstants.SOURCE_RFQ.equals(customerCO.getSource())){ - customerEntity.setSourceType(SourceType.RFQ); - } - return customerEntity; - } - - public CustomerCO dataToClient(CustomerDO customerDO){ - return customerConvertor.dataToClient(customerDO); - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/ContactE.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/ContactE.java deleted file mode 100644 index 70f6b1dd5..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/ContactE.java +++ /dev/null @@ -1,8 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.entity; - -public class ContactE { - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/OpportunityE.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/OpportunityE.java deleted file mode 100644 index 6291bce6f..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/entity/OpportunityE.java +++ /dev/null @@ -1,8 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.entity; - -public class OpportunityE { - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/factory/CustomerDomainFactory.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/factory/CustomerDomainFactory.java deleted file mode 100644 index 194197843..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/factory/CustomerDomainFactory.java +++ /dev/null @@ -1,23 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.factory; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.alibaba.sofa.domain.DomainFactoryI; -import ${package}.domain.customer.entity.CustomerE; -import ${package}.domain.customer.repository.ContactRepository; - -@Component -public class CustomerDomainFactory implements DomainFactoryI{ - - @Autowired - private ContactRepository contactRepository; - - public CustomerE create(){ - return new CustomerE(); - } - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/CustomerRepository.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/CustomerRepository.java deleted file mode 100644 index 7160052de..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/repository/CustomerRepository.java +++ /dev/null @@ -1,38 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.repository; - -import java.util.ArrayList; -import java.util.List; - -import ${package}.tunnel.dataobject.CustomerDO; -import ${package}.tunnel.datatunnel.CustomerTunnelI; -import ${package}.domain.customer.convertor.CustomerConvertor; -import ${package}.domain.customer.entity.CustomerE; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; -import com.alibaba.sofa.repository.RepositoryI; - -@Repository -public class CustomerRepository implements RepositoryI{ - - @Autowired - private CustomerTunnelI customerDBTunnel; - - @Autowired - private CustomerConvertor customerConvertor; - - public void persist(CustomerE customer) { - customerDBTunnel.create(customerConvertor.entityToData(customer)); - } - - public List findByCriteria(String... params){ - List customerDos = customerDBTunnel.findByCriteria(params); - List customerDs = new ArrayList<>(); - for (CustomerDO customerDo : customerDos) { - //customerDs.add(customerConvertor.toDomainObject(customerDo)); - } - return customerDs; - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extension/CustomerCGSRuleExt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extension/CustomerCGSRuleExt.java deleted file mode 100644 index 1738b17eb..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extension/CustomerCGSRuleExt.java +++ /dev/null @@ -1,22 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.rule.extension; - -import ${package}.common.BizCode; -import ${package}.domain.customer.entity.CustomerE; -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; -import ${package}.domain.customer.rule.extensionpoint.CustomerRuleExtPt; - -@Extension(bizCode= BizCode.CGS) -public class CustomerCGSRuleExt implements CustomerRuleExtPt { - Logger logger = LoggerFactory.getLogger(getClass()); - - @Override - public boolean addCustomerCheck(CustomerE customerE) { - //Any Customer can be added - return true; - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extension/CustomerDDRuleExt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extension/CustomerDDRuleExt.java deleted file mode 100644 index 18807f7b7..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extension/CustomerDDRuleExt.java +++ /dev/null @@ -1,29 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.rule.extension; - -import ${package}.common.BizCode; -import ${package}.domain.customer.entity.CustomerE; -import ${package}.domain.customer.rule.extensionpoint.CustomerRuleExtPt; -import ${package}.domain.customer.valueobject.SourceType; -import com.alibaba.sofa.exception.BizException; -import com.alibaba.sofa.extension.Extension; - -/** - * CustomerDDRuleExt - * - * @author Frank Zhang - * @date 2018-01-07 12:10 PM - */ -@Extension(bizCode = BizCode.DD) -public class CustomerDDRuleExt implements CustomerRuleExtPt { - - @Override - public boolean addCustomerCheck(CustomerE customerEntity) { - if(SourceType.AD == customerEntity.getSourceType()){ - throw new BizException("Sorry, Customer from advertisement can not be added in this period"); - } - return true; - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extensionpoint/CustomerRuleExtPt.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extensionpoint/CustomerRuleExtPt.java deleted file mode 100644 index dab657081..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-domain/src/main/java/domain/customer/rule/extensionpoint/CustomerRuleExtPt.java +++ /dev/null @@ -1,25 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.domain.customer.rule.extensionpoint; - -import com.alibaba.sofa.extension.ExtensionPointI; -import com.alibaba.sofa.rule.RuleI; -import ${package}.domain.customer.entity.CustomerE; - -/** - * CustomerRuleExtPt - * - * @author Frank Zhang - * @date 2018-01-07 12:03 PM - */ -public interface CustomerRuleExtPt extends RuleI, ExtensionPointI{ - - //Different business check for different biz - public boolean addCustomerCheck(CustomerE customerE); - - //Different upgrade policy for different biz - default public void customerUpgradePolicy(CustomerE customerE){ - //Nothing special - } -} \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/AppConstants.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/AppConstants.java deleted file mode 100644 index 9e74115bb..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/AppConstants.java +++ /dev/null @@ -1,18 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.common; - -/** - * AppConstants - * - * @author Frank Zhang - * @date 2018-01-08 11:06 AM - */ -public class AppConstants { - public static final String SOURCE_AD = "Advertisement"; - public static final String SOURCE_WB = "Web site"; - public static final String SOURCE_RFQ = "Request For Quota"; - public static final String SOURCE_MARKETING = "Marketing"; - public static final String SOURCE_OFFLINE = "Off Line"; -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/BizCode.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/BizCode.java deleted file mode 100644 index 9ca780b2d..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/common/BizCode.java +++ /dev/null @@ -1,17 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.common; - -public class BizCode { - - public final static String DD = "DD"; //钉钉的bizCode - - public final static String BAMBOO = "B_001"; //为知树的bizCode - - public final static String CGS = "CGS"; //中供的bizCode - - public final static String TP = "TP"; //诚信通的bizCode - - public final static String ICBU = "ICBU"; //icbu的bizCode -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/datatunnel/CustomerTunnelI.java b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/datatunnel/CustomerTunnelI.java deleted file mode 100644 index 7f79362a2..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/java/tunnel/datatunnel/CustomerTunnelI.java +++ /dev/null @@ -1,15 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.tunnel.datatunnel; - -import java.util.List; - -import com.alibaba.sofa.repository.DataTunnel; -import ${package}.tunnel.dataobject.CustomerDO; - -public interface CustomerTunnelI extends DataTunnel{ - - public List findByCriteria(String... params); - -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/app-boot-start.xml b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/app-boot-start.xml deleted file mode 100644 index a819dbc49..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/app-boot-start.xml +++ /dev/null @@ -1,20 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) - - - - - - - - ${package} - - - - - \ No newline at end of file diff --git a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/app.properties b/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/app.properties deleted file mode 100644 index 712a6a3ac..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/__rootArtifactId__-infrastructure/src/main/resources/app.properties +++ /dev/null @@ -1,3 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) diff --git a/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/TestApplication.java b/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/TestApplication.java deleted file mode 100644 index 90e24633e..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/TestApplication.java +++ /dev/null @@ -1,23 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ImportResource; -import org.springframework.context.annotation.PropertySource; - -/** - * 单元测试的Spring Boot配置类 - * @author fulan.zjf - */ -@ImportResource(locations = {"classpath*:app-boot-${artifactId}.xml"}) -@SpringBootApplication(scanBasePackages = {"${groupId}"}) -@PropertySource(value = { "classpath:test.properties" }) -public class TestApplication { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/app/CustomerServiceTest.java b/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/app/CustomerServiceTest.java deleted file mode 100644 index 3bf79a92e..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/app/CustomerServiceTest.java +++ /dev/null @@ -1,24 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.app; - -import ${package}.TestApplication; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Created by fulan.zjf on 2017/11/29. - */ -@RunWith(SpringRunner.class) -//@SpringBootTest(classes = {TestApplication.class}) -public class CustomerServiceTest { - - @Test - public void dummyTest(){ - Assert.assertEquals(true, true); - } -} diff --git a/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/tunnel/CustomerTunnelTest.java b/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/tunnel/CustomerTunnelTest.java deleted file mode 100644 index 6cd86c757..000000000 --- a/sofa-archetype/src/main/resources/archetype-resources/start/src/test/java/tunnel/CustomerTunnelTest.java +++ /dev/null @@ -1,10 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}.tunnel; - -/** - * Created by fulan.zjf on 2017/11/30. - */ -public class CustomerTunnelTest { -} diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/event/MetaqEvent.java b/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/event/MetaqEvent.java deleted file mode 100644 index 5da9193ba..000000000 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/dto/event/MetaqEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.alibaba.sofa.dto.event; - -/** - * - * @author shawnzhan.zxy - * @date 2017/11/17 - */ -public abstract class MetaqEvent extends Event { - - public abstract String getTopic(); - -} diff --git a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/enums/EventType.java b/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/enums/EventType.java deleted file mode 100644 index 93b7d14be..000000000 --- a/sofa-framework/sofa-common/src/main/java/com/alibaba/sofa/enums/EventType.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.alibaba.sofa.enums; - -/** - * @author shawnzhan.zxy - * @date 2017/11/21 - */ -public enum EventType { - CREATE, - UPDATE, - DELETE - ; -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ComponentExecutor.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ComponentExecutor.java deleted file mode 100644 index 7fcccc13a..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/ComponentExecutor.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.alibaba.sofa.boot; - -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; - -import java.util.function.Function; - -/** - * @author fulan.zjf - * @date 2017/12/21 - */ -public abstract class ComponentExecutor { - - public R execute(Class targetClz, Function exeFunction) { - C component = locateComponent(targetClz); - return exeFunction.apply(component); - } - - protected abstract C locateComponent(Class targetClz); -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/EventRegister.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/EventRegister.java deleted file mode 100644 index 43bd18d15..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/EventRegister.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2017 Alibaba.com All right reserved. This software is the - * confidential and proprietary information of Alibaba.com ("Confidential - * Information"). You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Alibaba.com. - */ -package com.alibaba.sofa.boot; - -import com.alibaba.sofa.common.CoreConstant; -import com.alibaba.sofa.dto.event.Event; -import com.alibaba.sofa.event.EventHandlerI; -import com.alibaba.sofa.event.EventHub; -import com.alibaba.sofa.exception.InfraException; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -import java.lang.reflect.Method; - -/** - * EventRegister - * - * @author shawnzhan.zxy - * @date 2017/11/20 - */ -@SuppressWarnings({ "rawtypes", "unchecked" }) -@Component -public class EventRegister implements RegisterI, ApplicationContextAware { - - @Autowired - private EventHub eventHub; - - private ApplicationContext applicationContext; - - @Override - public void doRegistration(Class targetClz) { - Class eventClz = getEventFromExecutor(targetClz); - EventHandlerI executor = (EventHandlerI) applicationContext.getBean(targetClz); - eventHub.register(eventClz, executor); - } - - private Class getEventFromExecutor(Class eventExecutorClz) { - Method[] methods = eventExecutorClz.getDeclaredMethods(); - for (Method method : methods) { - Class[] exeParams = method.getParameterTypes(); - /** - * This is for return right response type on exception scenarios - */ - if (CoreConstant.EXE_METHOD.equals(method.getName()) && exeParams.length == 1 - && Event.class.isAssignableFrom(exeParams[0]) && !method.isBridge()) { - eventHub.getResponseRepository().put(exeParams[0], method.getReturnType()); - return (Class) exeParams[0]; - } - } - throw new InfraException("Event param in " + eventExecutorClz + " " + CoreConstant.EXE_METHOD - + "() is not detected"); - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PlainRuleRegister.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PlainRuleRegister.java deleted file mode 100644 index 03151de33..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PlainRuleRegister.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.alibaba.sofa.boot; - -import com.alibaba.sofa.rule.PlainRuleRepository; -import com.alibaba.sofa.rule.RuleI; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -/** - * Plain Rule is Rule Component without ExtensionPoint - * @author fulan.zjf - * @date 2017/12/21 - */ -@Component -public class PlainRuleRegister implements RegisterI, ApplicationContextAware { - - @Autowired - private PlainRuleRepository plainRuleRepository; - - private ApplicationContext applicationContext; - - @Override - public void doRegistration(Class targetClz) { - RuleI plainRule = (RuleI) applicationContext.getBean(targetClz); - plainRuleRepository.getPlainRules().put(plainRule.getClass(), plainRule); - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PlainValidatorRegister.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PlainValidatorRegister.java deleted file mode 100644 index ce11346af..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/boot/PlainValidatorRegister.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.alibaba.sofa.boot; - -import com.alibaba.sofa.validator.PlainValidatorRepository; -import com.alibaba.sofa.validator.ValidatorI; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -/** - * Plain Validator is Validator Component without ExtensionPoint - * @author fulan.zjf - * @date 2017/12/21 - */ -@Component -public class PlainValidatorRegister implements RegisterI, ApplicationContextAware { - - @Autowired - private PlainValidatorRepository plainValidatorRepository; - - private ApplicationContext applicationContext; - - @Override - public void doRegistration(Class targetClz) { - ValidatorI plainValidator= (ValidatorI) applicationContext.getBean(targetClz); - plainValidatorRepository.getPlainValidators().put(plainValidator.getClass(), plainValidator); - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandBus.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandBus.java deleted file mode 100644 index 5d02338b9..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/CommandBus.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.alibaba.sofa.command; - -import com.alibaba.sofa.exception.BasicErrorCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.alibaba.sofa.context.TenantContext; -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.exception.CrmException; -import com.alibaba.sofa.exception.ErrorCodeI; -import com.alibaba.sofa.exception.InfraException; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; -/** - * Just send Command to CommandBus, - * - * @author fulan.zjf 2017年10月24日 上午12:47:18 - */ -@Component -public class CommandBus implements CommandBusI{ - - Logger logger = LoggerFactory.getLogger(CommandBus.class); - - @Autowired - private CommandHub commandHub; - - @SuppressWarnings("unchecked") - @Override - public Response send(Command cmd) { - Response response = null; - try { - response = commandHub.getCommandInvocation(cmd.getClass()).invoke(cmd); - } - catch (Exception exception) { - response = handleException(cmd, response, exception); - } - finally { - TenantContext.remove();//Clean up context - } - return response; - } - - private Response handleException(Command cmd, Response response, Exception exception) { - logger.error(exception.getMessage(), exception); - Class responseClz = commandHub.getResponseRepository().get(cmd.getClass()); - try { - response = (Response) responseClz.newInstance(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new InfraException(e.getMessage()); - } - if (exception instanceof CrmException) { - ErrorCodeI errCode = ((CrmException) exception).getErrCode(); - response.setErrCode(errCode.getErrCode()); - } - else { - response.setErrCode(BasicErrorCode.SYS_ERROR.getErrCode()); - } - response.setErrMessage(exception.getMessage()); - return response; - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/QueryExecutorI.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/QueryExecutorI.java deleted file mode 100644 index e6d19627e..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/command/QueryExecutorI.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.alibaba.sofa.command; - -import com.alibaba.sofa.dto.Command; -import com.alibaba.sofa.dto.Response; - -public interface QueryExecutorI extends CommandExecutorI{ - -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/ApplicationContextHelper.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/ApplicationContextHelper.java deleted file mode 100644 index bb970d668..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/ApplicationContextHelper.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.alibaba.sofa.common; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -/** - * ApplicationContextHelper - * - * @author Frank Zhang - * @date 2018-01-07 12:30 PM - */ -@Component -public class ApplicationContextHelper implements ApplicationContextAware{ - - private static ApplicationContext applicationContext; - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - ApplicationContextHelper.applicationContext = applicationContext; - } - - public static Object getBean(Class claz){ - return ApplicationContextHelper.applicationContext.getBean(claz); - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/CoreConstant.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/CoreConstant.java deleted file mode 100644 index 4fd99e423..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/common/CoreConstant.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2017 Alibaba.com All right reserved. This software is the - * confidential and proprietary information of Alibaba.com ("Confidential - * Information"). You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Alibaba.com. - */ -package com.alibaba.sofa.common; - -/** - * CoreConstant - * @author fulan.zjf 2017-11-04 - */ -public class CoreConstant { - - public final static String DEFAULT_BIZ_CODE = "$defaultBizCode$"; - public final static String DEFAULT_TENANT_ID = "$defaultTenantId$"; - - public final static String EXTENSION_EXTPT_NAMING = "ExtPt"; - public final static String VALIDATOR_NAMING = "Validator"; - public final static String RULE_NAMING = "Rule"; - - public final static String EXTENSIONPOINT_CLASS = "ExtensionPointI"; - public final static String VALIDATORI_CLASS = "ValidatorI"; - public final static String RULEI_CLASS = "RuleI"; - - public final static String EXE_METHOD = "execute"; -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/PvgContext.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/PvgContext.java deleted file mode 100644 index 80fb3da64..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/PvgContext.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.alibaba.sofa.context; - -import com.alibaba.sofa.exception.Preconditions; - -/** - * Pvg Context - *

- * Created by Danny.Lee on 2017/11/9. - */ -public class PvgContext { - - private static ThreadLocal pvgContext = new ThreadLocal<>(); - - private static class Pvg { - private String loginId; - private String userId; - private String roleName; - private String orgId; - private String corpId; - - public Pvg(String loginId, String roleName, String orgId, String corpId) { - this.loginId = loginId; - this.roleName = roleName; - this.orgId = orgId; - this.corpId = corpId; - } - } - - public static void set(String loginId, String roleName, String orgId, String corpId) { - Pvg pvg = new Pvg(loginId, roleName, orgId, corpId); - pvgContext.set(pvg); - } - - public static void remove() { - pvgContext.remove(); - } - - public static String getLoginId() { - Preconditions.checkArgument(null != pvgContext.get() && null != pvgContext.get().loginId, "No loginId in Context"); - return pvgContext.get().loginId; - } - - public static String getRoleName() { - Preconditions.checkArgument(null != pvgContext.get() && null != pvgContext.get().roleName, "No roleName in Context"); - return pvgContext.get().roleName; - } - - public static String getOrgId() { - Preconditions.checkArgument(null != pvgContext.get() && null != pvgContext.get().orgId, "No orgId in Context"); - return pvgContext.get().orgId; - } - - public static String getCorpId() { - Preconditions.checkArgument(null != pvgContext.get() && null != pvgContext.get().corpId, "No corpId in Context"); - return pvgContext.get().corpId; - } - - public static String getUserId() { - Preconditions.checkArgument(null != pvgContext.get() && null != pvgContext.get().userId, "No userId in Context"); - return pvgContext.get().userId; - } - -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/TenantContext.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/TenantContext.java deleted file mode 100644 index 7488abcbd..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/TenantContext.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.alibaba.sofa.context; - -import com.alibaba.sofa.exception.BizException; - -public class TenantContext { - - private static ThreadLocal tenantContext = new ThreadLocal<>(); - - private static class Tenant{ - String tenantId; - String bizCode; - private Tenant(String tenantId, String bizCode) { - this.tenantId = tenantId; - this.bizCode = bizCode; - } - } - - public static String getTenantId() { - if (tenantContext.get() == null || tenantContext.get().tenantId == null) { - throw new BizException("No tenantId in Context"); - } - return tenantContext.get().tenantId; - } - - public static String getBizCode() { - if (tenantContext.get() == null || tenantContext.get().bizCode == null) { - throw new BizException("No bizCode in Context"); - } - return tenantContext.get().bizCode; - } - - public static void set(String tenantId, String bizCode) { - Tenant tenant = new Tenant(tenantId, bizCode); - tenantContext.set(tenant); - } - - public static void remove() { - tenantContext.remove(); - } - -} - diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/package-info.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/package-info.java deleted file mode 100644 index bde07a541..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/context/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Domain objects (Entity) contains the core logic of Domain. - * - * @author fulan.zjf - */ -package com.alibaba.sofa.context; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/DomainFactoryI.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/DomainFactoryI.java deleted file mode 100644 index 0fb165dee..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/DomainFactoryI.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.alibaba.sofa.domain; - -/** - * 领域工厂 - * @author xueliang.sxl - * - */ -public interface DomainFactoryI { - - T create(); - -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/ServiceI.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/ServiceI.java deleted file mode 100644 index 7b043ae48..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/domain/ServiceI.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.alibaba.sofa.domain; - -/** - * 领域服务 - * @author xueliang.sxl - * - */ -public interface ServiceI { - -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventBus.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventBus.java deleted file mode 100644 index bc592531e..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventBus.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.alibaba.sofa.event; - -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.dto.event.Event; -import com.alibaba.sofa.exception.BasicErrorCode; -import com.alibaba.sofa.exception.CrmException; -import com.alibaba.sofa.exception.ErrorCodeI; -import com.alibaba.sofa.exception.InfraException; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * Event Bus - * - * @author shawnzhan.zxy - * @date 2017/11/20 - */ -@Component -public class EventBus implements EventBusI{ - Logger logger = LoggerFactory.getLogger(EventBus.class); - - @Autowired - private EventHub eventHub; - - @SuppressWarnings("unchecked") - @Override - public Response fire(Event event) { - Response response = null; - try { - response = eventHub.getEventHandler(event.getClass()).execute(event); - }catch (Exception exception) { - response = handleException(event, response, exception); - } - return response; - } - - private Response handleException(Event cmd, Response response, Exception exception) { - Class responseClz = eventHub.getResponseRepository().get(cmd.getClass()); - try { - response = (Response) responseClz.newInstance(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new InfraException(e.getMessage()); - } - if (exception instanceof CrmException) { - ErrorCodeI errCode = ((CrmException) exception).getErrCode(); - response.setErrCode(errCode.getErrCode()); - } - else { - response.setErrCode(BasicErrorCode.SYS_ERROR.getErrCode()); - } - response.setErrMessage(exception.getMessage()); - logger.error(exception.getMessage(), exception); - return response; - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventBusI.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventBusI.java deleted file mode 100644 index 25ceaae0d..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventBusI.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.alibaba.sofa.event; - -import com.alibaba.sofa.dto.event.Event; -import com.alibaba.sofa.dto.Response; - - -/** - * EventBus interface - * @author shawnzhan.zxy - * @date 2017/11/20 - */ -public interface EventBusI { - - /** - * Send event to EventBus - * - * @param event - * @return Response - */ - public Response fire(Event event); -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHandlerI.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHandlerI.java deleted file mode 100644 index 0673fc5c2..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHandlerI.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.alibaba.sofa.event; - -import com.alibaba.sofa.dto.event.Event; -import com.alibaba.sofa.dto.Response; - -/** - * event handler - * - * @author shawnzhan.zxy - * @date 2017/11/20 - */ -public interface EventHandlerI { - - public R execute(E e); -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHub.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHub.java deleted file mode 100644 index 36f185ff8..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/event/EventHub.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.alibaba.sofa.event; - -import com.alibaba.sofa.dto.event.Event; -import com.alibaba.sofa.exception.InfraException; -import lombok.Getter; -import lombok.Setter; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; - -/** - * 事件控制中枢 - * @author shawnzhan.zxy - * @date 2017/11/20 - */ -@SuppressWarnings("rawtypes") -@Component -public class EventHub { - @Getter - @Setter - private Map eventRepository = new HashMap<>(); - - @Getter - private Map responseRepository = new HashMap<>(); - - public EventHandlerI getEventHandler(Class eventClass) { - EventHandlerI eventHandlerI = findHandler(eventClass); - if (eventHandlerI == null) { - throw new InfraException(eventClass + "is not registered in eventHub, please register first"); - } - return eventHandlerI; - } - - /** - * 注册事件 - * @param eventClz - * @param executor - */ - public void register(Class eventClz, EventHandlerI executor){ - eventRepository.put(eventClz, executor); - } - - private EventHandlerI findHandler(Class eventClass){ - EventHandlerI eventHandlerI = null; - Class cls = eventClass; - eventHandlerI = eventRepository.get(cls); - return eventHandlerI; - } - -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/BasicErrorCode.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/BasicErrorCode.java deleted file mode 100644 index 9421a64c6..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/BasicErrorCode.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.alibaba.sofa.exception; - -/** - * - * 参数错误:1000 - 1999 - * 业务错误:2000 - 2999 - * 基础错误:3000 - 3999 - * 系统错误:4000 - 4999 - * - * Created by fulan.zjf on 2017/12/18. - */ -public enum BasicErrorCode implements ErrorCodeI{ - PARAM_ERROR("1000" , "请求参数校验错误" , false), - BIZ_ERROR("2000" , "业务逻辑错误" , false), - INFRA_ERROR("3000" , "基础设施(数据库,缓存,消息等)错误" , true), - SYS_ERROR("4000" , "未知的其它系统错误" , true); - - private String errCode; - private String errDesc; - private boolean retriable; - - private BasicErrorCode(String errCode, String errDesc, boolean retriable){ - this.errCode = errCode; - this.errDesc = errDesc; - this.retriable = retriable; - } - - @Override - public String getErrCode() { - return errCode; - } - - @Override - public String getErrDesc() { - return errDesc; - } - - @Override - public boolean isRetriable() { - return retriable; - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/InfraException.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/InfraException.java deleted file mode 100644 index 6d8c9f4d6..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/exception/InfraException.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.alibaba.sofa.exception; - -/** - * - * Infrastructure Exception - * - * @author fulan.zjf 2017年10月22日 下午5:56:57 - */ -public class InfraException extends CrmException{ - - private static final long serialVersionUID = 1L; - - public InfraException(String errMessage){ - super(errMessage); - this.setErrCode(BasicErrorCode.INFRA_ERROR); - } - - public InfraException(String errMessage, Throwable e) { - super(errMessage, e); - this.setErrCode(BasicErrorCode.INFRA_ERROR); - } -} \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionExecutor.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionExecutor.java deleted file mode 100644 index fe95d0010..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extension/ExtensionExecutor.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2017 Alibaba.com All right reserved. This software is the - * confidential and proprietary information of Alibaba.com ("Confidential - * Information"). You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Alibaba.com. - */ -package com.alibaba.sofa.extension; - -import com.alibaba.sofa.boot.ComponentExecutor; -import com.alibaba.sofa.common.CoreConstant; -import com.alibaba.sofa.common.DefaultBizCode; -import com.alibaba.sofa.context.TenantContext; -import com.alibaba.sofa.exception.InfraException; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * ExtensionExecutor - * @author fulan.zjf 2017-11-05 - */ -@Component -public class ExtensionExecutor extends ComponentExecutor{ - - private Logger logger = LoggerFactory.getLogger(ExtensionExecutor.class); - - @Autowired - private ExtensionRepository extensionRepository; - - @Override - protected C locateComponent(Class targetClz) { - C extension = locateExtension(targetClz); - logger.debug("[Located Extension]: "+extension.getClass().getSimpleName()); - return locateExtension(targetClz); - } - - /** - * @param targetClz - */ - @SuppressWarnings("unchecked") - protected Ext locateExtension(Class targetClz) { - String bizCode = TenantContext.getBizCode(); - String tenantId = TenantContext.getTenantId(); - ExtensionCoordinate extensionCoordinate = new ExtensionCoordinate(targetClz.getSimpleName(), bizCode, tenantId); - /** - * 1.First search key is: extensionPoint + bizCode + tenantId - */ - Ext extension = (Ext)extensionRepository.getExtensionRepo().get(extensionCoordinate); - if (extension != null) { - return extension; - } - /** - * 2.Second search key is: extensionPoint + bizCode - */ - extensionCoordinate.setTenantId(CoreConstant.DEFAULT_TENANT_ID); - extension = (Ext)extensionRepository.getExtensionRepo().get(extensionCoordinate); - if (extension != null) { - return extension; - } - /** - * 3.Third search key is: extensionPoint - */ - extensionCoordinate.setBizCode(DefaultBizCode.DEFAULT_BIZ_CODE); - extension = (Ext)extensionRepository.getExtensionRepo().get(extensionCoordinate); - if (extension != null) { - return extension; - } - throw new InfraException("Can not find extension for ExtensionPoint: "+targetClz); - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extensionpoint/MetaqEventConsumerExtPt.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extensionpoint/MetaqEventConsumerExtPt.java deleted file mode 100644 index ea3d26f72..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/extensionpoint/MetaqEventConsumerExtPt.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.alibaba.sofa.extensionpoint; - -import com.alibaba.sofa.dto.Response; - -/** - * Metaq消息消费扩展点 - * @author xueliang.sxl - * - */ -public interface MetaqEventConsumerExtPt { - - Response receive(String msg); -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/LoggerFactory.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/LoggerFactory.java deleted file mode 100644 index a8830c60b..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/LoggerFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.alibaba.sofa.logger; - -public class LoggerFactory { - - private static boolean useSysLogger = true; - - public static Logger getLogger(Class clazz) { - if(useSysLogger) - return SysLogger.singleton; - org.slf4j.Logger slfjLogger = org.slf4j.LoggerFactory.getLogger(clazz); - return new SLFJLogger(slfjLogger); - } - - /** - * This is just for test purpose, don't use it on product! - */ - public static void activateSysLogger() { - useSysLogger = true; - } - - public static void deactivateSysLogger() { - useSysLogger = false; - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/SysLogger.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/SysLogger.java deleted file mode 100644 index fdbcb27ab..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/logger/SysLogger.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.alibaba.sofa.logger; - -public class SysLogger implements Logger{ - - public static SysLogger singleton = new SysLogger(); - - @Override - public void debug(String msg) { - System.out.println("DEBUG: "+msg); - } - - @Override - public void info(String msg) { - System.out.println("INFO: "+msg); - } - - @Override - public void warn(String msg) { - System.out.println("WARN: "+msg); - } - - @Override - public void error(String msg) { - System.err.println("ERROR: "+msg); - } - - @Override - public void error(String msg, Throwable t) { - System.err.println("ERROR: "+msg); - t.printStackTrace(); - } - -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/DataObject.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/DataObject.java deleted file mode 100644 index 9489508ae..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/DataObject.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.alibaba.sofa.repository; - -import java.io.Serializable; - -/** - * This is the parent of all Data Objects. - * Data object only has fields and according getters and setters, you can also call it anemic objects - * @author fulan.zjf 2017年10月27日 上午10:21:01 - */ -public interface DataObject extends Serializable { -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/DataTunnel.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/DataTunnel.java deleted file mode 100644 index 2f9df681f..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/repository/DataTunnel.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.alibaba.sofa.repository; - -import java.util.List; - -/** - * Data Tunnel is the real Data CRUD Operator may interact with DB, service, cache etc... - * - * @author fulan.zjf 2017年10月27日 上午10:34:17 - */ -public interface DataTunnel { - - public T create(T dataObject); - - default public void delete(T dataObject) {}; - - default public void update(T dataObject){}; - - public T get(String id); - - public List getByEntity(T entity); -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/PlainRuleRepository.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/PlainRuleRepository.java deleted file mode 100644 index ef6d255a9..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/PlainRuleRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.alibaba.sofa.rule; - -import lombok.Getter; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; - -/** - * Plain Rule is Rule Component without ExtensionPoint - * @author fulan.zjf - * @date 2017/12/21 - */ -@Component -public class PlainRuleRepository { - @Getter - private Map, RuleI> plainRules = new HashMap<>(); -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/RuleExecutor.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/RuleExecutor.java deleted file mode 100644 index 3fdb07940..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/RuleExecutor.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2017 Alibaba.com All right reserved. This software is the - * confidential and proprietary information of Alibaba.com ("Confidential - * Information"). You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Alibaba.com. - */ -package com.alibaba.sofa.rule; - -import com.alibaba.sofa.extension.ExtensionExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * RuleExecutor - * - * Note that Rule is extensible as long as @Extension is added - * - * @author fulan.zjf 2017-11-04 - */ -@Component -public class RuleExecutor extends ExtensionExecutor { - - @Autowired - private PlainRuleRepository plainRuleRepository; - - @Override - protected C locateComponent(Class targetClz) { - C rule = (C) plainRuleRepository.getPlainRules().get(targetClz); - return null != rule ? rule : super.locateComponent(targetClz); - } - - public void validate(Class targetClz, Object... candidate) { - RuleI rule = this.locateComponent(targetClz); - rule.validate(candidate); - } -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/RuleI.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/RuleI.java deleted file mode 100644 index 6c34ea78d..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/RuleI.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.alibaba.sofa.rule; - -/** - * 业务规则接口,适合领域层的业务规则检查 - * @author xueliang.sxl - * - */ -public interface RuleI { - - /** - * 默认的规则检查接口,子接口可自定义 - * @param roleContext - * @return - */ - default boolean check(Object roleContext){ - return true; - } - - /** - * This is specific for Validation cases where no Return is needed - * @param candidate - */ - default void validate(Object... candidate){} -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/package-info.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/package-info.java deleted file mode 100644 index 9e68e3352..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Use {@link com.alibaba.sofa.rule.RuleI} to declare Rule, and use {@link com.alibaba.sofa.extension.Extension} if this Rule needs Extension. - * - * @author fulan.zjf - * @date 2017/12/22 - */ -package com.alibaba.sofa.rule; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/AbstractRule.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/AbstractRule.java deleted file mode 100644 index bc71c88cb..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/AbstractRule.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.alibaba.sofa.rule.ruleengine; - -import com.alibaba.sofa.rule.RuleI; - -/** - * 业务规则的抽象实现,可用于组合规则 - * @author xueliang.sxl - * - */ -public abstract class AbstractRule implements RuleI { - - public RuleI and(RuleI other) { - return new AndRule(this, other); - } - - public RuleI or(RuleI other) { - return new OrRule(this, other); - } - - public RuleI not() { - return new NotRule(this); - } - -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/AndRule.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/AndRule.java deleted file mode 100644 index 9cb5f1e1e..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/AndRule.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.alibaba.sofa.rule.ruleengine; - -import com.alibaba.sofa.rule.RuleI; - -/** - * 组合And的业务规则 - * @author xueliang.sxl - * - */ -public class AndRule extends AbstractRule { - RuleI one; - RuleI other; - - public AndRule(RuleI x, RuleI y){ - one = x; - other = y; - } - - @Override - public boolean check(Object candidate) { - return one.check(candidate) && other.check(candidate); - } - -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/NotRule.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/NotRule.java deleted file mode 100644 index 732e32718..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/NotRule.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.alibaba.sofa.rule.ruleengine; - -import com.alibaba.sofa.rule.RuleI; - -/** - * 组合Not的业务规则 - * @author xueliang.sxl - * - */ -public class NotRule extends AbstractRule { - RuleI wrapped; - - public NotRule(RuleI x){ - wrapped = x; - } - - @Override - public boolean check(Object candidate) { - return !wrapped.check(candidate); - } - -} \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/OrRule.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/OrRule.java deleted file mode 100644 index 97979bb42..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/rule/ruleengine/OrRule.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.alibaba.sofa.rule.ruleengine; - -import com.alibaba.sofa.rule.RuleI; - -/** - * 组合Or的业务规则 - * @author xueliang.sxl - * - */ -public class OrRule extends AbstractRule { - RuleI one; - RuleI other; - - public OrRule(RuleI x, RuleI y){ - one = x; - other = y; - } - - @Override - public boolean check(Object candidate) { - return one.check(candidate) || other.check(candidate); - } - -} \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/PlainValidatorRepository.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/PlainValidatorRepository.java deleted file mode 100644 index 79b5553f9..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/PlainValidatorRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.alibaba.sofa.validator; - -import lombok.Getter; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; - -/** - * Plain Validator is Validator Component without ExtensionPoint - * @author fulan.zjf - * @date 2017/12/21 - */ -@Component -public class PlainValidatorRepository { - @Getter - private Map, ValidatorI> plainValidators = new HashMap<>(); -} diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorExecutor.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorExecutor.java deleted file mode 100644 index 51ae8bfcd..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/ValidatorExecutor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2017 Alibaba.com All right reserved. This software is the - * confidential and proprietary information of Alibaba.com ("Confidential - * Information"). You shall not disclose such Confidential Information and shall - * use it only in accordance with the terms of the license agreement you entered - * into with Alibaba.com. - */ -package com.alibaba.sofa.validator; - -import com.alibaba.sofa.extension.ExtensionExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * ValidatorExecutor - * - * @author fulan.zjf 2017-11-04 - */ -@Component -public class ValidatorExecutor extends ExtensionExecutor { - - @Autowired - private PlainValidatorRepository plainValidatorRepository; - - public void validate(Class targetClz, Object candidate) { - ValidatorI validator = locateComponent(targetClz); - validator.validate(candidate); - } - - @Override - protected C locateComponent(Class targetClz) { - C validator = (C) plainValidatorRepository.getPlainValidators().get(targetClz); - return null != validator ? validator : super.locateComponent(targetClz); - } - -} \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/package-info.java b/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/package-info.java deleted file mode 100644 index 2e0cf2912..000000000 --- a/sofa-framework/sofa-core/src/main/java/com/alibaba/sofa/validator/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Use {@link com.alibaba.sofa.validator.ValidatorI} to declare Validator, and use {@link com.alibaba.sofa.extension.Extension} if this Validator needs Extension. - * - * @author fulan.zjf - */ -package com.alibaba.sofa.validator; \ No newline at end of file diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/AddCustomerCmdExe.java b/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/AddCustomerCmdExe.java deleted file mode 100644 index 594fe8efb..000000000 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/AddCustomerCmdExe.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.alibaba.sofa.test.customer; - -import com.alibaba.sofa.command.Command; -import com.alibaba.sofa.command.CommandExecutorI; -import com.alibaba.sofa.dto.Response; -import com.alibaba.sofa.extension.ExtensionExecutor; -import com.alibaba.sofa.logger.Logger; -import com.alibaba.sofa.logger.LoggerFactory; -import com.alibaba.sofa.test.customer.convertor.CustomerConvertorExtPt; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; -import com.alibaba.sofa.test.customer.validator.extensionpoint.AddCustomerValidatorExtPt; -import com.alibaba.sofa.validator.ValidatorExecutor; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * AddCustomerCmdExe - * - * @author Frank Zhang 2018-01-06 7:48 PM - */ -@Command -public class AddCustomerCmdExe implements CommandExecutorI { - - private Logger logger = LoggerFactory.getLogger(AddCustomerCmd.class); - - @Autowired - private ValidatorExecutor validatorExecutor; - - @Autowired - private ExtensionExecutor extensionExecutor; - - - @Override - public Response execute(AddCustomerCmd cmd) { - logger.info("Start processing command:" + cmd); - validatorExecutor.validate(AddCustomerValidatorExtPt.class, cmd); - - //Convert CO to Entity - CustomerEntity customerEntity = extensionExecutor.execute(CustomerConvertorExtPt.class, extension -> extension.clientToEntity(cmd.getCustomerCO())); - - //Call Domain Entity for business logic processing - logger.info("Call Domain Entity for business logic processing..."+customerEntity); - customerEntity.addNewCustomer(); - - logger.info("End processing command:" + cmd); - return Response.buildSuccess(); - } -} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerBizOneConvertorExt.java b/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerBizOneConvertorExt.java deleted file mode 100644 index 0047cda9e..000000000 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerBizOneConvertorExt.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.alibaba.sofa.test.customer.convertor; - -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.test.customer.Constants; -import com.alibaba.sofa.test.customer.CustomerCO; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; -import com.alibaba.sofa.test.customer.entity.SourceType; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * CustomerBizOneConvertorExt - * - * @author Frank Zhang - * @date 2018-01-07 3:05 AM - */ -@Extension(bizCode = Constants.BIZ_1) -public class CustomerBizOneConvertorExt implements CustomerConvertorExtPt{ - - @Autowired - private CustomerConvertor customerConvertor;//Composite basic convertor to do basic conversion - - @Override - public CustomerEntity clientToEntity(CustomerCO customerCO){ - CustomerEntity customerEntity = customerConvertor.clientToEntity(customerCO); - //In this business, AD and RFQ are regarded as different source - if(Constants.SOURCE_AD.equals(customerCO.getSource())) - { - customerEntity.setSourceType(SourceType.AD); - } - if (Constants.SOURCE_RFQ.equals(customerCO.getSource())){ - customerEntity.setSourceType(SourceType.RFQ); - } - return customerEntity; - } -} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerBizTwoConvertorExt.java b/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerBizTwoConvertorExt.java deleted file mode 100644 index 399389245..000000000 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerBizTwoConvertorExt.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.alibaba.sofa.test.customer.convertor; - -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.test.customer.Constants; -import com.alibaba.sofa.test.customer.CustomerCO; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; -import com.alibaba.sofa.test.customer.entity.SourceType; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * CustomerBizTwoConvertorExt - * - * @author Frank Zhang - * @date 2018-01-07 3:05 AM - */ -@Extension(bizCode = Constants.BIZ_2) -public class CustomerBizTwoConvertorExt implements CustomerConvertorExtPt{ - - @Autowired - private CustomerConvertor customerConvertor;//Composite basic convertor to do basic conversion - - @Override - public CustomerEntity clientToEntity(CustomerCO customerCO){ - CustomerEntity customerEntity = customerConvertor.clientToEntity(customerCO); - //In this business, if customers from RFQ and Advertisement are both regarded as Advertisement - if(Constants.SOURCE_AD.equals(customerCO.getSource()) || Constants.SOURCE_RFQ.equals(customerCO.getSource())) - { - customerEntity.setSourceType(SourceType.AD); - } - return customerEntity; - } - -} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerConvertor.java b/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerConvertor.java deleted file mode 100644 index 523d3634e..000000000 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerConvertor.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.alibaba.sofa.test.customer.convertor; - -import com.alibaba.sofa.common.ApplicationContextHelper; -import com.alibaba.sofa.convertor.ConvertorI; -import com.alibaba.sofa.test.customer.CustomerCO; -import com.alibaba.sofa.test.customer.CustomerDO; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; -import com.alibaba.sofa.test.customer.entity.rule.CustomerRuleExtPt; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -/** - * CustomerConvertor - * - * @author Frank Zhang - * @date 2018-01-07 3:08 AM - */ -@Component -public class CustomerConvertor implements ConvertorI{ - - @Override - public CustomerEntity clientToEntity(CustomerCO customerCO){ - CustomerEntity customerEntity = (CustomerEntity)ApplicationContextHelper.getBean(CustomerEntity.class); - customerEntity.setCompanyName(customerCO.getCompanyName()); - customerEntity.setCustomerType(customerCO.getCustomerType()); - return customerEntity; - } -} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerConvertorExtPt.java b/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerConvertorExtPt.java deleted file mode 100644 index 4c463237e..000000000 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/convertor/CustomerConvertorExtPt.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.alibaba.sofa.test.customer.convertor; - -import com.alibaba.sofa.convertor.ConvertorI; -import com.alibaba.sofa.extension.ExtensionPointI; -import com.alibaba.sofa.test.customer.CustomerCO; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; - -/** - * CustomerConvertorExtPt - * - * @author Frank Zhang - * @date 2018-01-07 2:37 AM - */ -public interface CustomerConvertorExtPt extends ConvertorI, ExtensionPointI { - - public CustomerEntity clientToEntity(CustomerCO customerCO); -} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerBizOneRuleExt.java b/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerBizOneRuleExt.java deleted file mode 100644 index 40c1dfe84..000000000 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerBizOneRuleExt.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.alibaba.sofa.test.customer.entity.rule; - -import com.alibaba.sofa.exception.BizException; -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.test.customer.Constants; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; -import com.alibaba.sofa.test.customer.entity.SourceType; - -/** - * CustomerBizOneRuleExt - * - * @author Frank Zhang - * @date 2018-01-07 12:10 PM - */ -@Extension(bizCode = Constants.BIZ_1) -public class CustomerBizOneRuleExt implements CustomerRuleExtPt{ - - @Override - public boolean addCustomerCheck(CustomerEntity customerEntity) { - if(SourceType.AD == customerEntity.getSourceType()){ - throw new BizException("Sorry, Customer from advertisement can not be added in this period"); - } - return true; - } -} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerBizTwoRuleExt.java b/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerBizTwoRuleExt.java deleted file mode 100644 index c34a758aa..000000000 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerBizTwoRuleExt.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.alibaba.sofa.test.customer.entity.rule; - -import com.alibaba.sofa.extension.Extension; -import com.alibaba.sofa.test.customer.Constants; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; - -/** - * CustomerBizTwoRuleExt - * - * @author Frank Zhang - * @date 2018-01-07 12:10 PM - */ -@Extension(bizCode = Constants.BIZ_2) -public class CustomerBizTwoRuleExt implements CustomerRuleExtPt{ - - @Override - public boolean addCustomerCheck(CustomerEntity customerEntity) { - //Any Customer can be added - return true; - } -} diff --git a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerRuleExtPt.java b/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerRuleExtPt.java deleted file mode 100644 index 5a13a2338..000000000 --- a/sofa-framework/sofa-core/src/test/java/com/alibaba/sofa/test/customer/entity/rule/CustomerRuleExtPt.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.alibaba.sofa.test.customer.entity.rule; - -import com.alibaba.sofa.extension.ExtensionPointI; -import com.alibaba.sofa.rule.RuleI; -import com.alibaba.sofa.test.customer.entity.CustomerEntity; - -/** - * CustomerRuleExtPt - * - * @author Frank Zhang - * @date 2018-01-07 12:03 PM - */ -public interface CustomerRuleExtPt extends RuleI, ExtensionPointI{ - - //Different business check for different biz - public boolean addCustomerCheck(CustomerEntity customerEntity); - - //Different upgrade policy for different biz - default public void customerUpgradePolicy(CustomerEntity customerEntity){ - //Nothing special - } -}