Search in sources :

Example 1 with AppNamespaceCreationEvent

use of com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent in project apollo by ctripcorp.

the class ServerNamespaceOpenApiService method createAppNamespace.

@Override
public OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDTO) {
    AppNamespace appNamespace = OpenApiBeanUtils.transformToAppNamespace(appNamespaceDTO);
    AppNamespace createdAppNamespace = appNamespaceService.createAppNamespaceInLocal(appNamespace, appNamespaceDTO.isAppendNamespacePrefix());
    publisher.publishEvent(new AppNamespaceCreationEvent(createdAppNamespace));
    return OpenApiBeanUtils.transformToOpenAppNamespaceDTO(createdAppNamespace);
}
Also used : AppNamespaceCreationEvent(com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 2 with AppNamespaceCreationEvent

use of com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent in project apollo by ctripcorp.

the class NamespaceController method createNamespace.

@PreAuthorize(value = "@consumerPermissionValidator.hasCreateNamespacePermission(#request, #appId)")
@RequestMapping(value = "/openapi/v1/apps/{appId}/appnamespaces", method = RequestMethod.POST)
public OpenAppNamespaceDTO createNamespace(@PathVariable String appId, @RequestBody OpenAppNamespaceDTO appNamespaceDTO, HttpServletRequest request) {
    if (!Objects.equals(appId, appNamespaceDTO.getAppId())) {
        throw new BadRequestException(String.format("AppId not equal. AppId in path = %s, AppId in payload = %s", appId, appNamespaceDTO.getAppId()));
    }
    RequestPrecondition.checkArgumentsNotEmpty(appNamespaceDTO.getAppId(), appNamespaceDTO.getName(), appNamespaceDTO.getFormat(), appNamespaceDTO.getDataChangeCreatedBy());
    if (!InputValidator.isValidAppNamespace(appNamespaceDTO.getName())) {
        throw new BadRequestException(String.format("Namespace格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & " + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE));
    }
    if (!ConfigFileFormat.isValidFormat(appNamespaceDTO.getFormat())) {
        throw new BadRequestException(String.format("Invalid namespace format. format = %s", appNamespaceDTO.getFormat()));
    }
    String operator = appNamespaceDTO.getDataChangeCreatedBy();
    if (userService.findByUserId(operator) == null) {
        throw new BadRequestException(String.format("Illegal user. user = %s", operator));
    }
    AppNamespace appNamespace = OpenApiBeanUtils.transformToAppNamespace(appNamespaceDTO);
    AppNamespace createdAppNamespace = appNamespaceService.createAppNamespaceInLocal(appNamespace);
    publisher.publishEvent(new AppNamespaceCreationEvent(createdAppNamespace));
    return OpenApiBeanUtils.transformToOpenAppNamespaceDTO(createdAppNamespace);
}
Also used : AppNamespaceCreationEvent(com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with AppNamespaceCreationEvent

use of com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent in project apollo by ctripcorp.

the class NamespaceController method createAppNamespace.

@PreAuthorize(value = "@permissionValidator.hasCreateAppNamespacePermission(#appId, #appNamespace)")
@RequestMapping(value = "/apps/{appId}/appnamespaces", method = RequestMethod.POST)
public AppNamespace createAppNamespace(@PathVariable String appId, @RequestBody AppNamespace appNamespace) {
    RequestPrecondition.checkArgumentsNotEmpty(appNamespace.getAppId(), appNamespace.getName());
    if (!InputValidator.isValidAppNamespace(appNamespace.getName())) {
        throw new BadRequestException(String.format("Namespace格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & " + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE));
    }
    AppNamespace createdAppNamespace = appNamespaceService.createAppNamespaceInLocal(appNamespace);
    if (portalConfig.canAppAdminCreatePrivateNamespace() || createdAppNamespace.isPublic()) {
        assignNamespaceRoleToOperator(appId, appNamespace.getName());
    }
    publisher.publishEvent(new AppNamespaceCreationEvent(createdAppNamespace));
    return createdAppNamespace;
}
Also used : AppNamespaceCreationEvent(com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with AppNamespaceCreationEvent

use of com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent in project apollo by ctripcorp.

the class NamespaceController method createAppNamespace.

@PreAuthorize(value = "@permissionValidator.hasCreateAppNamespacePermission(#appId, #appNamespace)")
@PostMapping("/apps/{appId}/appnamespaces")
public AppNamespace createAppNamespace(@PathVariable String appId, @RequestParam(defaultValue = "true") boolean appendNamespacePrefix, @Valid @RequestBody AppNamespace appNamespace) {
    if (!InputValidator.isValidAppNamespace(appNamespace.getName())) {
        throw new BadRequestException(String.format("Invalid Namespace format: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & " + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE));
    }
    AppNamespace createdAppNamespace = appNamespaceService.createAppNamespaceInLocal(appNamespace, appendNamespacePrefix);
    if (portalConfig.canAppAdminCreatePrivateNamespace() || createdAppNamespace.isPublic()) {
        namespaceService.assignNamespaceRoleToOperator(appId, appNamespace.getName(), userInfoHolder.getUser().getUserId());
    }
    publisher.publishEvent(new AppNamespaceCreationEvent(createdAppNamespace));
    return createdAppNamespace;
}
Also used : AppNamespaceCreationEvent(com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with AppNamespaceCreationEvent

use of com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent 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)

Aggregations

AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)5 AppNamespaceCreationEvent (com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent)5 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)1