Java Code Examples for org.alfresco.opencmis.dictionary.CMISStrictDictionaryService

The following examples show how to use org.alfresco.opencmis.dictionary.CMISStrictDictionaryService. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected static CMISStrictDictionaryService newInstance(CMISMapping cmisMapping, DictionaryService dictionaryService, DictionaryDAO dictionaryDAO)
{
    CMISStrictDictionaryService cmisDictionaryService = new CMISStrictDictionaryService();
    cmisDictionaryService.setCmisMapping(cmisMapping);
    cmisDictionaryService.setDictionaryService(dictionaryService);
    cmisDictionaryService.setDictionaryDAO(dictionaryDAO);
    cmisDictionaryService.setSingletonCache(new MemoryCache<String, CMISDictionaryRegistry>());

    RuntimePropertyLuceneBuilderMapping luceneBuilderMapping = new RuntimePropertyLuceneBuilderMapping();
    luceneBuilderMapping.setDictionaryService(dictionaryService);
    luceneBuilderMapping.setCmisDictionaryService(cmisDictionaryService);
    cmisDictionaryService.setPropertyLuceneBuilderMapping(luceneBuilderMapping);
    luceneBuilderMapping.afterPropertiesSet();
    cmisDictionaryService.init();
    return cmisDictionaryService;
}
 
Example 2
/**
 * Gets a DictionaryService, if an Alternative dictionary is specified it tries to get that.
 * It will attempt to get the DEFAULT dictionary service if null is specified or it can't find
 * a dictionary with the name of "alternativeDictionary"
 * @param alternativeDictionary - can be null;
 * @return DictionaryService
 */
public DictionaryComponent getDictionaryService(String alternativeDictionary)
{
    DictionaryComponent dictionaryComponent = null;

    if (alternativeDictionary != null && !alternativeDictionary.trim().isEmpty())
    {
        dictionaryComponent = dictionaryServices.get(alternativeDictionary);
    }

    if (dictionaryComponent == null)
    {
        dictionaryComponent = dictionaryServices.get(CMISStrictDictionaryService.DEFAULT);
    }
    return dictionaryComponent;
}
 
Example 3
public Solr4QueryParser getLuceneQueryParser(SearchParameters searchParameters, SolrQueryRequest req, FTSQueryParser.RerankPhase rerankPhase)
{
    Analyzer analyzer =  req.getSchema().getQueryAnalyzer();
    Solr4QueryParser parser = new Solr4QueryParser(req, Version.LATEST, searchParameters.getDefaultFieldName(), analyzer, rerankPhase);
    parser.setNamespacePrefixResolver(namespaceDAO);
    parser.setDictionaryService(getDictionaryService(CMISStrictDictionaryService.DEFAULT));
    parser.setTenantService(tenantService);
    parser.setSearchParameters(searchParameters);
    parser.setAllowLeadingWildcard(true);

    Properties props = new CoreDescriptorDecorator(req.getCore().getCoreDescriptor()).getProperties();
    int topTermSpanRewriteLimit = Integer.parseInt(props.getProperty("alfresco.topTermSpanRewriteLimit", "1000"));
    parser.setTopTermSpanRewriteLimit(topTermSpanRewriteLimit);

    return parser;
}
 
Example 4
@Override
public synchronized void initSkippingDescendantDocs()
{
    if (isSkippingDocsInitialized)
    {
        return;
    }

    Properties p = core.getResourceLoader().getCoreProperties();
    skipDescendantDocsForSpecificTypes = Boolean.parseBoolean(p.getProperty("alfresco.metadata.skipDescendantDocsForSpecificTypes", "false"));
    if (skipDescendantDocsForSpecificTypes)
    {
        initSkippingDescendantDocs(p, typesForSkippingDescendantDocs, PROP_PREFIX_PARENT_TYPE, FIELD_TYPE,
                qName -> (null != dataModel.getDictionaryService(CMISStrictDictionaryService.DEFAULT).getType(qName)));
    }

    skipDescendantDocsForSpecificAspects = Boolean.parseBoolean(p.getProperty("alfresco.metadata.skipDescendantDocsForSpecificAspects", "false"));
    if (skipDescendantDocsForSpecificAspects)
    {
        initSkippingDescendantDocs(p, aspectsForSkippingDescendantDocs, PROP_PREFIX_PARENT_ASPECT, FIELD_ASPECT,
                qName -> (null != dataModel.getDictionaryService(CMISStrictDictionaryService.DEFAULT).getAspect(qName)));
    }

    isSkippingDocsInitialized = true;
}
 
