use of com.netflix.metacat.common.dto.HasDataMetadata 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.HasDataMetadata in project metacat by Netflix.
the class BaseUserMetadataService method saveMetadata.
/**
* Saves user metadata.
*
* @param userId user name
* @param holder metadata
* @param merge true if the metadata should be merged with existing metadata
*/
@Override
public void saveMetadata(final String userId, final HasMetadata holder, final boolean merge) {
if (holder instanceof HasDefinitionMetadata) {
final HasDefinitionMetadata defDto = (HasDefinitionMetadata) holder;
// If the user is updating the definition metadata do a merge on the existing metadata
final ObjectNode newMetadata = defDto.getDefinitionMetadata();
if (newMetadata != null) {
saveDefinitionMetadata(defDto.getDefinitionName(), userId, Optional.of(newMetadata), merge);
}
}
if (holder instanceof HasDataMetadata) {
final HasDataMetadata dataDto = (HasDataMetadata) holder;
// If the user is updating the data metadata and a separate data location exists,
// do a merge on the existing metadata
final ObjectNode newMetadata = dataDto.getDataMetadata();
if (newMetadata != null && dataDto.isDataExternal()) {
saveDataMetadata(dataDto.getDataUri(), userId, Optional.of(newMetadata), merge);
}
}
}
use of com.netflix.metacat.common.dto.HasDataMetadata in project metacat by Netflix.
the class BaseUserMetadataService method populateMetadata.
/**
* Populate metadata.
*
* @param holder metadata
* @param definitionMetadata definition metadata
* @param dataMetadata data metadata
*/
@Override
public void populateMetadata(final HasMetadata holder, final ObjectNode definitionMetadata, final ObjectNode dataMetadata) {
if (holder instanceof HasDefinitionMetadata) {
final HasDefinitionMetadata defDto = (HasDefinitionMetadata) holder;
defDto.setDefinitionMetadata(definitionMetadata);
}
if (holder instanceof HasDataMetadata) {
final HasDataMetadata dataDto = (HasDataMetadata) holder;
if (dataDto.isDataExternal()) {
dataDto.setDataMetadata(dataMetadata);
}
}
}
use of com.netflix.metacat.common.dto.HasDataMetadata 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));
}
use of com.netflix.metacat.common.dto.HasDataMetadata in project metacat by Netflix.
the class MysqlUserMetadataService method saveMetadata.
@Override
public void saveMetadata(final String user, final List<? extends HasMetadata> metadatas, final boolean merge) {
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.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[]> insertPartitionDefinitionMetadatas = Lists.newArrayList();
final List<Object[]> updatePartitionDefinitionMetadatas = Lists.newArrayList();
final List<Object[]> insertDataMetadatas = Lists.newArrayList();
final List<Object[]> updateDataMetadatas = Lists.newArrayList();
definitionMetadatas.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) {
final Object[] o = new Object[] { metacatJson.toJsonString(oDef.getDefinitionMetadata()), user, user, name };
if (qualifiedName.isPartitionDefinition()) {
insertPartitionDefinitionMetadatas.add(o);
} else {
insertDefinitionMetadatas.add(o);
}
} else {
metacatJson.mergeIntoPrimary(oNode, oDef.getDefinitionMetadata());
final Object[] o = new Object[] { metacatJson.toJsonString(oNode), user, name };
if (qualifiedName.isPartitionDefinition()) {
updatePartitionDefinitionMetadatas.add(o);
} else {
updateDefinitionMetadatas.add(o);
}
}
}
});
dataMetadatas.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 });
}
}
});
if (!insertDefinitionMetadatas.isEmpty()) {
jdbcTemplate.batchUpdate(SQL.INSERT_DEFINITION_METADATA, insertDefinitionMetadatas, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
}
if (!updateDefinitionMetadatas.isEmpty()) {
jdbcTemplate.batchUpdate(SQL.UPDATE_DEFINITION_METADATA, updateDefinitionMetadatas, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
}
if (!insertPartitionDefinitionMetadatas.isEmpty()) {
jdbcTemplate.batchUpdate(SQL.INSERT_PARTITION_DEFINITION_METADATA, insertPartitionDefinitionMetadatas, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
}
if (!updatePartitionDefinitionMetadatas.isEmpty()) {
jdbcTemplate.batchUpdate(SQL.UPDATE_PARTITION_DEFINITION_METADATA, updatePartitionDefinitionMetadatas, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
}
if (!insertDataMetadatas.isEmpty()) {
jdbcTemplate.batchUpdate(SQL.INSERT_DATA_METADATA, insertDataMetadatas, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
}
if (!updateDataMetadatas.isEmpty()) {
jdbcTemplate.batchUpdate(SQL.UPDATE_DATA_METADATA, updateDataMetadatas, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
}
}
}
} catch (Exception e) {
log.error("Failed to save metadata", e);
throw new UserMetadataServiceException("Failed to save metadata", e);
}
}
Aggregations