Commit 49832e6c by Jason Song

fix admin service soft delete

parent 4f69747e
...@@ -30,10 +30,17 @@ public class AppService { ...@@ -30,10 +30,17 @@ public class AppService {
} }
@Transactional @Transactional
public void delete(long id, String owner) { public void delete(long id, String operator) {
appRepository.delete(id); App app = appRepository.findOne(id);
if (app == null) {
return;
}
app.setDeleted(true);
app.setDataChangeLastModifiedBy(operator);
appRepository.save(app);
auditService.audit(App.class.getSimpleName(), id, Audit.OP.DELETE, owner); auditService.audit(App.class.getSimpleName(), id, Audit.OP.DELETE, operator);
} }
public List<App> findAll(Pageable pageable) { public List<App> findAll(Pageable pageable) {
......
...@@ -62,10 +62,17 @@ public class ClusterService { ...@@ -62,10 +62,17 @@ public class ClusterService {
} }
@Transactional @Transactional
public void delete(long id, String owner) { public void delete(long id, String operator) {
clusterRepository.delete(id); Cluster cluster = clusterRepository.findOne(id);
if (cluster == null) {
return;
}
cluster.setDeleted(true);
cluster.setDataChangeLastModifiedBy(operator);
clusterRepository.save(cluster);
auditService.audit(Cluster.class.getSimpleName(), id, Audit.OP.DELETE, owner); auditService.audit(Cluster.class.getSimpleName(), id, Audit.OP.DELETE, operator);
} }
@Transactional @Transactional
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
...@@ -15,6 +8,13 @@ import com.ctrip.framework.apollo.biz.repository.NamespaceRepository; ...@@ -15,6 +8,13 @@ import com.ctrip.framework.apollo.biz.repository.NamespaceRepository;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.exception.NotFoundException; import com.ctrip.framework.apollo.core.exception.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;
@Service @Service
public class ItemService { public class ItemService {
...@@ -28,10 +28,17 @@ public class ItemService { ...@@ -28,10 +28,17 @@ public class ItemService {
private AuditService auditService; private AuditService auditService;
@Transactional @Transactional
public void delete(long id, String owner) { public void delete(long id, String operator) {
itemRepository.delete(id); Item item = itemRepository.findOne(id);
if (item == null) {
return;
}
item.setDeleted(true);
item.setDataChangeLastModifiedBy(operator);
itemRepository.save(item);
auditService.audit(Item.class.getSimpleName(), id, Audit.OP.DELETE, owner); auditService.audit(Item.class.getSimpleName(), id, Audit.OP.DELETE, operator);
} }
public Item findOne(String appId, String clusterName, String namespaceName, String key) { public Item findOne(String appId, String clusterName, String namespaceName, String key) {
......
...@@ -23,15 +23,15 @@ public class ItemSetService { ...@@ -23,15 +23,15 @@ public class ItemSetService {
@Transactional @Transactional
public void updateSet(ItemChangeSets changeSet) { public void updateSet(ItemChangeSets changeSet) {
String owner = changeSet.getDataChangeLastModifiedBy(); String operator = changeSet.getDataChangeLastModifiedBy();
if (!CollectionUtils.isEmpty(changeSet.getCreateItems())) { if (!CollectionUtils.isEmpty(changeSet.getCreateItems())) {
for (ItemDTO item : changeSet.getCreateItems()) { for (ItemDTO item : changeSet.getCreateItems()) {
Item entity = BeanUtils.transfrom(Item.class, item); Item entity = BeanUtils.transfrom(Item.class, item);
entity.setDataChangeCreatedBy(owner); entity.setDataChangeCreatedBy(operator);
entity.setDataChangeLastModifiedBy(owner); entity.setDataChangeLastModifiedBy(operator);
itemRepository.save(entity); itemRepository.save(entity);
} }
auditService.audit("ItemSet", null, Audit.OP.INSERT, owner); auditService.audit("ItemSet", null, Audit.OP.INSERT, operator);
} }
if (!CollectionUtils.isEmpty(changeSet.getUpdateItems())) { if (!CollectionUtils.isEmpty(changeSet.getUpdateItems())) {
...@@ -39,20 +39,20 @@ public class ItemSetService { ...@@ -39,20 +39,20 @@ public class ItemSetService {
Item entity = BeanUtils.transfrom(Item.class, item); Item entity = BeanUtils.transfrom(Item.class, item);
Item managedItem = itemRepository.findOne(entity.getId()); Item managedItem = itemRepository.findOne(entity.getId());
BeanUtils.copyEntityProperties(entity, managedItem); BeanUtils.copyEntityProperties(entity, managedItem);
managedItem.setDataChangeLastModifiedBy(owner); managedItem.setDataChangeLastModifiedBy(operator);
itemRepository.save(managedItem); itemRepository.save(managedItem);
} }
auditService.audit("ItemSet", null, Audit.OP.UPDATE, owner); auditService.audit("ItemSet", null, Audit.OP.UPDATE, operator);
} }
if (!CollectionUtils.isEmpty(changeSet.getDeleteItems())) { if (!CollectionUtils.isEmpty(changeSet.getDeleteItems())) {
for (ItemDTO item : changeSet.getDeleteItems()) { for (ItemDTO item : changeSet.getDeleteItems()) {
Item entity = BeanUtils.transfrom(Item.class, item); Item entity = BeanUtils.transfrom(Item.class, item);
entity.setDataChangeLastModifiedBy(owner); entity.setDeleted(true);
entity.setDataChangeLastModifiedBy(operator);
itemRepository.save(entity); itemRepository.save(entity);
itemRepository.delete(item.getId());
} }
auditService.audit("ItemSet", null, Audit.OP.DELETE, owner); auditService.audit("ItemSet", null, Audit.OP.DELETE, operator);
} }
} }
} }
...@@ -33,10 +33,17 @@ public class NamespaceService { ...@@ -33,10 +33,17 @@ public class NamespaceService {
} }
@Transactional @Transactional
public void delete(long id, String owner) { public void delete(long id, String operator) {
namespaceRepository.delete(id); Namespace namespace = namespaceRepository.findOne(id);
if (namespace == null) {
return;
}
namespace.setDeleted(true);
namespace.setDataChangeLastModifiedBy(operator);
namespaceRepository.save(namespace);
auditService.audit(Namespace.class.getSimpleName(), id, Audit.OP.DELETE, owner); auditService.audit(Namespace.class.getSimpleName(), id, Audit.OP.DELETE, operator);
} }
public Namespace findOne(Long namespaceId) { public Namespace findOne(Long namespaceId) {
......
...@@ -62,7 +62,7 @@ public class GlobalDefaultExceptionHandler { ...@@ -62,7 +62,7 @@ public class GlobalDefaultExceptionHandler {
errorAttributes.put("timestamp", errorAttributes.put("timestamp",
LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
errorAttributes.put("exception", resolveError(ex).getClass().getName()); errorAttributes.put("exception", resolveError(ex).getClass().getName());
errorAttributes.put("stackTrace", ex.getStackTrace()); // errorAttributes.put("stackTrace", ex.getStackTrace());
if (ex instanceof AbstractBaseException) { if (ex instanceof AbstractBaseException) {
errorAttributes.put("errorCode", ((AbstractBaseException) ex).getErrorCode()); errorAttributes.put("errorCode", ((AbstractBaseException) ex).getErrorCode());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment