Java Code Examples for org.alfresco.service.cmr.dictionary.PropertyDefinition#isMultiValued()

The following examples show how to use org.alfresco.service.cmr.dictionary.PropertyDefinition#isMultiValued() . 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
Source File: SelectorPropertyContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
private void afterPropertiesSet_validateSelectors()
{
    PropertyCheck.mandatory(this, "selectorClassName", this.selectorClassName);
    PropertyCheck.mandatory(this, "selectorPropertyName", this.selectorPropertyName);

    this.selectorClassQName = QName.resolveToQName(this.namespaceService, this.selectorClassName);
    this.selectorPropertyQName = QName.resolveToQName(this.namespaceService, this.selectorPropertyName);
    PropertyCheck.mandatory(this, "selectorClassQName", this.selectorClassQName);
    PropertyCheck.mandatory(this, "selectorPropertyQName", this.selectorPropertyQName);

    final ClassDefinition classDefinition = this.dictionaryService.getClass(this.selectorClassQName);
    if (classDefinition == null)
    {
        throw new IllegalStateException(this.selectorClassName + " is not a valid content model class");
    }

    final PropertyDefinition propertyDefinition = this.dictionaryService.getProperty(this.selectorPropertyQName);
    if (propertyDefinition == null || !DataTypeDefinition.TEXT.equals(propertyDefinition.getDataType().getName())
            || propertyDefinition.isMultiValued())
    {
        throw new IllegalStateException(
                this.selectorPropertyName + " is not a valid content model property of type single-valued d:text");
    }
}
 
Example 2
Source File: TypeRoutingContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
private void afterPropertiesSet_setupChangePolicies()
{
    if (this.moveStoresOnChangeOptionPropertyName != null)
    {
        this.moveStoresOnChangeOptionPropertyQName = QName.resolveToQName(this.namespaceService,
                this.moveStoresOnChangeOptionPropertyName);
        PropertyCheck.mandatory(this, "moveStoresOnChangeOptionPropertyQName", this.moveStoresOnChangeOptionPropertyQName);

        final PropertyDefinition moveStoresOnChangeOptionPropertyDefinition = this.dictionaryService
                .getProperty(this.moveStoresOnChangeOptionPropertyQName);
        if (moveStoresOnChangeOptionPropertyDefinition == null
                || !DataTypeDefinition.BOOLEAN.equals(moveStoresOnChangeOptionPropertyDefinition.getDataType().getName())
                || moveStoresOnChangeOptionPropertyDefinition.isMultiValued())
        {
            throw new IllegalStateException(this.moveStoresOnChangeOptionPropertyName
                    + " is not a valid content model property of type single-valued d:boolean");
        }
    }

    if (this.moveStoresOnChange || this.moveStoresOnChangeOptionPropertyQName != null)
    {
        this.policyComponent.bindClassBehaviour(OnSetNodeTypePolicy.QNAME, ContentModel.TYPE_BASE,
                new JavaBehaviour(this, "onSetNodeType", NotificationFrequency.EVERY_EVENT));
    }
}
 
Example 3
Source File: CustomModelProperty.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CustomModelProperty(PropertyDefinition propertyDefinition, MessageLookup messageLookup)
{
    this.name = propertyDefinition.getName().getLocalName();
    this.prefixedName = propertyDefinition.getName().toPrefixString();
    this.title = propertyDefinition.getTitle(messageLookup);
    this.dataType = propertyDefinition.getDataType().getName().toPrefixString();
    this.description = propertyDefinition.getDescription(messageLookup);
    this.isMandatory = propertyDefinition.isMandatory();
    this.isMandatoryEnforced = propertyDefinition.isMandatoryEnforced();
    this.isMultiValued = propertyDefinition.isMultiValued();
    this.defaultValue = propertyDefinition.getDefaultValue();
    this.isIndexed = propertyDefinition.isIndexed();
    this.facetable = propertyDefinition.getFacetable();
    this.indexTokenisationMode = propertyDefinition.getIndexTokenisationMode();
    List<ConstraintDefinition> constraintDefs = propertyDefinition.getConstraints();
    if (constraintDefs.size() > 0)
    {
        this.constraintRefs = new ArrayList<>();
        this.constraints = new ArrayList<>();
        for (ConstraintDefinition cd : constraintDefs)
        {
            if (cd.getRef() != null)
            {
                constraintRefs.add(cd.getRef().toPrefixString());
            }
            else
            {
                constraints.add(new CustomModelConstraint(cd, messageLookup));
            }
        }
    }
}
 
