use of com.ctrip.framework.apollo.portal.entity.bo.ItemBO in project apollo by ctripcorp.
the class NamespaceService method transformNamespace2BO.
private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) {
NamespaceBO namespaceBO = new NamespaceBO();
namespaceBO.setBaseInfo(namespace);
String appId = namespace.getAppId();
String clusterName = namespace.getClusterName();
String namespaceName = namespace.getNamespaceName();
fillAppNamespaceProperties(namespaceBO);
List<ItemBO> itemBOs = new LinkedList<>();
namespaceBO.setItems(itemBOs);
// latest Release
ReleaseDTO latestRelease;
Map<String, String> releaseItems = new HashMap<>();
latestRelease = releaseService.loadLatestRelease(appId, env, clusterName, namespaceName);
if (latestRelease != null) {
releaseItems = gson.fromJson(latestRelease.getConfigurations(), GsonType.CONFIG);
}
// not Release config items
List<ItemDTO> items = itemService.findItems(appId, env, clusterName, namespaceName);
int modifiedItemCnt = 0;
for (ItemDTO itemDTO : items) {
ItemBO itemBO = transformItem2BO(itemDTO, releaseItems);
if (itemBO.isModified()) {
modifiedItemCnt++;
}
itemBOs.add(itemBO);
}
// deleted items
List<ItemBO> deletedItems = parseDeletedItems(items, releaseItems);
itemBOs.addAll(deletedItems);
modifiedItemCnt += deletedItems.size();
namespaceBO.setItemModifiedCnt(modifiedItemCnt);
return namespaceBO;
}
use of com.ctrip.framework.apollo.portal.entity.bo.ItemBO in project apollo by ctripcorp.
the class NamespaceService method parseDeletedItems.
private List<ItemBO> parseDeletedItems(List<ItemDTO> newItems, Map<String, String> releaseItems) {
Map<String, ItemDTO> newItemMap = BeanUtils.mapByKey("key", newItems);
List<ItemBO> deletedItems = new LinkedList<>();
for (Map.Entry<String, String> entry : releaseItems.entrySet()) {
String key = entry.getKey();
if (newItemMap.get(key) == null) {
ItemBO deletedItem = new ItemBO();
deletedItem.setDeleted(true);
ItemDTO deletedItemDto = new ItemDTO();
deletedItemDto.setKey(key);
String oldValue = entry.getValue();
deletedItem.setItem(deletedItemDto);
deletedItemDto.setValue(oldValue);
deletedItem.setModified(true);
deletedItem.setOldValue(oldValue);
deletedItem.setNewValue("");
deletedItems.add(deletedItem);
}
}
return deletedItems;
}
use of com.ctrip.framework.apollo.portal.entity.bo.ItemBO in project apollo by ctripcorp.
the class NamespaceService method transformItem2BO.
private ItemBO transformItem2BO(ItemDTO itemDTO, Map<String, String> releaseItems) {
String key = itemDTO.getKey();
ItemBO itemBO = new ItemBO();
itemBO.setItem(itemDTO);
String newValue = itemDTO.getValue();
String oldValue = releaseItems.get(key);
// new item or modified
if (!StringUtils.isEmpty(key) && (oldValue == null || !newValue.equals(oldValue))) {
itemBO.setModified(true);
itemBO.setOldValue(oldValue == null ? "" : oldValue);
itemBO.setNewValue(newValue);
}
return itemBO;
}
use of com.ctrip.framework.apollo.portal.entity.bo.ItemBO in project apollo by ctripcorp.
the class OpenApiBeanUtils method transformFromNamespaceBO.
public static OpenNamespaceDTO transformFromNamespaceBO(NamespaceBO namespaceBO) {
Preconditions.checkArgument(namespaceBO != null);
OpenNamespaceDTO openNamespaceDTO = BeanUtils.transfrom(OpenNamespaceDTO.class, namespaceBO.getBaseInfo());
// app namespace info
openNamespaceDTO.setFormat(namespaceBO.getFormat());
openNamespaceDTO.setComment(namespaceBO.getComment());
openNamespaceDTO.setPublic(namespaceBO.isPublic());
// items
List<OpenItemDTO> items = new LinkedList<>();
List<ItemBO> itemBOs = namespaceBO.getItems();
if (!CollectionUtils.isEmpty(itemBOs)) {
items.addAll(itemBOs.stream().map(itemBO -> transformFromItemDTO(itemBO.getItem())).collect(Collectors.toList()));
}
openNamespaceDTO.setItems(items);
return openNamespaceDTO;
}
Aggregations