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