How to filter source file using gradle? - gradle

Is there any plugin or solution to filter source file. When i am using maven there is plugin https://github.com/wavesoftware/templating-maven-plugin
That plugin work like a charm is there any solution for gradle, to achieve the same result.
For example i am crate interface that holds all information about build:
public interface BuildConfig {
public static final String PROFILE_FAST = "fast";
public static final String PROFILE_DEV = "dev";
public static final String PROFILE_TEST = "test";
public static final String PROFILE_UAT = "uat";
public static final String PROFILE_PROD = "prod";
public static final String APP_CODE = "${app-code}";
public static final String PROFILE_ID = "${profile-id}";
public static final String APP_VERSION = "${project.version}";
public static final boolean DEBUG = !("${profile-id}").equals(PROFILE_PROD);
}
thanks

Related

SpringBoot 3 extend PostgresSQL Dialect

We have the custom postgres dialect, by extending Postgres Dialect, and registerFunctions, but looks like this is not supported in spring boot 3.
What are the alternative ways to implement this in spring boot 3.
public class GlobalPostgresDialect extends PostgreSQL10Dialect {
public static final String STRING_AGG = "string_agg";
public static final String STRING_AGG_ORDER_BY = "string_agg_order_by";
public static final String STRING_AGG_DISTINCT = "string_agg_distinct";
public static final String STRING_AGG_DISTINCT_ORDER_BY = "string_agg_distinct_order_by";
public static final String ARRAY_AGG = "array_agg";
public static final String ARRAY_AGG_DISTINCT = "array_agg_distinct";
public static final String ARRAY_AGG_ORDER_BY = "array_agg_order_by";
public static final String ARRAY_AGG_DISTINCT_ORDER_BY = "array_agg_distinct_order_by";
public static final String COUNT_DISTINCT_5_ARGS = "count_distinct_5_args";
public GlobalPostgresDialect() {
super();
registerFunction(STRING_AGG, new SQLFunctionTemplate(StandardBasicTypes.STRING, "string_agg(?1, ?2)"));
registerFunction(STRING_AGG_ORDER_BY, new SQLFunctionTemplate(StandardBasicTypes.STRING, "string_agg(?1, ?2 order by ?3)"));
registerFunction(STRING_AGG_DISTINCT, new SQLFunctionTemplate(StandardBasicTypes.STRING, "string_agg(distinct ?1, ?2)"));
registerFunction(STRING_AGG_DISTINCT_ORDER_BY, new SQLFunctionTemplate(StandardBasicTypes.STRING, "string_agg(distinct ?1, ?2 order by ?3)"));
registerFunction(ARRAY_AGG, new SQLFunctionTemplate(StandardBasicTypes.STRING, "array_agg(?1)"));
registerFunction(ARRAY_AGG_DISTINCT, new SQLFunctionTemplate(StandardBasicTypes.STRING, "array_agg(distinct ?1)"));
registerFunction(ARRAY_AGG_ORDER_BY, new SQLFunctionTemplate(StandardBasicTypes.STRING, "array_agg(?1 order by ?2)"));
registerFunction(ARRAY_AGG_DISTINCT_ORDER_BY, new SQLFunctionTemplate(StandardBasicTypes.STRING, "array_agg(?1, ?2 order by ?2)"));
registerFunction(COUNT_DISTINCT_5_ARGS, new SQLFunctionTemplate(LongType.INSTANCE, "count(distinct(?1, ?2, ?3, ?4, ?5))"));
}
}
You can use implement MetadataBuilderContributor and register
Documentation:https://docs.jboss.org/hibernate/stable/orm/javadocs/org/hibernate/boot/spi/MetadataBuilderContributor.html
Example:
public class HibernateMetadataBuilderContributor implements MetadataBuilderContributor {
public static final String I_LIKE_FN = "i_like";
public static final String PERSON_TYPES_CONTAINS_FN = "person_types_contains";
#Override
public void contribute(final MetadataBuilder metadataBuilder) {
metadataBuilder.applySqlFunction(I_LIKE_FN, new SQLFunctionTemplate(BooleanType.INSTANCE, "(?1 ilike ?2)"));
metadataBuilder.applySqlFunction(PERSON_TYPES_CONTAINS_FN, new SQLFunctionTemplate(BooleanType.INSTANCE, "(?1 && ?2::person_type_enum[])", true));
}
}
However I am not sure if you still need to register it by properties as well:
spring:
jpa:
properties:
hibernate: your.class.complete.package.HibernateMetadataBuilderContributor
Reference: https://github.com/spring-cloud-portfolio/person-service/blob/d2320f569eebb4c73e10f435dee9ff8618e6bf37/src/main/java/com/doroshenko/serhey/person/repository/core/jpa/HibernateMetadataBuilderContributor.java
You can also read this to see why doing it the way you have done is a bad idea. https://vladmihalcea.com/hibernate-sql-function-jpql-criteria-api-query/

