Skip to content

Commit

Permalink
implement DIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fulan.zjf committed Jul 2, 2020
1 parent 35d2707 commit b4fc71d
Show file tree
Hide file tree
Showing 70 changed files with 433 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public class CustomerEntityTest {

public void testCustomerConflict() {
System.out.println("Please mock tunnel, test pure Domain Knowledge");
System.out.println("Please mock gatewayimpl, test pure Domain Knowledge");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public class CustomerEntityTest {

public void testCustomerConflict() {
System.out.println("Please mock tunnel, test pure Domain Knowledge");
System.out.println("Please mock gatewayimpl, test pure Domain Knowledge");
}
}
2 changes: 1 addition & 1 deletion sample/craftsman/craftsman-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</dependency>
<dependency>
<groupId>com.alibaba.craftsman</groupId>
<artifactId>craftsman-domain</artifactId>
<artifactId>craftsman-infrastructure</artifactId>
</dependency>
<!-- JSR 303 Validation -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.alibaba.craftsman.domain.metrics.techinfluence.InfluenceMetric;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.ATAMetricAddCmd;
import com.alibaba.craftsman.repository.MetricRepository;
import com.alibaba.craftsman.domain.gateway.MetricGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -21,13 +21,13 @@
public class ATAMetricAddCmdExe{

@Autowired
private MetricRepository metricRepository;
private MetricGateway metricGateway;

public Response execute(ATAMetricAddCmd cmd) {
ATAMetricItem ataMetricItem = new ATAMetricItem();
BeanUtils.copyProperties(cmd.getAtaMetricCO(), ataMetricItem);
ataMetricItem.setSubMetric(new ATAMetric(new InfluenceMetric(new UserProfile(cmd.getAtaMetricCO().getOwnerId()))));
metricRepository.save(ataMetricItem);
metricGateway.save(ataMetricItem);
return Response.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.alibaba.craftsman.domain.metrics.techcontribution.ContributionMetric;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.CodeReviewMetricAddCmd;
import com.alibaba.craftsman.repository.MetricRepository;
import com.alibaba.craftsman.domain.gateway.MetricGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -21,13 +21,13 @@
public class CodeReviewMetricAddCmdExe{

@Autowired
private MetricRepository metricRepository;
private MetricGateway metricGateway;

public Response execute(CodeReviewMetricAddCmd cmd) {
CodeReviewMetricItem codeReviewMetricItem = new CodeReviewMetricItem();
BeanUtils.copyProperties(cmd, codeReviewMetricItem);
codeReviewMetricItem.setSubMetric(new CodeReviewMetric(new ContributionMetric(new UserProfile(cmd.getOwnerId()))));
metricRepository.save(codeReviewMetricItem);
metricGateway.save(codeReviewMetricItem);
return Response.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import com.alibaba.cola.dto.Response;
import com.alibaba.craftsman.dto.MetricDeleteCmd;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.craftsman.gatewayimpl.database.MetricMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
Expand All @@ -18,11 +17,11 @@
public class MetricDeleteCmdExe{

@Resource
private MetricTunnel metricTunnel;
private MetricMapper metricMapper;

public Response execute(MetricDeleteCmd cmd) {

metricTunnel.delete(cmd.getMetricId(), cmd.getOperater());
metricMapper.delete(cmd.getMetricId(), cmd.getOperater());

return Response.buildSuccess();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.alibaba.craftsman.domain.metrics.techcontribution.MiscMetricItem;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.MiscMetricAddCmd;
import com.alibaba.craftsman.repository.MetricRepository;
import com.alibaba.craftsman.domain.gateway.MetricGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

Expand All @@ -22,13 +22,13 @@
public class MiscMetricAddCmdExe{

@Resource
private MetricRepository metricRepository;
private MetricGateway metricGateway;

public Response execute(MiscMetricAddCmd cmd) {
MiscMetricItem miscMetricItem = new MiscMetricItem();
BeanUtils.copyProperties(cmd.getMiscMetricCO(), miscMetricItem);
miscMetricItem.setSubMetric(new MiscMetric(new ContributionMetric(new UserProfile(cmd.getMiscMetricCO().getOwnerId()))));
metricRepository.save(miscMetricItem);
metricGateway.save(miscMetricItem);
return Response.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.alibaba.craftsman.domain.metrics.techinfluence.PaperMetricItem;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.PaperMetricAddCmd;
import com.alibaba.craftsman.repository.MetricRepository;
import com.alibaba.craftsman.domain.gateway.MetricGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -21,14 +21,14 @@
public class PaperMetricAddCmdExe {

@Autowired
private MetricRepository metricRepository;
private MetricGateway metricGateway;

public Response execute(PaperMetricAddCmd cmd) {
PaperMetricItem paperMetricItem = new PaperMetricItem();
BeanUtils.copyProperties(cmd.getPaperMetricCO(), paperMetricItem);
paperMetricItem.setSubMetric(new PaperMetric(new InfluenceMetric(new UserProfile(cmd.getPaperMetricCO().getOwnerId()))));
paperMetricItem.setMetricOwner(new UserProfile(cmd.getPaperMetricCO().getOwnerId()));
metricRepository.save(paperMetricItem);
metricGateway.save(paperMetricItem);

return Response.buildSuccess();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.alibaba.craftsman.domain.metrics.techinfluence.PatentMetricItem;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.PatentMetricAddCmd;
import com.alibaba.craftsman.repository.MetricRepository;
import com.alibaba.craftsman.domain.gateway.MetricGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

Expand All @@ -23,14 +23,14 @@
public class PatentMetricAddCmdExe{

@Resource
private MetricRepository metricRepository;
private MetricGateway metricGateway;

public Response execute(PatentMetricAddCmd cmd) {
PatentMetricItem patentMetricItem = new PatentMetricItem();
BeanUtils.copyProperties(cmd.getPatentMetricCO(), patentMetricItem);
patentMetricItem.setSubMetric(new PatentMetric(new InfluenceMetric(new UserProfile(cmd.getPatentMetricCO().getOwnerId()))));
patentMetricItem.setAuthorType(AuthorType.valueOf(cmd.getPatentMetricCO().getAuthorType()));
metricRepository.save(patentMetricItem);
metricGateway.save(patentMetricItem);
return Response.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.alibaba.craftsman.domain.metrics.techcontribution.RefactoringMetricItem;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.RefactoringMetricAddCmd;
import com.alibaba.craftsman.repository.MetricRepository;
import com.alibaba.craftsman.domain.gateway.MetricGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -22,14 +22,14 @@
public class RefactoringMetricAddCmdExe{

@Autowired
private MetricRepository metricRepository;
private MetricGateway metricGateway;

public Response execute(RefactoringMetricAddCmd cmd) {
RefactoringMetricItem refactoringMetricItem = new RefactoringMetricItem();
BeanUtils.copyProperties(cmd.getRefactoringMetricCO(), refactoringMetricItem);
refactoringMetricItem.setSubMetric(new RefactoringMetric(new ContributionMetric(new UserProfile(cmd.getRefactoringMetricCO().getOwnerId()))));
refactoringMetricItem.setRefactoringLevel(RefactoringLevel.valueOf(cmd.getRefactoringMetricCO().getRefactoringLevel()));
metricRepository.save(refactoringMetricItem);
metricGateway.save(refactoringMetricItem);
return Response.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.RefreshScoreCmd;
import com.alibaba.craftsman.event.handler.MetricItemCreatedHandler;
import com.alibaba.craftsman.repository.MetricRepository;
import com.alibaba.craftsman.repository.UserProfileRepository;
import com.alibaba.craftsman.domain.gateway.MetricGateway;
import com.alibaba.craftsman.domain.gateway.UserProfileGateway;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
Expand All @@ -26,10 +26,10 @@ public class RefreshScoreCmdExe{
private Logger logger = LoggerFactory.getLogger(MetricItemCreatedHandler.class);

@Resource
private UserProfileRepository userProfileRepository;
private UserProfileGateway userProfileGateway;

@Resource
private MetricRepository metricRepository;
private MetricGateway metricGateway;

public Response execute(RefreshScoreCmd cmd) {
UserProfile userProfile = getUserProfile(cmd);
Expand All @@ -39,7 +39,7 @@ public Response execute(RefreshScoreCmd cmd) {
}

private UserProfile getUserProfile(RefreshScoreCmd cmd) {
UserProfile userProfile = userProfileRepository.getByUserId(cmd.getUserId());
UserProfile userProfile = userProfileGateway.getByUserId(cmd.getUserId());
Assert.notNull(userProfile, "There is no User Profile for "+cmd.getUserId()+" to update");
return userProfile;
}
Expand All @@ -54,29 +54,29 @@ private void calculateScore(UserProfile userProfile) {

private void loadAppQualityMetrics(UserProfile userProfile) {
AppQualityMetric appQualityMetric = new AppQualityMetric(userProfile);
AppMetric appMetric = metricRepository.getAppMetric(userProfile.getUserId());
AppMetric appMetric = metricGateway.getAppMetric(userProfile.getUserId());
appMetric.setParent(appQualityMetric);
}

private void loadDevQualityMetrics(UserProfile userProfile) {
DevQualityMetric devQualityMetric = new DevQualityMetric(userProfile);
BugMetric bugMetric = metricRepository.getBugMetric(userProfile.getUserId());
BugMetric bugMetric = metricGateway.getBugMetric(userProfile.getUserId());
bugMetric.setParent(devQualityMetric);
}

private void loadContributionMetrics(UserProfile userProfile) {
ContributionMetric contributionMetric = new ContributionMetric(userProfile);
List<SubMetric> subMetricList = metricRepository.listByTechContribution(userProfile.getUserId());
List<SubMetric> subMetricList = metricGateway.listByTechContribution(userProfile.getUserId());
subMetricList.forEach(subMetric -> subMetric.setParent(contributionMetric));
}

private void loadInfluenceMetric(UserProfile userProfile) {
InfluenceMetric influenceMetric = new InfluenceMetric(userProfile);
List<SubMetric> subMetricList = metricRepository.listByTechInfluence(userProfile.getUserId());
List<SubMetric> subMetricList = metricGateway.listByTechInfluence(userProfile.getUserId());
subMetricList.forEach(subMetric -> subMetric.setParent(influenceMetric));
}

private void update(UserProfile userProfile) {
userProfileRepository.update(userProfile);
userProfileGateway.update(userProfile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.alibaba.craftsman.domain.metrics.techinfluence.SharingScope;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.SharingMetricAddCmd;
import com.alibaba.craftsman.repository.MetricRepository;
import com.alibaba.craftsman.domain.gateway.MetricGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

Expand All @@ -23,14 +23,14 @@
public class SharingMetricAddCmdExe{

@Resource
private MetricRepository metricRepository;
private MetricGateway metricGateway;

public Response execute(SharingMetricAddCmd cmd) {
SharingMetricItem sharingMetricItem = new SharingMetricItem();
BeanUtils.copyProperties(cmd.getSharingMetricCO(), sharingMetricItem);
sharingMetricItem.setSubMetric(new SharingMetric(new InfluenceMetric(new UserProfile(cmd.getSharingMetricCO().getOwnerId()))));
sharingMetricItem.setSharingScope(SharingScope.valueOf(cmd.getSharingMetricCO().getSharingScope()));
metricRepository.save(sharingMetricItem);
metricGateway.save(sharingMetricItem);
return Response.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.alibaba.craftsman.convertor.UserProfileConvertor;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.UserProfileAddCmd;
import com.alibaba.craftsman.repository.UserProfileRepository;
import com.alibaba.craftsman.domain.gateway.UserProfileGateway;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
Expand All @@ -19,11 +19,11 @@
public class UserProfileAddCmdExe{

@Resource
private UserProfileRepository userProfileRepository;
private UserProfileGateway userProfileGateway;

public Response execute(UserProfileAddCmd cmd) {
UserProfile userProfile = UserProfileConvertor.toEntity(cmd.getUserProfileCO());
userProfileRepository.create(userProfile);
userProfileGateway.create(userProfile);
return Response.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.alibaba.craftsman.convertor.UserProfileConvertor;
import com.alibaba.craftsman.domain.user.UserProfile;
import com.alibaba.craftsman.dto.UserProfileUpdateCmd;
import com.alibaba.craftsman.repository.UserProfileRepository;
import com.alibaba.craftsman.domain.gateway.UserProfileGateway;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
Expand All @@ -13,11 +13,11 @@
public class UserProfileUpdateCmdExe{

@Resource
private UserProfileRepository userProfileRepository;
private UserProfileGateway userProfileGateway;

public Response execute(UserProfileUpdateCmd cmd) {
UserProfile userProfile = UserProfileConvertor.toEntity(cmd.getUserProfileCO());
userProfileRepository.update(userProfile);
userProfileGateway.update(userProfile);
return Response.buildSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.alibaba.craftsman.domain.metrics.SubMetricType;
import com.alibaba.craftsman.dto.ATAMetricQry;
import com.alibaba.craftsman.dto.clientobject.ATAMetricCO;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import com.alibaba.craftsman.tunnel.database.dataobject.MetricDO;
import com.alibaba.craftsman.gatewayimpl.database.MetricMapper;
import com.alibaba.craftsman.gatewayimpl.database.dataobject.MetricDO;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Component;

Expand All @@ -17,10 +17,10 @@
public class ATAMetricQryExe{

@Resource
private MetricTunnel metricTunnel;
private MetricMapper metricMapper;

public MultiResponse<ATAMetricCO> execute(ATAMetricQry cmd) {
List<MetricDO> metricDOList = metricTunnel.listBySubMetric(cmd.getOwnerId(), SubMetricType.ATA.getMetricSubTypeCode());
List<MetricDO> metricDOList = metricMapper.listBySubMetric(cmd.getOwnerId(), SubMetricType.ATA.getMetricSubTypeCode());
List<ATAMetricCO> ataMetricCOList = new ArrayList<>();
metricDOList.forEach(metricDO -> {
ATAMetricCO ataMetricCO = JSON.parseObject(metricDO.getMetricItem(), ATAMetricCO.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.craftsman.dto.UserProfileGetQry;
import com.alibaba.craftsman.dto.clientobject.UserProfileCO;
import com.alibaba.craftsman.tunnel.database.UserProfileTunnel;
import com.alibaba.craftsman.tunnel.database.dataobject.UserProfileDO;
import com.alibaba.craftsman.gatewayimpl.database.UserProfileMapper;
import com.alibaba.craftsman.gatewayimpl.database.dataobject.UserProfileDO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

Expand All @@ -14,10 +14,10 @@
public class UserProfileGetQryExe {

@Resource
private UserProfileTunnel userProfileTunnel;
private UserProfileMapper userProfileMapper;

public SingleResponse<UserProfileCO> execute(UserProfileGetQry qry) {
UserProfileDO userProfileDO = userProfileTunnel.getByUserId(qry.getUserId());
UserProfileDO userProfileDO = userProfileMapper.getByUserId(qry.getUserId());
UserProfileCO userProfileCO = new UserProfileCO();
BeanUtils.copyProperties(userProfileDO, userProfileCO);
return SingleResponse.of(userProfileCO);
Expand Down
Loading

0 comments on commit b4fc71d

Please sign in to comment.