use of com.netflix.metacat.common.dto.HasDefinitionMetadata in project metacat by Netflix.
the class BaseUserMetadataService method populateMetadata.
/**
* Populate the given metadata.
*
* @param holder metadata
*/
@Override
public void populateMetadata(final HasMetadata holder) {
Optional<ObjectNode> metadata = Optional.empty();
if (holder instanceof HasDataMetadata) {
final HasDataMetadata dataDto = (HasDataMetadata) holder;
if (dataDto.isDataExternal()) {
metadata = getDataMetadata(dataDto.getDataUri());
}
}
Optional<ObjectNode> definitionMetadata = Optional.empty();
if (holder instanceof HasDefinitionMetadata) {
final HasDefinitionMetadata definitionDto = (HasDefinitionMetadata) holder;
definitionMetadata = getDefinitionMetadata(definitionDto.getDefinitionName());
}
populateMetadata(holder, definitionMetadata.orElse(null), metadata.orElse(null));
}
use of com.netflix.metacat.common.dto.HasDefinitionMetadata in project metacat by Netflix.
the class MysqlUserMetadataService method deleteMetadatas.
@Override
public void deleteMetadatas(final String userId, final List<HasMetadata> holders) {
try {
final Connection conn = poolingDataSource.getConnection();
try {
final List<List<HasMetadata>> subLists = Lists.partition(holders, config.getUserMetadataMaxInClauseItems());
for (List<HasMetadata> hasMetadatas : subLists) {
final List<QualifiedName> names = hasMetadatas.stream().filter(m -> m instanceof HasDefinitionMetadata).map(m -> ((HasDefinitionMetadata) m).getDefinitionName()).collect(Collectors.toList());
if (!names.isEmpty()) {
_deleteDefinitionMetadatas(conn, names);
}
if (config.canSoftDeleteDataMetadata()) {
final List<String> uris = hasMetadatas.stream().filter(m -> m instanceof HasDataMetadata && ((HasDataMetadata) m).isDataExternal()).map(m -> ((HasDataMetadata) m).getDataUri()).collect(Collectors.toList());
if (!uris.isEmpty()) {
_softDeleteDataMetadatas(conn, userId, uris);
}
}
}
conn.commit();
} catch (SQLException e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
} catch (SQLException e) {
log.error("Sql exception", e);
throw new UserMetadataServiceException("Failed deleting data metadata", e);
}
}
use of com.netflix.metacat.common.dto.HasDefinitionMetadata 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;
});
}
use of com.netflix.metacat.common.dto.HasDefinitionMetadata in project metacat by Netflix.
the class MysqlUserMetadataService method saveMetadatas.
@Override
public void saveMetadatas(final String user, final List<? extends HasMetadata> metadatas, final boolean merge) {
try {
final Connection conn = poolingDataSource.getConnection();
try {
@SuppressWarnings("unchecked") final List<List<HasMetadata>> subLists = Lists.partition((List<HasMetadata>) metadatas, config.getUserMetadataMaxInClauseItems());
for (List<HasMetadata> hasMetadatas : subLists) {
final List<String> uris = Lists.newArrayList();
final List<QualifiedName> names = Lists.newArrayList();
// Get the names and uris
final List<HasDefinitionMetadata> definitionMetadatas = Lists.newArrayList();
final List<HasDataMetadata> dataMetadatas = Lists.newArrayList();
hasMetadatas.stream().forEach(hasMetadata -> {
if (hasMetadata instanceof HasDefinitionMetadata) {
final HasDefinitionMetadata oDef = (HasDefinitionMetadata) hasMetadata;
names.add(oDef.getDefinitionName());
if (oDef.getDefinitionMetadata() != null) {
definitionMetadatas.add(oDef);
}
}
if (hasMetadata instanceof HasDataMetadata) {
final HasDataMetadata oData = (HasDataMetadata) hasMetadata;
if (oData.isDataExternal() && oData.getDataMetadata() != null && oData.getDataMetadata().size() > 0) {
uris.add(oData.getDataUri());
dataMetadatas.add(oData);
}
}
});
if (!definitionMetadatas.isEmpty() || !dataMetadatas.isEmpty()) {
// Get the existing metadata based on the names and uris
final Map<String, ObjectNode> definitionMap = getDefinitionMetadataMap(names);
final Map<String, ObjectNode> dataMap = getDataMetadataMap(uris);
// Curate the list of existing and new metadatas
final List<Object[]> insertDefinitionMetadatas = Lists.newArrayList();
final List<Object[]> updateDefinitionMetadatas = Lists.newArrayList();
final List<Object[]> insertDataMetadatas = Lists.newArrayList();
final List<Object[]> updateDataMetadatas = Lists.newArrayList();
definitionMetadatas.stream().forEach(oDef -> {
final QualifiedName qualifiedName = oDef.getDefinitionName();
if (qualifiedName != null && oDef.getDefinitionMetadata() != null && oDef.getDefinitionMetadata().size() != 0) {
final String name = qualifiedName.toString();
final ObjectNode oNode = definitionMap.get(name);
if (oNode == null) {
insertDefinitionMetadatas.add(new Object[] { metacatJson.toJsonString(oDef.getDefinitionMetadata()), user, user, name });
} else {
metacatJson.mergeIntoPrimary(oNode, oDef.getDefinitionMetadata());
updateDefinitionMetadatas.add(new Object[] { metacatJson.toJsonString(oNode), user, name });
}
}
});
dataMetadatas.stream().forEach(oData -> {
final String uri = oData.getDataUri();
final ObjectNode oNode = dataMap.get(uri);
if (oData.getDataMetadata() != null && oData.getDataMetadata().size() != 0) {
if (oNode == null) {
insertDataMetadatas.add(new Object[] { metacatJson.toJsonString(oData.getDataMetadata()), user, user, uri });
} else {
metacatJson.mergeIntoPrimary(oNode, oData.getDataMetadata());
updateDataMetadatas.add(new Object[] { metacatJson.toJsonString(oNode), user, uri });
}
}
});
//Now run the queries
final QueryRunner runner = new QueryRunner();
if (!insertDefinitionMetadatas.isEmpty()) {
runner.batch(conn, SQL.INSERT_DEFINITION_METADATA, insertDefinitionMetadatas.toArray(new Object[insertDefinitionMetadatas.size()][4]));
}
if (!updateDefinitionMetadatas.isEmpty()) {
runner.batch(conn, SQL.UPDATE_DEFINITION_METADATA, updateDefinitionMetadatas.toArray(new Object[updateDefinitionMetadatas.size()][3]));
}
if (!insertDataMetadatas.isEmpty()) {
runner.batch(conn, SQL.INSERT_DATA_METADATA, insertDataMetadatas.toArray(new Object[insertDataMetadatas.size()][4]));
}
if (!updateDataMetadatas.isEmpty()) {
runner.batch(conn, SQL.UPDATE_DATA_METADATA, updateDataMetadatas.toArray(new Object[updateDataMetadatas.size()][3]));
}
}
}
conn.commit();
} catch (SQLException e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
} catch (SQLException e) {
log.error("Sql exception", e);
throw new UserMetadataServiceException("Failed to save metadata", e);
}
}
use of com.netflix.metacat.common.dto.HasDefinitionMetadata in project metacat by Netflix.
the class BaseUserMetadataService method populateMetadata.
/**
* Populate the given metadata.
*
* @param holder metadata
*/
@Override
public void populateMetadata(final HasMetadata holder, final boolean disableIntercetpor) {
Optional<ObjectNode> metadata = Optional.empty();
if (holder instanceof HasDataMetadata) {
final HasDataMetadata dataDto = (HasDataMetadata) holder;
if (dataDto.isDataExternal()) {
metadata = getDataMetadata(dataDto.getDataUri());
}
}
Optional<ObjectNode> definitionMetadata = Optional.empty();
if (holder instanceof HasDefinitionMetadata) {
final HasDefinitionMetadata definitionDto = (HasDefinitionMetadata) holder;
definitionMetadata = disableIntercetpor ? this.getDefinitionMetadata(definitionDto.getDefinitionName()) : this.getDefinitionMetadataWithInterceptor(definitionDto.getDefinitionName(), GetMetadataInterceptorParameters.builder().hasMetadata(holder).build());
}
populateMetadata(holder, definitionMetadata.orElse(null), metadata.orElse(null));
}
Aggregations