maximo-dev-tools
Version:
Tools used with the development of Maximo projects
1,011 lines (897 loc) • 191 kB
JavaScript
/* eslint-disable indent */
/* eslint-disable no-undef */
/* eslint-disable no-unused-vars */
// @ts-nocheck
MboConstants = Java.type("psdi.mbo.MboConstants");
SqlFormat = Java.type("psdi.mbo.SqlFormat");
MXServer = Java.type("psdi.server.MXServer");
System = Java.type("java.lang.System");
MXLoggerFactory = Java.type("psdi.util.logging.MXLoggerFactory");
MXServer = Java.type("psdi.server.MXServer");
var logger = MXLoggerFactory.getLogger("maximo.script.SHARPTREE.AUTOSCRIPT.LIBRARY");
// Array find polyfill.
if (typeof Array.prototype.find != "function") {
Array.prototype.find = function (callback) {
if (this === null) {
throw new TypeError("Array.prototype.find called on null or undefined");
} else if (typeof callback !== "function") {
throw new TypeError("callback must be a function");
}
var list = Object(this);
// Makes sure is always has an positive integer as length.
var length = list.length >>> 0;
var thisArg = arguments[1];
for (var i = 0; i < length; i++) {
var element = list[i];
if (callback.call(thisArg, element, i, list)) {
return element;
}
}
};
}
function MaxLogger(maxLogger) {
if (!maxLogger) {
throw new Error("A maxLogger JSON is required to create the MaxLogger object.");
} else if (typeof maxLogger.logger === "undefined") {
throw new Error("The logger property is required and must be a Maximo MaxLogger field value.");
}
this.logger = maxLogger.logger;
this.parentLogKey = typeof maxLogger.parentLogKey === "undefined" ? "" : maxLogger.parentLogKey;
this.logKey =
typeof maxLogger.logKey === "undefined" ? (this.parentLogKey ? this.parentLogKey + "." : "log4j.logger.maximo.") + maxLogger.logger : maxLogger.logKey;
this.logLevel = typeof maxLogger.logLevel === "undefined" ? "ERROR" : maxLogger.logLevel;
this.active = typeof maxLogger.active === "undefined" ? false : maxLogger.active == true;
this.appenders = typeof maxLogger.appenders === "undefined" ? "" : maxLogger.appenders;
if (this.parentLogKey && !this.logKey.startsWith(this.parentLogKey)) {
this.logKey = this.parentLogKey + "." + this.logger;
}
}
MaxLogger.prototype.constructor = MaxLogger;
MaxLogger.prototype.apply = function (mboSet) {
if (!mboSet) {
throw new Error("A MboSet is required to set values from the MaxLogger object.");
} else if (!(mboSet instanceof Java.type("psdi.mbo.MboSet"))) {
throw new Error("The mboSet parameter must be an instance of psdi.mbo.Mbo.");
} else if (!mboSet.isBasedOn("MAXLOGGER")) {
throw new Error("The mboSet parameter must be based on the MAXLOGGER Maximo object.");
}
var sqlFormat;
var maxLogger;
if (this.parentLogKey) {
sqlFormat = new SqlFormat("logkey = :1");
sqlFormat.setObject(1, "MAXLOGGER", "LOGKEY", this.parentLogKey);
mboSet.setWhere(sqlFormat.format());
if (mboSet.isEmpty()) {
throw new Error(
"The parent logger key value " + this.parentLogKey + " does not exist in the target system, cannot add child logger " + this.logger
);
} else {
var parent = mboSet.moveFirst();
var children = parent.getMboSet("CHILDLOGGERS");
var child = children.moveFirst();
while (child) {
if (child.getString("LOGGER").toLowerCase() == this.logger.toLowerCase()) {
child.setValue("ACTIVE", false);
child.delete();
break;
}
child = children.moveNext();
}
maxLogger = children.add();
maxLogger.setValue("LOGGER", this.logger);
}
} else {
sqlFormat = new SqlFormat("logger = :1");
sqlFormat.setObject(1, "MAXLOGGER", "LOGGER", this.logger);
mboSet.setWhere(sqlFormat.format());
if (!mboSet.isEmpty()) {
maxLogger = mboSet.moveFirst();
maxLogger.setValue("ACTIVE", false);
maxLogger.delete();
}
maxLogger = mboSet.add();
maxLogger.setValue("LOGGER", this.logger);
maxLogger.setValue("LOGKEY", this.logKey);
}
maxLogger.setValue("LOGLEVEL", this.logLevel);
maxLogger.setValue("ACTIVE", this.active);
maxLogger.setValue("APPENDERS", this.appenders);
mboSet.save();
// apply the logging settings
MXServer.getMXServer().lookup("LOGGING").applySettings(false);
};
function CronTask(cronTask) {
if (!cronTask) {
throw new Error("A integration object JSON is required to create the CronTask object.");
} else if (typeof cronTask.cronTaskName === "undefined") {
throw new Error("The cronTaskName property is required and must a Maximo CronTask field value.");
} else if (typeof cronTask.className === "undefined") {
throw new Error("The className property is required and must a Maximo CronTask field value.");
}
this.cronTaskName = cronTask.cronTaskName;
this.description = typeof cronTask.description === "undefined" ? "" : cronTask.description;
this.className = cronTask.className;
this.accessLevel = typeof cronTask.accessLevel === "undefined" || !cronTask.accessLevel ? "FULL" : cronTask.accessLevel;
if (typeof cronTask.cronTaskInstance !== "undefined" && Array.isArray(cronTask.cronTaskInstance)) {
cronTask.cronTaskInstance.forEach(function (instance) {
if (typeof instance.instanceName === "undefined" || !instance.instanceName) {
throw new Error("The CronTask object " + cronTask.cronTaskName + " instance is missing a name property for the instance name.");
}
instance.description = typeof instance.description === "undefined" ? "" : instance.description;
instance.schedule = typeof instance.schedule === "undefined" ? "1h,*,0,*,*,*,*,*,*,*" : instance.schedule;
instance.active = typeof instance.active === "undefined" ? false : instance.active == true;
instance.keepHistory = typeof instance.keepHistory === "undefined" ? true : instance.keepHistory == true;
instance.runAsUserId = typeof instance.runAsUserId === "undefined" ? "MAXADMIN" : instance.runAsUserId;
instance.maxHistory = typeof instance.maxHistory === "undefined" ? 1000 : instance.maxHistory;
if (typeof instance.cronTaskParam !== "undefined" && Array.isArray(instance.cronTaskParam)) {
instance.cronTaskParam.forEach(function (cronTaskParam) {
if (typeof cronTaskParam.parameter === "undefined" || !cronTaskParam.parameter) {
throw new Error(
"A CronTask object " + cronTask.cronTaskName + " instance " + instance.instanceName + " parameter is missing a parameter property."
);
}
cronTaskParam.value = typeof cronTaskParam.value === "undefined" ? "" : cronTaskParam.value;
});
} else {
instance.cronTaskParam = [];
}
});
this.cronTaskInstance = cronTask.cronTaskInstance;
} else {
this.cronTaskInstance = [];
}
}
CronTask.prototype.constructor = CronTask;
CronTask.prototype.setMboValues = function (mbo) {
if (!mbo) {
throw new Error("A Mbo is required to set values from the CronTask object.");
} else if (!(mbo instanceof Java.type("psdi.mbo.Mbo"))) {
throw new Error("The mbo parameter must be an instance of psdi.mbo.Mbo.");
} else if (!mbo.isBasedOn("CRONTASKDEF")) {
throw new Error("The mbo parameter must be based on the CRONTASKDEF Maximo object.");
}
if (mbo.toBeAdded()) {
mbo.setValue("CRONTASKNAME", this.cronTaskName);
mbo.setValue("CLASSNAME", this.className);
mbo.setValue("ACCESSLEVEL", this.accessLevel);
}
mbo.setValue("DESCRIPTION", this.description);
var cronTaskInstanceSet = mbo.getMboSet("CRONTASKINSTANCE");
var tmpCronTaskInstanceMbo = cronTaskInstanceSet.moveFirst();
while (tmpCronTaskInstanceMbo) {
tmpCronTaskInstanceMbo.setValue("ACTIVE", false);
tmpCronTaskInstanceMbo = cronTaskInstanceSet.moveNext();
}
// remove all the current instances
cronTaskInstanceSet.deleteAll();
this.cronTaskInstance.forEach(function (instance) {
var cronTaskInstanceMbo = cronTaskInstanceSet.add();
cronTaskInstanceMbo.setValue("INSTANCENAME", instance.instanceName);
cronTaskInstanceMbo.setValue("DESCRIPTION", instance.description);
cronTaskInstanceMbo.setValue("SCHEDULE", instance.schedule);
cronTaskInstanceMbo.setValue("RUNASUSERID", instance.runAsUserId);
cronTaskInstanceMbo.setValue("KEEPHISTORY", instance.keepHistory);
cronTaskInstanceMbo.setValue("ACTIVE", instance.active);
cronTaskInstanceMbo.setValue("MAXHISTORY", instance.maxHistory);
var cronTaskParamSet = cronTaskInstanceMbo.getMboSet("PARAMETER");
instance.cronTaskParam.forEach(function (param) {
var cronTaskParam = cronTaskParamSet.moveFirst();
while (cronTaskParam) {
if (cronTaskParam.getString("PARAMETER") == param.parameter) {
cronTaskParam.setValue("VALUE", param.value);
}
cronTaskParam = cronTaskParamSet.moveNext();
}
});
});
};
function EndPoint(endPoint) {
if (!endPoint) {
throw new Error("A integration object JSON is required to create the endPoint object.");
} else if (typeof endPoint.endPointName === "undefined") {
throw new Error("The endPointName property is required.");
} else if (typeof endPoint.handlerName === "undefined") {
throw new Error("The handler property is required and must a valid Maximo handler.");
}
this.endPointName = endPoint.endPointName;
this.description = typeof endPoint.description === "undefined" ? "" : endPoint.description;
this.handlerName = endPoint.handlerName;
this.maxEndPointDtl = typeof maxEndPoint.maxEndPointDtl === "undefined" ? [] : maxEndPoint.maxEndPointDtl;
if (!Array.isArray(this.maxEndPointDtl)) {
endPoint.endPointDtl.forEach(function (detail) {
if (typeof detail.property === "undefined" || !detail.property) {
throw new Error("Property " + detail.property + " is missing or has an empty value for the required Property name.");
}
detail.value = typeof detail.value === "undefined" ? "" : detail.value;
detail.allowOverride = typeof detail.allowOverride === "undefined" ? false : detail.allowOverride == true;
});
this.endPointDtl = endPoint.endPointDtl;
} else {
this.endPointDtl = [];
}
}
EndPoint.prototype.constructor = EndPoint;
EndPoint.prototype.setMboValues = function (mbo) {
if (!mbo) {
throw new Error("A Mbo is required to set values from the End Point object.");
} else if (!(mbo instanceof Java.type("psdi.mbo.Mbo"))) {
throw new Error("The mbo parameter must be an instance of psdi.mbo.Mbo.");
} else if (!mbo.isBasedOn("MAXENDPOINT")) {
throw new Error("The mbo parameter must be based on the MAXENDPOINT Maximo object.");
}
if (mbo.toBeAdded()) {
mbo.setValue("ENDPOINTNAME", this.endPointName);
}
mbo.setValue("DESCRIPTION", this.description);
mbo.setValue("HANDLERNAME", this.handlerName);
var endPointNameTemp = this.endPointName; //used to pass end point name to detail function
this.endPointDtl.forEach(function (detail) {
var maxEndPointDtlSet;
try {
maxEndPointDtlSet = mbo.getMboSet("MAXENDPOINTDTL");
var maxEndPointDtl = maxEndPointDtlSet.moveFirst();
while (maxEndPointDtl) {
if (maxEndPointDtl.getString("PROPERTY") == detail.property.toUpperCase()) {
maxEndPointDtl.setValue("VALUE", detail.value);
maxEndPointDtl.setValue("ALLOWOVERRIDE", detail.allowOverride);
break;
}
maxEndPointDtl = maxEndPointDtlSet.moveNext();
}
} finally {
__libraryClose(maxEndPointDtlSet);
}
});
};
function ExternalSystem(externalSystem) {
if (!externalSystem) {
throw new Error("A integration object JSON is required to create the ExternalSystem object.");
} else if (typeof externalSystem.extSysName === "undefined") {
throw new Error("The extSysName property is required and must a Maximo External System field value.");
}
this.extSysName = externalSystem.extSysName;
this.description = typeof externalSystem.description === "undefined" ? "" : externalSystem.description;
this.endPointName = typeof externalSystem.endPointName === "undefined" ? "" : externalSystem.endPointName;
this.bidiConfig = typeof externalSystem.bidiConfig === "undefined" ? "" : externalSystem.bidiConfig;
this.jmsMsgEncoding = typeof externalSystem.jmsMsgEncoding === "undefined" ? "" : externalSystem.jmsMsgEncoding;
this.enabled = typeof externalSystem.enabled === "undefined" ? false : externalSystem.enabled == true;
this.outSeqQueueName = typeof externalSystem.outSeqQueueName === "undefined" ? "" : externalSystem.outSeqQueueName;
this.inSeqQueueName = typeof externalSystem.inSeqQueueName === "undefined" ? "" : externalSystem.inSeqQueueName;
this.inContQueueName = typeof externalSystem.inContQueueName === "undefined" ? "" : externalSystem.inContQueueName;
//associated publish channels
if (externalSystem.maxExtIfaceOut && Array.isArray(externalSystem.maxExtIfaceOut)) {
externalSystem.maxExtIfaceOut.forEach(function (ifaceOut) {
if (typeof ifaceOut.ifaceName === "undefined" || !ifaceOut.ifaceName) {
throw new Error(
"An interface name for external system " +
externalSystem.extSysName +
" is missing or has an empty value for the required ifaceName property."
);
}
ifaceOut.endPointName = typeof ifaceOut.endPointName === "undefined" ? "" : ifaceOut.endPointName;
ifaceOut.enabled = typeof ifaceOut.enabled === "undefined" ? false : ifaceOut.enabled == true;
});
this.maxExtIfaceOut = externalSystem.maxExtIfaceOut;
} else {
this.maxExtIfaceOut = [];
}
//associated enterprise services
if (externalSystem.maxExtIfaceIn && Array.isArray(externalSystem.maxExtIfaceIn)) {
externalSystem.maxExtIfaceIn.forEach(function (ifaceIn) {
if (typeof ifaceIn.ifaceName === "undefined" || !ifaceIn.ifaceName) {
throw new Error(
"An interface name for external system " +
externalSystem.extSysName +
" is missing or has an empty value for the required ifaceName property."
);
}
ifaceIn.isContinuousQueue = typeof ifaceIn.isContinuousQueue === "undefined" ? true : ifaceIn.isContinuousQueue == true;
ifaceIn.enabled = typeof ifaceIn.enabled === "undefined" ? false : ifaceIn.enabled == true;
});
this.maxExtIfaceIn = externalSystem.maxExtIfaceIn;
} else {
this.maxExtIfaceIn = [];
}
}
ExternalSystem.prototype.constructor = ExternalSystem;
ExternalSystem.prototype.setMboValues = function (mbo) {
if (!mbo) {
throw new Error("A Mbo is required to set values from the External System object.");
} else if (!(mbo instanceof Java.type("psdi.mbo.Mbo"))) {
throw new Error("The mbo parameter must be an instance of psdi.mbo.Mbo.");
} else if (!mbo.isBasedOn("MAXEXTSYSTEM")) {
throw new Error("The mbo parameter must be based on the MAXEXTSYSTEM Maximo object.");
}
mbo.setValue("EXTSYSNAME", this.extSysName);
mbo.setValue("DESCRIPTION", this.description);
mbo.setValue("ENDPOINTNAME", this.endPointName);
mbo.setValue("JMSMSGENCODING", this.jmsMsgEncoding);
mbo.setValue("ENABLED", this.enabled);
mbo.setValue("OUTSEQQUEUENAME", this.outSeqQueueName);
mbo.setValue("INSEQQUEUENAME", this.inSeqQueueName);
mbo.setValue("INCONTQUEUENAME", this.inContQueueName);
var maxExtIfaceOutSet = mbo.getMboSet("MAXEXTIFACEOUT");
maxExtIfaceOutSet.deleteAll();
this.maxExtIfaceOut.forEach(function (ifaceOut) {
maxExtIfaceOut = maxExtIfaceOutSet.add();
maxExtIfaceOut.setValue("IFACENAME", ifaceOut.ifaceName);
maxExtIfaceOut.setValue("ENDPOINTNAME", ifaceOut.endPointName);
maxExtIfaceOut.setValue("ENABLED", ifaceOut.enabled);
});
var maxExtIfaceInSet = mbo.getMboSet("MAXEXTIFACEIN");
maxExtIfaceInSet.deleteAll();
this.maxExtIfaceIn.forEach(function (ifaceOut) {
maxExtIfaceIn = maxExtIfaceInSet.add();
maxExtIfaceIn.setValue("IFACENAME", ifaceOut.ifaceName);
maxExtIfaceIn.setValue("ISCONTINUOUSQUEUE", ifaceOut.isContinuousQueue);
maxExtIfaceIn.setValue("ENABLED", ifaceOut.enabled);
});
};
function Message(message) {
if (!message) {
throw new Error("A message JSON is required to create the Message object.");
} else if (typeof message.msgGroup === "undefined") {
throw new Error("The msgGroup property is required and must a Maximo Message Group field value.");
} else if (typeof message.msgKey === "undefined") {
throw new Error("The msgKey property is required and must a Maximo Message Key field value.");
} else if (typeof message.value === "undefined") {
throw new Error("The value property is required and must a Maximo Value field value.");
}
this.msgGroup = message.msgGroup;
this.msgKey = message.msgKey;
this.value = message.value;
this.msgId = typeof message.msgId === "undefined" ? null : message.msgId;
this.displayMethod = typeof message.displayMethod === "undefined" ? "MSGBOX" : message.displayMethod;
this.options = typeof message.options === "undefined" || !Array.isArray(message.options) ? ["ok"] : message.options;
this.prefix = typeof message.prefix === "undefined" ? "BMXZZ" : message.prefix;
this.suffix = typeof message.suffix === "undefined" ? "E" : message.suffix;
}
Message.prototype.constructor = Message;
Message.prototype.setMboValues = function (mbo) {
if (!mbo) {
throw new Error("A Mbo is required to set values from the Message object.");
} else if (!(mbo instanceof Java.type("psdi.mbo.Mbo"))) {
throw new Error("The mbo parameter must be an instance of psdi.mbo.Mbo.");
} else if (!mbo.isBasedOn("MAXMESSAGES")) {
throw new Error("The mbo parameter must be based on the MAXMESSAGES Maximo object.");
}
mbo.setValue("MSGGROUP", this.msgGroup);
mbo.setValue("MSGKEY", this.msgKey);
mbo.setValue("VALUE", this.value);
mbo.setValue("DISPLAYMETHOD", this.displayMethod);
if (this.msgId) {
mbo.setValue("MSGID", this.msgId);
} else {
this.prefix ? mbo.setValue("MSGIDPREFIX", this.prefix) : mbo.setValue("MSGIDPREFIX", "BMXZZ");
this.suffix ? mbo.setValue("MSGIDSUFFIX", this.suffix) : mbo.setValue("MSGIDSUFFIX", "E");
}
this.options.forEach(function (option) {
switch (option.toLowerCase()) {
case "ok":
mbo.setValue("OK", true);
break;
case "close":
mbo.setValue("CLOSE", true);
break;
case "cancel":
mbo.setValue("CANCEL", true);
break;
case "yes":
mbo.setValue("YES", true);
break;
case "no":
mbo.setValue("NO", true);
break;
}
});
};
function Property(property) {
if (typeof property.propName === "undefined") {
throw new Error("The propName property is required and must be a Maximo Property Name field value.");
}
this.propName = property.propName;
this.description = typeof property.description === "undefined" ? "" : property.description;
this.domainId = typeof property.domainId === "undefined" ? "" : property.domainId;
this.encrypted = typeof property.encrypted === "undefined" ? false : property.encrypted == true;
this.globalOnly = typeof property.globalOnly === "undefined" ? false : property.globalOnly == true;
this.instanceOnly = typeof property.instanceOnly === "undefined" ? false : property.instanceOnly == true;
this.liveRefresh = typeof property.liveRefresh === "undefined" ? true : property.liveRefresh == true;
this.masked = typeof property.masked === "undefined" ? false : property.masked == true;
this.maxType = typeof property.maxType === "undefined" ? "ALN" : property.maxType;
this.nullsAllowed = typeof property.nullsAllowed === "undefined" ? true : property.nullsAllowed == true;
this.onlineChanges = typeof property.onlineChanges === "undefined" ? true : property.onlineChanges == true;
this.secureLevel = typeof property.secureLevel === "undefined" ? "PUBLIC" : property.secureLevel;
this.propValue = typeof property.propValue === "undefined" ? "" : property.propValue;
this.maximoDefault = typeof property.maximoDefault === "undefined" ? "" : property.maximoDefault;
if (property.maxPropInstance && Array.isArray(property.maxPropInstance)) {
property.maxPropInstance.forEach(function (instance) {
if (typeof instance.serverName === "undefined" || !instance.serverName) {
throw new Error(
"A property instance for property " + property.propName + " is missing or has an empty value for the required serverName property."
);
}
if (instance.serverName.toLowerCase() == "common") {
throw new Error(
"A property instance for property " +
property.propName +
" has a value of COMMON for the serverName property, define COMMON property values using the dispPropValue property on the root property object."
);
}
instance.propValue = typeof instance.propValue === "undefined" ? "" : instance.propValue;
instance.serverHost = typeof instance.serverHost === "undefined" ? "" : instance.serverHost;
});
this.maxPropInstance = property.maxPropInstance;
} else {
this.maxPropInstance = [];
}
}
Property.prototype.constructor = Property;
Property.prototype.setMboValues = function (mbo) {
if (!mbo) {
throw new Error("A Mbo is required to set values from the Properties object.");
} else if (!(mbo instanceof Java.type("psdi.mbo.Mbo"))) {
throw new Error("The mbo parameter must be an instance of psdi.mbo.Mbo.");
} else if (!mbo.isBasedOn("MAXPROP")) {
throw new Error("The mbo parameter must be based on the MAXPROP Maximo object.");
}
// if this is a system only a select few things can be altered and the property can't be deleted.
if (mbo.isSystemProperty()) {
mbo.setValue("DESCRIPTION", this.description);
mbo.setValue("ENCRYPTED", this.encrypted);
mbo.setValue("MASKED", this.masked);
mbo.setValue("DISPPROPVALUE", this.propValue);
} else {
if (mbo.toBeAdded()) {
mbo.setValue("PROPNAME", this.propName);
}
mbo.setValue("MAXIMODEFAULT", this.maximoDefault, MboConstants.NOACCESSCHECK);
mbo.setValue("DESCRIPTION", this.description);
mbo.setValue("DOMAINID", this.domainId);
mbo.setValue("ENCRYPTED", this.encrypted);
mbo.setValue("GLOBALONLY", this.globalOnly);
mbo.setValue("INSTANCEONLY", this.instanceOnly);
mbo.setValue("LIVEREFRESH", this.liveRefresh);
mbo.setValue("MASKED", this.masked);
mbo.setValue("MAXTYPE", this.maxType);
mbo.setValue("NULLSALLOWED", this.nullsAllowed);
mbo.setValue("ONLINECHANGES", this.onlineChanges);
mbo.setValue("SECURELEVEL", this.secureLevel);
if (!this.instanceOnly) {
mbo.setValue("DISPPROPVALUE", this.propValue);
}
}
var maxPropInstanceSet = mbo.getMboSet("MAXPROPINSTANCE");
maxPropInstanceSet.deleteAll();
if (!this.globalOnly) {
this.maxPropInstance.forEach(function (instance) {
maxPropInstance = maxPropInstanceSet.add();
maxPropInstance.setValue("DISPPROPVALUE", instance.propValue, MboConstants.NOVALIDATION);
maxPropInstance.setValue("SERVERNAME", instance.serverName);
maxPropInstance.setValue("SERVERHOST", instance.serverHost);
});
}
return;
};
function IntegrationObject(intObject) {
if (!intObject) {
throw new Error("A integration object JSON is required to create the IntegrationObject object.");
} else if (typeof intObject.intObjectName === "undefined") {
throw new Error("The intObjectName property is required and must a Maximo Integration Object field value.");
} else if (typeof intObject.maxIntObjDetails === "undefined" || !Array.isArray(intObject.maxIntObjDetails) || intObject.maxIntObjDetails.length == 0) {
throw new Error("The maxIntObjDetails property is required and must an array that contains at least one Maximo Integration Object Detail object.");
}
this.intObjectName = intObject.intObjectName;
this.description = typeof intObject.description === "undefined" ? "" : intObject.description;
this.useWith = typeof intObject.useWith === "undefined" || !intObject.useWith ? "INTEGRATION" : intObject.useWith;
this.defClass = typeof intObject.defClass === "undefined" ? "" : intObject.defClass;
this.procClass = typeof intObject.procClass === "undefined" ? "" : intObject.procClass;
this.searchAttrs = typeof intObject.searchAttrs === "undefined" ? "" : intObject.searchAttrs;
this.restrictWhere = typeof intObject.restrictWhere === "undefined" ? "" : intObject.restrictWhere;
this.module = typeof intObject.module === "undefined" ? "" : intObject.module;
this.selfReferencing = typeof intObject.selfReferencing === "undefined" ? false : intObject.selfReferencing == true;
this.flatSupported = typeof intObject.flatSupported === "undefined" ? false : intObject.flatSupported == true;
this.queryOnly = typeof intObject.queryOnly === "undefined" ? false : intObject.queryOnly == true;
this.loadQueryFromApp = typeof intObject.loadQueryFromApp === "undefined" ? false : intObject.loadQueryFromApp == true;
this.useOSSecurity = typeof intObject.useOSSecurity === "undefined" ? false : intObject.useOSSecurity == true;
this.authApp = typeof intObject.authApp === "undefined" ? "" : intObject.authApp;
if (
intObject.maxIntObjDetails.find(function (maxIntObjDetail) {
return typeof maxIntObjDetail.objectName === "undefined" || !maxIntObjDetail.objectName;
})
) {
throw new Error("The integration object " + this.intObjectName + " contains a object detail record that does not contain an object name.");
}
if (
intObject.maxIntObjDetails.find(function (maxIntObjDetail) {
return (
typeof maxIntObjDetail.parentObjName !== "undefined" &&
maxIntObjDetail.parentObjName &&
(typeof maxIntObjDetail.relation === "undefined" || !maxIntObjDetail.relation)
);
})
) {
throw new Error("The integration object " + this.intObjectName + " contains a child object detail record that does not contain a relation name.");
}
var parents = intObject.maxIntObjDetails.filter(function (maxIntObjDetail) {
return typeof maxIntObjDetail.parentObjName === "undefined" || !maxIntObjDetail.parentObjName;
});
if (parents.length == 0) {
throw new Error(
"The integration object " +
this.intObjectName +
" does not have a top level object detail record, a top level parent must be defined for an integration object."
);
}
if (parents.length > 1) {
throw new Error(
"The integration object " +
this.intObjectName +
" has more than one top level object detail record, only one top level parent can be defined for an integration object."
);
}
intObject.maxIntObjDetails.forEach(function (maxIntObjDetail) {
if (typeof maxIntObjDetail.maxIntObjCols !== "undefined" && Array.isArray(maxIntObjDetail.maxIntObjCols)) {
maxIntObjDetail.maxIntObjCols.forEach(function (obj) {
if (typeof obj.name === "undefined" || !obj.name) {
throw new Error(
"The integration object " +
intObject.intObjectName +
" object " +
maxIntObjDetail.objectName +
" is missing a name property for a maxIntObjCols object."
);
}
if (typeof obj.intObjFldType === "undefined" || !obj.intObjFldType) {
throw new Error(
"The integration object " +
intObject.intObjectName +
" object " +
maxIntObjDetail.objectName +
" is missing a intObjFldType property for a maxIntObjCols object."
);
}
});
} else {
maxIntObjDetail.maxIntObjCols = [];
}
if (typeof maxIntObjDetail.maxIntObjAlias !== "undefined" && Array.isArray(maxIntObjDetail.maxIntObjAlias)) {
if (!intObject.flatSupported) {
throw new Error(
"The maxIntObjAlias entries can only be applied to integration objects that support flat structure, " +
intObject.objectName +
" does not support flat structure."
);
}
maxIntObjDetail.maxIntObjAlias.forEach(function (obj) {
if (typeof obj.name === "undefined" || !obj.name) {
throw new Error(
"The integration object " +
intObject.intObjectName +
" object " +
maxIntObjDetail.objectName +
" is missing a name property for a maxIntObjAlias object."
);
}
if (typeof obj.aliasName === "undefined" || !obj.aliasName) {
throw new Error(
"The integration object " +
intObject.intObjectName +
" object " +
maxIntObjDetail.objectName +
" is missing a aliasName property for a maxIntObjAlias object."
);
}
});
} else {
maxIntObjDetail.maxIntObjAlias = [];
}
if (typeof maxIntObjDetail.objectAppAuth !== "undefined" && Array.isArray(maxIntObjDetail.objectAppAuth)) {
maxIntObjDetail.objectAppAuth.forEach(function (obj) {
if (typeof obj.context === "undefined" || !obj.context) {
throw new Error(
"The integration object " +
intObject.intObjectName +
" object " +
maxIntObjDetail.objectName +
" is missing a context property for a objectAppAuth object."
);
}
});
} else {
maxIntObjDetail.objectAppAuth = [];
}
maxIntObjDetail.skipKeyUpdate = typeof maxIntObjDetail.skipKeyUpdate === "undefined" ? false : maxIntObjDetail.skipKeyUpdate == true;
maxIntObjDetail.excludeParentKey = typeof maxIntObjDetail.excludeParentKey === "undefined" ? false : maxIntObjDetail.excludeParentKey == true;
maxIntObjDetail.deleteOnCreate = typeof maxIntObjDetail.deleteOnCreate === "undefined" ? false : maxIntObjDetail.deleteOnCreate == true;
maxIntObjDetail.propagateEvent = typeof maxIntObjDetail.propagateEvent === "undefined" ? false : maxIntObjDetail.propagateEvent == true;
maxIntObjDetail.invokeExecute = typeof maxIntObjDetail.invokeExecute === "undefined" ? false : maxIntObjDetail.invokeExecute == true;
maxIntObjDetail.fdResource = typeof maxIntObjDetail.fdResource === "undefined" ? "" : maxIntObjDetail.fdResource;
});
intObject.maxIntObjDetails.sort(function (a, b) {
if (typeof a.parentObjName === "undefined" || !a.parentObjName) {
return -1;
} else if (typeof b.parentObjName === "undefined" || !b.parentObjName) {
return 1;
} else if (a.objectName == b.parentObjName) {
return -1;
} else if (b.objectName == a.parentObjName) {
return 1;
} else {
return 0;
}
});
this.maxIntObjDetails = intObject.maxIntObjDetails;
this.maxIntObjDetails.forEach(function (obj) {
obj.parentObjName = typeof obj.parentObjName === "undefined" ? "" : obj.parentObjName;
obj.relation = typeof obj.relation === "undefined" ? "" : obj.relation;
obj.altKey = typeof obj.altKey === "undefined" ? "" : obj.altKey;
obj.objectOrder = typeof obj.objectOrder === "undefined" ? 1 : obj.objectOrder;
obj.excludeByDefault = typeof obj.excludeByDefault === "undefined" ? false : obj.excludeByDefault == true;
});
if (typeof intObject.objectAppAuth !== "undefined" && intObject.objectAppAuth && Array.isArray(intObject.objectAppAuth)) {
intObject.objectAppAuth.forEach(function (obj) {
if (typeof obj.context === "undefined" || !obj.context) {
throw new Error("An objectAppAuth entry is missing the required context property.");
} else if (typeof obj.objectName === "undefined" || !obj.objectName) {
throw new Error("An objectAppAuth entry is missing the required objectName property.");
} else if (typeof obj.authApp === "undefined" || !obj.authApp) {
throw new Error("An objectAppAuth entry is missing the required authApp property.");
}
obj.description = typeof obj.description == "undefined" ? "" : obj.description;
});
this.objectAppAuth = intObject.objectAppAuth;
} else {
this.objectAppAuth = [];
}
if (typeof intObject.sigOption !== "undefined" && intObject.sigOption && Array.isArray(intObject.sigOption)) {
intObject.sigOption.forEach(function (option) {
if (typeof option.optionName === "undefined" || !option.optionName) {
throw new Error("A sigOption entry is missing the required optionName property.");
}
option.description = typeof option.description === "undefined" ? "" : option.description;
option.alsoGrants = typeof option.alsoGrants === "undefined" ? "" : option.alsoGrants;
option.alsoRevokes = typeof option.alsoRevokes === "undefined" ? "" : option.alsoRevokes;
option.prerequisite = typeof option.prerequisite === "undefined" ? "" : option.prerequisite;
option.esigEnabled = typeof option.esigEnabled === "undefined" ? false : option.esigEnabled == true;
option.visible = typeof option.visible === "undefined" ? true : option.visible == true;
});
this.sigOption = intObject.sigOption;
} else {
this.sigOption = [];
}
if (typeof intObject.osOSLCAction !== "undefined" && intObject.osOSLCAction && Array.isArray(intObject.osOSLCAction)) {
intObject.osOSLCAction.forEach(function (action) {
if (typeof action.name === "undefined" || !action.name) {
throw new Error("A osOSLCAction entry is missing the required name property.");
}
if (typeof action.implType === "undefined" || !action.implType) {
throw new Error("An osOSLCAction entry is missing the required implType property.");
} else {
action.implType = action.implType.toLowerCase();
}
var implTypes = ["script", "system", "workflow", "wsmethod"];
if (implTypes.indexOf(action.implType) < 0) {
throw new Error(
"The osOSLCAction implementation type " + action.implType + " is not valid, " + implTypes.join(",") + " are the valid implementation types."
);
}
if (action.implType == "script") {
if (typeof action.scriptName === "undefined" || !action.scriptName) {
throw new Error('The osOSLCAction entry is missing the required scriptName property for the implementation type of "script".');
}
} else if (action.implType == "system") {
if (typeof action.systemName === "undefined" || !action.systemName) {
throw new Error('The osOSLCAction entry is missing the required systemName property for the implementation type of "system".');
}
} else if (action.implType == "workflow") {
if (typeof action.processName === "undefined" || !action.processName) {
throw new Error('The osOSLCAction entry is missing the required processName property for the implementation type of "workflow".');
}
} else if (action.implType == "wsmethod") {
if (typeof action.methodName === "undefined" || !action.methodName) {
throw new Error('The osOSLCAction entry is missing the required methodName property for the implementation type of "wsmethod".');
}
}
action.description = typeof action.description === "undefined" ? "" : action.description;
action.optionName = typeof action.optionName === "undefined" ? "" : action.optionName;
action.collection = typeof action.collection === "undefined" ? false : action.collection == true;
});
this.osOSLCAction = intObject.osOSLCAction;
} else {
this.osOSLCAction = [];
}
if (typeof intObject.oslcQuery !== "undefined" && intObject.oslcQuery && Array.isArray(intObject.oslcQuery)) {
intObject.oslcQuery.forEach(function (query) {
if (typeof query.queryType === "undefined" || !query.queryType) {
throw new Error("A oslcQuery entry is missing the required queryType property.");
} else {
query.queryType = query.queryType.toLowerCase();
}
var queryTypes = ["appclause", "method", "osclause", "script"];
if (queryTypes.indexOf(query.queryType) < 0) {
throw new Error("The oslcQuery query type " + query.queryType + " is not valid, " + queryTypes.join(",") + " are the valid query types.");
}
if (query.queryType == "appclause") {
if (typeof action.app === "undefined" || !action.app) {
throw new Error('The oslcQuery entry is missing the required app property for the query type of "appclause".');
}
if (typeof action.clauseName === "undefined" || !action.clauseName) {
throw new Error('The oslcQuery entry is missing the required clauseName property for the query type of "appclause".');
}
} else if (query.queryType == "method") {
if (typeof action.method === "undefined" || !action.method) {
throw new Error('The oslcQuery entry is missing the required method property for the query type of "method".');
}
query.description = typeof query.description === "undefined" ? "" : query.description;
} else if (query.queryType == "osclause") {
if (typeof query.clauseName === "undefined" || !query.clauseName) {
throw new Error('The oslcQuery entry is missing the required clauseName property for the query type of "osclause".');
}
if (typeof query.clause === "undefined" || !query.clause) {
throw new Error('The oslcQuery entry is missing the required clause property for the query type of "osclause".');
}
query.description = typeof query.description === "undefined" ? "" : query.description;
query.isPublic = typeof query.isPublic === "undefined" ? true : query.isPublic == true;
} else if (query.queryType == "script") {
if (typeof action.scriptName === "undefined" || !query.scriptName) {
throw new Error('The oslcQuery entry is missing the required scriptName property for the query type of "script".');
}
}
});
this.oslcQuery = intObject.oslcQuery;
} else {
this.oslcQuery = [];
}
if (typeof intObject.queryTemplate !== "undefined" && intObject.queryTemplate && Array.isArray(intObject.queryTemplate)) {
intObject.queryTemplate.forEach(function (template) {
if (typeof template.templateName === "undefined" || !template.templateName) {
throw new Error("A queryTemplate entry is missing the required templateName property.");
}
template.description = typeof template.description === "undefined" ? "" : template.description;
template.pageSize = typeof template.pageSize === "undefined" ? "" : template.pageSize;
template.role = typeof template.role === "undefined" ? "" : template.role;
template.searchAttributes = typeof template.searchAttributes === "undefined" ? "" : template.searchAttributes;
template.timelineAttributes = typeof template.timelineAttributes === "undefined" ? "" : template.timelineAttributes;
template.isPublic = typeof template.isPublic === "undefined" ? true : template.isPublic == true;
if (typeof template.queryTemplateAttr !== "undefined" && template.queryTemplateAttr && Array.isArray(template.queryTemplateAttr)) {
template.queryTemplateAttr.forEach(function (attr) {
if (typeof attr.selectAttrName === "undefined" || !attr.selectAttrName) {
throw new Error("A queryTemplateAttr entry is missing the required selectAttrName property.");
}
attr.title = typeof attr.title === "undefined" ? "" : attr.title;
attr.selectOrder = typeof attr.selectOrder === "undefined" ? "" : attr.selectOrder;
attr.alias = typeof attr.alias === "undefined" ? "" : attr.alias;
attr.sortByOrder = typeof attr.sortByOrder === "undefined" ? "" : attr.sortByOrder;
attr.sortByOn = typeof attr.sortByOn === "undefined" ? false : attr.sortByOn == true;
attr.ascending = typeof attr.ascending === "undefined" ? false : attr.ascending == true;
});
} else {
template.queryTemplateAttr = [];
}
});
this.queryTemplate = intObject.queryTemplate;
} else {
this.queryTemplate = [];
}
}
IntegrationObject.prototype.constructor = IntegrationObject;
IntegrationObject.prototype.setMboValues = function (mbo) {
if (!mbo) {
throw new Error("A Mbo is required to set values from the IntegrationObject object.");
} else if (!(mbo instanceof Java.type("psdi.mbo.Mbo"))) {
throw new Error("The mbo parameter must be an instance of psdi.mbo.Mbo.");
} else if (!mbo.isBasedOn("MAXINTOBJECT")) {
throw new Error("The mbo parameter must be based on the MAXINTOBJECT Maximo object.");
}
if (mbo.toBeAdded()) {
mbo.setValue("INTOBJECTNAME", this.intObjectName);
}
mbo.setValue("DESCRIPTION", this.description);
mbo.setValue("USEWITH", this.useWith);
mbo.setValue("QUERYONLY", this.queryOnly);
mbo.setValue("FLATSUPPORTED", this.flatSupported);
mbo.setValue("LOADQUERYFROMAPP", this.loadQueryFromApp);
mbo.setValue("DEFCLASS", this.defClass);
mbo.setValue("PROCCLASS", this.procClass);
mbo.setValue("SEARCHATTRS", this.searchAttrs);
mbo.setValue("RESTRICTWHERE", this.restrictWhere);
mbo.setValue("MODULE", this.module);
var maxIntObjDetailSet = mbo.getMboSet("MAXINTOBJDETAIL");
this.maxIntObjDetails.forEach(function (obj) {
var maxIntObjDetail = maxIntObjDetailSet.add();
maxIntObjDetail.setValue("OBJECTNAME", obj.objectName);
maxIntObjDetail.setValue("ALTKEY", obj.altKey);
maxIntObjDetail.setValue("EXCLUDEBYDEFAULT", obj.excludeByDefault);
maxIntObjDetail.setValue("SKIPKEYUPDATE", obj.skipKeyUpdate);
maxIntObjDetail.setValue("EXCLUDEPARENTKEY", obj.excludeParentKey);
maxIntObjDetail.setValue("DELETEONCREATE", obj.deleteOnCreate);
maxIntObjDetail.setValue("PROPAGATEEVENT", obj.propagateEvent);
maxIntObjDetail.setValue("INVOKEEXECUTE", obj.invokeExecute);
maxIntObjDetail.setValue("FDRESOURCE", obj.fdResource);
if (obj.parentObjName) {
maxIntObjDetail.setValue("PARENTOBJNAME", obj.parentObjName);
maxIntObjDetail.setValue("RELATION", obj.relation);
maxIntObjDetail.setValue("OBJECTORDER", obj.objectOrder);
}
var maxIntObjColsSet = maxIntObjDetail.getMboSet("MAXINTOBJCOLS");
obj.maxIntObjCols.forEach(function (maxIntObjCol) {
var maxIntObjCols = maxIntObjColsSet.add();
maxIntObjCols.setValue("NAME", maxIntObjCol.name);
maxIntObjCols.setValue("INTOBJFLDTYPE", maxIntObjCol.intObjFldType);
});
var maxIntObjAliasSet = maxIntObjDetail.getMboSet("MAXINTOBJALIAS");
obj.maxIntObjAlias.forEach(function (maxIntObjAliasObj) {
var maxIntObjAlias = maxIntObjAliasSet.add();
maxIntObjAlias.setValue("NAME", maxIntObjAliasObj.name);
maxIntObjAlias.setValue("ALIASNAME", maxIntObjAliasObj.aliasName);
});
var objectAppAuthSet = maxIntObjDetail.getMboSet("$objectappauth", "OBJECTAPPAUTH", "1=1");
obj.objectAppAuth.forEach(function (objAppAuth) {
objectAppAuth = objectAppAuthSet.add();
objectAppAuth.setValue("CONTEXT", objAppAuth.context);
objectAppAuth.setValue("DESCRIPTION", objAppAuth.description);
objectAppAuth.setValue("OBJECTNAME", obj.objectName);
objectAppAuth.setValue("AUTHAPP", objAppAuth.authApp);
});
});
if (!this.useOSSecurity && this.authApp) {
mbo.setValue("AUTHAPP", this.authApp);
} else if (this.useOSSecurity) {
mbo.setValue("USEOSSECURITY", this.useOSSecurity);
}
var sigOptionSet = mbo.getMboSet("SIGOPTION");
this.sigOption.forEach(function (option) {
var sigOption = sigOptionSet.add();
sigOption.setValue("OPTIONNAME", option.optionName);
sigOption.setValue("DESCRIPTION", option.description);
sigOption.setValue("ALSOGRANTS", option.alsoGrants);
sigOption.setValue("ALSOREVOKES", option.alsoRevokes);
sigOption.setValue("PREREQUISITE", option.prerequisite);
sigOption.setValue("ESIGENABLED", option.esigEnabled);
sigOption.setValue("VISIBLE", option.visible);
});
var osOSLCActionSet = mbo.getMboSet("OSOSLCACTION");
var checkSigOptions = this.sigOption;
this.osOSLCAction.forEach(function (action) {
var osOSLCAction = osOSLCActionSet.add();
osOSLCAction.setValue("NAME", action.name);
osOSLCAction.setValue("DESCRIPTION", action.description);
osOSLCAction.setValue("IMPLTYPE", action.implType);
switch (action.implType) {
case "system":
osOSLCAction.setValue("SYSTEMNAME", action.systemName);
break;
case "script":
osOSLCAction.setValue("SCRIPTNAME", action.scriptName);
break;
case "workflow":
osOSLCAction.setValue("PROCESSNAME", action.processName);
break;
case "wsmethod":
osOSLCAction.setValue("METHODNAME", action.methodName);
break;
}
if (action.optionName) {
if (
checkSigOptions.find(function (option) {
return option.optionName === action.optionName;
})
) {
osOSLCAction.setValue("OPTIONNAME", action.optionName, MboConstants.NOVALIDATION);
} else {
osOSLCAction.setValue("OPTIONNAME", action.optionName);
}
}
osOSLCAction.setValue("COLLECTION", action.collection);
});
var oslcQuerySet = mbo.getMboSet("OSLCQUERY");
this.oslcQuery.forEach(function (query) {
var oslcQuery = oslcQuerySet.add();
oslcQuery.setValue("QUERYTYPE", query.queryType);
switch (query.queryType) {
case "appclause":
oslcQuery.setValue("APP", query.app);
oslcQuery.setValeu("CLAUSENAME", query.clauseName);
break;
case "method":
oslcQuery.setValue("METHO