java.lang.IllegalArgumentException: column '`kitType`' does not exist. Available columns: [..., dependencies, ൔ, DMLoader, ...]

I get an expcetion when I try query some data from db.(RoomDb Version used:2.2.5)
It never reproduced in DEV. It only happened in PRD sometime on API 27 28 29 30.
Crash scenes:
1. Some time columnName of my database was changed to garbled.
java.lang.IllegalArgumentException: column 'kitType' does not exist. Available columns: [kitName, apiLevel, pkgVersionCode, packageName, kitCodePath, moduleCodePath, soLibraryPath, dependencies, ൔ, DMLoader, archType, forceUpgrade, ignoreForceUpgradeTime, mainEntry, kitState, moduleState, usesLibraryPath, appClass, reservedString1, reservedString2, reservedInt1, reservedInt2, reservedInt3]
as show above:kitType was changed to ൔ.
2. Some time columnName of my database was changed to other columnName.
java.lang.IllegalArgumentException: column 'reservedInt2' does not exist. Available columns: [id, packageName, pkgVersionCode, classname, actions, categories, intentFilter, reservedString1, reservedString2, reservedInt1, reservedInp2, reservedInt3, packageState]
as show above: reservedInt2 was changed to reservedInp2.
This is my Entity code:
#Entity(tableName = PackageInfoEntity.PACKAGE_INFO_TABLE_NAME,
primaryKeys = {PackageInfoEntity.PACKAGE_NAME, PackageInfoEntity.PKG_VERSION_CODE})
public class PackageInfoEntity {
#Ignore
public static final String PACKAGE_INFO_TABLE_NAME = "PackageInfoTable";
#Ignore
public static final String PACKAGE_NAME = "packageName";
#Ignore
public static final String PKG_VERSION_CODE = "pkgVersionCode";
#Ignore
public static final String APPLICATION_INFO = "applicationInfo";
#Ignore
public static final String PACKAGE_INFO = "packageInfo";
#Ignore
public static final String REF_COUNT = "refCount";
#Ignore
public static final String LAST_MODIFY = "lastModify";
#Ignore
public static final String PACKAGE_STATE = "packageState";
#Ignore
public static final String MODULE_PKG_STATE = "modulePkgState";
#Ignore
public static final String INVALID_TIME = "invalidTime";
#Ignore
public static final String PRE_PKG_NAME = "prePkgNames";
#Ignore
public static final String FUTURE_PKG_NAME = "futurePkgName";
#Ignore
private static final String TAG = "PackageInfoEntity";
#Ignore
public static final String RESERVEDSTRING_01 = "reservedString1";
#Ignore
public static final String RESERVEDSTRING_02 = "reservedString2";
#Ignore
public static final String RESERVEDINT_01 = "reservedInt1";
#Ignore
public static final String RESERVEDINT_02 = "reservedInt2";
#Ignore
public static final String RESERVEDINT_03 = "reservedInt3";
#NonNull
public String packageName;
#NonNull
public int pkgVersionCode;
#NonNull
#ColumnInfo(typeAffinity = ColumnInfo.BLOB)
public ApplicationInfo applicationInfo;
#NonNull
#ColumnInfo(typeAffinity = ColumnInfo.BLOB)
public PackageInfo packageInfo;
public int packageState;
public int modulePkgState;
public long invalidTime;
public String prePkgNames;
public String futurePkgName;
public String reservedString1;
public String reservedString2;
public Integer reservedInt1;
public Integer reservedInt2;
public Integer reservedInt3;
}
What I have tried:
This error never happened on my In-progress version with same app version.
I want to try add a try/catch block,but this database query is located on so many functions.
So is any advice can I figure this out.

