void MasterCatalogModel::loadWorkSpaces(const QString workspaceList){
    QStringList parts = workspaceList.split("|");
    for(const QString& workspaceName : parts){
        QString basekey = "users/" + Ilwis::context()->currentUser() + "/workspace-" + workspaceName;
        addWorkSpace(workspaceName);
        WorkSpaceModel *wmodel = _workspaces.back();
        int operationCount = Ilwis::ilwisconfig(basekey + "/operation-count",0);
        int dataCount = Ilwis::ilwisconfig(basekey + "/data-count",0);
        QString ids = determineIdList(dataCount, operationCount, basekey);
        wmodel->addItems(ids);
    }

}
void MasterCatalogModel::addWorkSpace(const QString &name)
{
    if ( name == "" || name.toLower() == "default")
        return;

    for(auto ws : _workspaces){
        if ( ws->name() == name)
            return;
    }
    WorkSpaceModel *wmodel = new WorkSpaceModel(name, this);
    QString path = "ilwis://internalcatalog/workspaces/" + name;
    Resource resource(path,itWORKSPACE);
    CatalogView view(resource);
    wmodel->setView(view);
    _workspaces.push_back(wmodel);
    uicontext()->setCurrentWorkSpace(wmodel);
    emit workspacesChanged();
}
Ejemplo n.º 3
0
void OperationCatalogModel::gatherItems() {
    if (!_refresh)
        return;

    _allItems.clear();
    _refresh = false;


    WorkSpaceModel *currentModel = uicontext()->currentWorkSpace();
    bool isDefault = false;
    if (currentModel){
        auto n = currentModel->name();
        isDefault = n == "default";
    }
    if ( currentModel == 0 || isDefault){
        setDescription("main catalog for ilwis operations");

        QString serviceFilter = QString("(type=%1 and catalogitemproperties.propertyname='keyword' and catalogitemproperties.propertyvalue like '%service%')").arg(itSINGLEOPERATION);

        _services = mastercatalog()->select(serviceFilter);
    }else {
        setView(currentModel->viewRef());
    }

    std::vector<Resource> items = _view.items();
    std::sort(items.begin(), items.end(),[](const Resource& r1, const Resource& r2){
        QString name1 = r1["longname"].toString();
        if ( name1 == sUNDEF)
            name1 = r1.name();
        QString name2 = r2["longname"].toString();
        if ( name2 == sUNDEF)
            name2 = r2.name();
        return name1.toLower() < name2.toLower();


    });
    std::map<QString, std::vector<OperationModel *>> operationsByKey;
    std::set<QString> keywordset;

    for(const Resource& resource : items){
        OperationModel *operation = new OperationModel(resource, this);
        QString kws = resource["keyword"].toString();
        if ( kws.indexOf("internal") != -1)
            continue;
        _allItems.push_back(operation);
        QString keysstring = operation->resource()["keyword"].toString();
        QStringList keys = keysstring.split(",");
        for(auto key : keys){
            operationsByKey[key].push_back(operation);
            keywordset.insert(key);
        }
    }
    _operationsByKey.clear();
    for( const auto& item : operationsByKey){
         _operationsByKey.push_back(new OperationsByKeyModel(item.first, item.second, this));

    }
    _keywords.clear();
    for(auto keyword : keywordset)
        _keywords.push_back(keyword);


    qSort(_keywords.begin(), _keywords.end());
    _keywords.push_front(""); // all
    OperationCatalogModel *oc = uicontext()->globalOperationCatalog();
    if ( oc != this){
       oc->_refresh = true;
       oc->operations();
    }
}
void OperationCatalogModel::gatherItems() {
    if (!_refresh)
        return;

    WorkSpaceModel *currentModel = uicontext()->currentWorkSpace();
    bool isDefault = false;
    if (currentModel){
        auto n = currentModel->name();
        isDefault = n == "default";
    }
    if ( currentModel == 0 || isDefault){
        if ( !_view.isValid()){
            QUrl location("ilwis://operations");
            QString descr ="main catalog for ilwis operations";
            Resource res(location, itCATALOGVIEW ) ;
            res.name("ilwis-operations",false);
            QStringList lst;
            lst << location.toString();
            res.addProperty("locations", lst);
            res.addProperty("type", "operation" );
            res.addProperty("filter",QString("(type=%1 or type=%2)").arg(itSINGLEOPERATION).arg(itWORKFLOW));
            res.setDescription(descr);
            setView(CatalogView(res));

            location = QUrl("ilwis://operations");
            descr ="main catalog for ilwis services";
            res = Resource(location, itCATALOGVIEW ) ;
            res.name("ilwis-services",false);
            lst.clear();
            lst << location.toString();
            res.addProperty("locations", lst);
            res.addProperty("type", "operation" );
            res.addProperty("filter",QString("(type=%1 and keyword='service')").arg(itSINGLEOPERATION));
            res.setDescription(descr);
            CatalogView view(res);
            view.prepare();

            _services = view.items();
        }
    }else {
        setView(currentModel->view());
    }
    CatalogModel::gatherItems();
    std::set<QString> keywordset;
    std::map<QString, std::vector<OperationModel *>> operationsByKey;
    for(auto item : _currentItems){
        QString keywords = item->resource()["keyword"].toString();
        if ( !(item->resource().ilwisType() & itOPERATIONMETADATA))
            continue;
        if ( keywords.indexOf("internal") != -1)
            continue;
        _currentOperations.push_back(new OperationModel(item->resource(), this));
        if ( keywords == sUNDEF)
            keywords = TR("Uncatagorized");
        QStringList parts = keywords.split(",");
        for(auto keyword : parts){
            keywordset.insert(keyword);
        }
        for(auto keyword : parts){
            operationsByKey[keyword].push_back(new OperationModel(item->resource(), this));
        }
    }
    _keywords.clear();
    for(auto keyword : keywordset)
        _keywords.push_back(keyword);


    qSort(_keywords.begin(), _keywords.end());

    _keywords.push_front(""); // all

    for(auto operation : operationsByKey){
        _operationsByKey.push_back(new OperationsByKeyModel(operation.first, operation.second, this));
    }
}