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;
}
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;
}
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;
}
}
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;
}
}
Aggregations