Search in sources :

Example 6 with ApiVersion

use of it.niedermann.owncloud.notes.shared.model.ApiVersion in project nextcloud-notes by stefan-niedermann.

the class Migration_22_23 method sanitizeApiVersion.

@Nullable
public static String sanitizeApiVersion(@Nullable String raw) {
    if (TextUtils.isEmpty(raw)) {
        return null;
    }
    JSONArray a;
    try {
        a = new JSONArray(raw);
    } catch (JSONException e) {
        try {
            a = new JSONArray("[" + raw + "]");
        } catch (JSONException e1) {
            return null;
        }
    }
    final var result = new ArrayList<ApiVersion>();
    for (int i = 0; i < a.length(); i++) {
        try {
            final var version = ApiVersion.of(a.getString(i));
            if (version.getMajor() != 0 || version.getMinor() != 0) {
                result.add(version);
            }
        } catch (Exception ignored) {
        }
    }
    if (result.isEmpty()) {
        return null;
    }
    return "[" + result.stream().filter(Objects::nonNull).map(v -> v.getMajor() + "." + v.getMinor()).collect(Collectors.joining(",")) + "]";
}
Also used : OnConflictStrategy(androidx.room.OnConflictStrategy) NonNull(androidx.annotation.NonNull) Collection(java.util.Collection) TextUtils(android.text.TextUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) JSONException(org.json.JSONException) Nullable(androidx.annotation.Nullable) SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) ApiProvider(it.niedermann.owncloud.notes.persistence.ApiProvider) ContentValues(android.content.ContentValues) ApiVersion(it.niedermann.owncloud.notes.shared.model.ApiVersion) Migration(androidx.room.migration.Migration) JSONArray(org.json.JSONArray) Account(it.niedermann.owncloud.notes.persistence.entity.Account) Cursor(android.database.Cursor) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) Objects(java.util.Objects) JSONException(org.json.JSONException) JSONException(org.json.JSONException) Nullable(androidx.annotation.Nullable)

Aggregations

ApiVersion (it.niedermann.owncloud.notes.shared.model.ApiVersion)6 Test (org.junit.Test)4 Nullable (androidx.annotation.Nullable)2 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 TextUtils (android.text.TextUtils)1 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 OnConflictStrategy (androidx.room.OnConflictStrategy)1 Migration (androidx.room.migration.Migration)1 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)1 ApiProvider (it.niedermann.owncloud.notes.persistence.ApiProvider)1 Account (it.niedermann.owncloud.notes.persistence.entity.Account)1 Note (it.niedermann.owncloud.notes.persistence.entity.Note)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1