Search in sources :

Example 11 with NotFoundException

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);
    }
}
Also used : DynamicResourceAccess(org.structr.core.entity.DynamicResourceAccess) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode) SchemaNode(org.structr.core.entity.SchemaNode) NotFoundException(org.structr.api.NotFoundException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

NotFoundException (org.structr.api.NotFoundException)11 Tx (org.structr.core.graph.Tx)6 Test (org.junit.Test)5 FrameworkException (org.structr.common.error.FrameworkException)5 SixOneOneToOne (org.structr.core.entity.SixOneOneToOne)5 TestOne (org.structr.core.entity.TestOne)5 TestSix (org.structr.core.entity.TestSix)5 GraphObject (org.structr.core.GraphObject)4 LinkedHashSet (java.util.LinkedHashSet)2 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Record (org.neo4j.driver.v1.Record)1 StatementResult (org.neo4j.driver.v1.StatementResult)1 Value (org.neo4j.driver.v1.Value)1 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)1 TransientException (org.neo4j.driver.v1.exceptions.TransientException)1 DatabaseService (org.structr.api.DatabaseService)1 NetworkException (org.structr.api.NetworkException)1