Search in sources :

Example 1 with MetacatCreateTablePreEvent

use of com.netflix.metacat.common.server.events.MetacatCreateTablePreEvent in project metacat by Netflix.

the class TableServiceImpl method create.

@Override
public TableDto create(@Nonnull final QualifiedName name, @Nonnull final TableDto tableDto) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    validate(name);
    //
    // Set the owner,if null, with the session user name.
    //
    setOwnerIfNull(tableDto, metacatRequestContext.getUserName());
    log.info("Creating table {}", name);
    eventBus.postSync(new MetacatCreateTablePreEvent(name, metacatRequestContext, this, tableDto));
    final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
    final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
    service.create(connectorContext, converterUtil.fromTableDto(tableDto));
    if (tableDto.getDataMetadata() != null || tableDto.getDefinitionMetadata() != null) {
        log.info("Saving user metadata for table {}", name);
        userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, false);
        tag(name, tableDto.getDefinitionMetadata());
    }
    final TableDto dto = get(name, true).orElseThrow(() -> new IllegalStateException("Should exist"));
    eventBus.postAsync(new MetacatCreateTablePostEvent(name, metacatRequestContext, this, dto));
    return dto;
}
Also used : MetacatCreateTablePreEvent(com.netflix.metacat.common.server.events.MetacatCreateTablePreEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatCreateTablePostEvent(com.netflix.metacat.common.server.events.MetacatCreateTablePostEvent) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) TableDto(com.netflix.metacat.common.dto.TableDto)

Aggregations

MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)1 TableDto (com.netflix.metacat.common.dto.TableDto)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)1 MetacatCreateTablePostEvent (com.netflix.metacat.common.server.events.MetacatCreateTablePostEvent)1 MetacatCreateTablePreEvent (com.netflix.metacat.common.server.events.MetacatCreateTablePreEvent)1