Package org.apache.jackrabbit.vault.fs.impl.io

Examples of org.apache.jackrabbit.vault.fs.impl.io.ImportInfoImpl


        }
    }

    private ImportInfoImpl commit(Session session, TxInfo info) throws RepositoryException, IOException {
        log.debug("committing {}", info.path);
        ImportInfoImpl imp = null;
        if (info.artifacts == null) {
            log.debug("S {}", info.path);
        } else if (info.artifacts.isEmpty()) {
            // intermediate directory, check if node exists and filter
            // matches. in this case remove the node (bug #25370)
            // but only if intermediate is not processed yet (bug #42562)
            if (filter.contains(info.path) && session.nodeExists(info.path) && info.isIntermediate < 2) {
                Node node = session.getNode(info.path);
                imp = new ImportInfoImpl();
                if (aclManagement.isACLNode(node)) {
                    if (opts.getAccessControlHandling() == AccessControlHandling.OVERWRITE
                            || opts.getAccessControlHandling() == AccessControlHandling.CLEAR) {
                        imp.onDeleted(info.path);
                        aclManagement.clearACL(node.getParent());
                    }
                } else {
                    imp.onDeleted(info.path);
                    node.remove();
                }
            }
        } else if (info.artifacts.getPrimaryData() !=null && info.artifacts.size() == 1) {
            // simple case, only 1 primary artifact
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                imp = genericHandler.accept(filter, node, info.artifacts.getPrimaryData().getRelativePath(), info.artifacts);
                if (imp == null) {
                    throw new IllegalStateException("generic handler did not accept " + info.path);
                }
            }
        } else if (info.artifacts.getDirectory() != null) {
            for (TxInfo child: info.children().values()) {
                // add the directory artifacts as hint to this one.
                if (child.artifacts == null) {
                    // in this case it's some deleted intermediate directory???
                    String path = info.name + "/" + child.name;
                    info.artifacts.add(new HintArtifact(path));

                } else {
                    for (Artifact a: child.artifacts.values()) {
                        String path = info.name + "/" + a.getRelativePath();
                        info.artifacts.add(new HintArtifact(path));
                    }
                }
            }
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                if (info.isIntermediate == 2) {
                    // skip existing intermediate
                    log.debug("skipping intermediate node at {}", info.path);
                } else if (info.artifacts.getPrimaryData() == null) {
                    // create nt:folder node if not exists
                    imp = folderHandler.accept(filter, node, info.name,  info.artifacts);
                    if (imp == null) {
                        throw new IllegalStateException("folder handler did not accept " + info.path);
                    }
                } else {
                    imp = genericHandler.accept(filter, node, info.artifacts.getDirectory().getRelativePath(), info.artifacts);
                    if (imp == null) {
                        throw new IllegalStateException("generic handler did not accept " + info.path);
                    }
                }
            }
        } else if (info.artifacts.size(ArtifactType.FILE) > 0) {
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                imp = fileHandler.accept(filter, node, info.name,  info.artifacts);
                if (imp == null) {
                    throw new IllegalStateException("file handler did not accept " + info.path);
                }
            }
        } else {
            throw new UnsupportedOperationException("ArtifactSet not supported: " + info.artifacts);
        }

        if (imp != null) {
            for (Map.Entry<String, ImportInfo.Info> entry: imp.getInfos().entrySet()) {
                String path = entry.getKey();
                ImportInfo.Type type = entry.getValue().getType();
                if (type != ImportInfoImpl.Type.DEL) {
                    // mark intermediates as processed
                    TxInfo im = intermediates.remove(path);
                    if (im != null) {
                        log.debug("P {}", path);
                        removedIntermediates.put(path, im);
                        im.isIntermediate = 2;
                    }
                }
                switch (type) {
                    case CRE:
                        track("A", path);
                        autoSave.markResolved(path);
                        break;
                    case DEL:
                        track("D", path);
                        autoSave.markResolved(path);
                        break;
                    case MOD:
                        track("U", path);
                        autoSave.markResolved(path);
                        break;
                    case NOP:
                        track("-", path);
                        autoSave.markResolved(path);
                        break;
                    case REP:
                        track("R", path);
                        autoSave.markResolved(path);
                        break;
                    case MIS:
                        track("!", path);
                        autoSave.markMissing(path);
                        break;
                    case ERR:
                        Exception error = entry.getValue().getError();
                        if (error == null) {
                            track("E", path);
                        } else {
                            track(error, path);
                        }
                        hasErrors = true;
                        break;
                }

                // see if any child nodes need to be reordered and remember namelist.
                // only restore order if in filter scope if freshly created
                NodeNameList nameList = entry.getValue().getNameList();
                if (nameList != null && (filter.contains(path) || type == ImportInfo.Type.CRE)) {
                    TxInfo subInfo = info.findChild(path);
                    if (subInfo != null) {
                        subInfo.nameList = nameList;
                    }
                }
            }
            // check if node was remapped. currently we just skip them as it's not clear how the filter should be
            // reapplied or what happens if the remapping links to a tree we already processed.
            // in this case we don't descend in any children and can clear them right away
            if (imp.getRemapped().containsKey(info.path)) {
                info.children = null;
            }
        }
        log.debug("committed {}", info.path);
        return imp;