Example 5
/**
 * Given the field name, returns the name of the property definition.
 * If the property definition is not found, Empty optional is returned.
 *
 * @param field the field name.
 * @return the name of the associated property definition if present, Optional.Empty() otherwise
 */
static Optional<QName> getShardProperty(String field)
{
    if (StringUtils.isBlank(field))
    {
        throw new IllegalArgumentException("Sharding property " + SHARD_KEY_KEY + " has not been set.");
    }

    AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance();
    NamespaceDAO namespaceDAO = dataModel.getNamespaceDAO();
    DictionaryService dictionaryService = dataModel.getDictionaryService(CMISStrictDictionaryService.DEFAULT);
    PropertyDefinition propertyDef = QueryParserUtils.matchPropertyDefinition("http://www.alfresco.org/model/content/1.0",
            namespaceDAO,
            dictionaryService,
            field);

    return ofNullable(propertyDef).map(PropertyDefinition::getName);
}
 
Example 6
@Before
  public void before() throws Exception
  {
      ctx = getTestFixture().getApplicationContext();
      this.dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
      this.lockService = (LockService) ctx.getBean("lockService");
      this.tenantService = (TenantService)ctx.getBean("tenantService");
      this.cmisDictionary = (CMISStrictDictionaryService)ctx.getBean("OpenCMISDictionaryService");
      this.cmisTypeExclusions = (QNameFilter)ctx.getBean("cmisTypeExclusions");
this.nodeService = (NodeService) ctx.getBean("NodeService");
      this.fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
  	this.contentService = (ContentService)applicationContext.getBean("ContentService");
this.permissionService = (PermissionService) ctx.getBean("permissionService");
      
this.globalProperties = (Properties) ctx.getBean("global-properties");
this.globalProperties.setProperty(VersionableAspectTest.AUTO_VERSION_PROPS_KEY, "true");
  }
 
Example 7
/**
 * Constructs a dictionary by default.
 * 
 * @param qnameFilter QNameFilter
 * @param namespaceDAO NamespaceDAO
 * @param dictionaryService DictionaryComponent
 * @param dictionaryDAO DictionaryDAO
 * @return Map
 */
public static Map<DictionaryKey,CMISAbstractDictionaryService> constructDictionaries(QNameFilter qnameFilter, NamespaceDAO namespaceDAO,
		DictionaryComponent dictionaryService, DictionaryDAO dictionaryDAO) 
{
    DictionaryNamespaceComponent namespaceService = new DictionaryNamespaceComponent();
    namespaceService.setNamespaceDAO(namespaceDAO);

    CMISMapping cmisMapping = new CMISMapping();
    cmisMapping.setCmisVersion(CmisVersion.CMIS_1_0);
    cmisMapping.setFilter(qnameFilter);
    cmisMapping.setNamespaceService(namespaceService);
    cmisMapping.setDictionaryService(dictionaryService);
    cmisMapping.afterPropertiesSet();

    CMISMapping cmisMapping11 = new CMISMapping();
    cmisMapping11.setCmisVersion(CmisVersion.CMIS_1_1);
    cmisMapping11.setFilter(qnameFilter);
    cmisMapping11.setNamespaceService(namespaceService);
    cmisMapping11.setDictionaryService(dictionaryService);
    cmisMapping11.afterPropertiesSet();

    Map<DictionaryKey,CMISAbstractDictionaryService> dictionaries = new HashMap<DictionaryKey,CMISAbstractDictionaryService>();

    DictionaryKey key = new DictionaryKey(CmisVersion.CMIS_1_0, CMISStrictDictionaryService.DEFAULT);
    dictionaries.put(key, newInstance(cmisMapping, dictionaryService, dictionaryDAO));
    CMISMapping mappingWithExclusions = newInstanceOfExcludedCMISMapping(cmisMapping, qnameFilter);
    key = new DictionaryKey(CmisVersion.CMIS_1_0, DICTIONARY_FILTERED_WITH_EXCLUSIONS);
    dictionaries.put(key, newInstance(mappingWithExclusions, dictionaryService, dictionaryDAO));
    
    key = new DictionaryKey(CmisVersion.CMIS_1_1, CMISStrictDictionaryService.DEFAULT);
    dictionaries.put(key, newInstance(cmisMapping11, dictionaryService, dictionaryDAO));
    CMISMapping mappingWithExclusions11 = newInstanceOfExcludedCMISMapping(cmisMapping11, qnameFilter);
    key = new DictionaryKey(CmisVersion.CMIS_1_1, DICTIONARY_FILTERED_WITH_EXCLUSIONS);
    dictionaries.put(key, newInstance(mappingWithExclusions11, dictionaryService, dictionaryDAO));

    return dictionaries;
}
 
