Newer
Older
import("JditoFilter_lib");
import("KeywordRegistry_basic");
import("Keyword_lib");
import("system.db");
import("system.vars");
import("system.result");
import("Sql_lib");
import("Attribute_lib");
var uidTableAlias = "SELF";
var sqlSelect = "select SELF.AB_ATTRIBUTEID, SELF.ATTRIBUTE_PARENT_ID, SELF.ATTRIBUTE_ACTIVE, SELF.KEYWORD_CONTAINER, SELF.SORTING, SELF.ATTRIBUTE_TYPE, "
+ KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "SELF.ATTRIBUTE_TYPE") //3
+ ", '', SELF.ATTRIBUTE_NAME, PARENT1.ATTRIBUTE_NAME, PARENT2.ATTRIBUTE_NAME, PARENT3.ATTRIBUTE_NAME, PARENT3.ATTRIBUTE_PARENT_ID "
+ "left join AB_ATTRIBUTE PARENT1 on SELF.ATTRIBUTE_PARENT_ID = PARENT1.AB_ATTRIBUTEID " //always select the names of the next 3 parents so that less queries
+ "left join AB_ATTRIBUTE PARENT2 ON PARENT1.ATTRIBUTE_PARENT_ID = PARENT2.AB_ATTRIBUTEID " //are required later when buildung the full name
+ "left join AB_ATTRIBUTE PARENT3 ON PARENT2.ATTRIBUTE_PARENT_ID = PARENT3.AB_ATTRIBUTEID";
var sqlOrder = " order by SELF.ATTRIBUTE_PARENT_ID asc, SELF.SORTING asc";
var getGroups = vars.exists("$param.GetGroups_param") && vars.get("$param.GetGroups_param");
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param");
var parentType = vars.exists("$param.AttrParentType_param") && vars.get("$param.AttrParentType_param");
if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
condition.and("SELF.AB_ATTRIBUTEID in ('" + vars.get("$local.idvalues").join("','") + "')");
}
else if (getGroups) //if getGroups == true, it is the lookup for selecting the superordinate attribute
{
//this condition filters out the own id and the children to prevent loops
if ($AttributeTypes[type].isGroup && $AttributeTypes[type] != $AttributeTypes.COMBO
&& (parentType == $AttributeTypes.VOID || $AttributeTypes[type] != $AttributeTypes.VOID))
{
isGroupCondition.orPrepare(["AB_ATTRIBUTE", "ATTRIBUTE_TYPE", uidTableAlias], $AttributeTypes[type]);
condition.andSqlCondition(SqlCondition.begin()
.andPrepareVars(["AB_ATTRIBUTE", "AB_ATTRIBUTEID", uidTableAlias], "$param.AttrParentId_param", "# != ?")
.and("SELF.AB_ATTRIBUTEID not in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')")
}
else if (objectType) //if there's an objectType, it comes from the AttributeRelation entity
{
logging.log(vars.get("$param.FilteredAttributeIds_param"))
if (vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param")) {
var filteredAttributes = JSON.parse(vars.getString("$param.FilteredAttributeIds_param"));
var attributeCount;
if (vars.exists("$param.AttributeCount_param") && vars.get("$param.AttributeCount_param"))
attributeCount = JSON.parse(vars.getString("$param.AttributeCount_param"));
var ids = AttributeUtil.getPossibleAttributes(objectType, false, filteredAttributes, attributeCount);
if (filteredAttributes.length > 0)
condition.and("SELF.AB_ATTRIBUTEID in ('" + ids.join("','") + "')");
else // do not return anything, if parameter is there but an empty array
condition.and("1=2");
}
if (AttributeTypeUtil.isGroupType(parentType)) //condition for all subordinate attributes of an attribute
var parentId = vars.exists("$param.AttrParentId_param") && vars.get("$param.AttrParentId_param");
if (parentId)
condition.and("SELF.AB_ATTRIBUTEID in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')");
//when there are filters selected, add them to the conditon

Johannes Hörmann
committed
if (vars.exists("$local.filter") && vars.get("$local.filter"))

Johannes Hörmann
committed
var filter = vars.get("$local.filter");
if (filter.filter)
condition.andSqlCondition(JditoFilterUtils.getSqlCondition(filter.filter, "AB_ATTRIBUTE", uidTableAlias));
var attributes = db.table(condition.buildSql(sqlSelect, "1=1", sqlOrder));
//sorts the records in a way that a tree can be built and adds values
function _buildAttributeTable (pAttributes)
//fills the allIds object, the object is used for checking if a parent exists in the array
pAttributes.forEach(function (row) {allIds[row[0]] = true;});
var oldIndex = arrayIndex;
pAttributes.forEach(function (row)
{
//item will be added if the id is not already in the object and
//the parent is already added (or the parent is not in the array)
if (!(row[0] in this) && (row[1] in this || !allIds[row[1]]))
} while (oldIndex != arrayIndex); //stops the loop when no new items were added so that recursive relations between attributes don't cause an infinite loop
var displaySimpleName = vars.exists("$param.DisplaySimpleName_param") && vars.get("$param.DisplaySimpleName_param");
var sortedArray = new Array(Object.keys(rows).length);
for (let i in rows)
if (rowData[5].trim() != $AttributeTypes.COMBOVALUE)
{
let usages = db.array(db.COLUMN, SqlCondition.begin()
.andPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", rowData[0])
.buildSql("select OBJECT_TYPE from AB_ATTRIBUTEUSAGE")
);
var fullName = displaySimpleName
? rowData[8]
: _getFullName(rowData[8], rowData[9], rowData[10], rowData[11], rowData[12]);
rowData.splice(9, 4, fullName);
function _getFullName (pAttributeName, pParent1Name, pParent2Name, pParent3Name, pParent4Id)
var parent4FullName = pParent4Id ? AttributeUtil.getFullAttributeName(pParent4Id) : null;
pAttributeName = ArrayUtils.joinNonEmptyFields([parent4FullName, pParent3Name, pParent2Name, pParent1Name, pAttributeName], " / ");