View Full Code Here


    public Collection<Info> commit() throws RepositoryException, IOException {
        Map<String, Info> infos = new HashMap<String, Info>();

        // remember all nodes to checkin again
        ImportInfoImpl allInfos = new ImportInfoImpl();

        // first scan all changes for additions that need to be attached to a
        // .content.xml change
        if (!dotXmlNodes.isEmpty()) {
            Iterator<Change> iter = changes.iterator();
            while (iter.hasNext()) {
                Change c = iter.next();
                if (c.type == Type.ADDED) {
                    if (c.isa.getType() == ArtifactType.BINARY) {
                        DotXmlInfo dxi = dotXmlNodes.get(c.repoPath);
                        if (dxi != null) {
                            dxi.change.add(c);
                            iter.remove();
                        }
                    }
                } else if (c.type == Type.MKDIR) {
                    DotXmlInfo dxi = dotXmlNodes.get(c.repoPath);
                    if (dxi != null) {
                        iter.remove();
                    }
                }
            }
        }

        // process the changes and group them by artifact path
        Map<String, TxInfo> modified = new TreeMap<String, TxInfo>(new PathComparator());
        boolean ignoreMP = true;
        while (!changes.isEmpty()) {
            int size = changes.size();
            // process as many changes that have a parent file
            Iterator<Change> iter = changes.iterator();
            while (iter.hasNext()) {
                Change change = iter.next();
                if (processChange(change, modified, ignoreMP)) {
                    changes.remove(change);
                    iter = changes.iterator();
                }
            }
            if (changes.size() == size) {
                if (ignoreMP) {
                    ignoreMP = false;
                } else {
                    for (Change c: changes) {
                        infos.put(c.filePath, new Info(Type.ERROR, c.filePath));
                    }
                    // abort iteration
                    changes.clear();
                }
            } else {
                // write back the current collected modifications and generate a
                // new modified info list
                for (TxInfo info : modified.values()) {

                    // check if primary artifact is still present
                    if (info.out == null && info.aggregate == null) {
                        // this was an intermediate directory delete
                        for (String path: info.original.keySet()) {
                            infos.put(path, new Info(Type.DELETED, path));
                            if (verbose) {
                                log.info("...comitting  DEL {}", path);
                            }
                        }
                    } else if (info.out.getArtifacts().isEmpty() && info.aggregate != null) {
                        // delete entire node if aggregate is still attached
                        if (info.aggregate.isAttached()) {
                            info.aggregate.remove(false);
                        }
                        // generate infos for the deleted ones
                        for (String path: info.original.keySet()) {
                            infos.put(path, new Info(Type.DELETED, path));
                            if (verbose) {
                                log.info("...comitting  DEL {}", path);
                            }
                        }
                        // mark the primary artifact of the parent as modified
                        // TODO fix
                        String cXmlPath = info.parentFile.getPath();
                        if (cXmlPath.endsWith("/")) {
                            cXmlPath+= Constants.DOT_CONTENT_XML;
                        } else {
                            cXmlPath+= "/" + Constants.DOT_CONTENT_XML;
                        }
                        Info i = infos.get(cXmlPath);
                        if (i == null) {
                            infos.put(cXmlPath, new Info(Type.MODIFIED, cXmlPath));
                        }
                    } else if (info.aggregate == null) {
                        // this was and addition
                        // for now, just guess from the artifacts the new files
                        String parentPath = info.parentFile.getPath();
                        if (!parentPath.endsWith("/")) {
                            parentPath += "/";
                        }
                        for (Artifact a: info.out.getArtifacts().values()) {
                            if (a instanceof ImportArtifact) {
                                String path = parentPath + a.getPlatformPath();
                                infos.put(path, new Info(Type.ADDED, path));
                            }
                        }

                        ImportInfo ret = info.out.close();
                        if (ret != null) {
                            allInfos.merge(ret);
                            if (verbose) {
                                for (Map.Entry e: ret.getModifications().entrySet()) {
                                    log.info("...comitting  {} {}", e.getValue(), e.getKey());
                                }
                            }
                        }
                        // modify parent
                        infos.put(info.parentFile.getPath(), new Info(Type.MODIFIED, info.parentFile.getPath()));

                    } else {
                        // this was a modification
                        ImportInfo ret = info.out.close();
                        if (ret != null) {
                            allInfos.merge(ret);
                        }
                        for (VaultFile file: info.original.values()) {
                            infos.put(file.getPath(), new Info(Type.MODIFIED, file.getPath()));
                            if (verbose) {
                                log.info("...comitting  UPD {}", file.getPath());
                            }
                        }
                        if (verbose && ret != null) {
                            for (Map.Entry e: ret.getModifications().entrySet()) {
                                log.info("...comitting  {} {}", e.getValue(), e.getKey());
                            }
                        }
                    }
                }
            }
            modified.clear();
            fs.invalidate();
        }
        if (verbose) {
            log.info("Persisting changes...");
        }
        if (allInfos.numErrors() > 0) {
            try {
                fs.getAggregateManager().getSession().refresh(false);
            } catch (RepositoryException e) {
                // ignore
            }
            throw new RepositoryException("There were errors during commit. Aborting transaction.");
        }
        fs.getAggregateManager().getSession().save();
        allInfos.checkinNodes(fs.getAggregateManager().getSession());
        fs.invalidate();
        return infos.values();
    }
