“No completions available” in Eclipse 3.4 (PDT 2.0)

If after checkout PHP project to Eclipse (3.4 + PDT 2.0) you will tray to use autocomplete (Ctrl + space) but instead list hit you see

No completions available

in left bottom corner, try this solution:

  • click right button on project folder
  • select properties
  • go to PHP Include Path -> Libraries
  • click Add External Source Folder
  • chose folder with your project

After that autocomplete should be available.

Grails custom NIP validation

In my last project I worked on application where client was identified by NIP number. Validation of such number is depend on client country, so in my domain object representing client I used custom validator.

First step was to create util objects that will calculate NIP control sum to check if number is correct. I created interface:

 
interface CustomValidator{
    Boolean validate(value);
}
 

Next created validator for Polish Nip number:

 
class NipValidatorPolish implements CustomValidator {
 
    def static final CHECK_SUM_DIVISION = 11
 
    def static final NIP_CORRECT_LENGTH = 10
 
    def weights = [6, 5, 7, 2, 3, 4, 5, 6, 7]
 
    Boolean validate(rawNip){
        if (!canBySumed(rawNip)){
            return false;
        }
 
        def checkSum = 0
        weights.eachWithIndex(){value, index -> checkSum += value * rawNip.getAt(index).toInteger()}
        return checkSum % CHECK_SUM_DIVISION == rawNip.toList().last().toInteger()
    }
 
    private Boolean canBySumed(String rawNip){
        clearNip.size() == NIP_CORRECT_LENGTH && rawNip.isNumber()
    }
}
 

and default NIP validator for all countries where we don't want to validate controll sum:

 
class DefaultNipValidator implements CustomValidator {
    Boolean validate(rawNip){
        true
    }
}
 

Next, I created factory that produce specified validator depends on country code:

 
class NipValidatorFactory {
    static CustomValidator produce(String countryCode){
        if (countryCode == CountriesCodes.Poland){
            return new NipValidatorPolish()
        }
        return new DefaultNipValidator()
    }
}
 

where CountriesCodes is container with countries iso codes. Finally we could use this in ours domain object :

 
class Country {
    String name
    String countryCode
}
 
...
 
class Client {
    ....
    Country country
    String nip
    ...
    static constraints = {
        nip (nullable: true,
            validator: {value, object ->
                return value ? NipValidatorFactory.produce(object.properties['country']?.countryCode).validate(value) : true
            }
       )
    }
}
 

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.