Hi,
I am using ARIS 7.2. We have got some scripts customized by Software AG. This particular scripts updates ARIS with the data that is placed in an excel file at a particular location.
The script has the path of the location where this file is kept. this script creates a mapping file and updates ARIS object with attributes and connections and also creates new objects based on the data avaiable in the excel sheet.
Everything was working fine for past 1+ years when one fine day it started throwing error. the log says
"Error: TypeError: Cannot call method "Path" of null"
this is in production sever
and the same script gives the below error on test server
Error: TypeError: Cannot call method "keys" of null
Also when i execute the script it gives me message " the script was executed successfuly"
not sure why diff types of error with same script.
I am unable to figure out what went wrong all of a sudden
Is it the script ? ( how can it throw error one day suddenly)
is it some bug ? does it need any java update ? or patch update?
Our script is a combination of 3 scripts, and i see that its the third one when executed gives the above error in Log file. So i am attaching the 3rd script here for ref.
Please let me know if anyone can figure out what might be the cause and how to fix this. Request your support.
Thanks.
Anupama
Script--
/*
script 3
*/
var oDatabase = ArisData.getSelectedDatabases()[0];
var g_nloc = Context.getSelectedLanguage();
var oMethodFilter = ArisData.ActiveFilter();
var RemedyLastUpdateAttr = getAttrNumber("6d62e640-a3cf-11df-7689-001c23c36118");
var RemedyRelationshipAttr = getAttrNumber("88727c30-1f82-11e2-2fe3-005056bd7b5d");
var groupPath = "Main group/Object Library/ATM Object Library/Applications";
var comparePath = "Main group\\Object Library\\ATM Object Library\\Applications";
var oAppMainGroup = oDatabase.Group(groupPath, g_nloc);
var oMainGroup = oDatabase.Group(groupPath, g_nloc);
var mappingInfo = new Mapping(Constants.MT_ACS_DGM_PHYS,Constants.OT_APPL_SYS,new Array());
var reportStartTime = new Date();
var MAPPINGFILE = "RemedyMapping.xml";
var objectCreationCounts=0;
var objectAttributeCounts=0;
var objectForcedAttributeCount=0;
var objectReadCount=0;
var modelCount = 0;
var updateServers = true;
var updateBusiness_processL1 = true;
var updateLocations = true;
var updatePersons = false;
function main() {
var startRow = Context.getProperty("startRow");
//var startRow = "0";
startRow = parseInt(startRow);
var endRow = startRow + 1000;
if (updateServers)
mappingInfo.symbolTypes.push(Constants.ST_HW_CMP);
if (updateBusiness_processL1)
mappingInfo.symbolTypes.push(Constants.ST_FUNC);
if (updateLocations)
mappingInfo.symbolTypes.push(Constants.ST_LOC_1);
if (updatePersons)
mappingInfo.symbolTypes.push(Constants.ST_PERS_INT);
try {
var Prop = new XmlProperties;
var RAD = new RemedyRadGenerator;
Prop.init(MAPPINGFILE);
//import the actual file
var Excel = new ExcelImporter;
var fileName = Prop.importStringLookupLocation("ImporterFile", "Location", null, Prop);
fileName = fileName.replace("\\", "/");
Excel.readXLSWorkBook(fileName,0,1);
if (Excel.getLastRow() < endRow) {
endRow = Excel.getLastRow();
Context.setProperty("reportFinished", "true");
} else {
Context.setProperty("reportFinished", "false");
}
findAndUpdateObject(RAD, null, Prop, Excel, "ApplicationSystem", startRow, endRow);
updatePrivileges();
} catch(e) {
var error = e;
var stop = 1;
RAD.logger.writef("Error: " + error);
}
RAD.logger.writef("Updated model count: " + modelCount);
//dispose of classes
Prop.dispose();
Excel.dispose();
RAD.dispose();
CMDB = null;
Prop = null;
RAD = null;
}
function Mapping(modelMappingType, mainObjType, symbolTypes)
{
this.mainModelType = modelMappingType;
this.mainObjType = mainObjType;
this.symbolTypes = symbolTypes;
this.sourceGroup = null;
}
// to get the GUID type number for user difined attributes
function getAttrNumber(sGUID){
var Filter = ArisData.ActiveFilter();
if(sGUID.length != 36)
Dialogs.MsgBox(sGUID);
return Filter.UserDefinedAttributeTypeNum(sGUID);
}
// to update Relationship between the Main object (Physcial Appliction) and to other objects
function createRelationship(oMainModel, symbolType, symbolObj, mainObj) {
var mainModel = oMainModel;
var modelName = getAttribute(oMainModel, Constants.AT_NAME);
var mainOcc = null;
var occList = new Array();
// check whether models exits on the database for a particular physical applications
if (mainModel != null){
occList = mainModel.ObjOccList();
var mainOccs = mainObj.OccListInModel(mainModel);
if (mainOccs.length > 0)
mainOcc = mainOccs[0];
}
// If model does not exits for a particular physical applicatons then create an new model and assign connections
if (mainOcc == null)
mainOcc = mainModel.createObjOcc(Constants.ST_APPL_SYS, mainObj, 0, 0, true);
if (mainOcc != null) {
var boundingRect = mainModel.BoundingRect();
var moveSymbol = true;
var symbolOcc = null;
var symbolOccs = symbolObj.OccListInModel(mainModel);
if (symbolOccs.length == 0)
symbolOcc = mainModel.createObjOcc(symbolType, symbolObj, 0, 0, true);
else
symbolOcc = symbolOccs[0];
//check whether the conneciton is valid or not
if ((symbolOcc != null) && (symbolOcc.IsValid() == true)) {
//symbolOcc.setZOrder(1);
var cxnInfo= getCxn(mainObj, symbolObj);
var source = null;
var target = null;
if (cxnInfo != null) {
var createNewCxn = true;
var currCxns = symbolOcc.Cxns();
for (var i in currCxns) {
if ((currCxns[i].SourceObjOcc().equals(mainOcc)) || (currCxns[i].TargetObjOcc().equals(mainOcc))) {
createNewCxn = false;
break;
}
}
if (createNewCxn) {
if (cxnInfo.SourceObjDef().equals(mainObj)) {
source = mainOcc;
target = symbolOcc;
} else {
source = symbolOcc;
target = mainOcc;
}
var points = getPoints(source, target);
var newCxn = mainModel.CreateCxnOcc(true, source, target, cxnInfo.TypeNum(), points);
/*if(newCxn){
newCxn.setZOrder(1);
newCxn.ResetLine();
}*/
}
} else {
// no available cxns between mainObj & symObj
// delete sym occ
mainModel.deleteOcc(symbolOcc, false);
}
}
}
return;
}
// Creates a points set for the connections
function getPoints(obj1, obj2)
{
var points = new Array();
var onePosX = obj1.X();
var onePosY = obj1.Y();
var twoPosX = obj2.X();
var twoPosY = obj2.Y();
var oneWidth = obj1.Width();
var oneHeight = obj1.Height();
var twoWidth = obj2.Width();
var twoHeight = obj2.Height();
var oneSetX = 0;
var twoSetX = 0;
var oneSetY = 0;
var twoSetY = 0;
var point1 = new java.awt.Point();
var point2 = new java.awt.Point();
if (onePosX > twoPosX) {
oneSetX = onePosX;
twoSetX = twoPosX+twoWidth;
} else {
oneSetX = onePosX+oneWidth;
twoSetX = twoPosX;
}
oneSetY = onePosY+(oneHeight/2);
twoSetY = twoPosY+(twoHeight/2);
point1.setLocation(oneSetX, oneSetY);
point2.setLocation(twoSetX, twoSetY);
points.push(point1, point2);
return points;
}
// Get the Connection type between the two objects
function getCxn(mainSym, otherSym) {
var cxns = mainSym.CxnList();
for (var i in cxns){
var cxn = cxns[i];
if ((cxn.SourceObjDef().equals(mainSym) && cxn.TargetObjDef().equals(otherSym)) || (cxn.SourceObjDef().equals(otherSym) && cxn.TargetObjDef().equals(mainSym)))
return cxn;
}
return null;
}
// updates the privileges for the user groups
function updatePrivileges(){
var groupChildren = oMainGroup.Childs();
var userGroups = oDatabase.UserGroupList();
for(var i in groupChildren){
var child = groupChildren[i];
var children = child.Childs(true);
for (var j in userGroups){
var userGroup = userGroups[j];
var userRights = userGroup.AccessRights(child);
if(userRights && userRights != Constants.AR_NORIGHTS){
userGroup.SetAccessRights(children,userRights);
}
}
}
}
// Updates the Diagrams by creating connection between Physcial Application to Symbols set to true
function updateModel(appObj, oAcsDGM){
var modelName = getAttribute(oAcsDGM, Constants.AT_NAME);
var lastChange = null;
if (oAcsDGM)
lastChange = oAcsDGM.Attribute(Constants.AT_LAST_CHNG_2, Context.getSelectedLanguage());
if ((oAcsDGM) && ((lastChange.IsMaintained() == false) || ((lastChange.IsMaintained() == true) && (new Date(lastChange.getValue()) < reportStartTime)))) {
modelCount++;
for (var j in mappingInfo.symbolTypes) {
var symbolType = mappingInfo.symbolTypes[j];
var objType = oMethodFilter.SymbolObjType(symbolType);
var symbolObjs = getConnectedObjects(appObj, objType);
for (var k in symbolObjs) {
var symbolObj = symbolObjs[k];
if(symbolObj && symbolObj.IsValid())
createRelationship(oAcsDGM, symbolType, symbolObj, appObj);
}
}
var oObjOccs = oAcsDGM.ObjOccList();
for (var j in oObjOccs) {
if ((!oObjOccs[j].ObjDef().equals(appObj)) && (oObjOccs[j].Cxns().length == 0))
oAcsDGM.deleteOcc(oObjOccs[j], false);
}
ArisData.getModelOptions().getLayoutParameters(17).setSpacingX(30);
ArisData.getModelOptions().getLayoutParameters(17).setSpacingY(30);
ArisData.getModelOptions().getLayoutParameters(17).setArrangeSatellites(1);
ArisData.getModelOptions().getLayoutParameters(17).setInsertSpace(true);
try {
oAcsDGM.setTemplate("9171f710-158e-11e1-32d4-001c23babc67");
oAcsDGM.doLayout();
} catch(e) {}
}
return;
}
function getAttribute(oItem, attrNum) {
var value = "";
if ((oItem != null) && (oItem.IsValid())) {
try {
value = oItem.Attribute(attrNum, g_nloc).getValue();
} catch(e) {
var error = e;
value = "";
}
}
return value;
}
function findAndUpdateObject(RAD, defaultGroup, Prop, CMDB, objectTypeKey, startRow, endRow) {
var hObjectType= Prop.importStringLookup(objectTypeKey);
var objectAttrKey = objectTypeKey + "Attributes";
var hObjectAttrs = Prop.importIntLookup(objectAttrKey);
var foundObjectType = CMDB.search(hObjectType);
var foundObjectTypeKeys= foundObjectType.keys();
var tempAttrs;
var objectCreationCounts=0;
var objectAttributeCounts=0;
var objectForcedAttributeCount=0;
var objectReadCount=0;
var attributes = Prop.getForcedAttributes(objectTypeKey+"ForcedAttributes");
var objectChangeAttrKey = objectTypeKey + "ChangeAttributes";
var hObjectChangeAttrs = Prop.importIntLookup(objectChangeAttrKey);
var changeHash = RAD.generateChangeAttrHash(hObjectAttrs, hObjectChangeAttrs);
//for (var i in foundObjectTypeKeys){
for (var i = startRow; i <= endRow; i++) {
tempAttrs = CMDB.returnAttr(hObjectAttrs,foundObjectType.get(i));
var tempAttrkeys =tempAttrs.keys();
var tempStore;
var tempAdd;
for(var attr in tempAttrkeys){
tempAdd = Prop.additionalLookup(objectAttrKey,tempAttrkeys[attr]) + "";
if(tempAdd){
if(tempAdd.charAt(0) == "+"){
tempStore=tempAttrs.get(tempAttrkeys[attr])+tempAdd.slice(1);
tempAttrs.remove(tempAttrkeys[attr]);
tempAttrs.put(tempAttrkeys[attr], tempStore);
}else if(tempAdd.charAt(0) == "-"){
tempStore = tempAdd.slice(1) + tempAttrs.get(tempAttrkeys[attr]);
tempAttrs.remove(tempAttrkeys[attr]);
tempAttrs.put(tempAttrkeys[attr], tempStore);
}
tempStore=null;
tempAdd=null
}
}
var oObjDef = RAD.findObject(tempAttrs.get(Constants.AT_NAME), Constants.AT_NAME, Prop.getObjectType(objectTypeKey), null);
if (!oObjDef){
//create def then occurrence
var oGroup = defaultGroup;
if(!defaultGroup)
oGroup = RAD.findGroup(Prop.getObjectPath(objectTypeKey));
if(Prop.getSubLocation(objectTypeKey) != -1)
oGroup = RAD.findCreateGroup(oGroup.Path(Context.getSelectedLanguage()), foundObjectType.get(i).get(Prop.getSubLocation(objectTypeKey)));
oObjDef = RAD.createObjDef(oGroup, Prop.getObjectType(objectTypeKey), tempAttrs.get(Constants.AT_NAME));
objectCreationCounts++;
}
if (oObjDef) {
var lastChange = null;
if (oObjDef)
lastChange = new Date(oObjDef.Attribute(Constants.AT_LAST_CHNG_2, Context.getSelectedLanguage()).getValue())
if ((lastChange) && (lastChange < reportStartTime)) {
RAD.insertAttributesConditionally(oObjDef, tempAttrs, changeHash, RemedyLastUpdateAttr);
if(attributes && attributes.keys().length > 0) {
RAD.insertForcedAttributes(oObjDef,attributes);
objectForcedAttributeCount++;
}
}
var oModel = getDiagram(oObjDef);
if (oModel) {
try {
updateModel(oObjDef, oModel);
} catch(e) {
RAD.logger.writef("Could not update the following model: " + getAttribute(oObjDef, Constants.AT_NAME));
RAD.logger.writef("Error : " + e);
}
}
}
}
oObjDef = null;
oModel = null;
return;
}
function getConnectedObjects(appObj, objType) {
var cxns = appObj.CxnList();
var returnObjs = new Array();
for (var i in cxns) {
var remedyAttr = cxns[i].Attribute(RemedyRelationshipAttr, g_nloc).getValue().equals("True");
if ((remedyAttr) && (cxns[i].SourceObjDef().equals(appObj)) && (cxns[i].TargetObjDef().TypeNum() == objType))
returnObjs.push(cxns[i].TargetObjDef());
else if ((remedyAttr) && (cxns[i].TargetObjDef().equals(appObj)) && (cxns[i].SourceObjDef().TypeNum() == objType))
returnObjs.push(cxns[i].SourceObjDef());
}
return returnObjs;
}
function getDiagram(appObj) {
var oModel = null;
if (appObj.IsValid()) {
try {
var assignedModels = appObj.AssignedModels([mappingInfo.mainModelType]);
for (var j in assignedModels) {
if (assignedModels[j].Group().Path(g_nloc).toLowerCase().startsWith(comparePath.toLowerCase())) {
oModel = assignedModels[j];
break;
}
}
if (!oModel) {
var oModelList = appObj.OccList();
for (var j in oModelList) {
var modelName = getAttribute(oModelList[j].Model(), Constants.AT_NAME).toLowerCase().replaceAll("\\s", "");
if ((oModelList[j].Model().TypeNum() == mappingInfo.mainModelType) && (modelName.equals(appName.toLowerCase().replaceAll("\\s", "")))) {
oModel = oModelList[j].Model();
appObj.CreateAssignment(oModel, false);
break;
}
}
}
if (!oModel) {
var oObjName = getAttribute(appObj, Constants.AT_NAME);
var childGroup = null;
var childGroups = oMainGroup.Childs();
for (var j in childGroups) {
if (getAttribute(childGroups[j], Constants.AT_NAME).equals(oObjName))
childGroup = childGroups[j];
}
if ((childGroup == null) && (assignedModels.length == 0))
childGroup = oMainGroup.CreateChildGroup(oObjName, g_nloc);
if ((childGroup != null) && (assignedModels.length == 0))
oModel = childGroup.CreateModel(Constants.MT_ACS_DGM_PHYS, oObjName, g_nloc);
if ((oModel != null) && (oModel.IsValid() == true))
appObj.CreateAssignment(oModel, true);
}
if (oModel) {
if (appObj.OccListInModel(oModel).length == 0)
oModel.createObjOcc(Constants.ST_APPL_SYS, appObj, 0, 0, true, true);
}
} catch(e) {
oModel = null;
}
}
return oModel;
}
main();
Hi Anupama,
The script is quite big and to find out the cause of this error, you will need to debug it and find out the line number where the error is thrown from. Please use the debug watch window to find the values in the variables.
Both of the errors are because the methods are being called on variables having null value. One method to look into is
findAndUpdateObject(RAD, defaultGroup, Prop, CMDB, objectTypeKey, startRow, endRow)
Here the "defaultGroup" is being explicitly passed as null.
Regards,
Amol Patil