Search in sources :

Example 71 with BadRequestException

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

the class AppNamespaceService method deleteAppNamespace.

@Transactional
public AppNamespace deleteAppNamespace(String appId, String namespaceName) {
    AppNamespace appNamespace = appNamespaceRepository.findByAppIdAndName(appId, namespaceName);
    if (appNamespace == null) {
        throw new BadRequestException(String.format("AppNamespace not exists. AppId = %s, NamespaceName = %s", appId, namespaceName));
    }
    String operator = userInfoHolder.getUser().getUserId();
    // this operator is passed to com.ctrip.framework.apollo.portal.listener.DeletionListener.onAppNamespaceDeletionEvent
    appNamespace.setDataChangeLastModifiedBy(operator);
    // delete app namespace in portal db
    appNamespaceRepository.delete(appId, namespaceName, operator);
    // delete Permission and Role related data
    rolePermissionService.deleteRolePermissionsByAppIdAndNamespace(appId, namespaceName, operator);
    return appNamespace;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Transactional(org.springframework.transaction.annotation.Transactional)

Example 72 with BadRequestException

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

the class ClusterService method createCluster.

public ClusterDTO createCluster(Env env, ClusterDTO cluster) {
    if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, cluster.getName())) {
        throw new BadRequestException(String.format("cluster %s already exists.", cluster.getName()));
    }
    ClusterDTO clusterDTO = clusterAPI.create(env, cluster);
    Tracer.logEvent(TracerEventType.CREATE_CLUSTER, cluster.getAppId(), "0", cluster.getName());
    return clusterDTO;
}
Also used : ClusterDTO(com.ctrip.framework.apollo.common.dto.ClusterDTO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException)

Example 73 with BadRequestException

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

the class ConfigFileUtils method getNamespace.

/**
 * <pre>
 *  "application+default+application.properties" -> "application"
 *  "application+default+application.yml" -> "application.yml"
 *  "application+default+application.json" -> "application.json"
 *  "application+default+application.333.yml" -> "application.333.yml"
 * </pre>
 * @throws BadRequestException if file's name is invalid
 */
public static String getNamespace(final String originalFilename) {
    checkThreePart(originalFilename);
    final String[] threeParts = getThreePart(originalFilename);
    final String suffix = threeParts[2];
    if (!suffix.contains(".")) {
        throw new BadRequestException(originalFilename + " namespace and format is invalid!");
    }
    final int lastDotIndex = suffix.lastIndexOf(".");
    final String namespace = suffix.substring(0, lastDotIndex);
    // format after last character '.'
    final String format = suffix.substring(lastDotIndex + 1);
    if (!ConfigFileFormat.isValidFormat(format)) {
        throw new BadRequestException(originalFilename + " format is invalid!");
    }
    ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(format);
    if (configFileFormat.equals(ConfigFileFormat.Properties)) {
        return namespace;
    } else {
        // compatibility of other format
        return namespace + "." + format;
    }
}
Also used : ConfigFileFormat(com.ctrip.framework.apollo.core.enums.ConfigFileFormat) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException)

Example 74 with BadRequestException

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

the class UserInfoControllerTest method testCreateOrUpdateUserFailed.

@Test(expected = BadRequestException.class)
public void testCreateOrUpdateUserFailed() {
    UserPO user = new UserPO();
    user.setUsername("username");
    user.setPassword("password");
    String msg = "fake error message";
    Mockito.when(userPasswordChecker.checkWeakPassword(Mockito.anyString())).thenReturn(new CheckResult(Boolean.FALSE, msg));
    try {
        userInfoController.createOrUpdateUser(user);
    } catch (BadRequestException e) {
        Assert.assertEquals(msg, e.getMessage());
        throw e;
    }
}
Also used : CheckResult(com.ctrip.framework.apollo.portal.util.checker.CheckResult) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) UserPO(com.ctrip.framework.apollo.portal.entity.po.UserPO) Test(org.junit.Test)

Aggregations

BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)74 Transactional (org.springframework.transaction.annotation.Transactional)20 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)16 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)16 PostMapping (org.springframework.web.bind.annotation.PostMapping)14 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)11 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)9 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)8 App (com.ctrip.framework.apollo.common.entity.App)8 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)6 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)6 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)6 Item (com.ctrip.framework.apollo.biz.entity.Item)5 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)4 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)4 AccessKey (com.ctrip.framework.apollo.biz.entity.AccessKey)3 Release (com.ctrip.framework.apollo.biz.entity.Release)3 OpenItemDTO (com.ctrip.framework.apollo.openapi.dto.OpenItemDTO)3