Hapi Fhir Constants for "Common Parameters defined for all resources"

http://www.hl7.org/implement/standards/fhir/search.html#advanced
Common Parameters defined for all resources:
Name Type Description Paths
_id token Resource id (not a full URL) Resource.id
_lastUpdated date Date last updated. Server has discretion on the boundary precision Resource.meta.lastUpdated
_tag token Search by a resource tag Resource.meta.tag
_profile uri Search for all resources tagged with a profile Resource.meta.profile
_security token Search by a security label Resource.meta.security
_text string Text search against the narrative
_content string Text search against the entire resource
_list string All resources in nominated list (by id, not a full URL)
_query string Custom named query
Is there a Hapi Fhir "constant" somewhere for these?
Today I happen to be looking for "_profile".
I've check the SP_ values for
org.hl7.fhir.r4.model.DomainResource;
org.hl7.fhir.r4.model.ListResource;
org.hl7.fhir.r4.model.Resource
but no luck.
I found org.hl7.fhir.r4.model.Resource.SP_RES_ID (as "_id")
String SP_RES_ID = "_id";
But not for the other "standard" ones.
Thanks.
Gradle package reference:
implementation group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-structures-r4', version: hapiFhirVersion
hapiFhirVersion = '5.1.0'
I found some
https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-base/ca/uhn/fhir/rest/api/Constants.html#PARAM_PROFILE
Package ca.uhn.fhir.rest.api
Constants.PARAM_PROFILE
public static final String PARAM_PROFILE = "_profile";
and some others since you found this question!
/**
* Used in paging links
*/
public static final String PARAM_BUNDLETYPE = "_bundletype";
public static final String PARAM_FILTER = "_filter";
public static final String PARAM_CONTAINED = "_contained";
public static final String PARAM_CONTAINED_TYPE = "_containedType";
public static final String PARAM_CONTENT = "_content";
public static final String PARAM_COUNT = "_count";
public static final String PARAM_DELETE = "_delete";
public static final String PARAM_ELEMENTS = "_elements";
public static final String PARAM_ELEMENTS_EXCLUDE_MODIFIER = ":exclude";
public static final String PARAM_FORMAT = "_format";
public static final String PARAM_HAS = "_has";
public static final String PARAM_HISTORY = "_history";
public static final String PARAM_INCLUDE = "_include";
public static final String PARAM_INCLUDE_QUALIFIER_RECURSE = ":recurse";
public static final String PARAM_INCLUDE_RECURSE = "_include" + PARAM_INCLUDE_QUALIFIER_RECURSE;
public static final String PARAM_INCLUDE_QUALIFIER_ITERATE = ":iterate";
public static final String PARAM_INCLUDE_ITERATE = "_include" + PARAM_INCLUDE_QUALIFIER_ITERATE;
public static final String PARAM_LASTUPDATED = "_lastUpdated";
public static final String PARAM_NARRATIVE = "_narrative";
public static final String PARAM_PAGINGACTION = "_getpages";
public static final String PARAM_PAGINGOFFSET = "_getpagesoffset";
public static final String PARAM_PRETTY = "_pretty";
public static final String PARAM_PRETTY_VALUE_FALSE = "false";
public static final String PARAM_PRETTY_VALUE_TRUE = "true";
public static final String PARAM_PROFILE = "_profile";
public static final String PARAM_QUERY = "_query";
public static final String PARAM_RESPONSE_URL = "response-url"; //Used in messaging
public static final String PARAM_REVINCLUDE = "_revinclude";
public static final String PARAM_REVINCLUDE_RECURSE = PARAM_REVINCLUDE + PARAM_INCLUDE_QUALIFIER_RECURSE;
public static final String PARAM_REVINCLUDE_ITERATE = PARAM_REVINCLUDE + PARAM_INCLUDE_QUALIFIER_ITERATE;
public static final String PARAM_SEARCH = "_search";
public static final String PARAM_SECURITY = "_security";
public static final String PARAM_SINCE = "_since";
public static final String PARAM_SORT = "_sort";
public static final String PARAM_SORT_ASC = "_sort:asc";
public static final String PARAM_SORT_DESC = "_sort:desc";
public static final String PARAM_SOURCE = "_source";
public static final String PARAM_SUMMARY = "_summary";
public static final String PARAM_TAG = "_tag";
public static final String PARAM_TAGS = "_tags";
public static final String PARAM_TEXT = "_text";
public static final String PARAM_VALIDATE = "_validate";
public static final String PARAMQUALIFIER_MISSING = ":missing";
public static final String PARAMQUALIFIER_MISSING_FALSE = "false";
public static final String PARAMQUALIFIER_MISSING_TRUE = "true";
public static final String PARAMQUALIFIER_STRING_CONTAINS = ":contains";
public static final String PARAMQUALIFIER_STRING_EXACT = ":exact";
public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text";

