Search in sources :

Example 1 with BaseDto

use of com.netflix.metacat.common.dto.BaseDto in project metacat by Netflix.

the class MetadataService method deleteDefinitionMetadata.

/**
 * Deletes definition metadata for the given <code>name</code>.
 *
 * @param name                  qualified name
 * @param force                 If true, deletes the metadata without checking if database/table/partition exists
 * @param metacatRequestContext request context
 * @return true if deleted
 */
public boolean deleteDefinitionMetadata(final QualifiedName name, final boolean force, final MetacatRequestContext metacatRequestContext) {
    try {
        final MetacatService service = this.helper.getService(name);
        BaseDto dto = null;
        if (!force) {
            try {
                dto = service.get(name);
            } catch (final NotFoundException ignored) {
            }
        }
        if ((force || dto == null) && !"rds".equalsIgnoreCase(name.getCatalogName())) {
            if (dto != null) {
                this.helper.postPreUpdateEvent(name, metacatRequestContext, dto);
            } else {
                this.helper.postPreDeleteEvent(name, metacatRequestContext);
            }
            this.userMetadataService.deleteDefinitionMetadata(Lists.newArrayList(name));
            this.tagService.delete(name, false);
            log.info("Deleted definition metadata for {}", name);
            if (dto != null) {
                final BaseDto newDto = service.get(name);
                this.helper.postPostUpdateEvent(name, metacatRequestContext, dto, newDto);
            } else {
                this.helper.postPostDeleteEvent(name, metacatRequestContext);
            }
            return true;
        }
    } catch (Exception e) {
        log.warn("Failed deleting definition metadata for name {}.", name, e);
        throw e;
    }
    return false;
}
Also used : NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) BaseDto(com.netflix.metacat.common.dto.BaseDto) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException)

Example 2 with BaseDto

use of com.netflix.metacat.common.dto.BaseDto in project metacat by Netflix.

the class MetadataV1Resource method deleteDefinitionMetadata.

/**
     * {@inheritDoc}
     */
@Override
public void deleteDefinitionMetadata(final QualifiedName name, final Boolean force) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    requestWrapper.processRequest("deleteDefinitionMetadata", () -> {
        final MetacatService service = helper.getService(name);
        BaseDto dto = null;
        try {
            dto = service.get(name);
        } catch (NotFoundException ignored) {
        }
        if ((force || dto == null) && !"rds".equalsIgnoreCase(name.getCatalogName())) {
            helper.postPreUpdateEvent(name, metacatRequestContext, dto);
            userMetadataService.deleteDefinitionMetadatas(Lists.newArrayList(name));
            if (dto instanceof HasDefinitionMetadata) {
                ((HasDefinitionMetadata) dto).setDefinitionMetadata(null);
            }
            final BaseDto newDto = service.get(name);
            helper.postPostUpdateEvent(name, metacatRequestContext, dto, newDto);
        }
        return null;
    });
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatService(com.netflix.metacat.main.services.MetacatService) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) BaseDto(com.netflix.metacat.common.dto.BaseDto) HasDefinitionMetadata(com.netflix.metacat.common.dto.HasDefinitionMetadata)

Aggregations

BaseDto (com.netflix.metacat.common.dto.BaseDto)2 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)2 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)1 HasDefinitionMetadata (com.netflix.metacat.common.dto.HasDefinitionMetadata)1 MetacatService (com.netflix.metacat.main.services.MetacatService)1