Skip to content
Snippets Groups Projects
Commit 03002963 authored by S.Listl's avatar S.Listl
Browse files

Attribute_lib changes

parent de8d9237
No related branches found
No related tags found
No related merge requests found
......@@ -135,11 +135,6 @@
<state>AUTO</state>
<stateProcess>%aditoprj%/entity/Attribute_entity/entityfields/keyword_container/stateProcess.js</stateProcess>
</entityField>
<entityActionField>
<name>createLiquibaseScript</name>
<fieldType>ACTION</fieldType>
<onActionProcess>%aditoprj%/entity/Attribute_entity/entityfields/createliquibasescript/onActionProcess.js</onActionProcess>
</entityActionField>
</entityFields>
<recordContainers>
<dbRecordContainer>
......
import("system.logging");
import("system.text");
import("system.question");
var attributeJson = question.askUpload("yeet", "yeet", "yeet");
attributeJson = text.parseDocument(attributeJson);
var attributeObj = JSON.parse(attributeJson);
var attributes = attributeObj.AB_ATTRIBUTE;
var attributeUsages = attributeObj.AB_ATTRIBUTEUSAGE;
var inserts = "";
var rollbacks = "";
var sqlAttrObj = {};
var levelObj = {};
for (let i = 0; i < attributes.length; i++)
{
if (attributes[i].ATTRIBUTE_TYPE == "COMBO")
levelObj[attributes[i].AB_ATTRIBUTEID] = attributes[i].ATTRIBUTE_PARENT_ID != "";
}
for (let i = 0; i < attributes.length; i++)
{
if (attributes[i].ATTRIBUTE_TYPE != "SQLCOMBO")
{
var sort = attributes[i].ATTRIBUTE_SORT != "" ? attributes[i].ATTRIBUTE_SORT - 1 : "";
var level = 0;
if (attributes[i].ATTRIBUTE_PARENT_ID != "")
{
level++;
if (levelObj[attributes[i].ATTRIBUTE_PARENT_ID])
level++;
}
inserts += "<insert tableName=\"AB_ATTRIBUTE\">\n\
\t<column name=\"AB_ATTRIBUTEID\" value=\"" + attributes[i].AB_ATTRIBUTEID + "\"/>\n\
\t<column name=\"ATTRIBUTE_NAME\" value=\"" + attributes[i].ATTRIBUTE_NAME + "\"/>\n\
\t<column name=\"ATTRIBUTE_TYPE\" value=\"" + attributes[i].ATTRIBUTE_TYPE + "\"/>\n\
\t<column name=\"ATTRIBUTE_PARENT_ID\" value=\"" + attributes[i].ATTRIBUTE_PARENT_ID + "\"/>\n\
\t<column name=\"SORTING\" valueNumeric=\"" + sort + "\"/>\n\
\t<column name=\"ATTRIBUTE_ACTIVE\" valueNumeric=\"1\"/>\n\
\t<column name=\"ATTRIBUTE_LEVEL\" valueNumeric=\"" + level + "\"/>\n\
</insert>\n";
}
else
sqlAttrObj[attributes[i].AB_ATTRIBUTEID] = true;
}
for (let i = 0; i < attributeUsages.length; i++)
{
if (!sqlAttrObj[attributeUsages[i].AB_ATTRIBUTE_ID])
{
inserts += "<insert tableName=\"AB_ATTRIBUTEUSAGE\">\n\
\t<column name=\"AB_ATTRIBUTEUSAGEID\" value=\"" + attributeUsages[i].AB_ATTRIBUTEUSAGEID + "\"/>\n\
\t<column name=\"OBJECT_TYPE\" value=\"" + attributeUsages[i].ATTRIBUTE_NAME + "\"/>\n\
\t<column name=\"AB_ATTRIBUTE_ID\" value=\"" + attributeUsages[i].ATTRIBUTE_TYPE + "\"/>\n\
\t<column name=\"MIN_COUNT\" valueNumeric=\"" + attributeUsages.MINCOUNT + "\"/>\n\
\t<column name=\"MAX_COUNT\" valueNumeric=\"" + attributeUsages.MAXCOUNT + "\"/>\n\
</insert>\n";
}
else
sqlAttrObj[attributes[i].AB_ATTRIBUTEID] = true;
}
logging.log(inserts)
\ No newline at end of file
......@@ -5,9 +5,9 @@
<majorModelMode>DISTRIBUTED</majorModelMode>
<filterable v="true" />
<layout>
<boxLayout>
<groupLayout>
<name>layout</name>
</boxLayout>
</groupLayout>
</layout>
<children>
<treetableViewTemplate>
......
......@@ -139,18 +139,29 @@ function AttributeRelationUtils () {}
/**
* gets the value of an attributeRelation for one dataset (e. g. a person)
*
* @param {String} pAttributeId attribute-id
* @param {String} pObjectRowId row-id of the dataset
* @param {String} [pObjectType=null] object-type
*
* @return {String|null} the value of the attribute
*/
AttributeRelationUtils.getAttribute = function (pAttributeId, pObjectRowId, pObjectType)
{
var attrCond = SqlCondition().begin()
var attrCond = SqlCondition.begin()
.andPrepare("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", pAttributeId)
.andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", pObjectRowId);
if (pObjectType != null)
attrCond.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", pAttributeId);
var attrSql = AttributeRelationUtils.getSqlUtil();
var attributeValues = db.array(db.ROW, attrCond.buildSql(attrSql.sqlSelect));
return attrSql.getFieldFromType(attributeValues);
var attributeSql = attrCond.buildSql("select ATTRIBUTE_TYPE, " + AttributeTypeUtil.getAllDatabaseFields()
+ " from AB_ATTRIBUTERELATION join AB_ATTRIBUTE on AB_ATTRIBUTE_ID = AB_ATTRIBUTEID");
var attributeValues = db.array(db.ROW, attributeSql);
if (attributeValues.length == 0)
return null;
var valueIndex = AttributeTypeUtil.getTypeColumnIndex(attributeValues[0]) + 1;
return attributeValues[valueIndex];
}
AttributeRelationUtils.getAttributes = function ()
......@@ -166,59 +177,6 @@ AttributeRelationUtils.setAttribute = function ()
//TODO: implement
}
/**
* Builds an object for the work with the values of attributeRelations. This should make
* the attribute type definition more flexible, the returned object has the following properties
* and methods:
*
* columns = array of all database columns in AB_ATTRIBUTERELATION that hold attribute values
* typeColMap = object with the attribute type as key and the index in the columns-array with the column holding
* the value for that attribute type as value
* sqlSelect = an sql-select string where the columns are the type of the attribute plus the value columns
* getFieldFromType = a method that takes a one-dimensional array that has been created with a query using the 'sqlSelect' property
* and returns the value at the right position of that array depending on the type. For example:
* //type, values
* vals = ["TEXT", "abcdef", "", "", "", ""];
* the method would return "abcdef", because it looks at the first position where the type is, e. g. "TEXT"
* and then it gets the value at, for example, index 1 because the typeColMap object says that the value for type "TEXT"
* is at position 1.
*
*/
AttributeRelationUtils.getSqlUtil = function ()
{
var sqlMap = {
columns : [],
typeColMap : {}
};
for (let type in $AttributeTypes)
{
type = $AttributeTypes[type];
if (type.databaseField)
{
var typeKey = type.toString();
var colIndex = sqlMap.columns.indexOf(type.databaseField);
if (colIndex == -1)
{
colIndex = sqlMap.columns.length;
sqlMap.columns.push(type.databaseField);
}
sqlMap.typeColMap[typeKey] = colIndex;
}
}
sqlMap.sqlSelect = "select ATTRIBUTE_TYPE, " + sqlMap.columns.join(", ") + " from AB_ATTRIBUTERELATION "
+ " join AB_ATTRIBUTE on AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID ";
sqlMap.getFieldFromType = function (pTypeAndValues)
{
if (pTypeAndValues.length > 0)
return pTypeAndValues[this.typeColMap[pTypeAndValues[0]] + 1];
return null;
}
return sqlMap;
}
/*********************************************************************************************************************/
/**
......@@ -269,7 +227,7 @@ AttributeHandler.prototype.getAttributeType = function () //TODO: maybe the type
*/
AttributeHandler.prototype.getAttributeField = function ()
{
return $AttributeTypes.getEntityField(this.getAttributeType());
return AttributeTypeUtil.getEntityField(this.getAttributeType());
}
/**
......@@ -279,7 +237,7 @@ AttributeHandler.prototype.getAttributeField = function ()
*/
AttributeHandler.prototype.getAttributeContentType = function ()
{
return $AttributeTypes.getContentType(this.getAttributeType());
return AttributeTypeUtil.getContentType(this.getAttributeType());
}
/**
......@@ -377,6 +335,10 @@ $AttributeTypes.MEMO = {
entityField : "MEMO_VALUE"
};
function AttributeTypeUtil () {}
/**
* returns the required contentType for the given attribute type
*
......@@ -384,7 +346,7 @@ $AttributeTypes.MEMO = {
* (use the values of the AttributeTypes object, e. g. AttributeTypes.TEXT)
* @return {String} the contentType for the attribute
*/
$AttributeTypes.getContentType = function (pAttributeType)
AttributeTypeUtil.getContentType = function (pAttributeType)
{
if (pAttributeType in $AttributeTypes)
return $AttributeTypes[pAttributeType].contentType;
......@@ -398,7 +360,7 @@ $AttributeTypes.getContentType = function (pAttributeType)
* (use the values of the AttributeTypes object, e. g. AttributeTypes.TEXT)
* @return {String} the field for the attribute
*/
$AttributeTypes.getEntityField = function (pAttributeType)
AttributeTypeUtil.getEntityField = function (pAttributeType)
{
if (pAttributeType in $AttributeTypes)
return $AttributeTypes[pAttributeType].entityField;
......@@ -412,7 +374,7 @@ $AttributeTypes.getEntityField = function (pAttributeType)
* (use the values of the AttributeTypes object, e. g. AttributeTypes.TEXT)
* @return {String} the database field for the attribute
*/
$AttributeTypes.getDatabaseField = function (pAttributeType)
AttributeTypeUtil.getDatabaseField = function (pAttributeType)
{
if (pAttributeType in $AttributeTypes)
return $AttributeTypes[pAttributeType].databaseField;
......@@ -426,9 +388,46 @@ $AttributeTypes.getDatabaseField = function (pAttributeType)
* (use the values of the AttributeTypes object, e. g. AttributeTypes.TEXT)
* @return {String} the name the attribute
*/
$AttributeTypes.getName = function (pAttributeType)
AttributeTypeUtil.getName = function (pAttributeType)
{
if (pAttributeType in $AttributeTypes)
return translate.text($AttributeTypes[pAttributeType].displayName);
return null;
}
AttributeTypeUtil._initTypeColumnData = function ()
{
columns = [];
typeColumnMap = {};
for (let type in $AttributeTypes)
{
type = $AttributeTypes[type];
if (type.databaseField)
{
var typeKey = type.toString();
var colIndex = columns.indexOf(type.databaseField);
if (colIndex == -1)
{
colIndex = columns.length;
columns.push(type.databaseField);
}
typeColumnMap[typeKey] = colIndex;
}
}
this._allDBColumns = columns;
this._typeColumnMap = typeColumnMap;
}
AttributeTypeUtil.getAllDatabaseFields = function ()
{
if (this._allDBColumns == undefined)
AttributeTypeUtil._initTypeColumnData();
return this._allDBColumns;
}
AttributeTypeUtil.getTypeColumnIndex = function (pAttributeType)
{
if (this._typeColumnMap == undefined)
AttributeTypeUtil._initTypeColumnData();
return this._typeColumnMap[pAttributeType.trim()];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment