Declare custom rule type as Vulnerability in SonarQube 6.3 - sonarqube

I am using sonarQube 6.3 and when adding new custom rules for Php or Javascript, they are by default declared as Code smell. I would like to declare them as Vulnerability or bug.
Here is an example of a rule declaration
#Rule(key = "Rule1",
priority = Priority.MAJOR,
name = "Rule 1 sould be used.",
tags = {"suspicious" })
Is there a way to do it?

There is a way to set the rule type using some special tags.
Tag "bug" means type "bug"
Tag "security" means type "vulnerability"
So try for example:
tags = {"suspicious", "bug"}
NB: This is documented in API Javadoc (but hard to find I admit)

Related

Gradle - Get the default value (convention) of a Property

I want to achieve a very basic thing (in any normal language): I would like to get the default value (convention) of a Property. Gradle docs in chapter Lazy configuration, describes how to apply the convention to a Property:
def property = objects.property(String)
// Set a convention
property.convention("convention 1")
println("value = " + property.get())
// Can replace the convention
property.convention("convention 2")
println("value = " + property.get())
property.set("value")
// Once a value is set, the convention is ignored
property.convention("ignored convention")
println("value = " + property.get())
The problem is, that you cannot query the property to get information what is the convention (the default value) when you set a value. It seems that the only way it's to clear (nullify) the value:
property.value(null).get()
But this is just stupid because you are doing unnecessary actions, while the convention is somewhere there?
Does anyone know how to get it without clearing the value?
The answer (for 2022) is: No, you can't get the default value (convention) of a Property.
I'll try to answer why set overrides the convention once it's called. The convention is the default value, once the property has a value by calling set the convention is ignored because the property has a value. That makes sense because that's what a default value should mean. If I have a value use that otherwise use this default value. Convention and set seem to follow that pattern. I don't quite follow why this is surprising to how you want to use gradle, but just as an outside observer I think gradle is doing what is expected.
You can test if a property exists using
if( property.isPresent() ) {
// do whatever
}
I bet that isPresent() is going to say false when the convention would be returned by get(), but if you call set then isPresent() is going to return true.
Then there are other methods to help like:
def val = property.getOrElse( "SomeDefault" )
def maybe = property.getOrNull()
I do think Gradle doesn't always do a good job of making the API very accessible from their home page and docs (ie groovydoc) for answering more complex questions:
https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html
These methods are the super interface Provider and hence why it may not be obvious they are available if you don't look up the chain:
https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html

Ignore locale on thymeleaf #date.format()

I want to keep date format to fix standard regardless of locale. But however it is by default taking current locale and setting format based on locale.
th:text="${#dates.format(myDate, 'dd-MMM-yyyy')}"
I am always expecting format be like
09-Sep-2015
but with CA locale I am getting 09-de set.-2015
Is there a way to fix this.
UPDATE
This question is not duplicate of This question. My problem is related to locale formatting.
Not sure you are using Maven or Gradle. Add thymeleaf-extras-java8time as your dependency.
and instead of #dates use #temporal and specify locale as parameters as below.
th:text="${#temporals.format(myDate, 'dd-MMM-yyyy','en')}"
But make sure your myDate is in java.time.* format
The #temporals.format function is the correct one to use. However, the third "locale" argument must be a java.util.Locale object, not a string.
The following work:
#temporals.format(myDate, 'dd-MM-yyyy', new java.util.Locale('en'))
#temporals.format(myDate, 'dd-MM-yyyy', #java.util.Locale#ENGLISH)
Note that this is true even if you're working with Kotlin Spring Boot. The syntax in the Thymeleaf template isn't Java, it's an OGNL Expression.
https://commons.apache.org/proper/commons-ognl/language-guide.html
I'll quote the useful syntax used here:
#variable
Context variable reference
#class#method(args)
Static method reference
#class#field
Static field reference
new class(args)
Constructor call
Edit: one other option is to specify the Locale in the Thymeleaf context, if you just want to override the default system Locale. I've included a Kotlin snippet of how that might work:
val context = Context() // org.thymeleaf.Context
context.locale = Locale.ENGLISH
context.setVariable("x", 0)
templateEngine.process("classpath:template.html", context)

meta fields using elasticsearch-dsl

