def componentImport(obj,
                    protocol,
                    user=None,
                    refreshCache=False,
                    modelType=['activity', 'item']):
    """
    :param modelType: model or models to search
    :type modelType: str or iterable
    :returns: protocol (updated)
    """
    import itertools
    from girderformindlogger.models import pluralize, smartImport
    from girderformindlogger.utility import firstLower

    updatedProtocol = deepcopy(protocol)
    obj2 = {k: v for k, v in expand(deepcopy(obj)).items() if v is not None}
    try:
        for order in obj2.get("reprolib:terms/order", {}):
            for activity in order.get("@list", []):
                IRI = activity.get('url', activity.get('@id'))
                if reprolibPrefix(IRI) not in list(
                        itertools.chain.from_iterable([
                            protocol.get(mt, {}).keys()
                            for mt in ["activities", "items"]
                        ])):
                    activityComponent, activityContent, canonicalIRI =         \
                        smartImport(
                            IRI,
                            user=user,
                            refreshCache=refreshCache
                        ) if (IRI is not None and not IRI.startswith(
                            "Document not found"
                        )) else (None, None, None)
                    activity["url"] = activity[
                        "schema:url"] = canonicalIRI if (canonicalIRI
                                                         is not None) else IRI
                    activityComponent = pluralize(
                        firstLower(
                            activityContent.get(
                                '@type', [''])[0].split('/')[-1].split(':')[-1]
                        )) if (activityComponent is None and isinstance(
                            activityContent, dict)) else activityComponent
                    if activityComponent is not None:
                        activityComponents = (pluralize(activityComponent)
                                              if activityComponent != 'screen'
                                              else 'items')
                        updatedProtocol[activityComponents][
                            canonicalIRI] = deepcopy(
                                formatLdObject(activityContent,
                                               activityComponent,
                                               user,
                                               refreshCache=refreshCache))
        return (updatedProtocol.get('meta', updatedProtocol).get(
            modelType if isinstance(modelType, str) else modelType[0],
            updatedProtocol))
    except:
        import sys, traceback
        print("error!")
        print(sys.exc_info())
        print(traceback.print_tb(sys.exc_info()[2]))
def importAndCompareModelType(model, url, user, modelType):
    import threading
    from girderformindlogger.utility import firstLower

    if model is None:
        return (None, None)
    mt = model.get('@type', '')
    mt = mt[0] if isinstance(mt, list) else mt
    atType = mt.split('/')[-1].split(':')[-1]
    modelType = firstLower(atType) if len(atType) else modelType
    modelType = 'screen' if modelType.lower(
    ) == 'field' else 'protocol' if modelType.lower(
    ) == 'activityset' else modelType
    changedModel = ((atType != modelType and len(atType))
                    or (" " in modelType))
    modelType = firstLower(atType) if changedModel else modelType
    modelType = 'screen' if modelType.lower(
    ) == 'field' else 'protocol' if modelType.lower(
    ) == 'activityset' else modelType
    modelClass = MODELS()[modelType]()
    prefName = modelClass.preferredName(model)
    cachedDocObj = {}
    model = expand(url)
    print("Loaded {}".format(": ".join([modelType, prefName])))
    docCollection = getModelCollection(modelType)
    if modelClass.name in ['folder', 'item']:
        docFolder = FolderModel().createFolder(
            name=prefName,
            parent=docCollection,
            parentType='collection',
            public=True,
            creator=user,
            allowRename=True,
            reuseExisting=(modelType != 'applet'))
        if modelClass.name == 'folder':
            newModel = modelClass.setMetadata(
                docFolder,
                {modelType: {
                    **model, 'schema:url': url,
                    'url': url
                }})
        elif modelClass.name == 'item':
            newModel = modelClass.setMetadata(
                modelClass.createItem(name=prefName if prefName else str(
                    len(
                        list(FolderModel().childItems(FolderModel().load(
                            docFolder, level=None, user=user, force=True)))) +
                    1),
                                      creator=user,
                                      folder=docFolder,
                                      reuseExisting=True),
                {modelType: {
                    **model, 'schema:url': url,
                    'url': url
                }})
    formatted = _fixUpFormat(
        formatLdObject(newModel,
                       mesoPrefix=modelType,
                       user=user,
                       refreshCache=True))
    createCache(newModel, formatted, modelType, user)
    return (formatted, modelType)