Example 8
/**
 * Constructs a dictionary by default.
 * 
 * @param qnameFilter QNameFilter
 * @param dictionaryDAO DictionaryDAOImpl
 * @return Map
 */
public static Map<String, DictionaryComponent> constructDictionaryServices(QNameFilter qnameFilter, DictionaryDAOImpl dictionaryDAO)
{
    Map<String,DictionaryComponent> dictionaries = new HashMap<String,DictionaryComponent>();
    DictionaryComponent compo = new DictionaryComponent();
    compo.setDictionaryDAO(dictionaryDAO);
    dictionaries.put(CMISStrictDictionaryService.DEFAULT, compo);
    FilteredDictionaryComponent fdc  = new FilteredDictionaryComponent();
    fdc.setDictionaryDAO(dictionaryDAO);
    fdc.setFilter(qnameFilter);
    dictionaries.put(DICTIONARY_FILTERED_WITH_EXCLUSIONS, fdc);
    return dictionaries;
    
}
 
Example 9
/**
 * Returns the Alfresco models associated with the current dictionary.
 *
 * @return the Alfresco models associated with the current dictionary.
 */
public List<AlfrescoModel> getAlfrescoModels()
{
    return dictionaryDAO.getModels().stream()
            .map(qname -> {
                M2Model m2Model = dictionaryDAO.getCompiledModel(qname).getM2Model();
                return new AlfrescoModel(
                        m2Model,
                        getDictionaryService(
                                CMISStrictDictionaryService.DEFAULT).getModel(qname).getChecksum(ModelDefinition.XMLBindingType.DEFAULT));})
            .collect(Collectors.toList());
}
 
Example 10
private PropertyDefinition getPropertyDefinition(String identifier)
{
    return QueryParserUtils.matchPropertyDefinition(NamespaceService.CONTENT_MODEL_1_0_URI,
            getNamespaceDAO(),
            getDictionaryService(CMISStrictDictionaryService.DEFAULT),
            identifier);
}
 
Example 11
private boolean nodeTypeSupportsChildren(NodeMetaData metadata)
{
    return ofNullable(dataModel.getDictionaryService(CMISStrictDictionaryService.DEFAULT))
            .map(comp -> comp.getType(metadata.getType()))
            .map(TypeDefinition::getChildAssociations)
            .map(associations -> !associations.isEmpty())
            .orElse(false);
}
 
Example 12
private boolean atLeastOneAspectSupportsChildren(Set<QName> aspects)
{
    return notNullOrEmpty(aspects).stream()
            .map(aspect -> dataModel.getDictionaryService(CMISStrictDictionaryService.DEFAULT).getAspect(aspect))
            .filter(Objects::nonNull)
            .map(AspectDefinition::getChildAssociations)
            .filter(Objects::nonNull)
            .anyMatch(associations -> !associations.isEmpty());
}
 
