Class TargetAssocAutoCompletePlugin

java.lang.Object
fr.becpg.repo.autocomplete.impl.plugins.TargetAssocAutoCompletePlugin
All Implemented Interfaces:
AutoCompletePlugin
Direct Known Subclasses:
DataListItemAutoCompletePlugin, LinkedValueAutoCompletePlugin, ListValueAutoCompletePlugin

@Service("targetAssocAutoCompletePlugin") @BeCPGPublicApi public class TargetAssocAutoCompletePlugin extends Object implements AutoCompletePlugin

TargetAssocAutoCompletePlugin class.

Default autocomplete used to suggest target associations.

Example:

 
 <control template="/org/alfresco/components/form/controls/autocomplete-association.ftl">
     <control-param name="ds">becpg/autocomplete/targetassoc/associations/bcpg:product?classNames=bcpg:entityTplAspect&amp;excludeProps=bcpg:entityTplEnabled%7Cfalse</control-param>
     <control-param name="pageLinkTemplate">entity-data-lists?list=View-properties&amp;nodeRef={nodeRef}</control-param>
 </control>
 
 

Datasources:

 ds: /becpg/autocomplete/targetassoc/associations/{className}?classNames={classNames?}&excludeProps={excludeProps?}&path={path?}&filter={}

 param: {className} type of item to retrieve.
 param: {classNames} (optional) comma-separated list of classNames; can be used to filter by aspect or boost certain types (e.g., inc_ or ^).
 param: {extra.searchTemplate} (optional) allows defining a custom search template.
 

Examples:

   With aspect:
   classNames=bcpg:entityTplAspect
   Includes aspect (OR):
   classNames=inc_bcpg:entityTplAspect,inc_gs1:gs1Aspect
   Boost specific types:
   classNames=bcpg:rawMaterial^2

 param: {andProps} (optional/deprecated) comma-separated property|value pairs that items should have (filter=prop_to_filter|value).
 param: {filter} (optional) same as andProps.
 

Filter Examples:

  filter=prop_to_filter|value
        filter=cm:name|samplename
        filter=cm:name|{cm:title}
  filter=bcpg:code|{bcpg:code},cm:name|MP*
  filter=au:market|{au:market}
  filter=gs1:sortingBonusCriteria_or|{gs1:sortingBonusCriteria}  (when field is multiple; the default operator is AND; _or allows changing that).
  filter=bcpg:ingTypeV2|{htmlPropValue} (use the value of parent or parentAssoc control-param; @Since 4.2)
 

Parameters:

 param: {excludeProps} (optional) comma-separated property|value pairs that items should not have.
 param: {excludeClassNames} (optional) comma-separated lists of classNames to exclude.
 param: {path} (optional) retrieve items in a specific path; if the path doesn't contain /, it is relative to the current entity.
 

Example Path:

  path=System/Characts/bcpg:entityLists/Contacts
 

Additional Parameters:

 param: {extra.filterByAssoc} return items that have the same association as the current entity.
 

If a parent is provided, use it as the target association.

If itemId is provided, use itemId as the entity; otherwise, use currentEntity.

Examples:

 becpg/autocomplete/product?extra.filterByAssoc=bcpg:plant
 becpg/autocomplete/product?extra.filterByAssoc=bcpg:plant_or
 

Example Control:

 
    <control template="/org/alfresco/components/form/controls/autocomplete-association.ftl">
       <control-param name="ds">becpg/autocomplete/targetassoc/associations/bcpg:entityV2?extra.filterByAssoc=bcpg:trademarkRef</control-param>
       <control-param name="parentAssoc">sample_plTrademark</control-param>
    </control>
 
 
 param: {extra.getByAssoc} return items that are in association
 

If a parent is provided, use it as the target association.

If itemId is provided, use itemId as the entity; otherwise, use currentEntity.

Examples:

 becpg/autocomplete/bcpg:plant?extra.getByAssoc=bcpg:plant
 

Example Control:

 
     <control template="/org/alfresco/components/form/controls/autocomplete-association.ftl">
          <control-param name="ds">becpg/autocomplete/targetassoc/associations/bcpg:ing?extra.getByAssoc=bcpg:linkedSearchAssociation&extra.characNameFormat={ml_bcpg:charactName} - {bcpg:casNumber}</control-param>
          <control-param name="parentAssoc">bcpg_ingListIng</control-param>
     </control>
 
 