Example 4
Source File: SelectorPropertyContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
private void afterPropertiesSet_setupChangePolicies()
{
    if (this.moveStoresOnChangeOptionPropertyName != null)
    {
        this.moveStoresOnChangeOptionPropertyQName = QName.resolveToQName(this.namespaceService,
                this.moveStoresOnChangeOptionPropertyName);
        PropertyCheck.mandatory(this, "moveStoresOnChangeOptionPropertyQName", this.moveStoresOnChangeOptionPropertyQName);

        final PropertyDefinition moveStoresOnChangeOptionPropertyDefinition = this.dictionaryService
                .getProperty(this.moveStoresOnChangeOptionPropertyQName);
        if (moveStoresOnChangeOptionPropertyDefinition == null
                || !DataTypeDefinition.BOOLEAN.equals(moveStoresOnChangeOptionPropertyDefinition.getDataType().getName())
                || moveStoresOnChangeOptionPropertyDefinition.isMultiValued())
        {
            throw new IllegalStateException(this.moveStoresOnChangeOptionPropertyName
                    + " is not a valid content model property of type single-valued d:boolean");
        }
    }

    if (this.moveStoresOnChange || this.moveStoresOnChangeOptionPropertyQName != null)
    {
        this.policyComponent.bindClassBehaviour(OnUpdatePropertiesPolicy.QNAME, this.selectorClassQName,
                new JavaBehaviour(this, "onUpdateProperties", NotificationFrequency.EVERY_EVENT));

        final ClassDefinition classDefinition = this.dictionaryService.getClass(this.selectorClassQName);
        if (classDefinition.isAspect())
        {
            this.policyComponent.bindClassBehaviour(BeforeRemoveAspectPolicy.QNAME, this.selectorClassQName,
                    new JavaBehaviour(this, "beforeRemoveAspect", NotificationFrequency.EVERY_EVENT));
            this.policyComponent.bindClassBehaviour(OnAddAspectPolicy.QNAME, this.selectorClassQName,
                    new JavaBehaviour(this, "onAddAspect", NotificationFrequency.EVERY_EVENT));
        }
    }
}
 
Example 5
Source File: SiteRoutingContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
protected void afterPropertiesSet_setupChangePolicies()
{
    if (this.moveStoresOnNodeMoveOrCopyOverridePropertyName != null)
    {
        this.moveStoresOnNodeMoveOrCopyOverridePropertyQName = QName.resolveToQName(this.namespaceService,
                this.moveStoresOnNodeMoveOrCopyOverridePropertyName);
        PropertyCheck.mandatory(this, "moveStoresOnNodeMoveOrCopyOverridePropertyQName",
                this.moveStoresOnNodeMoveOrCopyOverridePropertyQName);

        final PropertyDefinition moveStoresOnChangeOptionPropertyDefinition = this.dictionaryService
                .getProperty(this.moveStoresOnNodeMoveOrCopyOverridePropertyQName);
        if (moveStoresOnChangeOptionPropertyDefinition == null
                || !DataTypeDefinition.BOOLEAN.equals(moveStoresOnChangeOptionPropertyDefinition.getDataType().getName())
                || moveStoresOnChangeOptionPropertyDefinition.isMultiValued())
        {
            throw new IllegalStateException(this.moveStoresOnNodeMoveOrCopyOverridePropertyName
                    + " is not a valid content model property of type single-valued d:boolean");
        }
    }

    if (this.moveStoresOnNodeMoveOrCopy || this.moveStoresOnNodeMoveOrCopyOverridePropertyQName != null)
    {
        PropertyCheck.mandatory(this, "policyComponent", this.policyComponent);
        PropertyCheck.mandatory(this, "dictionaryService", this.dictionaryService);
        PropertyCheck.mandatory(this, "nodeService", this.nodeService);

        this.policyComponent.bindClassBehaviour(OnCopyCompletePolicy.QNAME, ContentModel.TYPE_BASE,
                new JavaBehaviour(this, "onCopyComplete", NotificationFrequency.EVERY_EVENT));
        this.policyComponent.bindClassBehaviour(OnMoveNodePolicy.QNAME, ContentModel.TYPE_BASE,
                new JavaBehaviour(this, "onMoveNode", NotificationFrequency.EVERY_EVENT));
    }
}
 
