Search in sources :

Example 56 with AppNamespace

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;
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 57 with AppNamespace

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));
        }
    }
}
Also used : AppNamespaceCreationEvent(com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 58 with AppNamespace

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;
}
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 59 with AppNamespace

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);
}
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 60 with AppNamespace

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!");
    }
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Aggregations

AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)71 Test (org.junit.Test)32 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)15 Sql (org.springframework.test.context.jdbc.Sql)13 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)11 Transactional (org.springframework.transaction.annotation.Transactional)9 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)7 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)6 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 AppNamespaceCreationEvent (com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)3 App (com.ctrip.framework.apollo.common.entity.App)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Release (com.ctrip.framework.apollo.biz.entity.Release)2 AppNamespaceDTO (com.ctrip.framework.apollo.common.dto.AppNamespaceDTO)2 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2