Version:
$Id: $Id
Author:
matthieu
  • Field Details

    • logger

      private static final org.apache.commons.logging.Log logger
      Constant logger
    • PROP_FILTER_BY_ASSOC

      protected static final String PROP_FILTER_BY_ASSOC
      Constant PROP_FILTER_BY_ASSOC="filterByAssoc"
      See Also:
    • PROP_GET_BY_ASSOC

      protected static final String PROP_GET_BY_ASSOC
      Constant PROP_GET_BY_ASSOC="getByAssoc"
      See Also:
    • PROP_CHARAC_NAME_FORMAT

      protected static final String PROP_CHARAC_NAME_FORMAT
      Constant PROP_CHARAC_NAME_FORMAT="characNameFormat"
      See Also:
    • SOURCE_TYPE_TARGET_ASSOC

      protected static final String SOURCE_TYPE_TARGET_ASSOC
      Constant SOURCE_TYPE_TARGET_ASSOC="targetassoc"
      See Also:
    • DEFAULT_SEARCH_TEMPLATE

      protected static final String DEFAULT_SEARCH_TEMPLATE
      Constant searchTemplate="%(cm:name bcpg:erpCode bcpg:code bcpg:l"{trunked}
      See Also:
    • MIXED_SEARCH_TEMPLATE

      protected static final String MIXED_SEARCH_TEMPLATE
      Constant mixedSearchTemplate="%(cm:name bcpg:erpCode bcpg:code bcpg:c"{trunked}
      See Also:
    • LABEL_PROPERTIES

      private static final List<org.alfresco.service.namespace.QName> LABEL_PROPERTIES
      Properties holding the label of a suggestion of any type, read in this order until one is set.
    • CHARACT_SEARCH_TEMPLATE

      protected static final String CHARACT_SEARCH_TEMPLATE
      Constant charactSearchTemplate="%(bcpg:charactName bcpg:legalName)"
      See Also:
    • LISTVALUE_SEARCH_TEMPLATE

      protected static final String LISTVALUE_SEARCH_TEMPLATE
      Constant listValueSearchTemplate="%(bcpg:lvValue bcpg:legalName)"
      See Also:
    • PERSON_SEARH_TEMPLATE

      protected static final String PERSON_SEARH_TEMPLATE
      Constant personSearchTemplate="%(cm:userName cm:firstName cm:lastName "{trunked}
      See Also:
    • TYPE_SEARCH_TEMPLATE_CONF_PREFIX

      protected static final String TYPE_SEARCH_TEMPLATE_CONF_PREFIX
      Prefix of the system configuration key holding the search template of a target type, eg. beCPG.autocomplete.searchTemplate.bcpg_geoOrigin
      See Also:
    • PARAM_VALUES_SEPARATOR

      protected static final String PARAM_VALUES_SEPARATOR
      Constant PARAM_VALUES_SEPARATOR=","
      See Also:
    • nodeService

      @Autowired @Qualifier("NodeService") protected org.alfresco.service.cmr.repository.NodeService nodeService
    • namespaceService

      @Autowired protected org.alfresco.service.namespace.NamespaceService namespaceService
    • dictionaryService

      @Autowired protected org.alfresco.service.cmr.dictionary.DictionaryService dictionaryService
    • entityDictionaryService

      @Autowired protected EntityDictionaryService entityDictionaryService
    • autoNumService

      @Autowired protected AutoNumService autoNumService
    • attributeExtractorService

      @Autowired protected AttributeExtractorService attributeExtractorService
    • targetAssocValueExtractor

      @Autowired protected TargetAssocAutoCompleteExtractor targetAssocValueExtractor
    • associationService

      @Autowired protected AssociationService associationService
    • systemConfigurationService

      @Autowired private SystemConfigurationService systemConfigurationService
  • Constructor Details

    • TargetAssocAutoCompletePlugin

      public TargetAssocAutoCompletePlugin()
  • Method Details

    • getHandleSourceTypes

      public String[] getHandleSourceTypes()

      getHandleSourceTypes.

      Specified by:
      getHandleSourceTypes in interface AutoCompletePlugin
      Returns:
      sourceType that the plugin handle
    • suggest

      public AutoCompletePage suggest(String sourceType, String query, Integer pageNum, Integer pageSize, Map<String,Serializable> props)

      suggest.

      Specified by:
      suggest in interface AutoCompletePlugin
      Parameters:
      sourceType - a String object.
      query - a String object.
      pageNum - a Integer object.
      pageSize - a Integer object.
      props - a Map object.
      Returns:
      Suggested values page
    • suggestTargetAssoc

      public AutoCompletePage suggestTargetAssoc(String path, org.alfresco.service.namespace.QName type, String query, Integer pageNum, Integer pageSize, String[] arrClassNames, Map<String,Serializable> props)
      Suggest target class according to query Query path : +PATH:"/app:company_home/cm:System/cm:Lists/cm:Nuts/*" +TYPE:"bcpg:nut" +@cm\:name:"Nut1*".
      Parameters:
      path - a String object.
      type - the type
      query - the query
      pageNum - a Integer object.
      pageSize - a Integer object.
      arrClassNames - an array of String objects.
      props - a Map object.
      Returns:
      the map
    • suggestByRelevance

      private List<org.alfresco.service.cmr.repository.NodeRef> suggestByRelevance(BeCPGQueryBuilder queryBuilder, String query, org.alfresco.service.namespace.QName type, String path, String[] arrClassNames, Integer pageSize, Map<String,Serializable> props)
      Runs the suggestion query and puts the suggestions whose label best matches the query first, keeping the search engine order between equally relevant ones. People are left in the search engine order, their label being made of several properties, and so are suggestions filtered by association, whose unbounded query is not bulk fetched.
      Parameters:
      queryBuilder - the suggestion query
      query - the text typed by the user
      type - the type of the suggested items
      path - the path filter
      arrClassNames - the class filter
      pageSize - the page size
      props - the autocomplete parameters
      Returns:
      the suggestions sorted by relevance
    • isFilteredByAssoc

      private boolean isFilteredByAssoc(Map<String,Serializable> props)
      Tells whether the suggestions are filtered by the targets of an association.
      Parameters:
      props - the autocomplete parameters, may be null
      Returns:
      true when a filter by association is requested
    • resolveLabelProperties

      List<org.alfresco.service.namespace.QName> resolveLabelProperties(org.alfresco.service.namespace.QName type)
      Returns the properties a suggestion of the given type is labelled with, read in this order until one is set.
      Parameters:
      type - the type of the suggested items
      Returns:
      the label properties, empty when the suggestions are not ranked
    • sortByRelevance

      List<org.alfresco.service.cmr.repository.NodeRef> sortByRelevance(String query, List<org.alfresco.service.namespace.QName> labelProperties, List<org.alfresco.service.cmr.repository.NodeRef> suggestions)
      Puts the suggestions whose label best matches the query first, keeping the search engine order between equally relevant ones.
      Parameters:
      query - the text typed by the user
      labelProperties - the properties holding the label, read in this order until one is set
      suggestions - the suggestions, in the search engine order
      Returns:
      the suggestions sorted by relevance
    • readLabel

      private String readLabel(org.alfresco.service.cmr.repository.NodeRef nodeRef, List<org.alfresco.service.namespace.QName> labelProperties)
      Reads the label a suggestion is searched and shown on.
      Parameters:
      nodeRef - the suggested node
      labelProperties - the properties holding the label, read in this order until one is set
      Returns:
      the label, empty when the node has none
    • resolveTypeSearchTemplate

      String resolveTypeSearchTemplate(org.alfresco.service.namespace.QName type, String defaultTemplate)
      Returns the search template the system configuration sets for a target type, so that a type searched on its own codes (eg. the ISO codes of a geographic origin) needs no control parameter on every form field pointing at it.
      Parameters:
      type - the type of the suggested items
      defaultTemplate - the template used when the configuration sets none for the type
      Returns:
      the configured template, or defaultTemplate
    • getByAssoc

      private List<org.alfresco.service.cmr.repository.NodeRef> getByAssoc(String assocName, Map<String,Serializable> props)

      getByAssoc.

      Parameters:
      assocName - a String object
      props - a Map object
      Returns:
      a List object
    • filter

      protected List<org.alfresco.service.cmr.repository.NodeRef> filter(BeCPGQueryBuilder queryBuilder, String path, String[] arrClassNames, Integer pageSize, Map<String,Serializable> props)

      filter.

      Parameters:
      queryBuilder - a BeCPGQueryBuilder object
      path - a String object
      arrClassNames - an array of String objects
      pageSize - a Integer object
      props - a Map object
      Returns:
      a List object
    • extractEntityNodeRef

      protected org.alfresco.service.cmr.repository.NodeRef extractEntityNodeRef(Map<String,Serializable> props)

      extractEntityNodeRef.

      Parameters:
      props - a Map object
      Returns:
      a NodeRef object
    • excludeSources

      private void excludeSources(List<org.alfresco.service.cmr.repository.NodeRef> ret, String itemId, String fieldName)

      excludeSources.

      Parameters:
      ret - a List object
      itemId - a String object
      fieldName - a String object
    • extractAllSources

      private List<org.alfresco.service.cmr.repository.NodeRef> extractAllSources(org.alfresco.service.cmr.repository.NodeRef source, org.alfresco.service.namespace.QName fieldQname, List<org.alfresco.service.cmr.repository.NodeRef> allSources)

      extractAllSources.

      Parameters:
      source - a NodeRef object
      fieldQname - a QName object
      allSources - a List object
      Returns:
      a List object
    • filterByAssoc

      private List<org.alfresco.service.cmr.repository.NodeRef> filterByAssoc(BeCPGQueryBuilder queryBuilder, Integer pageSize, org.alfresco.service.cmr.repository.NodeRef entityNodeRef, String filterByAssoc, org.alfresco.service.cmr.repository.NodeRef targetNodeRef)

      filterByAssoc.

      Parameters:
      queryBuilder - a BeCPGQueryBuilder object
      pageSize - a Integer object
      entityNodeRef - a NodeRef object
      filterByAssoc - a String object
      targetNodeRef - a NodeRef object
      Returns:
      a List object
    • filterByPath

      private void filterByPath(BeCPGQueryBuilder queryBuilder, String path, org.alfresco.service.cmr.repository.NodeRef entityNodeRef)

      filterByPath.

      Parameters:
      queryBuilder - a BeCPGQueryBuilder object
      path - a String object
      entityNodeRef - a NodeRef object
    • getTargetAssocValueExtractor

      protected AutoCompleteExtractor<org.alfresco.service.cmr.repository.NodeRef> getTargetAssocValueExtractor()

      Getter for the field targetAssocValueExtractor.

      Returns:
      a AutoCompleteExtractor object.
    • filterByClass

      protected BeCPGQueryBuilder filterByClass(BeCPGQueryBuilder queryBuilder, String[] arrClassNames)

      filterByClass.

      Parameters:
      queryBuilder - a BeCPGQueryBuilder object.
      arrClassNames - an array of String objects.
      Returns:
      a BeCPGQueryBuilder object.
    • filterByQueryFilter

      protected BeCPGQueryBuilder filterByQueryFilter(BeCPGQueryBuilder queryBuilder, String queryFilters, org.alfresco.service.cmr.repository.NodeRef entityNodeRef, String propParent)

      filterByQueryFilter.

      Parameters:
      queryBuilder - a BeCPGQueryBuilder object
      queryFilters - a String object
      entityNodeRef - a NodeRef object
      propParent - a String object
      Returns:
      a BeCPGQueryBuilder object
    • excludeByProp

      protected BeCPGQueryBuilder excludeByProp(BeCPGQueryBuilder queryBuilder, String[] arrExcluseProps)

      excludeByProp.

      Parameters:
      queryBuilder - a BeCPGQueryBuilder object
      arrExcluseProps - an array of String objects
      Returns:
      a BeCPGQueryBuilder object
    • excludeByClass

      protected BeCPGQueryBuilder excludeByClass(BeCPGQueryBuilder queryBuilder, String[] arrClassNames)

      excludeByClass.

      Parameters:
      queryBuilder - a BeCPGQueryBuilder object
      arrClassNames - an array of String objects
      Returns:
      a BeCPGQueryBuilder object
    • isAllQuery

      protected boolean isAllQuery(String query)

      isAllQuery.

      Parameters:
      query - a String object.
      Returns:
      a boolean.
    • prepareQuery

      protected String prepareQuery(String query)

      prepareQuery.

      Parameters:
      query - a String object.
      Returns:
      a String object.
    • isQueryMatch

      public boolean isQueryMatch(String query, String entityName)

      isQueryMatch.

      Parameters:
      query - a String object.
      entityName - a String object.
      Returns:
      a boolean.
    • suggestDatalistItem

      protected AutoCompletePage suggestDatalistItem(org.alfresco.service.cmr.repository.NodeRef entityNodeRef, org.alfresco.service.namespace.QName datalistType, org.alfresco.service.namespace.QName propertyQName, String query, Integer pageNum, Integer pageSize)
      Suggest a dalist item
      Parameters:
      entityNodeRef - a NodeRef object.
      datalistType - a QName object.
      propertyQName - a QName object.
      query - a String object.
      pageNum - a Integer object.
      pageSize - a Integer object.
      Returns:
      a AutoCompletePage object.