Example 13
@Override
public void setUp() throws Exception
{
    if(client == null)
    {
        TenantService tenantService = new SingleTServiceImpl();

        dictionaryDAO = new DictionaryDAOImpl();
        NamespaceDAO namespaceDAO = dictionaryDAO;
        dictionaryDAO.setTenantService(tenantService);
        
        CompiledModelsCache compiledModelsCache = new CompiledModelsCache();
        compiledModelsCache.setDictionaryDAO(dictionaryDAO);
        compiledModelsCache.setTenantService(tenantService);
        compiledModelsCache.setRegistry(new DefaultAsynchronouslyRefreshedCacheRegistry());
        TraceableThreadFactory threadFactory = new TraceableThreadFactory();
        threadFactory.setThreadDaemon(true);
        threadFactory.setThreadPriority(Thread.NORM_PRIORITY);
        
        ThreadPoolExecutor threadPoolExecutor = new DynamicallySizedThreadPoolExecutor(20, 20, 90, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory,
                new ThreadPoolExecutor.CallerRunsPolicy());
        compiledModelsCache.setThreadPoolExecutor(threadPoolExecutor);
        dictionaryDAO.setDictionaryRegistryCache(compiledModelsCache);
        // TODO: use config ....
        dictionaryDAO.setDefaultAnalyserResourceBundleName("alfresco/model/dataTypeAnalyzers");
        dictionaryDAO.setResourceClassLoader(getResourceClassLoader());
        dictionaryDAO.init();

        DictionaryComponent dictionaryComponent = new DictionaryComponent();
        dictionaryComponent.setDictionaryDAO(dictionaryDAO);
        dictionaryComponent.setMessageLookup(new StaticMessageLookup());

        // cmis dictionary
        CMISMapping cmisMapping = new CMISMapping();
        cmisMapping.setCmisVersion(CmisVersion.CMIS_1_0);
        DictionaryNamespaceComponent namespaceService = new DictionaryNamespaceComponent();
        namespaceService.setNamespaceDAO(namespaceDAO);
        cmisMapping.setNamespaceService(namespaceService);
        cmisMapping.setDictionaryService(dictionaryComponent);
        cmisMapping.afterPropertiesSet();

        cmisDictionaryService = new CMISStrictDictionaryService();
        cmisDictionaryService.setCmisMapping(cmisMapping);
        cmisDictionaryService.setDictionaryService(dictionaryComponent);
        cmisDictionaryService.setDictionaryDAO(dictionaryDAO);
        cmisDictionaryService.setSingletonCache(new MemoryCache<String, CMISDictionaryRegistry>());
        cmisDictionaryService.setTenantService(tenantService);
        cmisDictionaryService.init();

        RuntimePropertyLuceneBuilderMapping luceneBuilderMapping = new RuntimePropertyLuceneBuilderMapping();
        luceneBuilderMapping.setDictionaryService(dictionaryComponent);
        luceneBuilderMapping.setCmisDictionaryService(cmisDictionaryService);
        cmisDictionaryService.setPropertyLuceneBuilderMapping(luceneBuilderMapping);

        luceneBuilderMapping.afterPropertiesSet();

        // Load the key store from the classpath
        ClasspathKeyResourceLoader keyResourceLoader = new ClasspathKeyResourceLoader();
        client = new SOLRAPIClient(getRepoClient(keyResourceLoader), dictionaryComponent, dictionaryDAO);
        trackModels();
    }
}
 
Example 14
public PropertyDefinition getPropertyDefinition(QName propertyQName)
{
    return getDictionaryService(CMISStrictDictionaryService.DEFAULT).getProperty(propertyQName);
}
 
Example 15
public Query getFTSQuery(Pair<SearchParameters, Boolean> searchParametersAndFilter, SolrQueryRequest req, FTSQueryParser.RerankPhase rerankPhase) throws ParseException
{

    SearchParameters searchParameters = searchParametersAndFilter.getFirst();
    Boolean isFilter = searchParametersAndFilter.getSecond();

    QueryModelFactory factory = new LuceneQueryModelFactory<Query, Sort, SyntaxError>();
    AlfrescoFunctionEvaluationContext functionContext = new AlfrescoSolr4FunctionEvaluationContext(namespaceDAO, getDictionaryService(CMISStrictDictionaryService.DEFAULT), NamespaceService.CONTENT_MODEL_1_0_URI, req.getSchema());

    FTSParser.Mode mode;

    if (searchParameters.getDefaultFTSOperator() == org.alfresco.service.cmr.search.SearchParameters.Operator.AND)
    {
        mode = FTSParser.Mode.DEFAULT_CONJUNCTION;
    }
    else
    {
        mode = FTSParser.Mode.DEFAULT_DISJUNCTION;
    }

    Constraint constraint = FTSQueryParser.buildFTS(searchParameters.getQuery(), factory, functionContext, null, null, mode,
            searchParameters.getDefaultFTSOperator() == org.alfresco.service.cmr.search.SearchParameters.Operator.OR ? Connective.OR : Connective.AND,
            searchParameters.getQueryTemplates(), searchParameters.getDefaultFieldName(), rerankPhase);
    org.alfresco.repo.search.impl.querymodel.Query queryModelQuery = factory.createQuery(null, null, constraint, new ArrayList<>());

    @SuppressWarnings("unchecked")
    LuceneQueryBuilder<Query, Sort, ParseException> builder = (LuceneQueryBuilder<Query, Sort, ParseException>) queryModelQuery;

    LuceneQueryBuilderContext<Query, Sort, ParseException> luceneContext = getLuceneQueryBuilderContext(searchParameters, req, CMISStrictDictionaryService.DEFAULT, rerankPhase);

    Set<String> selectorGroup = null;
    if (queryModelQuery.getSource() != null)
    {
        List<Set<String>> selectorGroups = queryModelQuery.getSource().getSelectorGroups(functionContext);

        if (selectorGroups.size() == 0)
        {
            throw new UnsupportedOperationException("No selectors");
        }

        if (selectorGroups.size() > 1)
        {
            throw new UnsupportedOperationException("Advanced join is not supported");
        }

        selectorGroup = selectorGroups.get(0);
    }
    Query luceneQuery = builder.buildQuery(selectorGroup, luceneContext, functionContext);
    // query needs some search parameters fro correct caching ....

    return new ContextAwareQuery(luceneQuery, Boolean.TRUE.equals(isFilter) ? null : searchParameters);
}
 