Example 6
Source File: SiteRoutingFileContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
protected void afterPropertiesSet_setupChangePolicies()
{
    if (this.moveStoresOnNodeMoveOrCopyOverridePropertyName != null)
    {
        this.moveStoresOnNodeMoveOrCopyOverridePropertyQName = QName.resolveToQName(this.namespaceService,
                this.moveStoresOnNodeMoveOrCopyOverridePropertyName);
        PropertyCheck.mandatory(this, "moveStoresOnNodeMoveOrCopyOverridePropertyQName",
                this.moveStoresOnNodeMoveOrCopyOverridePropertyQName);

        final PropertyDefinition moveStoresOnChangeOptionPropertyDefinition = this.dictionaryService
                .getProperty(this.moveStoresOnNodeMoveOrCopyOverridePropertyQName);
        if (moveStoresOnChangeOptionPropertyDefinition == null
                || !DataTypeDefinition.BOOLEAN.equals(moveStoresOnChangeOptionPropertyDefinition.getDataType().getName())
                || moveStoresOnChangeOptionPropertyDefinition.isMultiValued())
        {
            throw new IllegalStateException(this.moveStoresOnNodeMoveOrCopyOverridePropertyName
                    + " is not a valid content model property of type single-valued d:boolean");
        }
    }

    if (this.moveStoresOnNodeMoveOrCopy || this.moveStoresOnNodeMoveOrCopyOverridePropertyQName != null)
    {
        this.policyComponent.bindClassBehaviour(OnCopyCompletePolicy.QNAME, ContentModel.TYPE_BASE,
                new JavaBehaviour(this, "onCopyComplete", NotificationFrequency.EVERY_EVENT));
        this.policyComponent.bindClassBehaviour(OnMoveNodePolicy.QNAME, ContentModel.TYPE_BASE,
                new JavaBehaviour(this, "onMoveNode", NotificationFrequency.EVERY_EVENT));
    }
}
 
Example 7
Source File: AbstractMapBasedMetadataLoader.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void loadMetadataInternal(Metadata metadata, final Path metadataFile)
{
    final String metadataFilePath = FileUtils.getFileName(metadataFile);
    if (Files.isReadable(metadataFile))
    {
        Map<String, Serializable> metadataProperties = loadMetadataFromFile(metadataFile);

        for (String key : metadataProperties.keySet())
        {
            if (PROPERTY_NAME_TYPE.equals(key))
            {
                String typeName = (String) metadataProperties.get(key);
                QName type = QName.createQName(typeName, namespaceService);

                metadata.setType(type);
            }
            else if (PROPERTY_NAME_ASPECTS.equals(key))
            {
                String[] aspectNames = ((String) metadataProperties.get(key)).split(",");

                for (final String aspectName : aspectNames)
                {
                    QName aspect = QName.createQName(aspectName.trim(), namespaceService);
                    metadata.addAspect(aspect);
                }
            }
            else // Any other key => property
            {
                // ####TODO: figure out how to handle properties of type cm:content - they need to be streamed in via a Writer
                QName name = QName.createQName(key, namespaceService);
                PropertyDefinition propertyDefinition = dictionaryService.getProperty(name);// TODO: measure performance impact of this API call!!

                if (propertyDefinition != null)
                {
                    if (propertyDefinition.isMultiValued())
                    {
                        // Multi-valued property
                        ArrayList<Serializable> values = new ArrayList<Serializable>(
                                Arrays.asList(((String) metadataProperties.get(key)).split(multiValuedSeparator)));
                        metadata.addProperty(name, values);
                    }
                    else
                    {
                        // Single value property
                        metadata.addProperty(name, metadataProperties.get(key));
                    }
                }
                else
                {
                    if (log.isWarnEnabled())
                    {
                        log.warn("Property " + String.valueOf(name) + " from '" + metadataFilePath
                                + "' doesn't exist in the Data Dictionary.  Ignoring it.");
                    }
                }
            }
        }
    }
    else
    {
        if (log.isWarnEnabled())
        {
            log.warn("Metadata file '" + metadataFilePath + "' is not readable.");
        }
    }
}
 