How to get the property of sonar-project.properties from the Sonar java custom rules

How to get the property of sonar-project.properties from the Sonar java custom rules.
I have written a class , but it return null. I am using SONARQUBE 7.0
public class PropertyFinder {
private static final Logger LOG = LoggerFactory.getLogger(PropertyFinder.class);
public static Configuration settings = null;
public PropertyFinder(Configuration settings) {
this.settings = settings;
}
public static Settings getSettings() {
return settings;
}
Also
public class JavaRulesPlugin implements Plugin {
public static final String FILE_SUFFIXES_KEY = "sonar.java.file.suffixes";
#Override
public void define(Context context) {
context.addExtension(JavaRulesDefinition.class);
context.addExtension(PropertyFinder.class);
context.addExtension(SonarJavaFileScannersFactory.class);
}
I call PropertyFinder.getSettings() from Custom rule but it returns null.
public abstract class CustomBaseTreeVisitor extends BaseTreeVisitor implements JavaFileScanner {
private Configuration settings = PropertyFinder.getSettings();
}

MVC4 WebApplication - global variables available in views (cshtml files) using Razor engine

I wonder how it is now possible, using MVC4, to get such functionality which was possible in MVC3, to declare some variables (and/or constraints) which are then available in all cshtml files. I used this to make language files.
Earlier (in MVC3) I had App_Code folder in my Solution, where I put the file Lang.cshtml. In this file (valid resource for me) I had e.g.
#functions{
public static readonly string G_ADD = "Dodaj";
public static readonly string G_CREATE = "Utwórz";
public static readonly string G_SAVE = "Zapisz";
public static readonly string G_EDIT = "Edytuj";
public static readonly string G_DETAILS = "Szczegóły";
public static readonly string G_DELETE = "Usuń";
public static readonly string G_SEARCH = "Szukaj";
public static readonly string G_FIRST = "<< Pierwsza";
public static readonly string G_LAST = "Ostatnia >>";
public static readonly string G_PREV = "< Poprzednia";
public static readonly string G_NEXT = "Następna >";
public static readonly string G_ACTION = "Akcja";
public static readonly string G_ID = "ID";
public static readonly string G_PAGE = "STRONA";
public static readonly string G_OF = "z";
public static readonly string G_FROM = "z";
public static readonly string G_TO = "do";
public static readonly string G_ALL = "-- Wszystkie";
public static readonly string G_RECORDS = "Rekordów:";
public static readonly string G_CHOOSE = "Wybierz:";
public static readonly string G_BACK = "Wróć";
public static readonly string G_VIEW_CHART = "Wyświetl wykres";
}
so I could use the strings in any .cshtml (View) e.g.
#Lang.G_ADD
or even
#Html.ActionLink(#Lang.G_ADD, "AddContract", new { id = item.CONTRACT_ID });
Especially it makes my app more user-friendly for all those people working on i18n of it.
Now this solution doesn't work in MVC4 :/
The available resources solution is not much-effective. Imagine, that everytime you need to write AppName.Properties.Resources.G_ADD.
Also the XML in the Resources.resx looks baaaaaaadly. Very.
Writting any method to enumerate the Resources still do the job partially only as it is bloating the code and I am following "less the code the better" idea.
Please point me to the right direction. Also any ready solution is appreciated :)
Thank You all in advance!

Resources