Search in sources :

Example 56 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project SearchServices by Alfresco.

the class Solr4QueryParser method createIsNullQuery.

protected Query createIsNullQuery(String queryText, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException {
    PropertyDefinition pd = QueryParserUtils.matchPropertyDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, queryText);
    if (pd != null) {
        return createTermQuery(FIELD_NULLPROPERTIES, pd.getName().toString());
    } else {
        BooleanQuery.Builder query = new BooleanQuery.Builder();
        Query presenceQuery = getWildcardQuery(queryText, "*");
        if (presenceQuery != null) {
            query.add(createIsNodeQuery("T"), Occur.MUST);
            query.add(presenceQuery, Occur.MUST_NOT);
        }
        return query.build();
    }
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Builder(org.apache.lucene.search.BooleanQuery.Builder) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) Builder(org.apache.lucene.search.BooleanQuery.Builder)

Example 57 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project SearchServices by Alfresco.

the class Solr4QueryParser method attributeQueryBuilder.

private Query attributeQueryBuilder(String field, String queryText, SubQuery subQueryBuilder, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException {
    // TODO: Fix duplicate token generation for mltext, content and text.
    // -locale expansion here and in tokeisation -> duplicates
    // Get type info etc
    // TODO: additional suffixes
    Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(field);
    String expandedFieldName = null;
    QName propertyQName;
    PropertyDefinition propertyDef = QueryParserUtils.matchPropertyDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, fieldNameAndEnding.getFirst());
    IndexTokenisationMode tokenisationMode = IndexTokenisationMode.TRUE;
    if (propertyDef != null) {
        tokenisationMode = propertyDef.getIndexTokenisationMode();
        if (tokenisationMode == null) {
            tokenisationMode = IndexTokenisationMode.TRUE;
        }
        propertyQName = propertyDef.getName();
    } else {
        expandedFieldName = expandAttributeFieldName(field);
        propertyQName = QName.createQName(fieldNameAndEnding.getFirst());
    }
    if (isAllStar(queryText)) {
        return createTermQuery(FIELD_PROPERTIES, propertyQName.toString());
    }
    if (luceneFunction != LuceneFunction.FIELD) {
        if ((tokenisationMode == IndexTokenisationMode.FALSE) || (tokenisationMode == IndexTokenisationMode.BOTH)) {
            if (luceneFunction == LuceneFunction.LOWER) {
                if (false == queryText.toLowerCase().equals(queryText)) {
                    return createNoMatchQuery();
                }
            }
            if (luceneFunction == LuceneFunction.UPPER) {
                if (false == queryText.toUpperCase().equals(queryText)) {
                    return createNoMatchQuery();
                }
            }
            return functionQueryBuilder(expandedFieldName, fieldNameAndEnding.getSecond(), propertyQName, propertyDef, tokenisationMode, queryText, luceneFunction);
        }
    }
    // Mime type
    if (fieldNameAndEnding.getSecond().equals(FIELD_MIMETYPE_SUFFIX)) {
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))) {
            return subQueryBuilder.getQuery(AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyQName, ContentFieldType.MIMETYPE, FieldUse.ID).getFields().get(0).getField(), queryText, analysisMode, luceneFunction);
        }
    } else if (fieldNameAndEnding.getSecond().equals(FIELD_SIZE_SUFFIX)) {
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))) {
            return subQueryBuilder.getQuery(AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyQName, ContentFieldType.SIZE, FieldUse.ID).getFields().get(0).getField(), queryText, analysisMode, luceneFunction);
        }
    } else if (fieldNameAndEnding.getSecond().equals(FIELD_LOCALE_SUFFIX)) {
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))) {
            return subQueryBuilder.getQuery(AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyQName, ContentFieldType.LOCALE, FieldUse.ID).getFields().get(0).getField(), queryText, analysisMode, luceneFunction);
        }
    } else if (fieldNameAndEnding.getSecond().equals(FIELD_ENCODING_SUFFIX)) {
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))) {
            return subQueryBuilder.getQuery(AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyQName, ContentFieldType.ENCODING, FieldUse.ID).getFields().get(0).getField(), queryText, analysisMode, luceneFunction);
        }
    } else if (fieldNameAndEnding.getSecond().equals(FIELD_TRANSFORMATION_STATUS_SUFFIX)) {
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))) {
            return subQueryBuilder.getQuery(AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyQName, ContentFieldType.TRANSFORMATION_STATUS, FieldUse.ID).getFields().get(0).getField(), queryText, analysisMode, luceneFunction);
        }
    } else if (fieldNameAndEnding.getSecond().equals(FIELD_TRANSFORMATION_TIME_SUFFIX)) {
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))) {
            return subQueryBuilder.getQuery(AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyQName, ContentFieldType.TRANSFORMATION_TIME, FieldUse.ID).getFields().get(0).getField(), queryText, analysisMode, luceneFunction);
        }
    } else if (fieldNameAndEnding.getSecond().equals(FIELD_TRANSFORMATION_EXCEPTION_SUFFIX)) {
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))) {
            return subQueryBuilder.getQuery(AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyQName, ContentFieldType.TRANSFORMATION_EXCEPTION, FieldUse.ID).getFields().get(0).getField(), queryText, analysisMode, luceneFunction);
        }
    }
    if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT))) {
        // Build a sub query for each locale and or the results together -
        // the analysis will take care of
        // cross language matching for each entry
        BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
        List<Locale> locales = searchParameters.getLocales();
        List<Locale> expandedLocales = new ArrayList<Locale>();
        for (Locale locale : (((locales == null) || (locales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : locales)) {
            expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, false));
        }
        for (Locale locale : (((expandedLocales == null) || (expandedLocales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : expandedLocales)) {
            addMLTextAttributeQuery(field, propertyDef, queryText, subQueryBuilder, analysisMode, luceneFunction, expandedFieldName, propertyDef, tokenisationMode, booleanQuery, locale);
        }
        return getNonEmptyBooleanQuery(booleanQuery.build());
    } else // Content
    if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))) {
        // Identifier request are ignored for content
        // Build a sub query for each locale and or the results together -
        // - add an explicit condition for the locale
        List<Locale> locales = searchParameters.getLocales();
        List<Locale> expandedLocales = new ArrayList<Locale>();
        for (Locale locale : (((locales == null) || (locales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : locales)) {
            expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, addContentCrossLocaleWildcards()));
        }
        return addContentAttributeQuery(propertyDef, queryText, subQueryBuilder, analysisMode, luceneFunction, expandedFieldName, expandedLocales);
    } else if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT))) {
        // if (propertyQName.equals(ContentModel.PROP_USER_USERNAME) ||
        // propertyQName.equals(ContentModel.PROP_USERNAME) ||
        // propertyQName.equals(ContentModel.PROP_AUTHORITY_NAME))
        // {
        // // nasty work around for solr support for user and group look up
        // as we can not support lowercased identifiers in the model
        // if(isLucene())
        // {
        // return subQueryBuilder.getQuery(expandedFieldName, queryText,
        // analysisMode, luceneFunction);
        // }
        // }
        boolean withWildCards = propertyQName.equals(ContentModel.PROP_USER_USERNAME) || propertyQName.equals(ContentModel.PROP_USERNAME) || propertyQName.equals(ContentModel.PROP_AUTHORITY_NAME);
        BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
        List<Locale> locales = searchParameters.getLocales();
        List<Locale> expandedLocales = new ArrayList<Locale>();
        for (Locale locale : (((locales == null) || (locales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : locales)) {
            expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, withWildCards));
        }
        for (Locale locale : (((expandedLocales == null) || (expandedLocales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : expandedLocales)) {
            Locale fixedLocale = locale;
            if (fixedLocale.getLanguage().equals("*")) {
                fixedLocale = new Locale("??");
            }
            addTextAttributeQuery(field, propertyDef, queryText, subQueryBuilder, analysisMode, luceneFunction, expandedFieldName, tokenisationMode, booleanQuery, fixedLocale);
        }
        return getNonEmptyBooleanQuery(booleanQuery.build());
    } else {
        // Date does not support like
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME))) {
            if (analysisMode == AnalysisMode.LIKE) {
                throw new UnsupportedOperationException("Wild cards are not supported for the datetime type");
            }
        }
        // expand date for loose date parsing
        if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME) || propertyDef.getDataType().getName().equals(DataTypeDefinition.DATE))) {
            Pair<Date, Integer> dateAndResolution = parseDateString(queryText);
            BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
            IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), null, FieldUse.FTS);
            for (FieldInstance instance : indexedField.getFields()) {
                if (dateAndResolution != null) {
                    Query query = newRangeQuery(instance.getField(), getDateStart(dateAndResolution), getDateEnd(dateAndResolution), true, true);
                    if (query != null) {
                        bQuery.add(query, Occur.SHOULD);
                    }
                } else {
                    Query query = subQueryBuilder.getQuery(instance.getField(), queryText, AnalysisMode.DEFAULT, luceneFunction);
                    if (query != null) {
                        bQuery.add(query, Occur.SHOULD);
                    }
                }
            }
            if (bQuery.build().clauses().size() > 0) {
                return bQuery.build();
            } else {
                return createNoMatchQuery();
            }
        }
        if ((propertyDef != null) && (tenantService.isTenantUser()) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.NODE_REF)) && (queryText.contains(StoreRef.URI_FILLER))) {
            // ALF-6202
            queryText = tenantService.getName(new NodeRef(queryText)).toString();
        }
        // Dates are not special in this case
        if (propertyDef != null) {
            BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
            IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), null, FieldUse.FTS);
            for (FieldInstance instance : indexedField.getFields()) {
                Query query = subQueryBuilder.getQuery(instance.getField(), queryText, AnalysisMode.DEFAULT, luceneFunction);
                if (query != null) {
                    bQuery.add(query, Occur.SHOULD);
                }
            }
            if (bQuery.build().clauses().size() > 0) {
                return bQuery.build();
            } else {
                return createNoMatchQuery();
            }
        } else {
            Query query = subQueryBuilder.getQuery(expandedFieldName, queryText, AnalysisMode.DEFAULT, luceneFunction);
            if (query != null) {
                return query;
            } else {
                return createNoMatchQuery();
            }
        }
    }
}
Also used : Locale(java.util.Locale) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) QName(org.alfresco.service.namespace.QName) IndexedField(org.alfresco.solr.AlfrescoSolrDataModel.IndexedField) Builder(org.apache.lucene.search.BooleanQuery.Builder) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) IndexTokenisationMode(org.alfresco.repo.dictionary.IndexTokenisationMode) Builder(org.apache.lucene.search.BooleanQuery.Builder) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) LinkedList(java.util.LinkedList) FieldInstance(org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance)