Example 8
Source File: TypedPropertyValueGetter.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Serializable getValue(Object value, PropertyDefinition propDef)
{
    if (value == null)
    {
        return null;
    }

    // before persisting check data type of property
    if (propDef.isMultiValued()) 
    {
        return processMultiValuedType(value);
    }
    
    
    if (isBooleanProperty(propDef)) 
    {
        return processBooleanValue(value);
    }
    else if (isLocaleProperty(propDef)) 
    {
        return processLocaleValue(value);
    }
    else if (value instanceof String)
    {
        String valStr = (String) value;

        // make sure empty strings stay as empty strings, everything else
        // should be represented as null
        if (isTextProperty(propDef))
        {
            return valStr;
        }
        if(valStr.isEmpty())
        {
            return null;
        }
        if(isDateProperty(propDef) && !ISO8601DateFormat.isTimeComponentDefined(valStr))
        {
            // Special handling for day-only date storage (ALF-10243)
            return ISO8601DateFormat.parseDayOnly(valStr, TimeZone.getDefault());
        }
    }
    if (value instanceof Serializable)
    {
        return (Serializable) DefaultTypeConverter.INSTANCE.convert(propDef.getDataType(), value);
    }
    else
    {
        throw new FormException("Property values must be of a Serializable type! Value type: " + value.getClass());
    }
}
 
Example 9
Source File: OnPropertyUpdateRuleTrigger.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean havePropertiesBeenModified(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after, boolean newNode, boolean newContentOnly)
{
    if (newContentOnly && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT))
    {
        return false;
    }        

    Set<QName> keys = new HashSet<QName>(after.keySet());
    keys.addAll(before.keySet());

    // Compare all properties, ignoring protected properties and giving special treatment to content properties
    boolean nonNullContentProperties = false;
    boolean newContentProperties = false;
    boolean nonNewModifiedContentProperties = false;
    boolean modifiedNonContentProperties = false;
    for (QName name : keys)
    {
        // Skip rule firing on this content property for performance reasons
        if (name.equals(ContentModel.PROP_PREFERENCE_VALUES))
        {
            continue;
        }
        Serializable beforeValue = before.get(name);
        Serializable afterValue = after.get(name);
        PropertyDefinition propertyDefinition = this.dictionaryService.getProperty(name);
        if (propertyDefinition == null)
        {
            if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
            {
                modifiedNonContentProperties = true;
            }
        }
        // Ignore protected properties
        else if (!propertyDefinition.isProtected())
        {
            if (propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT)
                    && !propertyDefinition.isMultiValued())
            {
                // Remember whether the property was populated, regardless of the ignore setting
                if (afterValue != null)
                {
                    nonNullContentProperties = true;
                }                    
                if (this.ignoreEmptyContent)
                {
                    ContentData beforeContent = toContentData(before.get(name));
                    ContentData afterContent = toContentData(after.get(name));
                    if (!ContentData.hasContent(beforeContent) || beforeContent.getSize() == 0)
                    {
                        beforeValue = null;
                    }
                    if (!ContentData.hasContent(afterContent) || afterContent.getSize() == 0)
                    {
                        afterValue = null;
                    }
                }
                if (newNode)
                {
                    if (afterValue != null)
                    {
                        newContentProperties = true;
                    }
                }
                else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
                {
                    if (beforeValue == null)
                    {
                        newContentProperties = true;                            
                    }
                    else
                    {
                        nonNewModifiedContentProperties = true;                            
                    }
                }
            }
            else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
            {
                modifiedNonContentProperties = true;
            }
        }
    }

    if (newContentOnly)
    {
        return (newNode && !nonNullContentProperties ) || newContentProperties;
    }
    else
    {
        return modifiedNonContentProperties || nonNewModifiedContentProperties;
    }
}
 
