use of org.structr.api.NotFoundException in project structr by structr.
the class SchemaHelper method cleanUnusedDynamicGrants.
public static void cleanUnusedDynamicGrants(final List<SchemaNode> existingSchemaNodes) {
try {
final List<DynamicResourceAccess> existingDynamicGrants = StructrApp.getInstance().nodeQuery(DynamicResourceAccess.class).getAsList();
final Set<String> existingSchemaNodeNames = new HashSet<>();
for (final SchemaNode schemaNode : existingSchemaNodes) {
existingSchemaNodeNames.add(schemaNode.getResourceSignature());
}
for (final DynamicResourceAccess grant : existingDynamicGrants) {
boolean foundAllParts = true;
final String sig;
try {
sig = grant.getResourceSignature();
} catch (NotFoundException nfe) {
logger.debug("Unable to get signature from grant");
continue;
}
// Try to find schema nodes for all parts of the grant signature
final String[] parts = StringUtils.split(sig, "/");
if (parts != null) {
for (final String sigPart : parts) {
if ("/".equals(sigPart) || sigPart.startsWith("_")) {
continue;
}
// If one of the signature parts doesn't have an equivalent existing schema node, remove it
foundAllParts &= existingSchemaNodeNames.contains(sigPart);
}
}
if (!foundAllParts) {
logger.info("Did not find all parts of signature, will be removed: {}, ", new Object[] { sig });
removeDynamicGrants(sig);
}
}
} catch (Throwable t) {
logger.warn("", t);
}
}
Aggregations