Skip to content
Snippets Groups Projects
Commit 85f09a6a authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Knowledgemanagement sql refactoring with SqlBuilder

parent 4e3545a4
No related branches found
No related tags found
No related merge requests found
Showing
with 103 additions and 162 deletions
......@@ -18,8 +18,6 @@
<include relativeToChangelogFile="true" file="basic/2020.2.0/changelog.xml"/>
<include relativeToChangelogFile="true" file="basic/2020.2.1/changelog.xml"/>
<include relativeToChangelogFile="true" file="basic/2020.2.2/changelog.xml"/>
<include relativeToChangelogFile="true" file="basic/Knowledgemanagement/changelog_knowledgeManagement.xml"/>
<!--enable this only when you definetly want to overwrite the existing data with demo records:-->
<!--<include relativeToChangelogFile="true" file="basic/_demoData/changelog.xml" context="example"/>-->
......
......@@ -61,11 +61,6 @@
</entityField>
<entityConsumer>
<name>StatusKeyword</name>
<dependency>
<name>dependency</name>
<entityName>KeywordEntry_entity</entityName>
<fieldName>SpecificContainerKeywords</fieldName>
</dependency>
<children>
<entityParameter>
<name>ContainerName_param</name>
......@@ -76,6 +71,11 @@
<valueProcess>%aditoprj%/entity/KnowledgeDiscussion_entity/entityfields/statuskeyword/children/onlyactives_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
<dependency>
<name>dependency</name>
<entityName>KeywordEntry_entity</entityName>
<fieldName>SpecificContainerKeywords</fieldName>
</dependency>
</entityConsumer>
<entityProvider>
<name>ByKnowledgeId</name>
......@@ -128,7 +128,6 @@
</entityActionGroup>
<entityParameter>
<name>ParentId_param</name>
<valueProcess>%aditoprj%/entity/KnowledgeDiscussion_entity/entityfields/parentid_param/valueProcess.js</valueProcess>
<expose v="true" />
</entityParameter>
<entityParameter>
......
......@@ -2,6 +2,4 @@ import("system.vars");
import("system.neon");
if(vars.exists("$param.WithClosed_param") && vars.get("$param.WithClosed_param"))
vars.set("$context.showAll", vars.get("$param.WithClosed_param"))
//else if(!vars.exists("$context.showAll"))
// vars.set("$context.showAll", "false");
\ No newline at end of file
vars.set("$context.showAll", vars.get("$param.WithClosed_param"))
\ No newline at end of file
//import("system.vars");
//import("system.result");
//result.string(vars.exists("$sys.selection") && vars.get("$sys.selection"));
\ No newline at end of file
import("system.logging");
import("KnowledgeManagement_lib");
import("system.vars");
import("system.result");
......@@ -20,6 +19,5 @@ if(kId)
{
var discussions = KnowledgeDiscussion.getInstance(kId);
var retData = discussions.getDatasetCount(KnowledgeDiscussion.getMode(withClosed), idValues);
//logging.log("DATA: " + JSON.stringify([retData,idValues],null,"\t"));
result.object(retData);
}
\ No newline at end of file
import("Sql_lib");
import("system.vars");
import("system.result");
var id = (vars.exists("$param.KnowledgeManagementId_param")) ? vars.get("$param.KnowledgeManagementId_param") : null;
var localId = (vars.exists("$local.idvalue")) ? vars.get("$local.idvalue") : null;
var cond = newWhereIfSet("KNOWLEDGELINK.KNOWLEDGEMANAGEMENT_ID", "$param.KnowledgeManagementId_param")
.andIfSet("KNOWLEDGELINK.KNOWLEDGELINKID", localId);
var cond = "";
cond += (id) ? "KNOWLEDGEMANAGEMENT_ID = '" + id + "'" : "";
cond += (cond.length && localId) ? " and " : "";
cond += (localId) ? "KNOWLEDGELINKID = '" + localId + "'" : "";
if(cond.length)
result.string(cond);
else
result.string("1=2");
\ No newline at end of file
result.string(cond.toString(SqlBuilder.NORESULT_CONDITION()));
\ No newline at end of file
......@@ -2,4 +2,4 @@ import("system.vars");
import("system.result");
import("Sql_lib");
result.string(new SqlBuilder().select("TAG").from("KNOWLEDGETAG").where("KNOWLEDGETAGID = '" + vars.get("$field.TAG") + "'").cell());
\ No newline at end of file
result.string(new SqlBuilder().select("TAG").from("KNOWLEDGETAG").where("KNOWLEDGETAG.KNOWLEDGETAGID", "$field.TAG").cell());
\ No newline at end of file
......@@ -4,7 +4,11 @@ import("system.vars");
import("system.result");
if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value"))
result.query("select " + new SqlMaskingUtils().concat(["PERSON.FIRSTNAME","PERSON.LASTNAME"], " ", true)
+" from PERSON "
+" join CONTACT on PERSON.PERSONID = CONTACT.PERSON_ID "
+" where CONTACT.CONTACTID = '" + vars.get("$this.value") + "'");
\ No newline at end of file
{
result.string(newSelect(new SqlMaskingUtils().concatWithSeparator(["PERSON.FIRSTNAME","PERSON.LASTNAME"]))
.from("PERSON")
.join("CONTACT", "PERSON.PERSONID = CONTACT.PERSON_ID")
.where("CONTACT.CONTACTID", "$this.value")
.cell()
);
}
\ No newline at end of file
import("system.vars");
import("system.result");
import("system.neon");
import("system.datetime");
//if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
//{
// result.string(datetime.date());
//}
if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
result.string(vars.get("$sys.date"));
\ No newline at end of file
......@@ -5,31 +5,14 @@ import("Sql_lib");
if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT && !vars.getString("$this.value"))
{
// var config = entities.createConfigForLoadingConsumerRows()
// .consumer("TagsByKnowledgeId")
// .fields(["TAG"])
//
// var entityData = entities.getRows(config);
var knowledgeId = vars.get("$field.KNOWLEDGEMANAGEMENTID");
var isTagSet = newSelect("'1'")
.from("KNOWLEDGETAGLINK")
.join("KNOWLEDGETAG on KNOWLEDGETAG.KNOWLEDGETAGID = KNOWLEDGETAGLINK.KNOWLEDGETAG_ID")
.where("KNOWLEDGETAGLINK.KNOWLEDGEMANAGEMENT_ID = '" + knowledgeId + "'")
.and("KNOWLEDGETAG.TAG = 'News'")
.cell();
.from("KNOWLEDGETAGLINK")
.join("KNOWLEDGETAG", "KNOWLEDGETAG.KNOWLEDGETAGID = KNOWLEDGETAGLINK.KNOWLEDGETAG_ID")
.where("KNOWLEDGETAGLINK.KNOWLEDGEMANAGEMENT_ID", knowledgeId)
.and("KNOWLEDGETAG.TAG", "News")
.cell();
// if(entityData)
// {
// entityData.map(function(row)
// {
// if(row["TAG.displayValue"] == "News")
// {
// isTagSet = 1;
// return;
// }
// });
// }
result.string(isTagSet ? 1 : 0);
}
\ No newline at end of file
......@@ -3,10 +3,12 @@ import("system.neon");
import("system.vars");
import("system.result");
var x = 0;
if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value"))
result.query("select " + new SqlMaskingUtils().concat(["PERSON.FIRSTNAME","PERSON.LASTNAME"], " ", true)
+" from PERSON "
+" join CONTACT on PERSON.PERSONID = CONTACT.PERSON_ID "
+" where CONTACT.CONTACTID = '" + vars.get("$this.value") + "'");
\ No newline at end of file
{
result.string(newSelect(new SqlMaskingUtils().concatWithSeparator(["PERSON.FIRSTNAME","PERSON.LASTNAME"]))
.from("PERSON")
.join("CONTACT", "PERSON.PERSONID = CONTACT.PERSON_ID")
.where("CONTACT.CONTACTID", "$this.value")
.cell()
);
}
\ No newline at end of file
......@@ -5,16 +5,12 @@ import("system.vars");
import("system.tools");
import("system.result");
//var cond = ["knowledgemanagement.TYPE != '3'"]
//if(tools.hasRole(vars.get("$sys.user"), "PROJECT_Support"))
// cond.push("knowledgemanagement.PUBLISH in ('2','3')");
var cond = [];
var cond = newWhere();
if(vars.exists("$param.isDashlet_param") && vars.get("$param.isDashlet_param")) //check if the parameter exists and is filled
{
var userRoles = tools.getRoles(vars.get("$sys.user")); //get all Roles from the current User
var res = newWhere(null //create a new condition where we check if any data sets exists with the given parameters
cond.and(null //create a new condition where we check if any data sets exists with the given parameters
,newSelect("KNOWLEDGEROLES.ROLENAME") //create a subselect for all data sets with the current user roles
.from("KNOWLEDGEROLES")
.where("KNOWLEDGEROLES.KNOWLEDGEMANAGEMENT_ID = KNOWLEDGEMANAGEMENT.KNOWLEDGEMANAGEMENTID")
......@@ -23,10 +19,7 @@ if(vars.exists("$param.isDashlet_param") && vars.get("$param.isDashlet_param"))
,newSelect("KNOWLEDGETAGLINK.KNOWLEDGETAGLINKID")
.from("KNOWLEDGETAGLINK")
.where("KNOWLEDGETAGLINK.KNOWLEDGEMANAGEMENT_ID = KNOWLEDGEMANAGEMENT.KNOWLEDGEMANAGEMENTID")
.and("KNOWLEDGETAGLINK.KNOWLEDGETAG_ID", "1f035a33-e5a3-48e4-bda6-6d8b320177e4"), SqlBuilder.EXISTS())
.build();
cond.push(SqlUtils.translateConditionWithQuotes(res)); //db RecordContainer can't use preparedStatements
.and("KNOWLEDGETAGLINK.KNOWLEDGETAG_ID", "1f035a33-e5a3-48e4-bda6-6d8b320177e4"), SqlBuilder.EXISTS());
}
result.string(cond.join(" and "))
\ No newline at end of file
result.string(cond.toString());
\ No newline at end of file
import("Sql_lib");
import("system.result");
import("system.vars");
var op = vars.get("$local.comparison");
var val = vars.get("$local.rawvalue");
var condition = newWhere();
var tagLinkSql = newSelect("KNOWLEDGEMANAGEMENT_ID")
.from("KNOWLEDGETAGLINK")
.where("KNOWLEDGETAGLINK.KNOWLEDGEMANAGEMENT_ID = KNOWLEDGEMANAGEMENT.KNOWLEDGEMANAGEMENTID");
var condType = SqlBuilder.EXISTS();
var condition = "";
switch(op)
switch (vars.get("$local.comparison"))
{
case "EQUAL":
condition = " KNOWLEDGEMANAGEMENTID in "
+ " (select KNOWLEDGEMANAGEMENT_ID "
+ " from KNOWLEDGETAGLINK "
+ " where KNOWLEDGETAG_ID = '" + val + "')";
break;
case "NOT_EQUAL":
condition = " KNOWLEDGEMANAGEMENTID not in "
+ " (select KNOWLEDGEMANAGEMENT_ID "
+ " from KNOWLEDGETAGLINK "
+ " where KNOWLEDGETAG_ID = '" + val + "')";
condType = SqlBuilder.NOT_EXISTS();
case "EQUAL":
condition.and(null, tagLinkSqll.and("KNOWLEDGETAGLINK.KNOWLEDGETAG_ID", "$local.rawvalue"), condType);
break;
case "ISNULL":
condition = " not exists "
+ " (select KNOWLEDGEMANAGEMENT_ID "
+ " from KNOWLEDGETAGLINK "
+ " where KNOWLEDGETAGLINK.KNOWLEDGEMANAGEMENT_ID = KNOWLEDGEMANAGEMENT.KNOWLEDGEMANAGEMENTID)";
break;
condType = SqlBuilder.NOT_EXISTS();
case "ISNOTNULL":
condition = " exists "
+ " (select KNOWLEDGEMANAGEMENT_ID "
+ " from KNOWLEDGETAGLINK "
+ " where KNOWLEDGETAGLINK.KNOWLEDGEMANAGEMENT_ID = KNOWLEDGEMANAGEMENT.KNOWLEDGEMANAGEMENTID)";
condition.and(null, tagLinkSql, condType);
break;
default:
condition = " 1 = 2 ";
}
result.string(condition);
\ No newline at end of file
result.string(condition.toString(SqlBuilder.NORESULT_CONDITION()));
\ No newline at end of file
import("system.db");
import("Sql_lib");
import("system.result");
result.object(
db.table("select distinct KNOWLEDGETAGID, TAG from KNOWLEDGETAG order by TAG")
);
\ No newline at end of file
result.object(new SqlBuilder().selectDistinct(["KNOWLEDGETAGID", "TAG"]).from("KNOWLEDGETAG").orderBy("TAG").table());
\ No newline at end of file
import("system.db");
import("system.result");
import("Sql_lib");
result.object({
"COALESCE(KNOWLEDGEMANAGEMENT.DATE_EDIT, KNOWLEDGEMANAGEMENT.DATE_NEW)": db.DESCENDING
})
\ No newline at end of file
var sortOrder = {};
sortOrder[new SqlMaskingUtils().isNull("KNOWLEDGEMANAGEMENT.DATE_EDIT", "KNOWLEDGEMANAGEMENT.DATE_NEW")] = db.DESCENDING;
result.object(sortOrder);
\ No newline at end of file
import("system.result");
import("Sql_lib");
result.string("select " + new SqlMaskingUtils().concat(["PERSON.FIRSTNAME","PERSON.LASTNAME"], " ", true)
+" from PERSON "
+" join CONTACT on PERSON.PERSONID = CONTACT.PERSON_ID "
+" where CONTACT.CONTACTID = KNOWLEDGEMANAGEMENT.AUTHOR_CONTACT_ID");
\ No newline at end of file
result.string(
newSelect(new SqlMaskingUtils().concatWithSeparator(["PERSON.FIRSTNAME","PERSON.LASTNAME"]))
.from("PERSON")
.join("CONTACT", "PERSON.PERSONID = CONTACT.PERSON_ID")
.where("CONTACT.CONTACTID = KNOWLEDGEMANAGEMENT.AUTHOR_CONTACT_ID")
.toString()
);
\ No newline at end of file
import("Sql_lib");
import("system.vars");
import("system.result");
result.string("KNOWLEDGEMANAGEMENTID in (select KNOWLEDGEROLES.KNOWLEDGEMANAGEMENT_ID from KNOWLEDGEROLES where " + vars.get("$local.condition") + " )");
\ No newline at end of file
result.string(newWhere(null, newSelect("KNOWLEDGEROLES.KNOWLEDGEMANAGEMENT_ID")
.from("KNOWLEDGEROLES")
.where("KNOWLEDGEROLES.KNOWLEDGEMANAGEMENT_ID = KNOWLEDGEMANAGEMENTID")
.and(vars.get("$local.condition")), SqlBuilder.EXISTS())
);
\ No newline at end of file
import("system.result");
import("Sql_lib");
result.string("select " + new SqlMaskingUtils().concat(["PERSON.FIRSTNAME","PERSON.LASTNAME"], " ", true)
+" from PERSON "
+" join CONTACT on PERSON.PERSONID = CONTACT.PERSON_ID "
+" where CONTACT.CONTACTID = KNOWLEDGEMANAGEMENT.RESPONSIBLE_CONTACT_ID");
\ No newline at end of file
result.string(
newSelect(new SqlMaskingUtils().concatWithSeparator(["PERSON.FIRSTNAME","PERSON.LASTNAME"]))
.from("PERSON")
.join("CONTACT", "PERSON.PERSONID = CONTACT.PERSON_ID")
.where("CONTACT.CONTACTID = KNOWLEDGEMANAGEMENT.AUTHOR_CONTACT_ID")
.toString()
);
\ No newline at end of file
......@@ -15,7 +15,7 @@ switch (tableName)
res = [idValue];
break;
case "KNOWLEDGETAGLINK":
res = db.array(db.COLUMN, "select KNOWLEDGEMANAGEMENT_ID from KNOWLEDGETAGLINK where KNOWLEDGETAGLINKID = '" + idValue + "'");
res = newSelect("KNOWLEDGEMANAGEMENT_ID").from("KNOWLEDGETAGLINK").where("KNOWLEDGETAGLINK.KNOWLEDGETAGLINKID", idValue).arrayColumn();
break;
}
......
......@@ -4,39 +4,29 @@ import("KeywordRegistry_basic");
import("Sql_lib");
import("system.SQLTYPES");
var condition = "";
if ( vars.exists("$local.idvalue") )
{
var ids = vars.get("$local.idvalue");
condition = " where km1.KNOWLEDGEMANAGEMENTID in ('" + ids.join("', '") + "')";
}
// the case when construct is used to decide, to which sub group the entry belongs
var sql = "select km1.KNOWLEDGEMANAGEMENTID, km1.TITLE, " + new SqlMaskingUtils().castLob("CONTENTDECODED", 255)
+ ", km1.KNOWLEDGEMANAGEMENTID, km1.TITLE, km1.CONTENTDECODED, KNOWLEDGETAG.TAG, "
+ "case when exists( \
select '1' \
from KNOWLEDGEMANAGEMENT \
join KNOWLEDGETAGLINK on KNOWLEDGEMANAGEMENTID = KNOWLEDGEMANAGEMENT_ID \
join KNOWLEDGETAG on KNOWLEDGETAGID = KNOWLEDGETAG_ID \
where KNOWLEDGETAG.TAG = 'News' \
and KNOWLEDGEMANAGEMENT.KNOWLEDGEMANAGEMENTID = km1.KNOWLEDGEMANAGEMENTID \
) \
then 'News' \
else case when GITPATH is null and TYPE = 1 \
then 'Knowledgebase' \
else case when GITPATH is not null and TYPE = 2 \
then 'Editorial' \
else case when TYPE = 3 \
then 'Business process' \
end \
end \
end \
end "
+ ", ''"
+ " from KNOWLEDGEMANAGEMENT km1 "
+ " left join KNOWLEDGETAGLINK on KNOWLEDGEMANAGEMENTID = KNOWLEDGEMANAGEMENT_ID"
+ " left join KNOWLEDGETAG on KNOWLEDGETAGID = KNOWLEDGETAG_ID"
+ condition
+ " order by KNOWLEDGEMANAGEMENTID"
var sql = newSelect([
"km1.KNOWLEDGEMANAGEMENTID", "km1.TITLE", new SqlMaskingUtils().castLob("CONTENTDECODED", 255), "km1.KNOWLEDGEMANAGEMENTID",
"km1.TITLE", "km1.CONTENTDECODED", "KNOWLEDGETAG.TAG",
SqlBuilder.caseWhen(null, newSelect("KNOWLEDGEMANAGEMENTID")
.from("KNOWLEDGEMANAGEMENT")
.join("KNOWLEDGETAGLINK", "KNOWLEDGEMANAGEMENTID = KNOWLEDGEMANAGEMENT_ID")
.join("KNOWLEDGETAG", "KNOWLEDGETAGID = KNOWLEDGETAG_ID")
.where("KNOWLEDGETAG.TAG", "News")
.and("KNOWLEDGEMANAGEMENT.KNOWLEDGEMANAGEMENTID = km1.KNOWLEDGEMANAGEMENTID"))
.thenString("News")
.when(newWhere("GITPATH is null").and("TYPE = 1"))
.thenString("Knowledgebase")
.when(newWhere("GITPATH is not null").and("TYPE = 2"))
.thenString("Editorial")
.when("TYPE = 3")
.thenString("Business process"),
"''"
]).from("KNOWLEDGEMANAGEMENT", "km1")
.leftJoin("KNOWLEDGETAGLINK", "KNOWLEDGEMANAGEMENTID = KNOWLEDGEMANAGEMENT_ID")
.leftJoin("KNOWLEDGETAG", "KNOWLEDGETAGID = KNOWLEDGETAG_ID")
.orderBy("KNOWLEDGEMANAGEMENTID");
result.string(sql);
\ No newline at end of file
if (vars.exists("$local.idvalue"))
querySelect.whereIfSet("KNOWLEDGEMANAGEMENT.KNOWLEDGEMANAGEMENTID", "$local.idvalue");
result.string(sql.toString());
\ No newline at end of file
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