From bc9aa725932d769856ca0dffa0ec9a8df7b44427 Mon Sep 17 00:00:00 2001 From: lepdou Date: Tue, 7 Jun 2016 15:11:43 +0800 Subject: [PATCH] fix datachange create by --- .../ctrip/framework/apollo/biz/service/ItemSetService.java | 7 ++++--- .../com/ctrip/framework/apollo/common/utils/BeanUtils.java | 4 ++-- .../portal/controller/PortalServerConfigController.java | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java index d98960de5..cb3a06012 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java @@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.biz.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Item; @@ -23,7 +24,7 @@ public class ItemSetService { @Transactional public void updateSet(ItemChangeSets changeSet) { String owner = changeSet.getDataChangeLastModifiedBy(); - if (changeSet.getCreateItems() != null) { + if (!CollectionUtils.isEmpty(changeSet.getCreateItems())) { for (ItemDTO item : changeSet.getCreateItems()) { Item entity = BeanUtils.transfrom(Item.class, item); entity.setDataChangeCreatedBy(owner); @@ -33,7 +34,7 @@ public class ItemSetService { auditService.audit("ItemSet", null, Audit.OP.INSERT, owner); } - if (changeSet.getUpdateItems() != null) { + if (!CollectionUtils.isEmpty(changeSet.getUpdateItems())) { for (ItemDTO item : changeSet.getUpdateItems()) { Item entity = BeanUtils.transfrom(Item.class, item); Item managedItem = itemRepository.findOne(entity.getId()); @@ -44,7 +45,7 @@ public class ItemSetService { auditService.audit("ItemSet", null, Audit.OP.UPDATE, owner); } - if (changeSet.getDeleteItems() != null) { + if (!CollectionUtils.isEmpty(changeSet.getDeleteItems())) { for (ItemDTO item : changeSet.getDeleteItems()) { Item entity = BeanUtils.transfrom(Item.class, item); entity.setDataChangeLastModifiedBy(owner); diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/BeanUtils.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/BeanUtils.java index ff2bee8ab..4bc0c6e74 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/BeanUtils.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/BeanUtils.java @@ -218,7 +218,7 @@ public class BeanUtils { /** * The copy will ignore BaseEntity field - * + * * @param source * @param target */ @@ -226,5 +226,5 @@ public class BeanUtils { org.springframework.beans.BeanUtils.copyProperties(source, target, COPY_IGNORED_PROPERTIES); } - private static final String[] COPY_IGNORED_PROPERTIES = {"id", "dataChangeCreatedTime", "dataChangeLastModifiedTime"}; + private static final String[] COPY_IGNORED_PROPERTIES = {"id", "dataChangeCreatedBy", "dataChangeCreatedTime", "dataChangeLastModifiedTime"}; } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalServerConfigController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalServerConfigController.java index cb1922e25..e3b2c6373 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalServerConfigController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalServerConfigController.java @@ -4,6 +4,7 @@ package com.ctrip.framework.apollo.portal.controller; import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.core.exception.BadRequestException; import com.ctrip.framework.apollo.core.utils.StringUtils; +import com.ctrip.framework.apollo.portal.auth.UserInfoHolder; import com.ctrip.framework.apollo.portal.entity.po.ServerConfig; import com.ctrip.framework.apollo.portal.repository.ServerConfigRepository; @@ -21,6 +22,8 @@ public class PortalServerConfigController { @Autowired private ServerConfigRepository serverConfigRepository; + @Autowired + private UserInfoHolder userInfoHolder; @RequestMapping(value = "/server/config", method = RequestMethod.POST) public ServerConfig createOrUpdate(@RequestBody ServerConfig serverConfig) { @@ -29,8 +32,7 @@ public class PortalServerConfigController { throw new BadRequestException("request payload contains empty"); } - // TODO: 16/6/2 接入sso之后改成当前登录用户 - String modifiedBy = "admin"; + String modifiedBy = userInfoHolder.getUser().getUsername(); ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey()); -- GitLab