Example 10
Source File: NodePropertyHelper.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Map<QName, Serializable> convertToPublicProperties(Map<NodePropertyKey, NodePropertyValue> propertyValues)
{
    Map<QName, Serializable> propertyMap = new HashMap<QName, Serializable>(propertyValues.size(), 1.0F);
    // Shortcut
    if (propertyValues.size() == 0)
    {
        return propertyMap;
    }
    // We need to process the properties in order
    SortedMap<NodePropertyKey, NodePropertyValue> sortedPropertyValues = new TreeMap<NodePropertyKey, NodePropertyValue>(
            propertyValues);
    // A working map. Ordering is important.
    SortedMap<NodePropertyKey, NodePropertyValue> scratch = new TreeMap<NodePropertyKey, NodePropertyValue>();
    // Iterate (sorted) over the map entries and extract values with the same qname
    Long currentQNameId = Long.MIN_VALUE;
    Iterator<Map.Entry<NodePropertyKey, NodePropertyValue>> iterator = sortedPropertyValues.entrySet().iterator();
    while (true)
    {
        Long nextQNameId = null;
        NodePropertyKey nextPropertyKey = null;
        NodePropertyValue nextPropertyValue = null;
        // Record the next entry's values
        if (iterator.hasNext())
        {
            Map.Entry<NodePropertyKey, NodePropertyValue> entry = iterator.next();
            nextPropertyKey = entry.getKey();
            nextPropertyValue = entry.getValue();
            nextQNameId = nextPropertyKey.getQnameId();
        }
        // If the QName is going to change, and we have some entries to process, then process them.
        if (scratch.size() > 0 && (nextQNameId == null || !nextQNameId.equals(currentQNameId)))
        {
            QName currentQName = qnameDAO.getQName(currentQNameId).getSecond();
            PropertyDefinition currentPropertyDef = dictionaryService.getProperty(currentQName);
            // We have added something to the scratch properties but the qname has just changed
            Serializable collapsedValue = null;
            // We can shortcut if there is only one value
            if (scratch.size() == 1)
            {
                // There is no need to collapse list indexes
                collapsedValue = collapsePropertiesWithSameQNameAndListIndex(currentPropertyDef, scratch);
            }
            else
            {
                // There is more than one value so the list indexes need to be collapsed
                collapsedValue = collapsePropertiesWithSameQName(currentPropertyDef, scratch);
            }
            boolean forceCollection = false;
            // If the property is multi-valued then the output property must be a collection
            if (currentPropertyDef != null && currentPropertyDef.isMultiValued())
            {
                forceCollection = true;
            }
            else if (scratch.size() == 1 && scratch.firstKey().getListIndex().intValue() > -1)
            {
                // This is to handle cases of collections where the property is d:any but not
                // declared as multiple.
                forceCollection = true;
            }
            if (forceCollection && collapsedValue != null && !(collapsedValue instanceof Collection<?>))
            {
                // Can't use Collections.singletonList: ETHREEOH-1172
                ArrayList<Serializable> collection = new ArrayList<Serializable>(1);
                collection.add(collapsedValue);
                collapsedValue = collection;
            }
            
            // Store the value
            propertyMap.put(currentQName, collapsedValue);
            // Reset
            scratch.clear();
        }
        if (nextQNameId != null)
        {
            // Add to the current entries
            scratch.put(nextPropertyKey, nextPropertyValue);
            currentQNameId = nextQNameId;
        }
        else
        {
            // There is no next value to process
            break;
        }
    }
    // Done
    return propertyMap;
}
 