Example 16
/**
 *
 * return the stored field associated to potentialProperty parameter
 */
public String mapStoredProperty(String potentialProperty, SolrQueryRequest req)
{
    if(potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_"))
    {
        return potentialProperty;
    }

    if(potentialProperty.equalsIgnoreCase("score") || potentialProperty.equalsIgnoreCase("SEARCH_SCORE"))
    {
        return "score";
    }

    AlfrescoFunctionEvaluationContext functionContext =
        new AlfrescoSolr4FunctionEvaluationContext(
            getNamespaceDAO(),
            getDictionaryService(CMISStrictDictionaryService.DEFAULT),
            NamespaceService.CONTENT_MODEL_1_0_URI,
            req.getSchema());


    Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(potentialProperty);
    String luceneField =  functionContext.getLuceneFieldName(fieldNameAndEnding.getFirst());

    PropertyDefinition propertyDef = getPropertyDefinition(fieldNameAndEnding.getFirst());
    //Retry scan using luceneField.
    if(propertyDef == null)
    {
        if(luceneField.contains("@"))
        {
            int index = luceneField.lastIndexOf("@");
            propertyDef = getPropertyDefinition(luceneField.substring(index +1));
        }
    }

    if (propertyDef == null || propertyDef.getName() == null)
    {
        return mapNonPropertyFields(luceneField);
    }

    if (isDateOrDatetime(propertyDef.getDataType()) && isDerivedDateField(fieldNameAndEnding.getSecond()))
    {
        return getDateDerivedField(propertyDef.getName(), fieldNameAndEnding.getSecond());
    }
    else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT))
    {
        return getStoredTextField(propertyDef.getName(), fieldNameAndEnding.getSecond());
    }
    else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT))
    {
        return getStoredMLTextField(propertyDef.getName(), fieldNameAndEnding.getSecond());
    }
    else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
    {
        return getStoredContentField(propertyDef.getName(), fieldNameAndEnding.getSecond());
    }
    else
    {
        return mapAlfrescoField(FieldUse.FTS, 0, fieldNameAndEnding, luceneField, propertyDef)
                + fieldNameAndEnding.getSecond();
    }
}
 
Example 17
public String  mapProperty(String  potentialProperty,  FieldUse fieldUse, SolrQueryRequest req, int position)
{
    if(potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_"))
    {
        return potentialProperty;
    }

    if(potentialProperty.equalsIgnoreCase("score") || potentialProperty.equalsIgnoreCase("SEARCH_SCORE"))
    {
        return "score";
    }

    if(req.getSchema().getFieldOrNull(potentialProperty) != null)
    {
        return mapNonPropertyFields(potentialProperty);
    }

    AlfrescoFunctionEvaluationContext functionContext =
            new AlfrescoSolr4FunctionEvaluationContext(
                    getNamespaceDAO(),
                    getDictionaryService(CMISStrictDictionaryService.DEFAULT),
                    NamespaceService.CONTENT_MODEL_1_0_URI,
                    req.getSchema());

    Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(potentialProperty);
    String luceneField =  functionContext.getLuceneFieldName(fieldNameAndEnding.getFirst());

    PropertyDefinition propertyDef = getPropertyDefinition(fieldNameAndEnding.getFirst());
    //Retry scan using luceneField.
    if(propertyDef == null)
    {
        if(luceneField.contains("@"))
        {
            int index = luceneField.lastIndexOf("@");
            propertyDef = getPropertyDefinition(luceneField.substring(index +1));
        }
    }
    String solrSortField;
    solrSortField = mapAlfrescoField(fieldUse, position, fieldNameAndEnding, luceneField, propertyDef);
    return solrSortField;
}