Add-on type: Database Field extension (pagf)

General

A Database Field extension adds one or more (indexed) attributes to the PicApport database. The configuration of these attribute is declared in a Map and is returned in the init() method of the Add-on.

A groovy script is recognized as a Database Field extension if it extends the class: de.contecon.picapport.groovy.PhotoFieldProvider

See also de.contecon.picapport.groovy.PhotoFieldProvider for the methods that can be overwritten to create your own Database fields.

Updating

When a Database Field extension has been updated it will automatically be reloaded and compiled when:

  • When the PicApport Server starts
  • When the reloadaddons console command is executed

The init() Method

The init() method of a Database Field extension must return a Map which defines the metadata of the Fields:

versionStringnoVersion information

fields

List of Fields-Key-Value pairsno

A list of at least one field that is declared by this Add-on. A field must have a PicApport wide unique id   (e.g. osmCountry in the example below).
The field id is also used as the search operator for the filed value: e.G osmCountry:“Germany“ in the example below.

A field has the following configuration parameters:

 
typeStringno

PhotoFieldProvider.DATA_TYPE_* values

see PhotoFieldProvider for a list of possible types.

addToGlobalFulltextboolean

yes
(default = false)

If set to true, the String based content of this field is added to PicApports global full text search.

indexType

Stringno

PhotoFieldProvider.INDEX_TYPE_* values

see PhotoFieldProvider for a list of possible types.

addToReportStringno

If set to true, the String based content of this field is added to PicApports build-in metadata report.

addToGlobalKeywordsbooleanyes
(default = false)
If set to true, the String based content of this filed is added to PicApports internal keyword: serach
dataIdStringonly required if
addToGlobalKeywords=true

Because keywords can be removed with PicApports Web-GUI. The Add-on dataId must provided to give the Add-on a chance to delete the keywords if required by user.

See also method removeKeywords in PhotoFieldProvider 

Example init Method

private final static String FIELD_NAME_OSM         = "osm"
private final static String FIELD_NAME_OSM_COUNTRY = "osmCountry";
private final static String FIELD_NAME_OSM_STATE   = "osmState";
private final static String FIELD_NAME_OSM_POSTCODE= "osmPostcode";
private final static String FIELD_NAME_OSM_CITY=     "osmCity";
private final static String FIELD_NAME_OSM_ROAD=     "osmRoad";
   
   
public Map init(IAddonContext addonContext) {
    addonContext.getLogger().logMessage(" Addon loaded Autor: E. Schreiner (c)2020 Contecon Software GmbH" );
 
    def meta =  [
                version:'1.0.0',
                fields: [
                        (FIELD_NAME_OSM): [ // "display_name" returned from OSM
                                 type:                  PhotoFieldProvider.DATA_TYPE_STRING,
                                 addToGlobalFulltext:   true,
                                 indexType:             PhotoFieldProvider.INDEX_TYPE_FULLTEXT,
                                 addToReport:           true,
                                 ],
                        (FIELD_NAME_OSM_COUNTRY): [ // "country" returned from OSM
                                 type:                  PhotoFieldProvider.DATA_TYPE_STRING,
                                 addToGlobalFulltext:   false,
                                 indexType:             PhotoFieldProvider.INDEX_TYPE_FULLTEXT,
                                 addToReport:           true,
                                 ],
                        (FIELD_NAME_OSM_STATE): [ // "state" returned from OSM
                                 type:                  PhotoFieldProvider.DATA_TYPE_STRING,
                                 addToGlobalFulltext:   false,
                                 indexType:             PhotoFieldProvider.INDEX_TYPE_FULLTEXT,
                                 addToReport:           true,
                                 ],
                        (FIELD_NAME_OSM_POSTCODE): [ // "postcode" returned from OSM
                                 type:                  PhotoFieldProvider.DATA_TYPE_STRING,
                                 addToGlobalFulltext:   false,
                                 indexType:             PhotoFieldProvider.INDEX_TYPE_ID,
                                 addToReport:           true,
                                 ],
                        (FIELD_NAME_OSM_CITY): [ // "city", "town", "village" returned from OSM
                                 type:                  PhotoFieldProvider.DATA_TYPE_STRING,
                                 addToGlobalFulltext:   false,
                                 indexType:             PhotoFieldProvider.INDEX_TYPE_FULLTEXT,
                                 addToReport:           true,
                                 ],
                        (FIELD_NAME_OSM_ROAD): [ // "road" returned from OSM
                                 type:                  PhotoFieldProvider.DATA_TYPE_STRING,
                                 addToGlobalFulltext:   false,
                                 indexType:             PhotoFieldProvider.INDEX_TYPE_FULLTEXT,
                                 addToReport:           true,
                                 ]                              
                        ]
                ]                      
    }

Sample Implementation of a Database Field extension

See PicApport Add-on: OpenStreetMap Geo-Reverse-Encoder – PicApport Wiki (contecon.de) which contains a download-URL for our sample implementation of a Database Field extension

A short an straight forward example is our PicApport Add-on: NonJpgTitleField – PicApport Wiki (contecon.de) Add-on. Just see the complete code below:

import de.contecon.imageutils.IccImageMetaData;
 
import de.contecon.picapport.IPhotoMetaDataFilter;
import de.contecon.picapport.groovy.IAddonContext;
import de.contecon.picapport.groovy.PhotoFieldProvider;
 
class NonJpgTitleField extends PhotoFieldProvider {
   
public Map init(IAddonContext addonContext) {
    addonContext.getLogger().logMessage(" Addon loaded Autor: E. Schreiner (c)2020 Contecon Software GmbH" );
    [version:'1.0.0']; //return Map with version.                      
    }
  
public void setFieldValues(IAddonContext addonContext, IccImageMetaData metaDataFile, IPhotoMetaDataFilter metadataDatabase) {
   def oExt=metadataDatabase.getPhotoInFileSystem().getOriginalFileExtension();
   if(null != oExt && oExt.length() > 1) {
     oExt= oExt.substring(1).toUpperCase();
     if(!(oExt == "JPG" || oExt =="JPEG")) {
       metadataDatabase.setThumbTitle(oExt);
       metadataDatabase.setThumbTitleColor("#DD130E");
       }   
     }
   }      
}