Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor abstract queries #128

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ManualTests/ConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void TestOkValueSet()
Assert.IsTrue(actual_data.AvailableLanguages.Contains("en"));

Assert.AreEqual(actual_data.Id, getId);
Assert.IsFalse(String.IsNullOrEmpty(actual_data.Name));
Assert.IsFalse(String.IsNullOrEmpty(actual_data.Label));
Assert.IsTrue(actual_data.Values.Count > 0);
Assert.IsFalse(String.IsNullOrEmpty(actual_data.Values[0].Code));
Assert.IsFalse(String.IsNullOrEmpty(actual_data.Values[0].Text));
Expand All @@ -71,7 +71,7 @@ public void TestOkValueSet()
Assert.IsTrue(actual_data.AvailableLanguages.Contains("en"));

Assert.AreEqual(actual_data.Id, getId);
Assert.IsFalse(String.IsNullOrEmpty(actual_data.Name));
Assert.IsFalse(String.IsNullOrEmpty(actual_data.Label));
Assert.IsTrue(actual_data.Values.Count > 0);
Assert.IsFalse(String.IsNullOrEmpty(actual_data.Values[0].Code));
Assert.IsFalse(String.IsNullOrEmpty(actual_data.Values[0].Text));
Expand Down
12 changes: 6 additions & 6 deletions PCAxis.Sql/ApiUtils/ApiUtilStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ static ApiUtilStatic()
}

//Exceptions ? What if the valueset only exists in another language: Exceptions!
static public ValueSet GetValueSet(string name, string language)
static public ValueSet GetValueSet(string valueSetId, string language)
{
//validate input
string valueSetId = ValidateIdString(name);
string okValueSetId = ValidateIdString(valueSetId);
string languageCode = ValidateLangCodeString(language);

return ValueSetRepositoryStatic.GetValueSet(valueSetId, languageCode);
return ValueSetRepositoryStatic.GetValueSet(okValueSetId, languageCode);
}

static public Grouping GetGrouping(string name, string language)
static public Grouping GetGrouping(string groupingId, string language)
{
//validate input
string groupingId = ValidateIdString(name);
string okGroupingId = ValidateIdString(groupingId);
string languageCode = ValidateLangCodeString(language);

return GroupingRepositoryStatic.GetGrouping(groupingId, languageCode);
return GroupingRepositoryStatic.GetGrouping(okGroupingId, languageCode);
}