Example 11
Source File: SOLRAPIClient.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
private PropertyValue getPropertyValue(PropertyDefinition propertyDef, Object value) throws JSONException
{
    PropertyValue ret = null;

    if(value == null || value == JSONObject.NULL)
    {
        ret = null;
    }
    else if(propertyDef == null)
    {
        // assume a string
        ret = new StringPropertyValue((String)value);
    }
    else
    {
        DataTypeDefinition dataType = propertyDef.getDataType();
        
        boolean isMulti = propertyDef.isMultiValued();
        if(isMulti)
        {
            if(!(value instanceof JSONArray))
            {
                throw new IllegalArgumentException("Expected json array, got " + value.getClass().getName());
            }

            MultiPropertyValue multi = new MultiPropertyValue();
            JSONArray array = (JSONArray)value;
            for(int j = 0; j < array.length(); j++)
            {
                multi.addValue(getSinglePropertyValue(dataType, array.get(j)));
            }

            ret = multi;
        }
        else
        {
            ret = getSinglePropertyValue(dataType, value);
        }
    }
    
    return ret;
}
 
Example 12
Source File: AlfrescoSolrDataModel.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void addSortSearchFields( PropertyDefinition propertyDefinition , IndexedField indexedField)
{
    // Can only order on single valued fields
    DataTypeDefinition dataTypeDefinition = propertyDefinition.getDataType();
    if(dataTypeDefinition.getName().equals(DataTypeDefinition.TEXT))
    {
        if(!propertyDefinition.isMultiValued())
        {
            if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.FALSE)
                    || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH))
            {
                indexedField.addField(getFieldForText(false, false, true, propertyDefinition), false, true);
            }
            else if (isIdentifierTextProperty(propertyDefinition.getName()))
            {
                indexedField.addField(getFieldForText(false, false, false, propertyDefinition), false, false);
            }
            else
            {
                if(crossLocaleSearchDataTypes.contains(propertyDefinition.getDataType().getName()) || crossLocaleSearchProperties.contains(propertyDefinition.getName()))
                {
                    indexedField.addField(getFieldForText(false, true, false, propertyDefinition), false, false);
                }
                else
                {
                    indexedField.addField(getFieldForText(true, true, false, propertyDefinition), false, false);
                }
            }
        }
    }

    if(dataTypeDefinition.getName().equals(DataTypeDefinition.MLTEXT))
    {
        if(!propertyDefinition.isMultiValued())
        {
            if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.FALSE)
                    || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH))
            {
                indexedField.addField(getFieldForText(false, false, true, propertyDefinition), false, true);
            }
            else
            {
                if(crossLocaleSearchDataTypes.contains(propertyDefinition.getDataType().getName()) || crossLocaleSearchProperties.contains(propertyDefinition.getName()))
                {
                    indexedField.addField(getFieldForText(false, true, false, propertyDefinition), false, false);
                }
                else
                {
                    indexedField.addField(getFieldForText(true, true, false, propertyDefinition), false, false);
                }
            }
        }
    }
}
 
Example 13
Source File: AlfrescoSolrDataModel.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get all the field names into which we must copy the source data
 *
 * @param propertyQName QName
 * @return IndexedField
 */
