Search in sources :

Example 36 with BadRequestException

use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.

the class ClusterService method saveWithoutInstanceOfAppNamespaces.

@Transactional
public Cluster saveWithoutInstanceOfAppNamespaces(Cluster entity) {
    if (!isClusterNameUnique(entity.getAppId(), entity.getName())) {
        throw new BadRequestException("cluster not unique");
    }
    // protection
    entity.setId(0);
    Cluster cluster = clusterRepository.save(entity);
    auditService.audit(Cluster.class.getSimpleName(), cluster.getId(), Audit.OP.INSERT, cluster.getDataChangeCreatedBy());
    return cluster;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with BadRequestException

use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.

the class NamespaceService method namespacePublishInfo.

public Map<String, Boolean> namespacePublishInfo(String appId) {
    List<Cluster> clusters = clusterService.findParentClusters(appId);
    if (CollectionUtils.isEmpty(clusters)) {
        throw new BadRequestException("app not exist");
    }
    Map<String, Boolean> clusterHasNotPublishedItems = Maps.newHashMap();
    for (Cluster cluster : clusters) {
        String clusterName = cluster.getName();
        List<Namespace> namespaces = findNamespaces(appId, clusterName);
        for (Namespace namespace : namespaces) {
            boolean isNamespaceNotPublished = isNamespaceNotPublished(namespace);
            if (isNamespaceNotPublished) {
                clusterHasNotPublishedItems.put(clusterName, true);
                break;
            }
        }
        clusterHasNotPublishedItems.putIfAbsent(clusterName, false);
    }
    return clusterHasNotPublishedItems;
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 38 with BadRequestException

use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.

the class ItemController method update.

@PreAcquireNamespaceLock
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}", method = RequestMethod.PUT)
public ItemDTO update(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @PathVariable("itemId") long itemId, @RequestBody ItemDTO itemDTO) {
    Item entity = BeanUtils.transfrom(Item.class, itemDTO);
    ConfigChangeContentBuilder builder = new ConfigChangeContentBuilder();
    Item managedEntity = itemService.findOne(itemId);
    if (managedEntity == null) {
        throw new BadRequestException("item not exist");
    }
    Item beforeUpdateItem = BeanUtils.transfrom(Item.class, managedEntity);
    // protect. only value,comment,lastModifiedBy can be modified
    managedEntity.setValue(entity.getValue());
    managedEntity.setComment(entity.getComment());
    managedEntity.setDataChangeLastModifiedBy(entity.getDataChangeLastModifiedBy());
    entity = itemService.update(managedEntity);
    builder.updateItem(beforeUpdateItem, entity);
    itemDTO = BeanUtils.transfrom(ItemDTO.class, entity);
    if (builder.hasContent()) {
        Commit commit = new Commit();
        commit.setAppId(appId);
        commit.setClusterName(clusterName);
        commit.setNamespaceName(namespaceName);
        commit.setChangeSets(builder.build());
        commit.setDataChangeCreatedBy(itemDTO.getDataChangeLastModifiedBy());
        commit.setDataChangeLastModifiedBy(itemDTO.getDataChangeLastModifiedBy());
        commitService.save(commit);
    }
    return itemDTO;
}
Also used : ConfigChangeContentBuilder(com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder) Item(com.ctrip.framework.apollo.biz.entity.Item) Commit(com.ctrip.framework.apollo.biz.entity.Commit) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) PreAcquireNamespaceLock(com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with BadRequestException

use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.

the class NamespaceBranchController method checkBranch.

private void checkBranch(String appId, String clusterName, String namespaceName, String branchName) {
    // 1. check parent namespace
    checkNamespace(appId, clusterName, namespaceName);
    // 2. check child namespace
    Namespace childNamespace = namespaceService.findOne(appId, branchName, namespaceName);
    if (childNamespace == null) {
        throw new BadRequestException(String.format("Namespace's branch not exist. AppId = %s, ClusterName = %s, " + "NamespaceName = %s, BranchName = %s", appId, clusterName, namespaceName, branchName));
    }
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace)

Example 40 with BadRequestException

use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.

the class ConsumerService method assignAppRoleToConsumer.

@Transactional
public ConsumerRole assignAppRoleToConsumer(String token, String appId) {
    Long consumerId = getConsumerIdByToken(token);
    if (consumerId == null) {
        throw new BadRequestException("Token is Illegal");
    }
    Role masterRole = rolePermissionService.findRoleByRoleName(RoleUtils.buildAppMasterRoleName(appId));
    if (masterRole == null) {
        throw new BadRequestException("App's role does not exist. Please check whether app has created.");
    }
    long roleId = masterRole.getId();
    ConsumerRole managedModifyRole = consumerRoleRepository.findByConsumerIdAndRoleId(consumerId, roleId);
    if (managedModifyRole != null) {
        return managedModifyRole;
    }
    String operator = userInfoHolder.getUser().getUserId();
    ConsumerRole consumerRole = createConsumerRole(consumerId, roleId, operator);
    return consumerRoleRepository.save(consumerRole);
}
Also used : Role(com.ctrip.framework.apollo.portal.entity.po.Role) ConsumerRole(com.ctrip.framework.apollo.openapi.entity.ConsumerRole) ConsumerRole(com.ctrip.framework.apollo.openapi.entity.ConsumerRole) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)46 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 Transactional (org.springframework.transaction.annotation.Transactional)12 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)9 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)7 App (com.ctrip.framework.apollo.common.entity.App)6 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)5 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)5 Item (com.ctrip.framework.apollo.biz.entity.Item)4 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)4 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)3 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)3 OpenItemDTO (com.ctrip.framework.apollo.openapi.dto.OpenItemDTO)3 ConfigPublishEvent (com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent)3 PreAcquireNamespaceLock (com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)2 Commit (com.ctrip.framework.apollo.biz.entity.Commit)2 NamespaceLock (com.ctrip.framework.apollo.biz.entity.NamespaceLock)2 Release (com.ctrip.framework.apollo.biz.entity.Release)2