Maximo

 View Only
Expand all | Collapse all

Update view definition via Maximo UI

  • 1.  Update view definition via Maximo UI

    Posted Sat August 14, 2021 12:13 PM
    Edited by System Test Wed March 22, 2023 11:49 AM

    MAM 7.6.1.2; Oracle 19c:

    I have views that are Maximo DB config objects. I want to make minor changes to the logic behind existing calculated fields in the views (i.e. the SELECT clause).

    Updating views through the db is not a viable option for me. It would be best if I could make the changes myself through the Maximo UI.

    As it stands right now, I think I would need to build a custom action/autoscript in the Database Configuration application that could update Maximo views.

    Question:
    Is there a Java method that I can use to update Maximo database view definitions? Or some other option that I've overlooked? (other than CREATE VIEW privileges in the db)


    Thanks.


    #AssetandFacilitiesManagement
    #Maximo


  • 2.  RE: Update view definition via Maximo UI

    Posted Sat August 14, 2021 06:14 PM
    Edited by System Test Wed March 22, 2023 11:46 AM


  • 3.  RE: Update view definition via Maximo UI

    Posted Sun August 15, 2021 09:18 PM
    If a view is defined inside of Maximo (IE not imported) you would be able to modify the where, select, or view from attributes inside of Database Configuration. There are challenges with views that make it harder to change from the front end. For example, when adding an attribute through the UI manually to a view it's always going to mark it as non-persistent which makes searching on it not possible. That's where DBC files or imported views become useful. 

    Because Maximo requires database owner privileges (to create/drop tables, indexes, views, etc.), it has the access required to modify views. You'd have to build the framework aspect of it (tracking what you want the view to be and making any changes required to make MAXATTRIBUTE table for example) and you ultimately still need an outage or to execute a DB config to make Maximo aware of any attribute related changes. If you're just looking to adjust the where clause, you could modify that on a view without needing to update Maximo necessarily (especially if it's an imported view). 

    If you want to go down the path of adjusting a view from a Maximo automation script, I can help with opening the database connection and executing SQL commands in context of the MAXIMO user account which would allow you to modify the view.

    I think part of the reason views aren't well supported in the front end (beyond simple extensions of a table like WORKORDER with a different where clause) is the challenges they represent to the framework to get back into a MBO record. For example, I can create a view where one of the columns concatenates two attributes together. Database platform handle this with ease. But the Maximo framework would have to be intelligent enough to know this field has to be read-only (because the database platform won't allow an update to it since it wouldn't know how to store it) and the Maximo framework would have to know the absolute maximum length this could be by adding the length of the two attributes (and any additional characters if they're concatenated with - for example) to avoid errors retrieving the data from the database to store in the MBO. 

    For UI use cases, I think the REST API along with the new framework will make a lot of these scenarios easier to support. The REST API is really powerful and is only going to grow in capabilities. There are other scenarios (such as reporting) where view capabilities would be advantageous and things could be easier if the framework could make assumptions such as that it would never be instantiated in a MBO for example. Not saying any of this would ever happen but it's how I'd probably go about trying to solve the problem.

    ------------------------------
    Steven Shull
    ------------------------------



  • 4.  RE: Update view definition via Maximo UI

    Posted Wed September 08, 2021 09:52 PM
    Edited by System Test Wed March 22, 2023 11:45 AM
    Thanks Steven. That's really helpful.

    What do you think about this script as a way to create a db view?
    (The idea is that I can import the db view into Maximo as an object. As you mentioned, imported views have advantages over views that are created right in Maximo.)


    from psdi.server import MXServer
    mxserver = MXServer.getMXServer()

    userInfo = mxserver.getSystemUserInfo()
    conKey = mxserver.getSystemUserInfo().getConnectionKey()
    con = mxserver.getDBManager().getConnection(conKey)
    s= con.createStatement()

    rs=s.executeQuery("create or replace view CGTESTWO_VW as (select wonum, workorderid from workorder)")
    print "rs",rs
    rs.close()
    s.close()
    con.commit()
    mxserver.getDBManager().freeConnection(conKey)

    print ""
    print "The SQL statement has been executed successfully."


    Source: Execute update statement through automation script


    #AssetandFacilitiesManagement
    #Maximo


  • 5.  RE: Update view definition via Maximo UI

    Posted Wed September 08, 2021 09:56 PM
    For what it's worth, I stumbled across a Java method called buildCreateViewStatement.
    I'm not sure if it's useful to us or not.

    https://bportaluri.com/wp-content/MaximoJavaDocs76/psdi/configure/Util.html#buildCreateViewStatement(java.util.HashMap,%20boolean,%20boolean)





  • 6.  RE: Update view definition via Maximo UI

    Posted Thu September 09, 2021 08:20 AM
    I would personally avoid this because it's designed around Maximo specific logic. That viewInfo HashMap needs to be provided information in a specific format (as if it was coming from DB config with all the various attributes that can be defined there) which would be hard to do in the case that you're creating a new view that doesn't exist yet (which would have to be the case to get the "imported" capability).

    ------------------------------
    Steven Shull
    ------------------------------



  • 7.  RE: Update view definition via Maximo UI

    Posted Wed October 20, 2021 10:45 AM
    Edited by System Test Wed March 22, 2023 11:45 AM


  • 8.  RE: Update view definition via Maximo UI

    Posted Wed October 20, 2021 11:15 AM
    Edited by System Test Wed March 22, 2023 11:47 AM
    More info about DBShortcut here:


    How to Retrieve a JDBC connection in Automation Scripts

    Of course, you could do the standard application approach where you get the connection string, username and password and then open a connection yourself. However, the Maximo Server object can give us the connect object. This eliminates the need to have the username and password stored somewhere (security audits like that). As such I will not be covering that approach here. In both examples, we will be using the Maximo Server Object (MXServer) to get the database connection.


    JDBC Connection

    Here is a sample that shows how to get a JDBC connection from Maximo connection pool (and correctly release it).

    from psdi.server import MXServer
    from psdi.security import ConnectionKey
    from java.sql import Connection
    from java.sql import Statement
    
    mxServer = MXServer.getMXServer()
    conKey = mxServer.getSystemUserInfo().getConnectionKey()
    con = mxServer.getDBManager().getConnection(conKey)
    
    c = 0
    try:
        stmt = con.createStatement()
        rs = stmt.executeQuery("select count(1) from asset")
        while rs.next():
            c = rs.getInt(1)
        rs.close()
        stmt.close()
        con.commit()
    except:
        #error do something meaningful about the error
        c = -1
    finally:
        mxServer.getDBManager().freeConnection(conKey)
    
    
    

    If you have done any java JDBC programming at all you will see that this is a pretty standard approach. We first get the credentials for connecting to the database (conKey). Then we use it to get a connection object (con) from the Maximo database connection pool. Then we use a Statement object (stmt) to get a ResultSet object (rs). We then process that ResultSet. Take special note of the last line:

                  mxServer.getDBManager().freeConnection(conKey)

    This is how you tell Maximo that you are done with the JDBC connection so it can free it to the connect pool. Eventually the garbage collection would see that your script is complete and free the connection, but issuing the command makes it happen immediately, lessoning the change of running out of available connections. (e.g. when you are processing thousands of records, so the script is running thousands of times.)

    DBShortcut class

    A quick easy way to get a java.sql.ResultSet object is to use DBShortcut class. This object comes in the psdi.mbo package and is designed to quickly retrieve result-sets or run update statements against the database.

    from psdi.server import MXServer
    from psdi.security import ConnectionKey
    from psdi.mbo import DBShortcut
    from java.sql import Connection
    
    mxServer = MXServer.getMXServer()
    conKey = mxServer.getSystemUserInfo().getConnectionKey()
    dbs = DBShortcut()
    dbs.connect(conKey)
    
    c = 0
    try:
        rs = dbs.executeQuery("select count(1) from asset")
        while rs.next():
            c = rs.getInt(1)
        rs.close()
        dbs.commit()
    except:
        #error do something meaningful about the error
        c = -1
    finally:
        dbs.close()
    
    
    

    The big difference here is that by using the DBShortcut class, Maximo controls all of the required connection objects (e.g. Connection, Statement) so you do not have to worry about them. It just gives you a ResultSet. Where this really is shown is in the cleanup. We don't have a Statement object to close, instead of committing the connection, we tell DBShortcut to commit(), and by simply calling the close() method on the DBShortcut variable, it will automatically free up the connection. The DBShortcut is doing everything we did in the JDBC Connection example, it just does it for you so you can use few lines of code.



    Other articles by Michael (M.L.) Chrisman:

    https://www.linkedin.com/in/michaelchrisman/detail/recent-activity/posts/



    Related post here:
    USE ESCALATION/ACTION TO TRUNCATE AND RELOAD A CUSTOM TABLE?

    #Maximo
    #AssetandFacilitiesManagement


  • 9.  RE: Update view definition via Maximo UI

    Posted Thu September 09, 2021 08:43 AM
    I prefer to utilize DBShortcut. I provided a query example here https://moremaximo.com/communities/community-home/digestviewer/viewthread?GroupId=37&MessageKey=a41bc178-57db-44e2-ae50-117d1a758881&CommunityKey=784e8753-d7af-4281-8463-e86f3b5d7076&tab=digestviewer

    You need to use the SQLFormat library which helps with parameterization of statements anyways which is why I like using DBShortcut. You would call execute in this case since it's not a query. You would then potentially call commit, though I assume creating a view is not something that can be rolled back so I don't think it'll actually do anything.

    The most important part is you always want to wrap it with try, except, finally and ensure you close in the finally step. You don't want an exception to occur and leave the connection open. DBShortcut in its close will also call the freeConnection so you don't need to have that in your finally, just the close.

    ------------------------------
    Steven Shull
    ------------------------------



  • 10.  RE: Update view definition via Maximo UI

    Posted Thu September 09, 2021 09:11 AM
    Edited by System Test Wed March 22, 2023 11:53 AM
    For my records, here is the script from the link that Steven provided:


    "Is it possible to retrieve data from a database view using a REST API?"

    "Yes, and how will depend on whether or not Maximo is aware of the view (IE is it configured as an object inside of Maximo). If it's an object inside of Maximo you should create an object structure to process it. If Maximo is not aware of the view, but the Maximo account has access to the database view, you can write an Automation Script and invoke that automation script from the REST API. Section 14 of the REST API document covers calling a script from the REST API pretty well. Overview (ibm.com)


    If you've never written an automation script to query the database, using DBShortcut is probably the easiest approach. If you call the script from the REST API, you'll have an implicit variable of request which you can call request.getUserInfo() to get their userInfo which is necessary to get their connection key. We typically use python and wrap this with a try except finally to ensure that the database connection is closed when we're done. I've written a really basic shell of the code to execute a database query, but you'll at least need to build the responseBody implicit variable to return back to your code."


    from psdi.mbo import DBShortcut,SqlFormat

    try:
        dbShortcut=DBShortcut()
        dbShortcut.connect(request.getUserInfo().getConnectionKey())
        sqfQuery=SqlFormat("SELECT * FROM asset WHERE siteid=:1 and status='OPERATING'")
        sqfQuery.setObject(1,"ASSET","SITEID","BEDFORD")
        resultSet=dbShortcut.executeQuery(sqfQuery.format())

        while resultSet.next():
        resultSet.getString("ASSETNUM")
    except:
        # put your error handling here, whether that's emailing or what. Be careful that it won't generate another exception though
    finally:
        dbShortcut.close()
    #Maximo
    #AssetandFacilitiesManagement


  • 11.  RE: Update view definition via Maximo UI

    Posted Thu September 09, 2021 06:00 PM
    Edited by System Test Wed March 22, 2023 11:53 AM

    There's a related script here that executes an SQL statement:

    Bruno Portaluri - Automation Script to reset user's Start Centers

    I think it could be repurposed to run a CREATE OR REPLACE VIEW statement.


    # Reset users Start Centers
    # Object: MAXGROUP
    # Resets the Start Centers for all users assigned to the selected Security Group
    # Should be called when all users are logged off so the start center is reloaded after the login
    # See: http://bportaluri.com/2012/11/how-to-reset-users-start-centers.html

    from psdi.server import MXServer
    from psdi.util.logging import MXLoggerFactory

    mxserver = MXServer.getMXServer()
    logger = MXLoggerFactory.getLogger("maximo.maximodev")
    logger.info("Entering MXD_RESETSC")

    # Execute delete statement
    def execDelete(objectName, where):
    sql = "delete from " + objectName + " where " + where
    logger.debug("Executing SQL statement: " + sql)
    conKey = mxserver.getSystemUserInfo().getConnectionKey()
    con = mxserver.getDBManager().getConnection(conKey)
    s= con.createStatement()
    s.executeUpdate(sql)
    s.close()
    con.commit()
    mxserver.getDBManager().freeConnection(conKey)

    grpname = mbo.getString("GROUPNAME")

    where1 = "scconfigid IN (SELECT scconfigid FROM scconfig WHERE groupname='" + grpname + "')"
    where2 = "layoutid IN (SELECT layoutid FROM layout WHERE " +where1+ ")"

    execDelete("PORTLETDISPLAY", where2)
    execDelete("REPORTLISTCFG", where2)
    execDelete("RSCONFIG", where2)
    execDelete("FACONFIG", where2)
    execDelete("INBXCONFIG", where2)
    execDelete("KPILCONFIG", where2)
    execDelete("KPIGCONFIG", where2)
    execDelete("ACTIONSCFG", where2)
    execDelete("LAYOUT", where2)

    execDelete("SCCONFIG", where1)


    #AssetandFacilitiesManagement
    #Maximo