protected NameSpaceContainer doGetEntity(final NamespaceKey key, Type type, List<NameSpaceContainer> entitiesOnPath) throws NamespaceException { NameSpaceContainer container = lastElement(entitiesOnPath); return container; }
@VisibleForTesting NameSpaceContainer deleteEntity(final NamespaceKey path, final Type type, String version, boolean deleteRoot) throws NamespaceException { final List<NameSpaceContainer> entitiesOnPath = getEntitiesOnPath(path); final NameSpaceContainer container = lastElement(entitiesOnPath); if (container == null) { throw new NamespaceNotFoundException(path, String.format("Entity %s not found", path)); } return doDeleteEntity(path, type, version, entitiesOnPath, deleteRoot); }
protected NameSpaceContainer doDeleteEntity(final NamespaceKey path, final Type type, String version, List<NameSpaceContainer> entitiesOnPath, boolean deleteRoot) throws NamespaceException { final NamespaceInternalKey key = new NamespaceInternalKey(path, keyNormalization); final NameSpaceContainer container = lastElement(entitiesOnPath); traverseAndDeleteChildren(key, container); if(deleteRoot) { namespace.delete(key.getKey(), version); } return container; }
/** * Helper method which retrieves the entity with given key. No authorization check done. * * @param key * @return * @throws NamespaceException */ private NameSpaceContainer getEntity(final NamespaceKey key, Type type) throws NamespaceException { final List<NameSpaceContainer> entitiesOnPath = getEntitiesOnPath(key); NameSpaceContainer container = lastElement(entitiesOnPath); if (container == null || container.getType() != type) { throw new NamespaceNotFoundException(key, "not found"); } return doGetEntity(key, type, entitiesOnPath); }
protected void doCreateOrUpdateEntity(final NamespaceEntity entity, List<NameSpaceContainer> entitiesOnPath, NamespaceAttribute... attributes) throws NamespaceException { final NameSpaceContainer prevContainer = lastElement(entitiesOnPath); ensureIdExistsTypeMatches(entity, prevContainer); namespace.put(entity.getPathKey().getKey(), entity.getContainer()); }
@Override public List<NameSpaceContainer> list(NamespaceKey root) throws NamespaceException { final List<NameSpaceContainer> entitiesOnPath = getEntitiesOnPath(root); final NameSpaceContainer rootContainer = lastElement(entitiesOnPath); if (rootContainer == null) { throw new NamespaceNotFoundException(root, "not found"); } if (!isListable(rootContainer.getType())) { throw new NamespaceNotFoundException(root, "no listable entity found"); } return doList(root, entitiesOnPath); }