Search in sources :

Example 1 with VNode

use of nl.uva.vlet.vrs.VNode in project lobcder by skoulouzis.

the class Assimilator method assimilate.

private void assimilate(List<StorageSite> sites) throws SQLException, MalformedURLException, VlException, NoSuchAlgorithmException, Exception {
    Connection c = getConnection();
    StorageSiteClient ssClient;
    for (StorageSite site : sites) {
        String username = site.getCredential().getStorageSiteUsername();
        String password = site.getCredential().getStorageSitePassword();
        String ssURI = site.getResourceURI();
        long ssID = getStorageSiteID(c, ssURI);
        if (ssID == -1) {
            long credentialsID = addCredentials(c, username, password);
            ssID = addStorageSite(c, site, credentialsID, false);
        }
        URI importedURI = new URI(site.getResourceURI());
        String importedFolderName = "ImportedFrom-" + importedURI.getScheme() + "-" + importedURI.getHost();
        // Add imported folder
        LogicalData imported = getLogicalDataByPath(Path.path(importedFolderName), c);
        Long importedUid;
        if (imported == null) {
            importedUid = addRegisteredFolder(importedFolderName, c);
        } else {
            importedUid = imported.getUid();
        }
        // 
        ssClient = new StorageSiteClient(username, password, ssURI);
        VNode dir = ssClient.getStorageSiteClient().getNode(new VRL(ssURI));
        // VFSClient client = (VFSClient) ssClient.getStorageSiteClient();
        // VDir dir = client.openDir(new VRL(ssURI));
        // build folders first
        nl.uva.vlet.vdriver.vrs.http.HTTPNode k = (nl.uva.vlet.vdriver.vrs.http.HTTPNode) dir;
        // k.getInputStream()
        add((VComposite) dir, dir.getPath(), c, ssID, false);
        VNode[] nodes = ((VComposite) dir).getNodes();
        for (VNode n : nodes) {
            if (!n.isComposite()) {
                VFile f = (VFile) n;
                String fileName = n.getName();
                VRL currentPath = new VRL(f.getPath().replaceFirst(dir.getPath(), ""));
                LogicalData parent = getLogicalDataByPath(Path.path(currentPath.getPath()), c);
                Long parentRef;
                if (parent != null) {
                    parentRef = parent.getUid();
                } else {
                    parentRef = importedUid;
                }
                LogicalData registered = getLogicalDataByParentRefAndName(parentRef, fileName, c);
                System.err.println(currentPath);
                if (registered == null) {
                    addFile(c, f, parentRef, ssID);
                }
            }
        }
    }
    c.commit();
    c.close();
}
Also used : URI(java.net.URI) VFile(nl.uva.vlet.vfs.VFile) LogicalData(nl.uva.cs.lobcder.resources.LogicalData) VRL(nl.uva.vlet.vrl.VRL) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) VNode(nl.uva.vlet.vrs.VNode) VComposite(nl.uva.vlet.vrs.VComposite)

Example 2 with VNode

use of nl.uva.vlet.vrs.VNode in project lobcder by skoulouzis.

the class Assimilator method add.

public void add(VComposite dir, String base, Connection connection, long ssid, boolean addFiles) throws MalformedURLException, VlException, SQLException, NoSuchAlgorithmException {
    VNode[] nodes = dir.getNodes();
    for (VNode f : nodes) {
        VRL currentPath = new VRL(f.getPath().replaceFirst(base, ""));
        LogicalData register = getLogicalDataByPath(Path.path(currentPath.getPath()), connection);
        LogicalData parent = getLogicalDataByPath(Path.path(currentPath.getPath()).getParent(), connection);
        Long parentRef = new Long(1);
        if (parent == null) {
            parentRef = new Long(1);
        } else {
            parentRef = parent.getUid();
        }
        if (f.isComposite()) {
            if (register == null) {
                LogicalData entry = new LogicalData();
                if (f instanceof VDir) {
                    VDir d = (VDir) f;
                    entry.setCreateDate(d.getModificationTime());
                    entry.setModifiedDate(d.getModificationTime());
                } else {
                    entry.setCreateDate(System.currentTimeMillis());
                    entry.setModifiedDate(System.currentTimeMillis());
                }
                entry.setName(f.getName());
                entry.setOwner(importingOwner);
                entry.setParentRef(parentRef);
                register = registerDirLogicalData(entry, connection);
            }
            add((VComposite) f, base, connection, ssid, addFiles);
        } else if (addFiles) {
            if (register == null) {
                System.err.println(f.getVRL());
                addFile(connection, (VFile) f, parentRef, ssid);
            }
        }
    }
}
Also used : VRL(nl.uva.vlet.vrl.VRL) LogicalData(nl.uva.cs.lobcder.resources.LogicalData) VNode(nl.uva.vlet.vrs.VNode) VDir(nl.uva.vlet.vfs.VDir) VFile(nl.uva.vlet.vfs.VFile)

Aggregations

LogicalData (nl.uva.cs.lobcder.resources.LogicalData)2 VFile (nl.uva.vlet.vfs.VFile)2 VRL (nl.uva.vlet.vrl.VRL)2 VNode (nl.uva.vlet.vrs.VNode)2 URI (java.net.URI)1 StorageSite (nl.uva.cs.lobcder.resources.StorageSite)1 VDir (nl.uva.vlet.vfs.VDir)1 VComposite (nl.uva.vlet.vrs.VComposite)1