예제 #1
0
void WebDavInventoryDataModel::UploadFile(const QString &file_path, AbstractInventoryItem *parent_folder)
{
    if (!parent_folder)
        parent_folder = GetFirstChildFolderByName("My Inventory");

    InventoryFolder *parentFolder = dynamic_cast<InventoryFolder *>(parent_folder);
    if (!parentFolder)
        return;

    QString filePath = file_path;
    QString filename = filePath.split("/").last();
    QString parentPath = ValidateFolderPath(parentFolder->GetID());
    QStringList result = webdavclient_.call("uploadFile", QVariantList() << filePath << parentPath << filename).toStringList();

    if (result.count() >= 1)
    {
        if (result[0] == "True")
        {
            FetchInventoryDescendents(parent_folder);
            InventoryModule::LogInfo(QString("Webdav | Upload of file %1 to path %2%3 succeeded\n").arg(filePath, parentPath, filename).toStdString());
        }
        else
            InventoryModule::LogInfo(QString("Webdav | Upload of file %1 to path %2%3 failed\n").arg(filePath, parentPath, filename).toStdString());
    }
}
예제 #2
0
bool WebDavInventoryDataModel::FetchInventoryDescendents(AbstractInventoryItem *item)
{
    InventoryFolder *selected = dynamic_cast<InventoryFolder *>(item);
    if (!selected)
        return false;

    // Delete children
    selected->GetChildren().clear();

    QString itemPath = selected->GetID();
    QStringList children = webdavclient_.call("listResources", QVariantList() << itemPath).toStringList();
    if ( children.count() >=1 )
    {
        // Process child list to map
        QMap<QString, QString> childMap;
        for (int index=0; index<=children.count(); index++)
        {
            childMap[children.value(index)] = children.value(index+1);
            index++;
        }

        AbstractInventoryItem *newItem = 0;
        QString path, name, type;
        for (QMap<QString, QString>::iterator iter = childMap.begin(); iter!=childMap.end(); ++iter)
        {
            path = iter.key();
            name = path.midRef(path.lastIndexOf("/")+1).toString();
            type = iter.value();
            if (name != "")
            {
                if (type == "resource")
                    newItem = new InventoryAsset(path, "", name, selected);
                else
                    newItem = new InventoryFolder(path, name, selected, true);
                selected->AddChild(newItem);
            }
        }

        InventoryModule::LogInfo(QString("Webdav | Fetched %1 children to path /%2").arg(QString::number(childMap.count()), itemPath).toStdString());
    }

    return true;
}
예제 #3
0
AbstractInventoryItem *WebDavInventoryDataModel::GetOrCreateNewFolder(const QString &id, AbstractInventoryItem &parentFolder,
        const QString &name, const bool &notify_server)
{
    InventoryFolder *parent = dynamic_cast<InventoryFolder *>(&parentFolder);
    if (!parent)
        return 0;

    if (RexUUID::IsValid(id.toStdString()))
    {
        // This is a new folder if the id is RexUUID 
        // RexUUID generated in data model, cant do nothing about this...
        QString parentPath = parent->GetID();
        QString newFolderName = name;
        QStringList result = webdavclient_.call("createDirectory", QVariantList() << parentPath << newFolderName).toStringList();
        if (result.count() >= 1)
        {
            if (result[0] == "True")
            {
                FetchInventoryDescendents(parent);
                InventoryModule::LogInfo(QString("Webdav | Created folder named %1 to path %2\n").arg(newFolderName, parentPath).toStdString());
            }
            else
                InventoryModule::LogInfo(QString("Webdav | Could not create folder named %1 to path %2\n").arg(newFolderName, parentPath).toStdString());
        }
    }
    else
    {
        // If its not RexUUID or and existing item in this folder,
        // then its a move command. Lets do that to the webdav server then...
        InventoryFolder *existingItem = parent->GetChildFolderById(id);
        if (!existingItem)
        {
            InventoryFolder *currentFolder = rootFolder_->GetChildFolderById(name);
            if (!currentFolder)
                return 0;

            QString currentPath = ValidateFolderPath(currentFolder->GetParent()->GetID());
            QString newPath = ValidateFolderPath(parent->GetID());
            QString folderName = name;
            QString deepCopy = "False";
            if (currentFolder->HasChildren())
                deepCopy = "True";
            QStringList result = webdavclient_.call("moveResource", QVariantList() << currentPath << newPath << folderName).toStringList();
            if (result.count() >= 1)
            {
                if (result[0] == "True")
                {
                    FetchInventoryDescendents(parent);
                    InventoryModule::LogInfo(QString("Webdav | Moved folder %1 from %2 to %3\nNote: This fucntionality is experimental,").append(
                        "dont assume it went succesfull\n").arg(folderName, currentPath, newPath).toStdString());
                }
                else
                {
                    InventoryModule::LogInfo(QString("Webdav | Failed to move folder %1 from %2 to %3\n").arg(
                        folderName, currentPath, newPath).toStdString());
                }
            }
        }
        else
            return existingItem;
    }

    // Return 0 to data model, we just updated 
    // folder content from webdav, no need to return the real item
    return 0;
}