View Full Code Here

            throws RepositoryException {
        if (fullCoverage && !recursive) {
            // todo: allow smarter removal
            throw new RepositoryException("Unable to remove content since aggregation has children and recursive is not set.");
        }
        ImportInfo info = new ImportInfoImpl();
        info.onDeleted(node.getPath());
        Node parent = node.getParent();
        if (getAclManagement().isACLNode(node)) {
            getAclManagement().clearACL(parent);
        } else {
            node.remove();
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public ImportInfo remove(Node node, boolean recursive, boolean trySave) throws RepositoryException {
        ImportInfo info = new ImportInfoImpl();
        info.onDeleted(node.getPath());
        Node parent = node.getParent();
        node.remove();
        if (trySave) {
            parent.save();
        }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public ImportInfo remove(Node node, boolean recursive, boolean trySave)
            throws RepositoryException {
        ImportInfo info = new ImportInfoImpl();
        info.onDeleted(node.getPath());
        Node parent = node.getParent();
        node.remove();
        if (trySave) {
            parent.save();
        }
View Full Code Here

        }
    }

    private ImportInfoImpl commit(Session session, TxInfo info) throws RepositoryException, IOException {
        log.debug("committing {}", info.path);
        ImportInfoImpl imp = null;
        if (info.artifacts == null) {
            log.debug("S {}", info.path);
        } else if (info.artifacts.isEmpty()) {
            // intermediate directory, check if node exists and filter
            // matches. in this case remove the node (bug #25370)
            // but only if intermediate is not processed yet (bug #42562)
            if (filter.contains(info.path) && session.nodeExists(info.path) && info.isIntermediate < 2) {
                Node node = session.getNode(info.path);
                imp = new ImportInfoImpl();
                if (aclManagement.isACLNode(node)) {
                    if (opts.getAccessControlHandling() == AccessControlHandling.OVERWRITE
                            || opts.getAccessControlHandling() == AccessControlHandling.CLEAR) {
                        imp.onDeleted(info.path);
                        aclManagement.clearACL(node.getParent());
                    }
                } else {
                    imp.onDeleted(info.path);
                    node.remove();
                }
            }
        } else if (info.artifacts.getPrimaryData() !=null && info.artifacts.size() == 1) {
            // simple case, only 1 primary artifact
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                imp = genericHandler.accept(filter, node, info.artifacts.getPrimaryData().getRelativePath(), info.artifacts);
                if (imp == null) {
                    throw new IllegalStateException("generic handler did not accept " + info.path);
                }
            }
        } else if (info.artifacts.getDirectory() != null) {
            for (TxInfo child: info.children().values()) {
                // add the directory artifacts as hint to this one.
                if (child.artifacts == null) {
                    // in this case it's some deleted intermediate directory???
                    String path = info.name + "/" + child.name;
                    info.artifacts.add(new HintArtifact(path));

                } else {
                    for (Artifact a: child.artifacts.values()) {
                        String path = info.name + "/" + a.getRelativePath();
                        info.artifacts.add(new HintArtifact(path));
                    }
                }
            }
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                if (info.isIntermediate == 2) {
                    // skip existing intermediate
                    log.debug("skipping intermediate node at {}", info.path);
                } else if (info.artifacts.getPrimaryData() == null) {
                    // create nt:folder node if not exists
                    imp = folderHandler.accept(filter, node, info.name,  info.artifacts);
                    if (imp == null) {
                        throw new IllegalStateException("folder handler did not accept " + info.path);
                    }
                } else {
                    imp = genericHandler.accept(filter, node, info.artifacts.getDirectory().getRelativePath(), info.artifacts);
                    if (imp == null) {
                        throw new IllegalStateException("generic handler did not accept " + info.path);
                    }
                }
            }
        } else if (info.artifacts.size(ArtifactType.FILE) > 0) {
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                imp = fileHandler.accept(filter, node, info.name,  info.artifacts);
                if (imp == null) {
                    throw new IllegalStateException("file handler did not accept " + info.path);
                }
            }
        } else {
            throw new UnsupportedOperationException("ArtifactSet not supported: " + info.artifacts);
        }

        if (imp != null) {
            for (Map.Entry<String, ImportInfo.Info> entry: imp.getInfos().entrySet()) {
                String path = entry.getKey();
                ImportInfo.Type type = entry.getValue().getType();
                if (type != ImportInfoImpl.Type.DEL) {
                    // mark intermediates as processed
                    TxInfo im = intermediates.remove(path);
                    if (im != null) {
                        log.debug("P {}", path);
                        removedIntermediates.put(path, im);
                        im.isIntermediate = 2;
                    }
                }
                switch (type) {
                    case CRE:
                        track("A", path);
                        autoSave.markResolved(path);
                        break;
                    case DEL:
                        track("D", path);
                        autoSave.markResolved(path);
                        break;
                    case MOD:
                        track("U", path);
                        autoSave.markResolved(path);
                        break;
                    case NOP:
                        track("-", path);
                        autoSave.markResolved(path);
                        break;
                    case REP:
                        track("R", path);
                        autoSave.markResolved(path);
                        break;
                    case MIS:
                        track("!", path);
                        autoSave.markMissing(path);
                        break;
                    case ERR:
                        Exception error = entry.getValue().getError();
                        if (error == null) {
                            track("E", path);
                        } else {
                            track(error, path);
                        }
                        hasErrors = true;
                        break;
                }

                // see if any child nodes need to be reordered and remember namelist.
                // only restore order if in filter scope if freshly created
                NodeNameList nameList = entry.getValue().getNameList();
                if (nameList != null && (filter.contains(path) || type == ImportInfo.Type.CRE)) {
                    TxInfo subInfo = info.findChild(path);
                    if (subInfo != null) {
                        subInfo.nameList = nameList;
                    }
                }
            }
            // check if node was remapped. currently we just skip them as it's not clear how the filter should be
            // reapplied or what happens if the remapping links to a tree we already processed.
            // in this case we don't descend in any children and can clear them right away
            if (imp.getRemapped().containsKey(info.path)) {
                info.children = null;
            }
        }
        log.debug("committed {}", info.path);
        return imp;
