use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class MockBeanFactory method mockAppNamespace.
public static AppNamespace mockAppNamespace(String appId, String name, boolean isPublic) {
AppNamespace instance = new AppNamespace();
instance.setAppId(appId);
instance.setName(name);
instance.setPublic(isPublic);
return instance;
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class ConfigsImportService method importAppNamespace.
private void importAppNamespace(String appNamespace, String operator) {
AppNamespace toImportPubAppNS = gson.fromJson(appNamespace, AppNamespace.class);
String appId = toImportPubAppNS.getAppId();
String namespaceName = toImportPubAppNS.getName();
boolean isPublic = toImportPubAppNS.isPublic();
AppNamespace managedAppNamespace = isPublic ? appNamespaceService.findPublicAppNamespace(namespaceName) : appNamespaceService.findByAppIdAndName(appId, namespaceName);
if (managedAppNamespace == null) {
managedAppNamespace = new AppNamespace();
managedAppNamespace.setAppId(toImportPubAppNS.getAppId());
managedAppNamespace.setPublic(isPublic);
managedAppNamespace.setFormat(toImportPubAppNS.getFormat());
managedAppNamespace.setComment(toImportPubAppNS.getComment());
managedAppNamespace.setDataChangeCreatedBy(operator);
managedAppNamespace.setDataChangeLastModifiedBy(operator);
managedAppNamespace.setName(namespaceName);
AppNamespace createdAppNamespace = appNamespaceService.importAppNamespaceInLocal(managedAppNamespace);
// application namespace will be auto created when creating app
if (!ConfigConsts.NAMESPACE_APPLICATION.equals(namespaceName)) {
publisher.publishEvent(new AppNamespaceCreationEvent(createdAppNamespace));
}
}
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace 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.entity.AppNamespace 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.entity.AppNamespace 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