public IndexedField getIndexedFieldNamesForProperty(QName propertyQName)
{
    // TODO: Cache and throw on model refresh

    IndexedField indexedField = new IndexedField();
    PropertyDefinition propertyDefinition = getPropertyDefinition(propertyQName);
    if((propertyDefinition == null))
    {
        return indexedField;
    }
    if(!propertyDefinition.isIndexed() && !propertyDefinition.isStoredInIndex())
    {
        return indexedField;
    }

    DataTypeDefinition dataTypeDefinition = propertyDefinition.getDataType();
    if(isTextField(propertyDefinition))
    {
        if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.TRUE)
                || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH))
        {
            indexedField.addField(getFieldForText(true, true, false, propertyDefinition), true, false);
            if(crossLocaleSearchDataTypes.contains(propertyDefinition.getDataType().getName()) || crossLocaleSearchProperties.contains(propertyDefinition.getName()))
            {
                indexedField.addField(getFieldForText(false, true, false, propertyDefinition), false, false);
            }
        }

        if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.FALSE)
                || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH
                || isIdentifierTextProperty(propertyDefinition.getName())))
        {
            indexedField.addField(getFieldForText(true, false, false, propertyDefinition), true, false);
            indexedField.addField(getFieldForText(false, false, false, propertyDefinition), false, false);
        }

        if(dataTypeDefinition.getName().equals(DataTypeDefinition.TEXT))
        {
            if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.FALSE)
                    || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH))
            {
                if(!propertyDefinition.isMultiValued())
                {
                    indexedField.addField(getFieldForText(false, false, true, propertyDefinition), false, true);
                }
            }
            else if (!isIdentifierTextProperty(propertyDefinition.getName()))
            {
                if(propertyDefinition.getFacetable() == Facetable.TRUE)
                {
                    indexedField.addField(getFieldForText(false, false, false, propertyDefinition), false, false);
                }
            }
        }

        if(dataTypeDefinition.getName().equals(DataTypeDefinition.MLTEXT))
        {
            if ((propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.FALSE)
                    || (propertyDefinition.getIndexTokenisationMode() == IndexTokenisationMode.BOTH))
            {
                if(!propertyDefinition.isMultiValued())
                {
                    indexedField.addField(getFieldForText(true, false, true, propertyDefinition), true, true);
                }
            }
        }

        if(isSuggestable(propertyQName))
        {
            indexedField.addField("suggest_@" + propertyDefinition.getName().toString(), false, false);
        }
    }
    else
    {
        indexedField.addField(getFieldForNonText(propertyDefinition), false, false);
    }

    return indexedField;
}
 
Example 14
Source File: SOLRSerializer.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public PropertyValue serialize(QName propName, Serializable value) throws IOException, JSONException
{
    if(value == null)
    {
        return new PropertyValue(false, "null");
    }

    PropertyDefinition propertyDef = dictionaryService.getProperty(propName);
    if (propertyDef == null)
    {
        // Treat it as text
        return new PropertyValue(true, serializeToJSONString(value));
    }
    DataTypeDefinition dataType = propertyDef.getDataType();
    QName dataTypeName = dataType.getName();
    if (propertyDef.isMultiValued())
    {
        if(!(value instanceof Collection))
        {
            throw new IllegalArgumentException("Multi value: expected a collection, got " + value.getClass().getName());
        }

        Collection<Serializable> c = (Collection<Serializable>)value;

        JSONArray body = new JSONArray();
        for(Serializable o : c)
        {
            if(dataTypeName.equals(DataTypeDefinition.MLTEXT))
            {
                MLText source = (MLText)o;
                JSONArray array = new JSONArray();
                for(Locale locale : source.getLocales())
                {
                    JSONObject json = new JSONObject();
                    json.put("locale", DefaultTypeConverter.INSTANCE.convert(String.class, locale));
                    json.put("value", source.getValue(locale));
                    array.put(json);
                }
                body.put(array);
            }
            else if(dataTypeName.equals(DataTypeDefinition.CONTENT))
            {
                throw new RuntimeException("Multi-valued content properties are not supported");
            }
            else
            {
                body.put(serializeToJSONString(o));
            }
            
        }
        
        return new PropertyValue(false, body.toString());
    }
    else
    {
        boolean encodeString = true;
        if(dataTypeName.equals(DataTypeDefinition.MLTEXT))
        {
            encodeString = false;
        }
        else if(dataTypeName.equals(DataTypeDefinition.CONTENT))
        {
            encodeString = false;
        }
        else
        {
            encodeString = true;
        }

        String sValue = null;
        if (value instanceof String && encodeString) {
        	sValue = (String)jsonUtils.encodeJSONString(value);
        } else {
        	sValue = serializeToJSONString(value);
        }

        return new PropertyValue(encodeString, sValue);
    }
}
 
