用户个人简介
404 – 找不到个人简介
会员起始日期:三月 1, 2016
Louis Lu · 八月 6, 2024 转到文章
Include EnsConstants

/// Get Settings from Production and Create DefaultSettingsClass CONNECTORSPKG.Utility.DefaultSettings
{

/// List productionsClassMethod ListProductions(printAs%Boolean = 1, namespace As%String = {$NAMESPACE}) As%String
{
    new$NAMESPACEset$NAMESPACE = namespace
    set production = ""ifprint
    {
        write"Productions in namespace " _ namespace _ ":",!
    }

    set prdRS = ##class(%ResultSet).%New("Ens.Config.Production:ProductionStatus")
    do prdRS.Execute()

    while (prdRS.Next())
    {
        set status = prdRS.Data("Status")

        if status = "Running"
        {
            set production = prdRS.Data("Production")
        }

        ifprint
        {
            write prdRS.Data("Production")," (",status,")",!
        }
    }

    return production
}

/// Export to settingsfileClassMethod Export() As%Status
{
    return##class(Ens.Config.DefaultSettings).%Export("/home/irisowner/systemdefaults/Ens.Config.DefaultSettings.esd", "MONDRIAAN.FoundationProduction")
}

/// Export from settingsfileClassMethod Import() As%Status
{
    set sc = ##class(Ens.Config.DefaultSettings).%Import("/home/irisowner/systemdefaults/Ens.Config.DefaultSettings.esd", .count, .idsimported)

    write"Imported ",count," settings",!

    return sc
}

/// Connectors actionClassMethod SettingsFromProduction(removeFromProduction As%Boolean = 0, updateSettings As%Boolean = 1) As%Status
{
    return..GetSettingsFromProduction("CONNECTORSPKG.FoundationProduction", "*:HTTPServer,SSLConfig;CONNECTORSPKG.BO.GenericHTTP.Operation:HttpMethod,AcceptHeader,ContentType,URL,AuthorizationType,Credentials,CustomAuthorizationHeader,AlertOnError,ReplyCodeActions", removeFromProduction, updateSettings)
}

/// Get settings From ProductionClassMethod GetSettingsFromProduction(production As%String = {..ListProductions(0, $NAMESPACE)}, filter As%String = "", removeFromProduction As%Boolean = 0, updateSettings As%Boolean = 1) As%Status
{
    write"Settings in production '",production _ "':",!
    set xdataId = production _ "||ProductionDefinition"set xdata = ##class(%Dictionary.XDataDefinition).%OpenId(xdataId, , .sc)

    if$$$ISERR(sc)
    {
        write"Failed to open XData block '" _ xdataId,"': ",$SYSTEM.Status.GetErrorText(sc),!
        return sc
    }

    set tProduction = ##class(Ens.Config.Production).%OpenId(production,,.sc)

    if$$$ISERR(sc)
    {
        write"Failed to open production '",production,"': ",$SYSTEM.Status.GetErrorText(sc),"; settings will not be removed from the production",!
        set removeFromProduction = 0
    }

    set sc = ##class(%XML.TextReader).ParseStream(xdata.Data, .textreader)
    #dim textreader as%XML.TextReaderif$$$ISERR(sc)
    {
        write"Failed to parse XData block '" _xdataId,"': ",$SYSTEM.Status.GetErrorText(sc),!
        return sc
    }

    set currentItemName = ""set currentItemClass = ""#dim tRemovedItemCount as%Integer = 0while textreader.Read()
    {
        if (textreader.NodeType '= "element")
        {
            continue
        }

        if (textreader.LocalName = "Item")
        {
            if (textreader.MoveToAttributeName("Name"))
            {
                set currentItemName = textreader.Value
            }

            if (textreader.MoveToAttributeName("ClassName"))
            {
                set currentItemClass = textreader.Value
            }
            #; write "Found Item with Name='" _ currentItemName _ "' of class '" _ currentItemClass _ "':",!continue
        }

        if (textreader.LocalName = "Setting")
        {
            do..HandleXDataSetting(textreader, tProduction, currentItemName, currentItemClass, filter, removeFromProduction, updateSettings, .tRemovedItemCount)
        }
    }

    if tRemovedItemCount > 0
    {
        write"Removed ",tRemovedItemCount," settings; now saving Production '",production,"':"return..SaveProduction(tProduction)
    }

    return$$$OK
}

/// Hanlde setting found in the XData ClassMethod HandleXDataSetting(textreader As%XML.TextReader, tProduction As Ens.Config.Production, currentItemName As%String, currentItemClass As%String, filter As%String, removeFromProduction As%Boolean, updateSettings As%Boolean, ByRef tRemovedItemCount As%Integer)
{
    if (textreader.MoveToAttributeName("Target"))
    {
        set target = textreader.Value
    }
    if (textreader.MoveToAttributeName("Name"))
    {
        set name = textreader.Value
    }

    do textreader.Read() // Read valueset value = textreader.Value

    #; write "Found Setting Target=",target,", name=",name,", Value=",value,!if..InFilter(filter, currentItemName, currentItemClass, target, name, value)
    {
        if updateSettings && $$$ISERR(..HandleSetting(tProduction.Name, currentItemName, currentItemClass, target, name, value))
        {
            return
        }

        if removeFromProduction && ..RemoveSettingFromProduction(tProduction, currentItemName, target, name)
        {
            set tRemovedItemCount = tRemovedItemCount + 1
        }
    }
}

/// SaveProductionClassMethod SaveProduction(tProduction As Ens.Config.Production) As%Status
{
    // Save the changes we made to the productionset sc = tProduction.%Save(1)

    if$$$ISERR(sc)
    {
        write" failed: ",$SYSTEM.Status.GetErrorText(sc),!
        return sc
    }
    write !

    // Regenerate the XData in the corresponding classwrite"Save Production XData: "Set sc = tProduction.SaveToClass()

    if$$$ISERR(sc)
    {
        write" failed: ",$SYSTEM.Status.GetErrorText(sc),!
        return sc
    }
    write !

    // Grab the state of the productionset sc = ##class(Ens.Director).GetProductionStatus(.tRunningProduction, .tState)

    if$$$ISERR(sc)
    {
        write"Failed to get Production status: ",$SYSTEM.Status.GetErrorText(sc),!
        return sc
    }

    // Finally, does the production need updating?if (tRunningProduction = tProduction.Name) && (tState = $$$eProductionStateRunning)
    {
        // Update the running production with the new settingswrite"Update running production: "set sc = ##class(Ens.Director).UpdateProduction(##class(Ens.Director).GetRunningProductionUpdateTimeout())

        if$$$ISERR(sc)
        {
            write" failed: ",$SYSTEM.Status.GetErrorText(sc),!
            return sc
        }
    }

    return$$$OK
}

/// Determine if the setting is in the Filter ClassMethod InFilter(filter As%String, itemName As%String, classAs%String, target As%String, varName As%String, value As%String) As%Boolean
{
    if filter = ""
    {
        return1
    }

    for classIndex = 1:1:$LENGTH(filter, ";")
    {
        set classPart = $PIECE(filter, ";", classIndex)
        set configClass = $PIECE(classPart, ":", 1)

        if (configClass '= "*") && (configClass '= class)
        {
            continue
        }

        set vars = $PIECE(classPart, ":", 2)

        for varIndex = 1:1:$LENGTH(vars, ",")
        {
            if$PIECE(vars, ",", varIndex) = varName
            {
                return1
            }
        }
    }

    return0
}

/// Handle SettingClassMethod HandleSetting(production As%String, item As%String, classAs%String, target As%String, varName As%String, value As%String) As%Status
{
    if##class(Ens.Config.DefaultSettings).IdKeyExists(production, item, class, varName, .id)
    {
        set defaultSetting = ##class(Ens.Config.DefaultSettings).%OpenId(id, , .sc)

        if$$$ISERR(sc)
        {
            write"Failed to get default setting named '",item,":",varName,"': ",$SYSTEM.Status.GetErrorText(sc),!
            return sc
        }

        if defaultSetting.SettingValue = value
        {            
            write"Skipping '",item,":",varName,"' as it already exists with the same value",!
            return$$$OK
        }

        write"Updating '",item,":",varName,"' from '",defaultSetting.SettingValue,"' to '",value,"'",!
    }
    else
    {
        set defaultSetting = ##class(Ens.Config.DefaultSettings).%New()
        set defaultSetting.ProductionName = production
        set defaultSetting.ItemName = item
        set defaultSetting.HostClassName = classset defaultSetting.SettingName = varName
        set defaultSetting.Deployable = 1write"Creating '",item,":",varName,"' from '",defaultSetting.SettingValue,"' with value '",value,"'",!
    }

    set defaultSetting.SettingValue = value

    set sc =  defaultSetting.%Save()

    if$$$ISERR(sc)
    {
        write"Failed setting default setting named '",item,":",varName,"' to '",value,"': ",$SYSTEM.Status.GetErrorText(sc),!
    }

    return sc
}

/// Rmove Setting from productionClassMethod RemoveSettingFromProduction(tProduction As Ens.Config.Production, item As%String, target As%String, varName As%String) As%Boolean
{
    #dim tItemObj as Ens.Config.Item = tProduction.FindItemByConfigName(item, .sc, 1)

    if '$IsObject(tItemObj)
    {
        write"Failed to get item '",item,"': ",$SYSTEM.Status.GetErrorText(sc),!
        return0
    }

    for i = 1:1:tItemObj.Settings.Count()
    {
        #dim tSetting As Ens.Config.Setting = tItemObj.Settings.GetAt(i)

        if (tSetting.Name = varName) && (tSetting.Target = target)
        {
            do tItemObj.Settings.RemoveAt(i, .success)
            return success
        }
    }

    return0
}

}
Louis Lu · 五月 29, 2023 转到文章

这个函数是java调用IRIS上的方法或者routine。

比如有一个routine的名字是NativeRoutine,routine中有一个方法的名字是fnString,方法调用的参数是"World"

那么从Java调用就可以:

String stringVal = irisjv.functionString("fnString",routineName,"World");

详细文档可以参考:https://docs.intersystems.com/irisforhealthlatest/csp/docbook/DocBook.UI.Page.cls?KEY=BJAVNAT_call

认证与 Credly 徽章:
Louis 还没有认证与 Credly 徽章.
关注者:
Louis 还没有关注者。
正在关注:
Louis 尚未关注任何人。