use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.
the class MysqlUserMetadataService method softDeleteDataMetadatas.
@Override
public void softDeleteDataMetadatas(final String user, @Nonnull final List<String> uris) {
try {
final Connection conn = poolingDataSource.getConnection();
try {
final List<List<String>> subLists = Lists.partition(uris, config.getUserMetadataMaxInClauseItems());
for (List<String> subUris : subLists) {
_softDeleteDataMetadatas(conn, user, subUris);
}
conn.commit();
} catch (SQLException e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
} catch (SQLException e) {
log.error("Sql exception", e);
throw new UserMetadataServiceException(String.format("Failed deleting the data metadata for %s", uris), e);
}
}
use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.
the class MysqlUserMetadataService method deleteDefinitionMetadatas.
@Override
public void deleteDefinitionMetadatas(@Nonnull final List<QualifiedName> names) {
try {
final Connection conn = poolingDataSource.getConnection();
try {
final List<List<QualifiedName>> subLists = Lists.partition(names, config.getUserMetadataMaxInClauseItems());
for (List<QualifiedName> subNames : subLists) {
_deleteDefinitionMetadatas(conn, subNames);
}
conn.commit();
} catch (SQLException e) {
conn.rollback();
throw e;
} finally {
conn.close();
}
} catch (SQLException e) {
log.error("Sql exception", e);
throw new UserMetadataServiceException(String.format("Failed deleting the definition metadata for %s", names), e);
}
}
use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.
the class MySqlLookupService method setValues.
/**
* Saves the lookup value.
*
* @param name lookup name
* @param values multiple values
* @return returns the lookup with the given name.
*/
@Override
public Lookup setValues(final String name, final Set<String> values) {
try {
final Lookup lookup = findOrCreateLookupByName(name);
final Set<String> inserts;
Set<String> deletes = Sets.newHashSet();
final Set<String> lookupValues = lookup.getValues();
if (lookupValues == null || lookupValues.isEmpty()) {
inserts = values;
} else {
inserts = Sets.difference(values, lookupValues).immutableCopy();
deletes = Sets.difference(lookupValues, values).immutableCopy();
}
lookup.setValues(values);
if (!inserts.isEmpty()) {
insertLookupValues(lookup.getId(), inserts);
}
if (!deletes.isEmpty()) {
deleteLookupValues(lookup.getId(), deletes);
}
return lookup;
} catch (Exception e) {
final String message = String.format("Failed to set the lookup values for name %s", name);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
}
}
use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.
the class MySqlTagService method list.
/**
* Returns the list of <code>QualifiedName</code> of items that are tagged by the
* given <code>includeTags</code> and do not contain the given <code>excludeTags</code>.
*
* @param includeTags include items that contain tags
* @param excludeTags include items that do not contain tags
* @param sourceName catalog/source name
* @param databaseName database name
* @param tableName table name
* @return list of qualified names of the items
*/
@Override
@Transactional(readOnly = true)
public List<QualifiedName> list(@Nullable final Set<String> includeTags, @Nullable final Set<String> excludeTags, @Nullable final String sourceName, @Nullable final String databaseName, @Nullable final String tableName) {
Set<String> includedNames = Sets.newHashSet();
final Set<String> excludedNames = Sets.newHashSet();
final String wildCardName = QualifiedName.toWildCardString(sourceName, databaseName, tableName);
// Includes
final Set<String> localIncludes = includeTags != null ? includeTags : Sets.newHashSet();
try {
String query = String.format(QUERY_SEARCH, "in ('" + Joiner.on("','").skipNulls().join(localIncludes) + "')");
final Object[] params = { localIncludes.size() == 0 ? 1 : 0, wildCardName == null ? 1 : 0, wildCardName };
includedNames.addAll(jdbcTemplate.query(query, params, new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR }, (rs, rowNum) -> rs.getString("name")));
if (excludeTags != null && !excludeTags.isEmpty()) {
// Excludes
query = String.format(QUERY_SEARCH, "in ('" + Joiner.on("','").skipNulls().join(excludeTags) + "')");
final Object[] eParams = { excludeTags.size() == 0 ? 1 : 0, wildCardName == null ? 1 : 0, wildCardName };
excludedNames.addAll(jdbcTemplate.query(query, eParams, new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR }, (rs, rowNum) -> rs.getString("name")));
}
} catch (Exception e) {
final String message = String.format("Failed getting the list of qualified names for tags %s", includeTags);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
}
if (excludeTags != null && !excludeTags.isEmpty()) {
includedNames = Sets.difference(includedNames, excludedNames);
}
return includedNames.stream().map(s -> QualifiedName.fromString(s, false)).collect(Collectors.toList());
}
use of com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException in project metacat by Netflix.
the class MySqlTagService method setTableTags.
/**
* Tags the given table with the given <code>tags</code>.
*
* @param name table name
* @param tags list of tags
* @return return the complete list of tags associated with the table
*/
@Override
public Set<String> setTableTags(final QualifiedName name, final Set<String> tags, final boolean updateUserMetadata) {
addTags(tags);
try {
final TagItem tagItem = findOrCreateTagItemByName(name.toString());
final Set<String> inserts;
Set<String> deletes = Sets.newHashSet();
Set<String> values = tagItem.getValues();
if (values == null || values.isEmpty()) {
inserts = tags;
} else {
inserts = Sets.difference(tags, values).immutableCopy();
deletes = Sets.difference(values, tags).immutableCopy();
}
values = tags;
if (!inserts.isEmpty()) {
insertTagItemTags(tagItem.getId(), inserts);
}
if (!deletes.isEmpty()) {
removeTagItemTags(tagItem.getId(), deletes);
}
if (updateUserMetadata) {
// Set the tags in user metadata
final Map<String, Set<String>> data = Maps.newHashMap();
data.put(NAME_TAGS, values);
userMetadataService.saveDefinitionMetadata(name, "admin", Optional.of(metacatJson.toJsonObject(data)), true);
}
} catch (Exception e) {
final String message = String.format("Failed to remove tags for name %s", name);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
}
return tags;
}
Aggregations