public static void addCommonSchemaData()

in sdk/appcenter/src/main/java/com/microsoft/appcenter/ingestion/models/one/CommonSchemaDataUtils.java [53:150]


    public static void addCommonSchemaData(List<TypedProperty> properties, CommonSchemaLog dest) {
        if (properties == null) {
            return;
        }
        try {

            /* Part B and C are mixed into the same top level data property. */
            Data data = new Data();
            dest.setData(data);

            /* We also build Part A metadata extension at the same time to reflect the data. */
            MetadataExtension metadata = new MetadataExtension();
            for (TypedProperty property : properties) {

                /* Validate property and get type. */
                Object value;
                try {
                    value = validateProperty(property);
                } catch (IllegalArgumentException e) {
                    AppCenterLog.warn(LOG_TAG, e.getMessage());
                    continue;
                }

                /* Get metadata type. */
                Integer metadataType = getMetadataType(property);

                /* Split property name by dot. */
                String key = property.getName();
                String[] keys = key.split("\\.", -1);
                int lastIndex = keys.length - 1;

                /* Handle all intermediate keys. */
                JSONObject destProperties = data.getProperties();
                JSONObject destMetadata = metadata.getMetadata();
                for (int i = 0; i < lastIndex; i++) {

                    /* Add data sub object. */
                    String subKey = keys[i];
                    JSONObject subDataObject = destProperties.optJSONObject(subKey);
                    if (subDataObject == null) {
                        if (destProperties.has(subKey)) {
                            AppCenterLog.warn(LOG_TAG, "Property key '" + subKey + "' already has a value, the old value will be overridden.");
                        }

                        /* Add sub data intermediate object. */
                        subDataObject = new JSONObject();
                        destProperties.put(subKey, subDataObject);
                    }
                    destProperties = subDataObject;

                    /* Handle metadata. */
                    destMetadata = addIntermediateMetadata(destMetadata, subKey);
                }

                /* Handle the last key for data, the leaf. */
                String lastKey = keys[lastIndex];
                if (destProperties.has(lastKey)) {
                    AppCenterLog.warn(LOG_TAG, "Property key '" + lastKey + "' already has a value, the old value will be overridden.");
                }
                destProperties.put(lastKey, value);

                /* Handle the last key for meta-data, the leaf. */
                addLeafMetadata(metadataType, destMetadata, lastKey);
            }

            /* Warn/cleanup if baseData and baseType are not paired. */
            JSONObject dataObject = data.getProperties();
            String baseType = dataObject.optString(BASE_TYPE, null);
            JSONObject baseData = dataObject.optJSONObject(BASE_DATA);
            if (baseType == null && baseData != null) {

                /* Discard unpaired data and metadata. */
                AppCenterLog.warn(LOG_TAG, "baseData was set but baseType is missing.");
                dataObject.remove(BASE_DATA);
                JSONObject baseMetaData = metadata.getMetadata().optJSONObject(METADATA_FIELDS);

                /* baseMetaData is always non null as baseData has at least 1 sub object and not cleaned up yet if empty. */
                baseMetaData.remove(BASE_DATA);
            }
            if (baseType != null && baseData == null) {

                /* Discard unpaired base type. */
                AppCenterLog.warn(LOG_TAG, "baseType was set but baseData is missing.");
                dataObject.remove(BASE_TYPE);
            }

            /* Add metadata extension only if not empty after cleanup. */
            if (!cleanUpEmptyObjectsInMetadata(metadata.getMetadata())) {
                if (dest.getExt() == null) {
                    dest.setExt(new Extensions());
                }
                dest.getExt().setMetadata(metadata);
            }
        } catch (JSONException ignore) {

            /* Can only happen with NaN or Infinite but this is already checked before. */
        }
    }