use of com.thinkbiganalytics.metadata.api.MissingUserPropertyException in project kylo by Teradata.
the class JcrPropertyUtil method setUserProperties.
/**
* Sets the specified user-defined properties on the specified node.
*
* @param node the target node
* @param fields the predefined user fields
* @param properties the map of user-defined property names to values
* @throws IllegalStateException if a property name is encoded incorrectly
* @throws MetadataRepositoryException if the metadata repository is unavailable
*/
public static void setUserProperties(@Nonnull final Node node, @Nonnull final Set<UserFieldDescriptor> fields, @Nonnull final Map<String, String> properties) {
// Verify required properties are not empty
for (final UserFieldDescriptor field : fields) {
if (field.isRequired() && StringUtils.isEmpty(properties.get(field.getSystemName()))) {
throw new MissingUserPropertyException("Missing required property: " + field.getSystemName());
}
}
// Set properties on node
final Set<String> newProperties = new HashSet<>(properties.size());
final String prefix = JcrMetadataAccess.USR_PREFIX + ":";
properties.forEach((key, value) -> {
try {
final String name = prefix + URLEncoder.encode(key, USER_PROPERTY_ENCODING);
newProperties.add(name);
node.setProperty(name, value);
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to set user property \"" + key + "\" on node: " + node, e);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e.toString(), e);
}
});
// Get node properties
final PropertyIterator iterator;
try {
iterator = node.getProperties();
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to get properties for node: " + node, e);
}
// Remove properties from node
while (iterator.hasNext()) {
final Property property = iterator.nextProperty();
try {
final String name = property.getName();
if (name.startsWith(prefix) && !newProperties.contains(name)) {
property.remove();
}
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to remove property \"" + property + "\" on node: " + node, e);
}
}
}
use of com.thinkbiganalytics.metadata.api.MissingUserPropertyException in project kylo by Teradata.
the class JcrPropertyUtil method setUserProperties.
/**
* Sets the specified user-defined properties on the specified node.
*
* @param node the target node
* @param fields the predefined user fields
* @param properties the map of user-defined property names to values
* @throws IllegalStateException if a property name is encoded incorrectly
* @throws MetadataRepositoryException if the metadata repository is unavailable
*/
public static void setUserProperties(@Nonnull final Node node, @Nonnull final Set<UserFieldDescriptor> fields, @Nonnull final Map<String, String> properties, boolean enforceRequired) {
// Verify required properties are not empty
for (final UserFieldDescriptor field : fields) {
if (enforceRequired && field.isRequired() && StringUtils.isEmpty(properties.get(field.getSystemName()))) {
throw new MissingUserPropertyException("Missing required property: " + field.getSystemName());
}
}
// Set properties on node
final Set<String> newProperties = new HashSet<>(properties.size());
final String prefix = JcrMetadataAccess.USR_PREFIX + ":";
properties.forEach((key, value) -> {
try {
final String name = prefix + URLEncoder.encode(key, USER_PROPERTY_ENCODING);
newProperties.add(name);
node.setProperty(name, value);
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to set user property \"" + key + "\" on node: " + node, e);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e.toString(), e);
}
});
// Get node properties
final PropertyIterator iterator;
try {
iterator = node.getProperties();
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to get properties for node: " + node, e);
}
// Remove properties from node
while (iterator.hasNext()) {
final Property property = iterator.nextProperty();
try {
final String name = property.getName();
if (name.startsWith(prefix) && !newProperties.contains(name)) {
property.remove();
}
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to remove property \"" + property + "\" on node: " + node, e);
}
}
}
Aggregations