Example 58 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method convertToCustomModelProperty.

private List<CustomModelProperty> convertToCustomModelProperty(ClassDefinition classDefinition, boolean includeInherited) {
    Collection<PropertyDefinition> ownProperties = null;
    ClassDefinition parentDef = classDefinition.getParentClassDefinition();
    if (!includeInherited && parentDef != null) {
        // Remove inherited properties
        ownProperties = removeRightEntries(classDefinition.getProperties(), parentDef.getProperties()).values();
    } else {
        ownProperties = classDefinition.getProperties().values();
    }
    List<CustomModelProperty> customProperties = new ArrayList<>(ownProperties.size());
    for (PropertyDefinition propDef : ownProperties) {
        customProperties.add(new CustomModelProperty(propDef, dictionaryService));
    }
    return customProperties;
}
Also used : ArrayList(java.util.ArrayList) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty)

Example 59 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.

the class DeclarativeSpreadsheetWebScript method generateSpreadsheet.

/**
 * Generates the spreadsheet, based on the properties in the header
 *  and a callback for the body.
 */
public void generateSpreadsheet(Object resource, String format, WebScriptRequest req, Status status, Map<String, Object> model) throws IOException {
    Pattern qnameMunger = Pattern.compile("([A-Z][a-z]+)([A-Z].*)");
    String delimiterParam = req.getParameter(PARAM_REQ_DELIMITER);
    CSVStrategy reqCSVstrategy = null;
    if (delimiterParam != null && !delimiterParam.isEmpty()) {
        reqCSVstrategy = new CSVStrategy(delimiterParam.charAt(0), '"', CSVStrategy.COMMENTS_DISABLED);
    }
    // Build up the details of the header
    List<Pair<QName, Boolean>> propertyDetails = buildPropertiesForHeader(resource, format, req);
    String[] headings = new String[propertyDetails.size()];
    String[] descriptions = new String[propertyDetails.size()];
    boolean[] required = new boolean[propertyDetails.size()];
    for (int i = 0; i < headings.length; i++) {
        Pair<QName, Boolean> property = propertyDetails.get(i);
        if (property == null || property.getFirst() == null) {
            headings[i] = "";
            required[i] = false;
        } else {
            QName column = property.getFirst();
            required[i] = property.getSecond();
            // Ask the dictionary service nicely for the details
            PropertyDefinition pd = dictionaryService.getProperty(column);
            if (pd != null && pd.getTitle(dictionaryService) != null) {
                // Use the friendly titles, which may even be localised!
                headings[i] = pd.getTitle(dictionaryService);
                descriptions[i] = pd.getDescription(dictionaryService);
            } else {
                // Nothing friendly found, try to munge the raw qname into
                // something we can show to a user...
                String raw = column.getLocalName();
                raw = raw.substring(0, 1).toUpperCase() + raw.substring(1);
                Matcher m = qnameMunger.matcher(raw);
                if (m.matches()) {
                    headings[i] = m.group(1) + " " + m.group(2);
                } else {
                    headings[i] = raw;
                }
            }
        }
    }
    // Build a list of just the properties
    List<QName> properties = new ArrayList<QName>(propertyDetails.size());
    for (Pair<QName, Boolean> p : propertyDetails) {
        QName qn = null;
        if (p != null) {
            qn = p.getFirst();
        }
        properties.add(qn);
    }
    // Output
    if ("csv".equals(format)) {
        StringWriter sw = new StringWriter();
        CSVPrinter csv = new CSVPrinter(sw, reqCSVstrategy != null ? reqCSVstrategy : getCsvStrategy());
        csv.println(headings);
        populateBody(resource, csv, properties);
        model.put(MODEL_CSV, sw.toString());
    } else {
        Workbook wb;
        if ("xlsx".equals(format)) {
            wb = new XSSFWorkbook();
        // TODO Properties
        } else {
            wb = new HSSFWorkbook();
        // TODO Properties
        }
        // Add our header row
        Sheet sheet = wb.createSheet("Export");
        Row hr = sheet.createRow(0);
        sheet.createFreezePane(0, 1);
        Font fb = wb.createFont();
        fb.setBold(true);
        Font fi = wb.createFont();
        fi.setBold(true);
        fi.setItalic(true);
        CellStyle csReq = wb.createCellStyle();
        csReq.setFont(fb);
        CellStyle csOpt = wb.createCellStyle();
        csOpt.setFont(fi);
        // Populate the header
        Drawing draw = null;
        for (int i = 0; i < headings.length; i++) {
            Cell c = hr.createCell(i);
            c.setCellValue(headings[i]);
            if (required[i]) {
                c.setCellStyle(csReq);
            } else {
                c.setCellStyle(csOpt);
            }
            if (headings[i].length() == 0) {
                sheet.setColumnWidth(i, 3 * 250);
            } else {
                sheet.setColumnWidth(i, 18 * 250);
            }
            if (descriptions[i] != null && descriptions[i].length() > 0) {
                // Add a description for it too
                if (draw == null) {
                    draw = sheet.createDrawingPatriarch();
                }
                ClientAnchor ca = wb.getCreationHelper().createClientAnchor();
                ca.setCol1(c.getColumnIndex());
                ca.setCol2(c.getColumnIndex() + 1);
                ca.setRow1(hr.getRowNum());
                ca.setRow2(hr.getRowNum() + 2);
                Comment cmt = draw.createCellComment(ca);
                cmt.setAuthor("");
                cmt.setString(wb.getCreationHelper().createRichTextString(descriptions[i]));
                cmt.setVisible(false);
                c.setCellComment(cmt);
            }
        }
        // Have the contents populated
        populateBody(resource, wb, sheet, properties);
        // Save it for the template
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        wb.write(baos);
        model.put(MODEL_EXCEL, baos.toByteArray());
    }
}
Also used : Drawing(org.apache.poi.ss.usermodel.Drawing) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Font(org.apache.poi.ss.usermodel.Font) CSVPrinter(org.apache.commons.csv.CSVPrinter) StringWriter(java.io.StringWriter) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Cell(org.apache.poi.ss.usermodel.Cell) Pair(org.alfresco.util.Pair) Pattern(java.util.regex.Pattern) Comment(org.apache.poi.ss.usermodel.Comment) QName(org.alfresco.service.namespace.QName) CSVStrategy(org.apache.commons.csv.CSVStrategy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 60 with PropertyDefinition

use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.

the class SOLRSerializer method serialize.

@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);
    }
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) PlatformRuntimeException(org.springframework.extensions.surf.exception.PlatformRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONObject(org.json.JSONObject) MLText(org.alfresco.service.cmr.repository.MLText) Collection(java.util.Collection)

Aggregations

PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)77 QName (org.alfresco.service.namespace.QName)51 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)24 NodeRef (org.alfresco.service.cmr.repository.NodeRef)16 Map (java.util.Map)15 Serializable (java.io.Serializable)14 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)11 ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)11 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)9 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)9 Collection (java.util.Collection)7 List (java.util.List)7 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)7 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)7 BooleanQuery (org.apache.lucene.search.BooleanQuery)7 Builder (org.apache.lucene.search.BooleanQuery.Builder)7 Constraint (org.alfresco.service.cmr.dictionary.Constraint)6 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)6 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)6