use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.
the class ItemService method getNamespaceId.
private long getNamespaceId(NamespaceIdentifier namespaceIdentifier) {
String appId = namespaceIdentifier.getAppId();
String clusterName = namespaceIdentifier.getClusterName();
String namespaceName = namespaceIdentifier.getNamespaceName();
Env env = namespaceIdentifier.getEnv();
NamespaceDTO namespaceDTO;
try {
namespaceDTO = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new BadRequestException(String.format("namespace not exist. appId:%s, env:%s, clusterName:%s, namespaceName:%s", appId, env, clusterName, namespaceName));
}
throw e;
}
return namespaceDTO.getId();
}
use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.
the class AppService method updateAppInLocal.
@Transactional
public App updateAppInLocal(App app) {
String appId = app.getAppId();
App managedApp = appRepository.findByAppId(appId);
if (managedApp == null) {
throw new BadRequestException(String.format("App not exists. AppId = %s", appId));
}
managedApp.setName(app.getName());
managedApp.setOrgId(app.getOrgId());
managedApp.setOrgName(app.getOrgName());
String ownerName = app.getOwnerName();
UserInfo owner = userService.findByUserId(ownerName);
if (owner == null) {
throw new BadRequestException(String.format("App's owner not exists. owner = %s", ownerName));
}
managedApp.setOwnerName(owner.getUserId());
managedApp.setOwnerEmail(owner.getEmail());
String operator = userInfoHolder.getUser().getUserId();
managedApp.setDataChangeLastModifiedBy(operator);
return appRepository.save(managedApp);
}
use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.
the class AppNamespaceService method importAppNamespaceInLocal.
@Transactional
public AppNamespace importAppNamespaceInLocal(AppNamespace appNamespace) {
// globally uniqueness check for public app namespace
if (appNamespace.isPublic()) {
checkAppNamespaceGlobalUniqueness(appNamespace);
} else {
// check private app namespace
if (appNamespaceRepository.findByAppIdAndName(appNamespace.getAppId(), appNamespace.getName()) != null) {
throw new BadRequestException("Private AppNamespace " + appNamespace.getName() + " already exists!");
}
// should not have the same with public app namespace
checkPublicAppNamespaceGlobalUniqueness(appNamespace);
}
AppNamespace createdAppNamespace = appNamespaceRepository.save(appNamespace);
String operator = appNamespace.getDataChangeCreatedBy();
roleInitializationService.initNamespaceRoles(appNamespace.getAppId(), appNamespace.getName(), operator);
roleInitializationService.initNamespaceEnvRoles(appNamespace.getAppId(), appNamespace.getName(), operator);
return createdAppNamespace;
}
use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.
the class AppNamespaceService method createDefaultAppNamespace.
@Transactional
public void createDefaultAppNamespace(String appId) {
if (!isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {
throw new BadRequestException(String.format("App already has application namespace. AppId = %s", appId));
}
AppNamespace appNs = new AppNamespace();
appNs.setAppId(appId);
appNs.setName(ConfigConsts.NAMESPACE_APPLICATION);
appNs.setComment("default app namespace");
appNs.setFormat(ConfigFileFormat.Properties.getValue());
String userId = userInfoHolder.getUser().getUserId();
appNs.setDataChangeCreatedBy(userId);
appNs.setDataChangeLastModifiedBy(userId);
appNamespaceRepository.save(appNs);
}
use of com.ctrip.framework.apollo.common.exception.BadRequestException in project apollo by ctripcorp.
the class AppNamespaceService method checkAppNamespaceGlobalUniqueness.
private void checkAppNamespaceGlobalUniqueness(AppNamespace appNamespace) {
checkPublicAppNamespaceGlobalUniqueness(appNamespace);
List<AppNamespace> privateAppNamespaces = findAllPrivateAppNamespaces(appNamespace.getName());
if (!CollectionUtils.isEmpty(privateAppNamespaces)) {
Set<String> appIds = Sets.newHashSet();
for (AppNamespace ans : privateAppNamespaces) {
appIds.add(ans.getAppId());
if (appIds.size() == PRIVATE_APP_NAMESPACE_NOTIFICATION_COUNT) {
break;
}
}
throw new BadRequestException("Public AppNamespace " + appNamespace.getName() + " already exists as private AppNamespace in appId: " + APP_NAMESPACE_JOINER.join(appIds) + ", etc. Please select another name!");
}
}
Aggregations