I'm looking at the changelog for the elasticsearch-dsl python library, and one of the comments says:
you can no longer access meta fields on a Document instance by
specifying ._id or similar. Instead all access needs to happen via the
.meta attribute.
Can I get a little more color on that? My old (5.x) code did this
self._id = a_nice_natural_identiifer
How should that be replaced?
self.meta._id = a_nice_natural_identifier
or
self.meta['_id'] = a_nice_natural_identifier
or
self.meta['id'] = a_nice_natural_identifier
It appears that the correct answer is
self.meta['id'] = a_nice_natural_identifier
(Interestingly, you can also set meta properties at construction time by doing)
foo = SomeSubclassOfDocument(_id=a_nice_natural_identifier)

FHIR.net Property added to Practitioner

We're currently using FHIR.net library(STU3). The FHIR Server from which we are receiving information has added a practitionerRole property to the Practitioner. Thus when Reading a Practitioner, we get the following Exception:
Encountered unknown member 'practitionerRole' while de-serializing (at path 'line 1, pos 2') in Hl7.Fhir.Rest.HttpToEntryExtensions.parseResource(String bodyText, String contentType, ParserSettings settings, Boolean throwOnFormatException)
The only solution I could think of is to add a practitionerRole property in the Model\Generated\Practitioner.cs class that would go like that:
[FhirElement("practitionerRole", InSummary = true, Order = 115)]
[Cardinality(Min = 0, Max = -1)]
[DataMember]
public List<Hl7.Fhir.Model.PractitionerRole> PractitionerRole
{
get { if (_PractitionerRole == null) _PractitionerRole = new List<Hl7.Fhir.Model.PractitionerRole>(); return _PractitionerRole; }
set { _PractitionerRole = value; OnPropertyChanged("PractitionerRole"); }
}
private List<Hl7.Fhir.Model.PractitionerRole> _PractitionerRole;
Is there any other solution than that? If so, which one?
Thank you in advance
It sounds like you're talking to a DSTU2 server. You'll need some sort of a conversion layer between your system and theirs.
As stated by FHIR employees in https://sea-region.github.com/standardhealth/shr_spec/issues/187 , DSTU2 and STU3 are two different versions of FHIR standard. If you check their last commits (https://www.nuget.org/packages?q=Fhir) as in August 2019, you will see they are maintaining both standards. That is probably due to the hospitals using STU3 version and do not want to adapt to the new version of FHIR, which is DSTU2.
The problem arises when you want to reach a class, let's say Patient, that coexists in two versions. Compiler can not decide which "Patient" class you refer to.
Normally, you could specialize using imports or predescription such as :
Hl7.Fhir.Model.Patient p = new Hl7.Fhir.Model.Patient();
BUT, Patient classes in both versions are described as Hl7.Fhir.Model.Patient. Their namespace is "Hl7.Fhir.Model" and their class name is "Patient".
Normally, you could workaround using keyword:
extern alias
BUT, since model classes in FHIR are read only, you can not use both versions in same project.
You need to uninstall unwanted FHIR version and install wanted version. To do these in Visual Studio,
go to Solution Manager> right click on "Manage Nuget Packages" > Search "Fhir" > uninstall unwanted FHIR version > install wanted version
You can also follow the unanswered question below:
C# T4 Template equivalent for "extern alias"

Grails define custom error message for command object

I am writing a Grails (2.3.3 currently) application and have created a validateable command object similar to the following:
#Validateable
class MyCustomCommand {
String name
static constraints = {
name blank: false
}
}
In my i18n/messages.properties file I defined the following properties to override the default error messages.
MyCustomCommand.name.blank=Name must be provided.
MyCustomCommand.name.null=Name must be provided.
Which per the Grails documentation should be of the format [Class Name].[Property Name].[Constraint Code] as I have done. When I run my application if I leave the value blank I still get the default message for a null property.
I also tried following the example of the default messages and defining them a follows, but still get the default message.
MyCustomCommand.name.blank.message=Name must be provided.
MyCustomCommand.name.null.message=Name must be provided.
I am assuming that I am missing something simple here, but have yet to stumble upon what. Any suggestions on what I am doing incorrectly?
It is simple indeed. Message should look like:
myCustomCommand.name.blank=Name must be provided.
myCustomCommand.name.nullable=Name must be provided.
//className.propertyName.blank (camelCase with first letter of class name lower)
So, as I anticipated it was something simple. I was using the defaults as an example which used null where as what I really needed was nullable. Which does make sense as that matches the constraint name.
Therefore the correct version is:
myCustomCommand.name.blank=Name must be provided.
myCustomCommand.name.nullable=Name must be provided.

Resources