@Override @Transactional(readOnly = true) public List<String> getDeletedDataMetadataUris(final Date deletedPriorTo, final Integer offset, final Integer limit) { try { return jdbcTemplate.query(String.format(SQL.GET_DELETED_DATA_METADATA_URI, offset, limit), new Object[]{deletedPriorTo}, new int[]{Types.TIMESTAMP}, (rs, rowNum) -> rs.getString("uri")); } catch (Exception e) { final String message = String.format("Failed to get deleted data metadata uris deleted prior to %s", deletedPriorTo); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
} catch (UserMetadataServiceException e) { collectRequestExceptionMetrics(tags, e.getClass().getSimpleName()); final String message = String.format("%s.%s -- %s usermetadata operation failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name); throw new MetacatUserMetadataException(message); } catch (MetacatUnAuthorizedException e) {
@Override @Transactional(readOnly = true) public List<String> getDescendantDataUris(@Nonnull final String uri) { final List<String> result; try { result = jdbcTemplate.query(SQL.GET_DESCENDANT_DATA_URIS, new Object[]{uri + "/%"}, new int[]{Types.VARCHAR}, (rs, rowNum) -> rs.getString("uri")); } catch (Exception e) { final String message = String.format("Failed to get descendant uris for %s", uri); log.error(message, e); throw new UserMetadataServiceException(message, e); } return result; }
private Lookup addTags(final Set<String> tags) { try { return lookupService.addValues(LOOKUP_NAME_TAG, tags); } catch (Exception e) { final String message = String.format("Failed adding the tags %s", tags); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
@Override @Transactional(readOnly = true) public List<QualifiedName> getDescendantDefinitionNames(@Nonnull final QualifiedName name) { final List<String> result; try { result = jdbcTemplate .query(SQL.GET_DESCENDANT_DEFINITION_NAMES, new Object[]{name.toString() + "/%"}, new int[]{Types.VARCHAR}, (rs, rowNum) -> rs.getString("name")); } catch (Exception e) { final String message = String.format("Failed to get descendant names for %s", name); log.error(message, e); throw new UserMetadataServiceException(message, e); } return result.stream().map(QualifiedName::fromString).collect(Collectors.toList()); }
/** * Returns the list of tags of the tag item id. * * @param tagItemId tag item id * @return list of tags */ private Set<String> getValues(final Long tagItemId) { try { return MySqlServiceUtil.getValues(jdbcTemplate, SQL_GET_TAG_ITEM_TAGS, tagItemId); } catch (EmptyResultDataAccessException e) { return Sets.newHashSet(); } catch (Exception e) { final String message = String.format("Failed to get the tags for id %s", tagItemId); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
/** * Returns the list of values of the lookup name. * * @param name lookup name * @return list of lookup values */ @Override @Transactional(readOnly = true) public Set<String> getValues(final String name) { try { return MySqlServiceUtil.getValues(jdbcTemplate, SQL_GET_LOOKUP_VALUES_BY_NAME, name); } catch (EmptyResultDataAccessException e) { return Sets.newHashSet(); } catch (Exception e) { final String message = String.format("Failed to get the lookup values for name %s", name); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
/** * Returns the list of values of the lookup name. * * @param lookupId lookup id * @return list of lookup values */ @Override @Transactional(readOnly = true) public Set<String> getValues(final Long lookupId) { try { return MySqlServiceUtil.getValues(jdbcTemplate, SQL_GET_LOOKUP_VALUES, lookupId); } catch (EmptyResultDataAccessException e) { return Sets.newHashSet(); } catch (Exception e) { final String message = String.format("Failed to get the lookup values for id %s", lookupId); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
/** * executeUpdateForKey. * * @param query sql query string * @param keyValues parameters * @return number of updated rows */ private int executeUpdateForKey(final String query, final String... keyValues) { try { final SqlParameterValue[] values = Arrays.stream(keyValues).map(keyValue -> new SqlParameterValue(Types.VARCHAR, keyValue)) .toArray(SqlParameterValue[]::new); return jdbcTemplate.update(query, (Object[]) values); } catch (Exception e) { final String message = String.format("Failed to save data for %s", Arrays.toString(keyValues)); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
final String message = String.format("Failed getting the list of qualified names for tag %s", tag); log.error(message, e); throw new UserMetadataServiceException(message, e);
private void deleteDataMetadatasWithBatch(final List<String> uris, final boolean removeDataMetadata) { try { final List<List<String>> subLists = Lists.partition(uris, config.getUserMetadataMaxInClauseItems()); for (List<String> subUris : subLists) { _deleteDataMetadata(subUris, removeDataMetadata); } } catch (Exception e) { final String message = String.format("Failed deleting the data metadata for %s", uris); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
@Override @Transactional(readOnly = true) public List<QualifiedName> searchByOwners(final Set<String> owners) { final List<QualifiedName> result = Lists.newArrayList(); final StringBuilder query = new StringBuilder(SQL.SEARCH_DEFINITION_METADATA_NAMES); final List<SqlParameterValue> paramList = Lists.newArrayList(); query.append(" where 1=0"); owners.forEach(s -> { query.append(" or data like ?"); paramList.add(new SqlParameterValue(Types.VARCHAR, "%\"userId\":\"" + s.trim() + "\"%")); }); final SqlParameterValue[] params = new SqlParameterValue[paramList.size()]; try { // Handler for reading the result set final ResultSetExtractor<Void> handler = rs -> { while (rs.next()) { final String definitionName = rs.getString("name"); result.add(QualifiedName.fromString(definitionName, false)); } return null; }; jdbcTemplate.query(query.toString(), paramList.toArray(params), handler); } catch (Exception e) { log.error("Failed to search by owners", e); throw new UserMetadataServiceException("Failed to search by owners", e); } return result; }
final String message = String.format("Invalid json %s for name %s", e.getInputJson(), keyValue); log.error(message, e); throw new UserMetadataServiceException(message, e); } catch (Exception e) { final String message = String.format("Failed to get data for %s", keyValue); log.error(message, e); throw new UserMetadataServiceException(message, e);
@Override public void softDeleteDataMetadata( final String user, @Nonnull final List<String> uris ) { try { final List<List<String>> subLists = Lists.partition(uris, config.getUserMetadataMaxInClauseItems()); for (List<String> subUris : subLists) { _softDeleteDataMetadata(user, subUris); } } catch (Exception e) { final String message = String.format("Failed deleting the data metadata for %s", uris); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
@Override public void deleteDefinitionMetadata( @Nonnull final List<QualifiedName> names ) { try { final List<List<QualifiedName>> subLists = Lists.partition(names, config.getUserMetadataMaxInClauseItems()); for (List<QualifiedName> subNames : subLists) { _deleteDefinitionMetadata(subNames); } } catch (Exception e) { final String message = String.format("Failed deleting the definition metadata for %s", names); log.error(message, e); throw new UserMetadataServiceException(message, e); } }
} catch (MetacatJsonException e) { log.error("Invalid json '{}' for name '{}'", json, name); throw new UserMetadataServiceException( String.format("Invalid json %s for name %s", json, name), e); final String message = String.format("Failed to get data for %s", keys); log.error(message, e); throw new UserMetadataServiceException(message, e);
@Override public void delete(final QualifiedName name, final boolean updateUserMetadata) { try { jdbcTemplate .update(SQL_DELETE_TAG_ITEM_TAGS_BY_NAME, new SqlParameterValue(Types.VARCHAR, name.toString())); jdbcTemplate.update(SQL_DELETE_TAG_ITEM, new SqlParameterValue(Types.VARCHAR, name.toString())); if (updateUserMetadata) { // Set the tags in user metadata final Map<String, Set<String>> data = Maps.newHashMap(); data.put(NAME_TAGS, Sets.newHashSet()); userMetadataService .saveDefinitionMetadata(name, "admin", Optional.of(metacatJson.toJsonObject(data)), true); } } catch (Exception e) { final String message = String.format("Failed to delete all tags for name %s", name); log.error(message, e); throw new UserMetadataServiceException(message, 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);
@Override public void deleteMetadata(final String userId, final List<HasMetadata> holders) { 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()) { _deleteDefinitionMetadata(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()) { _softDeleteDataMetadata(userId, uris); } } } } catch (Exception e) { log.error("Failed deleting metadatas", e); throw new UserMetadataServiceException("Failed deleting metadatas", e); } }
/** * remove. * * @param name qualifiedName * @param tags tags * @param updateUserMetadata flag to update user metadata */ public void remove(final QualifiedName name, final Set<String> tags, final boolean updateUserMetadata) { try { jdbcTemplate.update(String.format(SQL_DELETE_TAG_ITEM_TAGS_BY_NAME_TAGS, "'" + Joiner.on("','").skipNulls().join(tags) + "'"), new SqlParameterValue(Types.VARCHAR, name.toString())); if (updateUserMetadata) { final TagItem tagItem = get(name); tagItem.getValues().removeAll(tags); final Map<String, Set<String>> data = Maps.newHashMap(); data.put(NAME_TAGS, tagItem.getValues()); 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); } }