N4: Universal Query API

Set up API user

Modify node’s tomcat-users.xml. i.e add n4api user like below:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
    <role rolename="tomcat"/>
    <role rolename="role1"/>
   <role rolename="n4api"/>
    <user username="tomcat" password="tomcat" roles="tomcat"/>
    <user username="both" password="tomcat" roles="tomcat,role1"/>
    <user username="role1" password="tomcat" roles="role1"/>
   <user username="n4api" password="showmeinfo" roles="n4api"/>
</tomcat-users>


Set up N4 user and Table Filter

In N4 create the querying user. Then set up a Table Filter exclusive to the querying user. Also do not specify a role to the filter.

Universal Query on a Basic Table Filter

http://n4api:showmeinfo@134.37.165.174:9080/apex/api/query?filtername=N4APIFEEDERS&operatorId=CTW&complexId=DEWVN&facilityId=CTW&yardId=CTW1

<?xml version="1.0" encoding="UTF-8"?>
<query-response>
  <data-table filter="N4APIFEEDERS" count="3">
    <columns>
      <column>Visit</column>
      <column>Line</column>
      <column>Vessel Name</column>
      <column>Phase</column>
      <column>ETA</column>
      <column>ETD</column>
      <column>Class</column>
    </columns>
    <rows>
      <row primary-key="118447345">
        <field>SEJ_HEIEHL_1431</field>
        <field>SEJ</field>
        <field>HEINRICH EHLER</field>
        <field>Inbound</field>
        <field>2014-07-27 1400</field>
        <field>2014-07-27 2200</field>
        <field>Feeder</field>
      </row>
     </rows>
  </data-table>
</query-response>

Parametrized query

http://134.37.165.174:9080/apex/api/query?filtername=N4APIVESSELS&operatorId=CTW&complexId=DEWVN&facilityId=CTW&yardId=CTW1&PARM_PARM_Classification=BARGE

<?xml version="1.0" encoding="UTF-8"?>
<query-response>
  <data-table filter="N4APIVESSELS" count="4">
    <columns>
      <column>Visit</column>
      <column>Line</column>
      <column>Vessel Name</column>
      <column>Phase</column>
      <column>ETA</column>
      <column>ETD</column>
      <column>Class</column>
    </columns>
    <rows>
      <row primary-key="124621778">
        <field>BLG_KUGEL_022</field>
        <field>BLG</field>
        <field>KUGELBAKE</field>
        <field>Inbound</field>
        <field>2014-07-08 0600</field>
        <field>2014-07-08 1400</field>
        <field>Barge</field>
      </row>
    </rows>
    </data-table>
  </query-response>

Trouble shoot parametrized query

This query does not work:

http://134.37.165.174:9080/apex/api/query?filtername=N4APIVESSELS&Classification=Deepsea&operatorId=CTW&complexId=DEWVN&facilityId=CTW&yardId=CTW1&Classification=Deepsea

<?xml version="1.0" encoding="UTF-8"?>
<query-response>
  <error>Required query parameter for field Classification with label PARM_Classification was not provided.</error>
</code>
</query-response>

Need to write the parameter as PARM_ otherwise things don’t work. So if you named the N4 parameter PARM_Classification then the URL’s parameter must be PARM_PARM_Classification.
Better not mark the N4 parameter as required, because not sure if this works.


Code lookup

Need to do some code lookup to find valid parameter values.
Open Table Info and find entity name in the XML description that appears.

<table id="VSL005" defaultSearchfieldId="cvdCv.cvId">
  <title>Vessel Visits</title>
  <entity>
    <name>VesselVisitDetails</name>
    <primaryKey>vvdGkey</primaryKey>
  </entity>

Then perform code lookup with the URL set-up like this:

http://134.37.165.174:9080/apex/api/codeLookup?entity=VesselVisitDetails&tag=Classification&operatorId=CTW&complexId=DEWVN&facilityId=CTW&yardId=CTW1

<?xml version="1.0" encoding="UTF-8"?>
<codes entity="VesselVisitDetails" tag="Classification">
  <code dbvalue="DEEPSEA" desc="Deepsea" />
  <code dbvalue="FEEDER" desc="Feeder" />
  <code dbvalue="BARGE" desc="Barge" />
</codes>

Leave a Reply

Your email address will not be published. Required fields are marked *