private Set setResourceTags()

in metacat-main/src/main/java/com/netflix/metacat/main/api/v1/TagController.java [224:303]


    private Set<String> setResourceTags(@NonNull final TagCreateRequestDto tagCreateRequestDto) {
        final QualifiedName name = tagCreateRequestDto.getName();
        final Set<String> tags = new HashSet<>(tagCreateRequestDto.getTags());
        final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
        Set<String> result = new HashSet<>();
        switch (name.getType()) {
            case CATALOG:
                //catalog service will throw exception if not found
                this.catalogService.get(name, GetCatalogServiceParameters.builder()
                    .includeDatabaseNames(false).includeUserMetadata(false).build());
                return this.tagService.setTags(name, tags, true);
            case DATABASE:
                if (!this.databaseService.exists(name)) {
                    throw new DatabaseNotFoundException(name);
                }
                result = this.tagService.setTags(name, tags, true);
                this.eventBus.post(
                    new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this)
                );
                return result;
            case TABLE:
                if (!this.tableService.exists(name)) {
                    throw new TableNotFoundException(name);
                }
                final TableDto oldTable = this.tableService
                    .get(name, GetTableServiceParameters.builder()
                        .includeInfo(true)
                        .includeDataMetadata(true)
                        .includeDefinitionMetadata(true)
                        .disableOnReadMetadataIntercetor(false)
                        .build())
                    .orElseThrow(IllegalStateException::new);
                result = this.tagService.setTags(name, tags, true);
                final TableDto currentTable = this.tableService
                    .get(name, GetTableServiceParameters.builder()
                        .includeInfo(true)
                        .includeDataMetadata(true)
                        .includeDefinitionMetadata(true)
                        .disableOnReadMetadataIntercetor(false)
                        .build())
                    .orElseThrow(IllegalStateException::new);
                this.eventBus.post(
                    new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable)
                );
                return result;
            case MVIEW:
                if (!this.mViewService.exists(name)) {
                    throw new MetacatNotFoundException(name.toString());
                }
                final Optional<TableDto> oldView = this.mViewService.getOpt(name, GetTableServiceParameters.builder()
                    .includeInfo(true)
                    .includeDataMetadata(true)
                    .includeDefinitionMetadata(true)
                    .disableOnReadMetadataIntercetor(false)
                    .build()
                );
                if (oldView.isPresent()) {
                    result = this.tagService.setTags(name, tags, true);
                    final Optional<TableDto> currentView = this.mViewService
                        .getOpt(name, GetTableServiceParameters.builder()
                            .includeInfo(true)
                            .includeDataMetadata(true)
                            .includeDefinitionMetadata(true)
                            .disableOnReadMetadataIntercetor(false)
                            .build());
                    currentView.ifPresent(p ->
                        this.eventBus.post(
                            new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldView.get(),
                                currentView.get())
                        )
                    );
                    return result;
                }
                break;
            default:
                throw new MetacatNotFoundException("Unsupported qualifiedName type {}" + name);

        }
        return result;
    }