Search in sources :

Example 1 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class ItemController method updateItem.

@PreAuthorize(value = "@consumerPermissionValidator.hasModifyNamespacePermission(#request, #appId, #namespaceName)")
@RequestMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key:.+}", method = RequestMethod.PUT)
public void updateItem(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String key, @RequestBody OpenItemDTO item, HttpServletRequest request) {
    RequestPrecondition.checkArguments(item != null, "item payload can not be empty");
    RequestPrecondition.checkArguments(!StringUtils.isContainEmpty(item.getKey(), item.getValue(), item.getDataChangeLastModifiedBy()), "key,value,dataChangeLastModifiedBy can not be empty");
    RequestPrecondition.checkArguments(item.getKey().equals(key), "Key in path and payload is not consistent");
    if (userService.findByUserId(item.getDataChangeLastModifiedBy()) == null) {
        throw new BadRequestException("user(dataChangeLastModifiedBy) not exists");
    }
    ItemDTO toUpdateItem = itemService.loadItem(Env.fromString(env), appId, clusterName, namespaceName, item.getKey());
    if (toUpdateItem == null) {
        throw new BadRequestException("item not exists");
    }
    // protect. only value,comment,lastModifiedBy can be modified
    toUpdateItem.setComment(item.getComment());
    toUpdateItem.setValue(item.getValue());
    toUpdateItem.setDataChangeLastModifiedBy(item.getDataChangeLastModifiedBy());
    itemService.updateItem(appId, Env.fromString(env), clusterName, namespaceName, toUpdateItem);
}
Also used : ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO 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 ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class ItemController method deleteItem.

@PreAuthorize(value = "@consumerPermissionValidator.hasModifyNamespacePermission(#request, #appId, #namespaceName, #env)")
@DeleteMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key:.+}")
public void deleteItem(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String key, @RequestParam String operator, HttpServletRequest request) {
    if (userService.findByUserId(operator) == null) {
        throw new BadRequestException("user(operator) not exists");
    }
    ItemDTO toDeleteItem = itemService.loadItem(Env.valueOf(env), appId, clusterName, namespaceName, key);
    if (toDeleteItem == null) {
        throw new BadRequestException("item not exists");
    }
    this.itemOpenApiService.removeItem(appId, env, clusterName, namespaceName, key, operator);
}
Also used : ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class ServerItemOpenApiService method createItem.

@Override
public OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
    ItemDTO toCreate = OpenApiBeanUtils.transformToItemDTO(itemDTO);
    // protect
    toCreate.setLineNum(0);
    toCreate.setId(0);
    toCreate.setDataChangeLastModifiedBy(toCreate.getDataChangeCreatedBy());
    toCreate.setDataChangeLastModifiedTime(null);
    toCreate.setDataChangeCreatedTime(null);
    ItemDTO createdItem = itemService.createItem(appId, Env.valueOf(env), clusterName, namespaceName, toCreate);
    return OpenApiBeanUtils.transformFromItemDTO(createdItem);
}
Also used : OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Example 5 with ItemDTO

use of com.ctrip.framework.apollo.common.dto.ItemDTO in project apollo by ctripcorp.

the class ServerItemOpenApiService method removeItem.

@Override
public void removeItem(String appId, String env, String clusterName, String namespaceName, String key, String operator) {
    ItemDTO toDeleteItem = this.itemService.loadItem(Env.valueOf(env), appId, clusterName, namespaceName, key);
    this.itemService.deleteItem(Env.valueOf(env), toDeleteItem.getId(), operator);
}
Also used : OpenItemDTO(com.ctrip.framework.apollo.openapi.dto.OpenItemDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO)

Aggregations

ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)44 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)14 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)12 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)11 Test (org.junit.Test)11 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 Item (com.ctrip.framework.apollo.biz.entity.Item)6 OpenItemDTO (com.ctrip.framework.apollo.openapi.dto.OpenItemDTO)6 HashMap (java.util.HashMap)6 ItemBO (com.ctrip.framework.apollo.portal.entity.bo.ItemBO)5 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)4 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)4 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Sql (org.springframework.test.context.jdbc.Sql)4 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)3 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)3 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)3 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)3 RestTemplate (org.springframework.web.client.RestTemplate)3