View Full Code Here

        }
    }

    private void commit(Session session, TxInfo info, LinkedList<TxInfo> skipList) throws RepositoryException, IOException {
        try {
            ImportInfoImpl imp = null;
            if (skipList.isEmpty()) {
                if (info == cpTxInfo) {
                    // don't need to import again, just set import info
                    log.debug("skipping last checkpoint info {}", info.path);
                    imp = cpImportInfo;
                } else {
                    imp = commit(session, info);
                    if (imp != null) {
                        nodesToCheckin.addAll(imp.getToVersion());
                        memberships.putAll(imp.getMemberships());
                        autoSave.modified(imp.numModified());
                    }
                }
            } else if (log.isDebugEnabled()) {
                StringBuilder skips = new StringBuilder();
                for (TxInfo i: skipList) {
View Full Code Here

        }
    }

    private ImportInfoImpl commit(Session session, TxInfo info) throws RepositoryException, IOException {
        log.debug("committing {}", info.path);
        ImportInfoImpl imp = null;
        if (info.artifacts == null) {
            log.debug("S {}", info.path);
        } else if (info.artifacts.isEmpty()) {
            // intermediate directory, check if node exists and filter
            // matches. in this case remove the node (bug #25370)
            // but only if intermediate is not processed yet (bug #42562)
            if (filter.contains(info.path) && session.nodeExists(info.path) && info.isIntermediate < 2) {
                Node node = session.getNode(info.path);
                imp = new ImportInfoImpl();
                if (aclManagement.isACLNode(node)) {
                    if (opts.getAccessControlHandling() == AccessControlHandling.OVERWRITE
                            || opts.getAccessControlHandling() == AccessControlHandling.CLEAR) {
                        imp.onDeleted(info.path);
                        aclManagement.clearACL(node.getParent());
                    }
                } else {
                    imp.onDeleted(info.path);
                    node.remove();
                }
            }
        } else if (info.artifacts.getPrimaryData() !=null && info.artifacts.size() == 1) {
            // simple case, only 1 primary artifact
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                imp = genericHandler.accept(filter, node, info.artifacts.getPrimaryData().getRelativePath(), info.artifacts);
                if (imp == null) {
                    throw new IllegalStateException("generic handler did not accept " + info.path);
                }
            }
        } else if (info.artifacts.getDirectory() != null) {
            for (TxInfo child: info.children().values()) {
                // add the directory artifacts as hint to this one.
                if (child.artifacts == null) {
                    // in this case it's some deleted intermediate directory???
                    String path = info.name + "/" + child.name;
                    info.artifacts.add(new HintArtifact(path));

                } else {
                    for (Artifact a: child.artifacts.values()) {
                        String path = info.name + "/" + a.getRelativePath();
                        info.artifacts.add(new HintArtifact(path));
                    }
                }
            }
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                if (info.isIntermediate == 2) {
                    // skip existing intermediate
                    log.debug("skipping intermediate node at {}", info.path);
                } else if (info.artifacts.getPrimaryData() == null) {
                    // create nt:folder node if not exists
                    imp = folderHandler.accept(filter, node, info.name,  info.artifacts);
                    if (imp == null) {
                        throw new IllegalStateException("folder handler did not accept " + info.path);
                    }
                } else {
                    imp = genericHandler.accept(filter, node, info.artifacts.getDirectory().getRelativePath(), info.artifacts);
                    if (imp == null) {
                        throw new IllegalStateException("generic handler did not accept " + info.path);
                    }
                }
            }
        } else if (info.artifacts.size(ArtifactType.FILE) > 0) {
            Node node = info.getParentNode(session);
            if (node == null) {
                imp = new ImportInfoImpl();
                imp.onError(info.path, new IllegalStateException("Parent node not found."));
            } else {
                imp = fileHandler.accept(filter, node, info.name,  info.artifacts);
                if (imp == null) {
                    throw new IllegalStateException("file handler did not accept " + info.path);
                }
            }
        } else {
            throw new UnsupportedOperationException("ArtifactSet not supported: " + info.artifacts);
        }

        if (imp != null) {
            for (Map.Entry<String, ImportInfoImpl.Type> entry: imp.getModifications().entrySet()) {
                String path = entry.getKey();
                ImportInfoImpl.Type type = entry.getValue();
                if (type != ImportInfoImpl.Type.DEL) {
                    // mark intermediates as processed
                    TxInfo im = intermediates.remove(path);
                    if (im != null) {
                        log.debug("P {}", path);
                        removedIntermediates.put(path, im);
                        im.isIntermediate = 2;
                    }
                }
                switch (type) {
                    case CRE:
                        track("A", path);
                        autoSave.markResolved(path);
                        break;
                    case DEL:
                        track("D", path);
                        autoSave.markResolved(path);
                        break;
                    case MOD:
                        track("U", path);
                        autoSave.markResolved(path);
                        break;
                    case NOP:
                        track("-", path);
                        autoSave.markResolved(path);
                        break;
                    case REP:
                        track("R", path);
                        autoSave.markResolved(path);
                        break;
                    case MIS:
                        track("!", path);
                        autoSave.markMissing(path);
                        break;
                    case ERR:
                        Exception error = imp.getError(path);
                        if (error == null) {
                            track("E", path);
                        } else {
                            track(error, path);
                        }
                        hasErrors = true;
                        break;
                }
            }
            // see if any child nodes need to be reordered and remember namelist. we can only reorder the children
            if (imp.getNameList() != null && imp.getNode() != null && imp.getNameList().needsReorder(imp.getNode())) {
                // only restore order if in filter scope (bug #31906)
                // or if freshly created (bug #32075)
                if (filter.contains(info.path) || imp.getModifications().get(info.path) == ImportInfo.Type.CRE) {
                    assert(info.path.equals(imp.getNode().getPath()));
                    log.debug("remember to be reordered. path={} node.path={}", info.path, imp.getNode().getPath());
                    info.nameList = imp.getNameList();
                }
            }
            // check if node was remapped. currently we just skip them as it's not clear how the filter should be
            // reapplied or what happens if the remapping links to a tree we already processed.
            // in this case we don't descend in any children and can clear them right away
            if (imp.getRemapped().containsKey(info.path)) {
                info.children = null;
            }
        }
        log.debug("committed {}", info.path);
        return imp;
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.vault.fs.impl.io.ImportInfoImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.