Commit 49832e6c by Jason Song

fix admin service soft delete

parent 4f69747e
......@@ -30,10 +30,17 @@ public class AppService {
}
@Transactional
public void delete(long id, String owner) {
appRepository.delete(id);
public void delete(long id, String operator) {
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) {
......
......@@ -62,10 +62,17 @@ public class ClusterService {
}
@Transactional
public void delete(long id, String owner) {
clusterRepository.delete(id);
public void delete(long id, String operator) {
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
......
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.Item;
import com.ctrip.framework.apollo.biz.entity.Namespace;
......@@ -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.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
public class ItemService {
......@@ -28,10 +28,17 @@ public class ItemService {
private AuditService auditService;
@Transactional
public void delete(long id, String owner) {
itemRepository.delete(id);
public void delete(long id, String operator) {
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) {
......
......@@ -23,15 +23,15 @@ public class ItemSetService {
@Transactional
public void updateSet(ItemChangeSets changeSet) {
String owner = changeSet.getDataChangeLastModifiedBy();
String operator = changeSet.getDataChangeLastModifiedBy();
if (!CollectionUtils.isEmpty(changeSet.getCreateItems())) {
for (ItemDTO item : changeSet.getCreateItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);
entity.setDataChangeCreatedBy(owner);
entity.setDataChangeLastModifiedBy(owner);
entity.setDataChangeCreatedBy(operator);
entity.setDataChangeLastModifiedBy(operator);
itemRepository.save(entity);
}
auditService.audit("ItemSet", null, Audit.OP.INSERT, owner);
auditService.audit("ItemSet", null, Audit.OP.INSERT, operator);
}
if (!CollectionUtils.isEmpty(changeSet.getUpdateItems())) {
......@@ -39,20 +39,20 @@ public class ItemSetService {
Item entity = BeanUtils.transfrom(Item.class, item);
Item managedItem = itemRepository.findOne(entity.getId());
BeanUtils.copyEntityProperties(entity, managedItem);
managedItem.setDataChangeLastModifiedBy(owner);
managedItem.setDataChangeLastModifiedBy(operator);
itemRepository.save(managedItem);
}
auditService.audit("ItemSet", null, Audit.OP.UPDATE, owner);
auditService.audit("ItemSet", null, Audit.OP.UPDATE, operator);
}
if (!CollectionUtils.isEmpty(changeSet.getDeleteItems())) {
for (ItemDTO item : changeSet.getDeleteItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);
entity.setDataChangeLastModifiedBy(owner);
entity.setDeleted(true);
entity.setDataChangeLastModifiedBy(operator);
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 {
}
@Transactional
public void delete(long id, String owner) {
namespaceRepository.delete(id);
public void delete(long id, String operator) {
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) {
......
......@@ -62,7 +62,7 @@ public class GlobalDefaultExceptionHandler {
errorAttributes.put("timestamp",
LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
errorAttributes.put("exception", resolveError(ex).getClass().getName());
errorAttributes.put("stackTrace", ex.getStackTrace());
// errorAttributes.put("stackTrace", ex.getStackTrace());
if (ex instanceof AbstractBaseException) {
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