Example 15
Source File: DataDictionaryBuilderImpl.java    From alfresco-bulk-import with Apache License 2.0 4 votes vote down vote up
private String classDefinitionToString(final ClassDefinition definition)
{
    StringBuilder result = null;
    
    if (definition != null)
    {
        result = new StringBuilder(1024);
        result.append("\n\t\t\t");
        result.append(definition.getName().toPrefixString());
        
        result.append("\n\t\t\t\tParent: ");
        result.append(definition.getParentName() == null ? "<none>" : definition.getParentName().getPrefixString());
        
        result.append("\n\t\t\t\tProperties:");
        Map<QName,PropertyDefinition> properties = definition.getProperties();
        if (properties != null && properties.size() > 0)
        {
            for (QName propertyName : properties.keySet())
            {
                PropertyDefinition propertyDefinition = properties.get(propertyName);
                
                result.append("\n\t\t\t\t\t");
                result.append(propertyName.toPrefixString());
                result.append(" (");
                result.append(propertyDefinition.getDataType().getName().getPrefixString());
                result.append(")");
                
                if (propertyDefinition.isMultiValued())
                {
                    result.append(" (multi-valued)");
                }
                
                if (propertyDefinition.isMandatoryEnforced())
                {
                    result.append(" (mandatory)");
                }
                
                List<ConstraintDefinition> propertyConstraints = propertyDefinition.getConstraints();
                if (propertyConstraints != null && propertyConstraints.size() > 0)
                {
                    result.append(" (constraints: ");
                    for (ConstraintDefinition propertyConstraint : propertyConstraints)
                    {
                        result.append(propertyConstraint.getName().toPrefixString());
                        result.append(", ");
                    }
                    
                    result.delete(result.length() - ", ".length(), result.length());
                    result.append(")");
                }
            }
        }
        else
        {
            result.append("\n\t\t\t\t\t<none>");
        }
        
        result.append("\n\t\t\t\tAssociations:");
        Map<QName, AssociationDefinition> associations = definition.getAssociations();
        if (associations != null && associations.size() > 0)
        {
            for (QName associationName : associations.keySet())
            {
                AssociationDefinition associationDefinition = associations.get(associationName);
                
                result.append("\n\t\t\t\t\t");
                result.append(associationName.toPrefixString());
                
                result.append(associationDefinition.isChild() ? " (parent/child)" : " (peer)");
                
                result.append(" (source: ");
                result.append(associationDefinition.getSourceClass().getName().toPrefixString());
                result.append(")");
                
                result.append(" (target: ");
                result.append(associationDefinition.getTargetClass().getName().toPrefixString());
                result.append(")");
            }
        }
        else
        {
            result.append("\n\t\t\t\t\t<none>");
        }
    }
    
    return(result == null ? null : result.toString());
}
 
Example 16
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Checks if the given property definition refers to a field that can be destructured in parts.
 * A field can be destructured only if:
 *
 * <ul>
 *     <li>It is not multivalued</li>
 *     <li>Destructuring is not disabled in configuration</li>
 *     <li>Its data type is {@link DataTypeDefinition#DATE} or {@link DataTypeDefinition#DATETIME}</li>
 * </ul>
 */
boolean canBeDestructured(PropertyDefinition definition, String fieldName)
{
    return !definition.isMultiValued() &&
            fieldName != null &&
            fieldName.contains("@") && // avoid static date/datetime fields
            dateFieldDestructuringHasBeenEnabledOnThisInstance &&
            (definition.getDataType().getName().equals(DataTypeDefinition.DATETIME) ||
                    definition.getDataType().getName().equals(DataTypeDefinition.DATE));
}