Search in sources :

Example 1 with ItemBO

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;
}
Also used : ItemBO(com.ctrip.framework.apollo.portal.entity.bo.ItemBO) NamespaceBO(com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO)

Example 2 with ItemBO

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;
}
Also used : ItemBO(com.ctrip.framework.apollo.portal.entity.bo.ItemBO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Example 3 with ItemBO

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;
}
Also used : ItemBO(com.ctrip.framework.apollo.portal.entity.bo.ItemBO)

Example 4 with 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;
}
Also used : OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) ItemBO(com.ctrip.framework.apollo.portal.entity.bo.ItemBO) OpenNamespaceDTO(com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO) LinkedList(java.util.LinkedList)

Aggregations

ItemBO (com.ctrip.framework.apollo.portal.entity.bo.ItemBO)4 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)2 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)1 OpenItemDTO (com.ctrip.framework.apollo.openapi.dto.OpenItemDTO)1 OpenNamespaceDTO (com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO)1 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)1 LinkedList (java.util.LinkedList)1