Expand Down
2 changes: 1 addition & 1 deletion PCAxis.Sql/Models/Grouping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PCAxis.Sql.Models
public class Grouping
{
public string Id { get; set; }
public string Name { get; set; }
public string Label { get; set; }

public List<GroupedValue> Values { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion PCAxis.Sql/Models/ValueSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PCAxis.Sql.Models
public class ValueSet
{
public string Id { get; set; }
public string Name { get; set; }
public string Label { get; set; }

public List<Value> Values { get; set; }

Expand Down
96 changes: 48 additions & 48 deletions PCAxis.Sql/QueryLib_21/Queries.cs
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
using System;

using PCAxis.Sql.DbConfig;
using PCAxis.Sql.Repositories;

namespace PCAxis.Sql.QueryLib_21
{
public class Queries
internal class Queries : AbstractQueries
{
public static string GetValueSetExistsIn(SqlDbConfig_21 db, string lang, PxSqlCommand sqlCommand)
private readonly SqlDbConfig_21 _db;
internal Queries(SqlDbConfig db)
{
if (db == null) throw new ArgumentNullException("db");

_db = (SqlDbConfig_21)db;
}

internal override string GetValueSetExistsIn(string lang, PxSqlCommand sqlCommand)
{
return $@"select '{lang}' As Language
from
{db.ValueSetLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
{_db.ValueSetLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
where
{db.ValueSetLang2.ValueSetCol.Id(lang)} = {sqlCommand.GetParameterRef("aValueSet")}";
{_db.ValueSetLang2.ValueSetCol.Id(lang)} = {sqlCommand.GetParameterRef("aValueSet")}";
}

public static string GetValueSetQuery(SqlDbConfig_21 db, string lang, PxSqlCommand sqlCommand)
internal override string GetValueSetQuery(string lang, PxSqlCommand sqlCommand)
{
if (db == null) throw new ArgumentNullException("db");

return $@"select
{db.ValueSetLang2.ValueSetCol.Id(lang)} AS ValueSet,
{db.ValueSetLang2.PresTextCol.Id(lang)} AS PresText,
{db.ValueSetLang2.DescriptionCol.Id(lang)} AS Description
{_db.ValueSetLang2.ValueSetCol.Id(lang)} AS ValueSet,
{_db.ValueSetLang2.PresTextCol.Id(lang)} AS PresText,
{_db.ValueSetLang2.DescriptionCol.Id(lang)} AS Description
from
{db.ValueSetLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
{_db.ValueSetLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
where
{db.ValueSetLang2.ValueSetCol.Id(lang)} = {sqlCommand.GetParameterRef("aValueSet")}";
{_db.ValueSetLang2.ValueSetCol.Id(lang)} = {sqlCommand.GetParameterRef("aValueSet")}";
}

public static string GetValueSetValuesQuery(SqlDbConfig_21 db, string lang, PxSqlCommand sqlCommand)
internal override string GetValueSetValuesQuery(string lang, PxSqlCommand sqlCommand)
{
if (db == null) throw new ArgumentNullException("db");

return $@"SELECT
{db.ValueLang2.ValueCodeCol.Id(lang)} AS valuecode,
{db.ValueLang2.ValuePoolCol.Id(lang)} AS valuepool,
{db.VSValueLang2.ValueCodeCol.Id(lang)} AS valueset,
{db.ValueLang2.ValueTextLCol.Id(lang)} AS valuetextl,
{db.ValueLang2.ValueTextSCol.Id(lang)} AS valuetexts,
{db.ValueLang2.SortCodeCol.Id(lang)} AS sortcodevalue,
{db.VSValueLang2.ValueCodeCol.Id(lang)} AS sortcodevsvalue
{_db.ValueLang2.ValueCodeCol.Id(lang)} AS valuecode,
{_db.ValueLang2.ValuePoolCol.Id(lang)} AS valuepool,
{_db.VSValueLang2.ValueCodeCol.Id(lang)} AS valueset,
{_db.ValueLang2.ValueTextLCol.Id(lang)} AS valuetextl,
{_db.ValueLang2.ValueTextSCol.Id(lang)} AS valuetexts,
{_db.ValueLang2.SortCodeCol.Id(lang)} AS sortcodevalue,
{_db.VSValueLang2.ValueCodeCol.Id(lang)} AS sortcodevsvalue
FROM
{db.ValueLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
{_db.ValueLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
JOIN
{db.VSValueLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
ON ( {db.ValueLang2.ValuePoolCol.Id(lang)} = {db.VSValueLang2.ValuePoolCol.Id(lang)}
AND {db.ValueLang2.ValueCodeCol.Id(lang)} = {db.VSValueLang2.ValueCodeCol.Id(lang)} )
where {db.VSValueLang2.ValueSetCol.Id(lang)} = {sqlCommand.GetParameterRef("aValueSet")}
{_db.VSValueLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
ON ( {_db.ValueLang2.ValuePoolCol.Id(lang)} = {_db.VSValueLang2.ValuePoolCol.Id(lang)}
AND {_db.ValueLang2.ValueCodeCol.Id(lang)} = {_db.VSValueLang2.ValueCodeCol.Id(lang)} )
where {_db.VSValueLang2.ValueSetCol.Id(lang)} = {sqlCommand.GetParameterRef("aValueSet")}

ORDER BY
{db.VSValueLang2.SortCodeCol.Id(lang)},
{db.ValueLang2.SortCodeCol.Id(lang)},
{db.ValueLang2.ValueCodeCol.Id(lang)}";
{_db.VSValueLang2.SortCodeCol.Id(lang)},
{_db.ValueLang2.SortCodeCol.Id(lang)},
{_db.ValueLang2.ValueCodeCol.Id(lang)}";

}

public static string GetGroupingExistsIn(SqlDbConfig_21 db, string lang, PxSqlCommand sqlCommand)
internal override string GetGroupingQuery(string lang, PxSqlCommand sqlCommand)
{
if (db == null) throw new ArgumentNullException("db");
return $@"SELECT
{_db.GroupingLang2.GroupingCol.Id(lang)} AS Grouping,
{_db.GroupingLang2.PresTextCol.Id(lang)} AS Name
FROM
{_db.GroupingLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
WHERE
{_db.GroupingLang2.GroupingCol.Id(lang)} = {sqlCommand.GetParameterRef("aGrouping")}";
}

internal override string GetGroupingExistsIn(string lang, PxSqlCommand sqlCommand)
{
return $@"select '{lang}' As Language
from
{db.GroupingLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
{_db.GroupingLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
where
{db.GroupingLang2.GroupingCol.Id(lang)} = {sqlCommand.GetParameterRef("aGrouping")}";
{_db.GroupingLang2.GroupingCol.Id(lang)} = {sqlCommand.GetParameterRef("aGrouping")}";
}

public static string GetGroupingQuery(SqlDbConfig_21 db, string lang, PxSqlCommand sqlCommand)
{
if (db == null) throw new ArgumentNullException("db");

return $@"SELECT
{db.GroupingLang2.GroupingCol.Id(lang)} AS Grouping,
{db.GroupingLang2.PresTextCol.Id(lang)} AS Name
FROM
{db.GroupingLang2.GetNameAndAlias(lang).RemoveUnderscoreForDefaultLanguage()}
WHERE
{db.GroupingLang2.GroupingCol.Id(lang)} = {sqlCommand.GetParameterRef("aGrouping")}";
}

public static string GetGroupingValuesQuery(SqlDbConfig_21 db, string lang, PxSqlCommand sqlCommand)
internal override string GetGroupingValuesQuery(string lang, PxSqlCommand sqlCommand)
{
//?
throw new NotImplementedException();

}
}

Expand Down
Loading
Loading