mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Save Wikidata entity ID in contributions DB (#2317)
This commit is contained in:
parent
dc5bca113b
commit
4bbbfc839b
3 changed files with 51 additions and 16 deletions
|
|
@ -16,8 +16,10 @@ import javax.inject.Named;
|
|||
import javax.inject.Provider;
|
||||
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.utils.StringUtils;
|
||||
|
||||
import static fr.free.nrw.commons.contributions.ContributionDao.Table.ALL_FIELDS;
|
||||
import static fr.free.nrw.commons.contributions.ContributionDao.Table.COLUMN_WIKI_DATA_ENTITY_ID;
|
||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.uriForId;
|
||||
|
||||
|
|
@ -109,6 +111,7 @@ public class ContributionDao {
|
|||
cv.put(Table.COLUMN_WIDTH, contribution.getWidth());
|
||||
cv.put(Table.COLUMN_HEIGHT, contribution.getHeight());
|
||||
cv.put(Table.COLUMN_LICENSE, contribution.getLicense());
|
||||
cv.put(Table.COLUMN_WIKI_DATA_ENTITY_ID, contribution.getWikiDataEntityId());
|
||||
return cv;
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +125,7 @@ public class ContributionDao {
|
|||
} else {
|
||||
index = cursor.getColumnIndex(Table.COLUMN_LICENSE);
|
||||
}
|
||||
return new Contribution(
|
||||
Contribution contribution = new Contribution(
|
||||
uriForId(cursor.getInt(cursor.getColumnIndex(Table.COLUMN_ID))),
|
||||
cursor.getString(cursor.getColumnIndex(Table.COLUMN_FILENAME)),
|
||||
parseUri(cursor.getString(cursor.getColumnIndex(Table.COLUMN_LOCAL_URI))),
|
||||
|
|
@ -140,6 +143,13 @@ public class ContributionDao {
|
|||
cursor.getInt(cursor.getColumnIndex(Table.COLUMN_HEIGHT)),
|
||||
cursor.getString(index)
|
||||
);
|
||||
|
||||
String wikidataEntityId = cursor.getString(cursor.getColumnIndex(COLUMN_WIKI_DATA_ENTITY_ID));
|
||||
if (!StringUtils.isNullOrWhiteSpace(wikidataEntityId)) {
|
||||
contribution.setWikiDataEntityId(wikidataEntityId);
|
||||
}
|
||||
|
||||
return contribution;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -174,6 +184,7 @@ public class ContributionDao {
|
|||
public static final String COLUMN_WIDTH = "width";
|
||||
public static final String COLUMN_HEIGHT = "height";
|
||||
public static final String COLUMN_LICENSE = "license";
|
||||
public static final String COLUMN_WIKI_DATA_ENTITY_ID = "wikidataEntityID";
|
||||
|
||||
// NOTE! KEEP IN SAME ORDER AS THEY ARE DEFINED UP THERE. HELPS HARD CODE COLUMN INDICES.
|
||||
public static final String[] ALL_FIELDS = {
|
||||
|
|
@ -192,7 +203,8 @@ public class ContributionDao {
|
|||
COLUMN_MULTIPLE,
|
||||
COLUMN_WIDTH,
|
||||
COLUMN_HEIGHT,
|
||||
COLUMN_LICENSE
|
||||
COLUMN_LICENSE,
|
||||
COLUMN_WIKI_DATA_ENTITY_ID
|
||||
};
|
||||
|
||||
public static final String DROP_TABLE_STATEMENT = "DROP TABLE IF EXISTS " + TABLE_NAME;
|
||||
|
|
@ -213,7 +225,8 @@ public class ContributionDao {
|
|||
+ "multiple INTEGER,"
|
||||
+ "width INTEGER,"
|
||||
+ "height INTEGER,"
|
||||
+ "LICENSE STRING"
|
||||
+ "LICENSE STRING,"
|
||||
+ "wikidataEntityID STRING"
|
||||
+ ");";
|
||||
|
||||
// Upgrade from version 1 ->
|
||||
|
|
@ -232,6 +245,9 @@ public class ContributionDao {
|
|||
static final String ADD_LICENSE_FIELD = "ALTER TABLE " + TABLE_NAME + " ADD COLUMN license STRING;";
|
||||
static final String SET_DEFAULT_LICENSE = "UPDATE " + TABLE_NAME + " SET license='" + Prefs.Licenses.CC_BY_SA_3 + "';";
|
||||
|
||||
// Upgrade from version 8 ->
|
||||
static final String ADD_WIKI_DATA_ENTITY_ID_FIELD = "ALTER TABLE " + TABLE_NAME + " ADD COLUMN wikidataEntityID STRING;";
|
||||
|
||||
|
||||
public static void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(CREATE_TABLE_STATEMENT);
|
||||
|
|
@ -284,6 +300,13 @@ public class ContributionDao {
|
|||
onUpdate(db, from, to);
|
||||
return;
|
||||
}
|
||||
if (from == 8) {
|
||||
// Added place field
|
||||
db.execSQL(ADD_WIKI_DATA_ENTITY_ID_FIELD);
|
||||
from++;
|
||||
onUpdate(db, from, to);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import fr.free.nrw.commons.modifications.ModifierSequenceDao;
|
|||
public class DBOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static final String DATABASE_NAME = "commons.db";
|
||||
private static final int DATABASE_VERSION = 8;
|
||||
private static final int DATABASE_VERSION = 9;
|
||||
|
||||
/**
|
||||
* Do not use directly - @Inject an instance where it's needed and let
|
||||
|
|
|
|||
|
|
@ -119,6 +119,15 @@ class ContributionDaoTest {
|
|||
verifyZeroInteractions(database)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun migrateTableVersionFrom_v8_to_v9() {
|
||||
Table.onUpdate(database, 8, 9)
|
||||
// Table changed in version 9
|
||||
inOrder(database) {
|
||||
verify<SQLiteDatabase>(database).execSQL(Table.ADD_WIKI_DATA_ENTITY_ID_FIELD)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun saveNewContribution_nonNullFields() {
|
||||
whenever(client.insert(isA(), isA())).thenReturn(contentUri)
|
||||
|
|
@ -328,19 +337,22 @@ class ContributionDaoTest {
|
|||
MatrixCursor(Table.ALL_FIELDS, 1).apply {
|
||||
addRow(listOf("111", "file", localUri, "image",
|
||||
created, STATE_QUEUED, 222L, uploaded, 88L, SOURCE_GALLERY, "desc",
|
||||
"create", if (multiple) 1 else 0, 640, 480, "007"))
|
||||
"create", if (multiple) 1 else 0, 640, 480, "007", "Q1"))
|
||||
moveToFirst()
|
||||
}
|
||||
|
||||
private fun createContribution(isMultiple: Boolean, localUri: Uri?, imageUrl: String?, dateUploaded: Date?, filename: String?) =
|
||||
Contribution(localUri, imageUrl, filename, "desc", 222L, Date(321L), dateUploaded,
|
||||
"create", "edit", "coords").apply {
|
||||
state = STATE_COMPLETED
|
||||
transferred = 333L
|
||||
source = SOURCE_CAMERA
|
||||
license = "007"
|
||||
multiple = isMultiple
|
||||
width = 640
|
||||
height = 480 // VGA should be enough for anyone, right?
|
||||
}
|
||||
private fun createContribution(isMultiple: Boolean, localUri: Uri?, imageUrl: String?, dateUploaded: Date?, filename: String?): Contribution {
|
||||
val contribution = Contribution(localUri, imageUrl, filename, "desc", 222L, Date(321L), dateUploaded,
|
||||
"create", "edit", "coords").apply {
|
||||
state = STATE_COMPLETED
|
||||
transferred = 333L
|
||||
source = SOURCE_CAMERA
|
||||
license = "007"
|
||||
multiple = isMultiple
|
||||
width = 640
|
||||
height = 480 // VGA should be enough for anyone, right?
|
||||
}
|
||||
contribution.wikiDataEntityId = "Q1"
|
||||
return contribution
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue