mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Issue-5662-kotlinstyle (#5833)
* *.kt: bulk correction of formatting using ktlint --format * *.kt: replace wildcard imports and second stage auto format ktlint --format * QuizQuestionTest.kt: modified property names to camel case to meet ktlint standard * LevelControllerTest.kt: modified property names to camel case to meet ktlint standard * QuizActivityUnitTest.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: modified property names to camel case to meet ktlint standard * UploadWorker.kt: modified property names to camel case to meet ktlint standard * UploadClient.kt: modified property names to camel case to meet ktlint standard * BasePagingPresenter.kt: modified property names to camel case to meet ktlint standard * DescriptionEditActivity.kt: modified property names to camel case to meet ktlint standard * OnSwipeTouchListener.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: corrected excessive line length to meet ktlint standard * DepictedItem.kt: corrected property name format and catch format to for ktlint standard * UploadCategoryAdapter.kt: corrected class definition format to meet ktlint standard * CustomSelectorActivity.kt: reformatted function names to first letter lowercase to meet ktlint standard * MediaDetailFragmentUnitTests.kt: fix string literal indentation to meet ktlint standard * NotForUploadDao.kt: file renamed to match class name, new file NotForUploadStatusDao.kt * UploadedDao.kt: file renamed to match class name, new file UploadedStatusDao.kt * Urls.kt: fixed excessive line length for ktLint standard * Snak_partial.kt & Statement_partial.kt: refactored to remove underscores in class names to meet ktLint standard * *.kt: fixed consecutive KDOC error for ktLint * PageableBaseDataSourceTest.kt & UploadPresenterTest.kt: fixed excessive line lengths to meet ktLint standard * CheckboxTriStatesTest.kt: renamed file to match class name to meet ktLint standard * .kt: resolved backing-property-naming error in ktLint, made matching properties public, matched names and refactored * TestConnectionFactory.kt: fixed property naming to adhere to ktLint standard
This commit is contained in:
parent
950539c55c
commit
2d82a430c4
405 changed files with 11032 additions and 9137 deletions
|
|
@ -5,20 +5,27 @@ import retrofit2.Retrofit
|
|||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
class CommonsServiceFactory(private val okHttpClient: OkHttpClient) {
|
||||
|
||||
class CommonsServiceFactory(
|
||||
private val okHttpClient: OkHttpClient,
|
||||
) {
|
||||
private val builder: Retrofit.Builder by lazy {
|
||||
// All instances of retrofit share this configuration, but create it lazily
|
||||
Retrofit.Builder().client(okHttpClient)
|
||||
Retrofit
|
||||
.Builder()
|
||||
.client(okHttpClient)
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.addConverterFactory(GsonConverterFactory.create(GsonUtil.getDefaultGson()))
|
||||
}
|
||||
|
||||
private val retrofitCache: MutableMap<String, Retrofit> = mutableMapOf()
|
||||
|
||||
fun <T : Any> create(baseUrl: String, service: Class<T>): T = retrofitCache.getOrPut(baseUrl) {
|
||||
// Cache instances of retrofit based on API backend
|
||||
builder.baseUrl(baseUrl).build()
|
||||
}.create(service)
|
||||
|
||||
}
|
||||
fun <T : Any> create(
|
||||
baseUrl: String,
|
||||
service: Class<T>,
|
||||
): T =
|
||||
retrofitCache
|
||||
.getOrPut(baseUrl) {
|
||||
// Cache instances of retrofit based on API backend
|
||||
builder.baseUrl(baseUrl).build()
|
||||
}.create(service)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,65 +16,84 @@ import javax.inject.Singleton
|
|||
* Wikibase Client for calling WikiBase APIs
|
||||
*/
|
||||
@Singleton
|
||||
class WikiBaseClient @Inject constructor(
|
||||
private val wikiBaseInterface: WikiBaseInterface,
|
||||
@param:Named(NetworkingModule.NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient
|
||||
) {
|
||||
fun postEditEntity(fileEntityId: String?, data: String?): Observable<Boolean> {
|
||||
return csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface.postEditEntity(fileEntityId!!, editToken, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
}
|
||||
class WikiBaseClient
|
||||
@Inject
|
||||
constructor(
|
||||
private val wikiBaseInterface: WikiBaseInterface,
|
||||
@param:Named(NetworkingModule.NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient,
|
||||
) {
|
||||
fun postEditEntity(
|
||||
fileEntityId: String?,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postEditEntity(fileEntityId!!, editToken, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the server call for posting new depicts
|
||||
*
|
||||
* @param filename name of the file
|
||||
* @param data data of the depicts to be uploaded
|
||||
* @return Observable<Boolean>
|
||||
</Boolean> */
|
||||
fun postEditEntityByFilename(filename: String?, data: String?): Observable<Boolean> {
|
||||
return csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface.postEditEntityByFilename(filename!!, editToken, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Makes the server call for posting new depicts
|
||||
*
|
||||
* @param filename name of the file
|
||||
* @param data data of the depicts to be uploaded
|
||||
* @return Observable<Boolean>
|
||||
</Boolean> */
|
||||
fun postEditEntityByFilename(
|
||||
filename: String?,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postEditEntityByFilename(filename!!, editToken, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
fun getClaimIdsByProperty(fileEntityId: String, property: String ): Observable<List<String>> {
|
||||
return wikiBaseInterface.getClaimsByProperty(fileEntityId, property).map { claimsResponse ->
|
||||
claimsResponse.claims[property]?.mapNotNull { claim -> claim.id } ?: emptyList()
|
||||
}
|
||||
}
|
||||
fun getClaimIdsByProperty(
|
||||
fileEntityId: String,
|
||||
property: String,
|
||||
): Observable<List<String>> =
|
||||
wikiBaseInterface.getClaimsByProperty(fileEntityId, property).map { claimsResponse ->
|
||||
claimsResponse.claims[property]?.mapNotNull { claim -> claim.id } ?: emptyList()
|
||||
}
|
||||
|
||||
fun postDeleteClaims(entityId: String, data: String?): Observable<Boolean> {
|
||||
return csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface.postDeleteClaims(editToken, entityId, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
}
|
||||
fun postDeleteClaims(
|
||||
entityId: String,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postDeleteClaims(editToken, entityId, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
fun getFileEntityId(uploadResult: UploadResult): Observable<Long> {
|
||||
return wikiBaseInterface.getFileEntityId(uploadResult.createCanonicalFileName())
|
||||
.map { response: MwQueryResponse -> response.query()!!.pages()!![0].pageId().toLong() }
|
||||
}
|
||||
fun getFileEntityId(uploadResult: UploadResult): Observable<Long> =
|
||||
wikiBaseInterface
|
||||
.getFileEntityId(uploadResult.createCanonicalFileName())
|
||||
.map { response: MwQueryResponse ->
|
||||
response
|
||||
.query()!!
|
||||
.pages()!![0]
|
||||
.pageId()
|
||||
.toLong()
|
||||
}
|
||||
|
||||
fun addLabelsToWikidata(
|
||||
fileEntityId: Long,
|
||||
languageCode: String?,
|
||||
captionValue: String?
|
||||
): Observable<MwPostResponse> {
|
||||
return csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface.addLabelstoWikidata(
|
||||
PAGE_ID_PREFIX + fileEntityId,
|
||||
editToken,
|
||||
languageCode,
|
||||
captionValue
|
||||
)
|
||||
}
|
||||
}
|
||||
fun addLabelsToWikidata(
|
||||
fileEntityId: Long,
|
||||
languageCode: String?,
|
||||
captionValue: String?,
|
||||
): Observable<MwPostResponse> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface.addLabelstoWikidata(
|
||||
PAGE_ID_PREFIX + fileEntityId,
|
||||
editToken,
|
||||
languageCode,
|
||||
captionValue,
|
||||
)
|
||||
}
|
||||
|
||||
private fun csrfToken(): Observable<String> = Observable.fromCallable {
|
||||
csrfTokenClient.getTokenBlocking()
|
||||
private fun csrfToken(): Observable<String> =
|
||||
Observable.fromCallable {
|
||||
csrfTokenClient.getTokenBlocking()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,35 @@
|
|||
package fr.free.nrw.commons.wikidata
|
||||
|
||||
import com.google.gson.Gson
|
||||
import fr.free.nrw.commons.wikidata.model.Statement_partial
|
||||
import fr.free.nrw.commons.wikidata.model.StatementPartial
|
||||
import fr.free.nrw.commons.wikidata.model.WbCreateClaimResponse
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import io.reactivex.Observable
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class WikidataClient @Inject constructor(
|
||||
private val wikidataInterface: WikidataInterface,
|
||||
private val gson: Gson
|
||||
) {
|
||||
/**
|
||||
* Create wikidata claim to add P18 value
|
||||
*
|
||||
* @return revisionID of the edit
|
||||
*/
|
||||
fun setClaim(claim: Statement_partial?, tags: String?): Observable<Long> {
|
||||
return csrfToken().flatMap { csrfToken: String? ->
|
||||
wikidataInterface.postSetClaim(gson.toJson(claim), tags!!, csrfToken!!)
|
||||
}.map { mwPostResponse: WbCreateClaimResponse -> mwPostResponse.pageinfo.lastrevid }
|
||||
}
|
||||
class WikidataClient
|
||||
@Inject
|
||||
constructor(
|
||||
private val wikidataInterface: WikidataInterface,
|
||||
private val gson: Gson,
|
||||
) {
|
||||
/**
|
||||
* Create wikidata claim to add P18 value
|
||||
*
|
||||
* @return revisionID of the edit
|
||||
*/
|
||||
fun setClaim(
|
||||
claim: StatementPartial?,
|
||||
tags: String?,
|
||||
): Observable<Long> =
|
||||
csrfToken()
|
||||
.flatMap { csrfToken: String? ->
|
||||
wikidataInterface.postSetClaim(gson.toJson(claim), tags!!, csrfToken!!)
|
||||
}.map { mwPostResponse: WbCreateClaimResponse -> mwPostResponse.pageinfo.lastrevid }
|
||||
|
||||
/**
|
||||
* Get csrf token for wikidata edit
|
||||
*/
|
||||
private fun csrfToken(): Observable<String?> =
|
||||
wikidataInterface.getCsrfToken().map { it.query()?.csrfToken() }
|
||||
}
|
||||
/**
|
||||
* Get csrf token for wikidata edit
|
||||
*/
|
||||
private fun csrfToken(): Observable<String?> = wikidataInterface.getCsrfToken().map { it.query()?.csrfToken() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package fr.free.nrw.commons.wikidata
|
||||
|
||||
|
||||
enum class WikidataDisambiguationItems(val id: String) {
|
||||
DISAMBIGUATION_PAGE("Q4167410"), INTERNAL_ITEM("Q17442446"), CATEGORY("Q4167836");
|
||||
enum class WikidataDisambiguationItems(
|
||||
val id: String,
|
||||
) {
|
||||
DISAMBIGUATION_PAGE("Q4167410"),
|
||||
INTERNAL_ITEM("Q17442446"),
|
||||
CATEGORY("Q4167836"),
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun isDisambiguationItem(ids: List<String>) =
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ import fr.free.nrw.commons.wikidata.model.DataValue;
|
|||
import fr.free.nrw.commons.wikidata.model.DataValue.ValueString;
|
||||
import fr.free.nrw.commons.wikidata.model.EditClaim;
|
||||
import fr.free.nrw.commons.wikidata.model.RemoveClaim;
|
||||
import fr.free.nrw.commons.wikidata.model.Snak_partial;
|
||||
import fr.free.nrw.commons.wikidata.model.Statement_partial;
|
||||
import fr.free.nrw.commons.wikidata.model.SnakPartial;
|
||||
import fr.free.nrw.commons.wikidata.model.StatementPartial;
|
||||
import fr.free.nrw.commons.wikidata.model.WikiBaseMonolingualTextValue;
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwPostResponse;
|
||||
import io.reactivex.Observable;
|
||||
|
|
@ -198,19 +198,19 @@ public class WikidataEditService {
|
|||
|
||||
public Long addImageAndMediaLegends(final WikidataItem wikidataItem, final String fileName,
|
||||
final Map<String, String> captions) {
|
||||
final Snak_partial p18 = new Snak_partial("value",
|
||||
final SnakPartial p18 = new SnakPartial("value",
|
||||
WikidataProperties.IMAGE.getPropertyName(),
|
||||
new ValueString(fileName.replace("File:", "")));
|
||||
|
||||
final List<Snak_partial> snaks = new ArrayList<>();
|
||||
final List<SnakPartial> snaks = new ArrayList<>();
|
||||
for (final Map.Entry<String, String> entry : captions.entrySet()) {
|
||||
snaks.add(new Snak_partial("value",
|
||||
snaks.add(new SnakPartial("value",
|
||||
WikidataProperties.MEDIA_LEGENDS.getPropertyName(), new DataValue.MonoLingualText(
|
||||
new WikiBaseMonolingualTextValue(entry.getValue(), entry.getKey()))));
|
||||
}
|
||||
|
||||
final String id = wikidataItem.getId() + "$" + UUID.randomUUID().toString();
|
||||
final Statement_partial claim = new Statement_partial(p18, "statement", "normal", id,
|
||||
final StatementPartial claim = new StatementPartial(p18, "statement", "normal", id,
|
||||
Collections.singletonMap(WikidataProperties.MEDIA_LEGENDS.getPropertyName(), snaks),
|
||||
Arrays.asList(WikidataProperties.MEDIA_LEGENDS.getPropertyName()));
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,6 @@ interface WikidataInterface {
|
|||
fun postSetClaim(
|
||||
@Field("claim") request: String,
|
||||
@Field("tags") tags: String,
|
||||
@Field("token") token: String
|
||||
@Field("token") token: String,
|
||||
): Observable<WbCreateClaimResponse>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ package fr.free.nrw.commons.wikidata
|
|||
|
||||
import fr.free.nrw.commons.BuildConfig
|
||||
|
||||
enum class WikidataProperties(val propertyName: String) {
|
||||
enum class WikidataProperties(
|
||||
val propertyName: String,
|
||||
) {
|
||||
IMAGE("P18"),
|
||||
DEPICTS(BuildConfig.DEPICTS_PROPERTY),
|
||||
COMMONS_CATEGORY("P373"),
|
||||
INSTANCE_OF("P31"),
|
||||
MEDIA_LEGENDS("P2096");
|
||||
MEDIA_LEGENDS("P2096"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import okhttp3.Cookie
|
|||
import okhttp3.CookieJar
|
||||
import okhttp3.HttpUrl
|
||||
|
||||
class CommonsCookieJar(private val cookieStorage: CommonsCookieStorage) : CookieJar {
|
||||
class CommonsCookieJar(
|
||||
private val cookieStorage: CommonsCookieStorage,
|
||||
) : CookieJar {
|
||||
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
||||
val cookieList = mutableListOf<Cookie>()
|
||||
val domain: String = url.toUri().getAuthority()
|
||||
|
|
@ -21,7 +23,10 @@ class CommonsCookieJar(private val cookieStorage: CommonsCookieStorage) : Cookie
|
|||
return cookieList
|
||||
}
|
||||
|
||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||
override fun saveFromResponse(
|
||||
url: HttpUrl,
|
||||
cookies: List<Cookie>,
|
||||
) {
|
||||
if (cookies.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
|
@ -66,7 +71,9 @@ class CommonsCookieJar(private val cookieStorage: CommonsCookieStorage) : Cookie
|
|||
}
|
||||
|
||||
private fun buildCookieList(
|
||||
outList: MutableList<Cookie>, inList: MutableList<Cookie>, prefix: String?
|
||||
outList: MutableList<Cookie>,
|
||||
inList: MutableList<Cookie>,
|
||||
prefix: String?,
|
||||
) {
|
||||
var cookieJarModified = false
|
||||
|
||||
|
|
@ -90,14 +97,11 @@ class CommonsCookieJar(private val cookieStorage: CommonsCookieStorage) : Cookie
|
|||
}
|
||||
}
|
||||
|
||||
private fun Cookie.expiredOrDeleted(): Boolean =
|
||||
expiresAt < System.currentTimeMillis() || "deleted" == value
|
||||
private fun Cookie.expiredOrDeleted(): Boolean = expiresAt < System.currentTimeMillis() || "deleted" == value
|
||||
|
||||
private fun Cookie.domainSpec(url: HttpUrl): String =
|
||||
domain.ifEmpty { url.toUri().getAuthority() }
|
||||
private fun Cookie.domainSpec(url: HttpUrl): String = domain.ifEmpty { url.toUri().getAuthority() }
|
||||
|
||||
fun clear() {
|
||||
cookieStorage.clear()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,27 +5,32 @@ import com.google.gson.TypeAdapter
|
|||
import com.google.gson.stream.JsonReader
|
||||
import com.google.gson.stream.JsonWriter
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.wikidata.model.WikiSite
|
||||
import okhttp3.Cookie
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import fr.free.nrw.commons.wikidata.model.WikiSite
|
||||
|
||||
private const val COOKIE_STORE = "cookie_store"
|
||||
|
||||
class CommonsCookieStorage(private val preferences: JsonKvStore? = null) {
|
||||
private val gson = GsonBuilder().registerTypeAdapter(
|
||||
CommonsCookieStorage::class.java,
|
||||
CookieStorageTypeAdapter()
|
||||
).create()
|
||||
class CommonsCookieStorage(
|
||||
private val preferences: JsonKvStore? = null,
|
||||
) {
|
||||
private val gson =
|
||||
GsonBuilder()
|
||||
.registerTypeAdapter(
|
||||
CommonsCookieStorage::class.java,
|
||||
CookieStorageTypeAdapter(),
|
||||
).create()
|
||||
private val cookieMap: MutableMap<String, List<Cookie>> = mutableMapOf()
|
||||
|
||||
val domains : Set<String> get() = cookieMap.keys.toSet()
|
||||
val domains: Set<String> get() = cookieMap.keys.toSet()
|
||||
|
||||
operator fun set(domainSpec: String, cookies: MutableList<Cookie>) =
|
||||
cookieMap.put(domainSpec, cookies.toList())
|
||||
operator fun set(
|
||||
domainSpec: String,
|
||||
cookies: MutableList<Cookie>,
|
||||
) = cookieMap.put(domainSpec, cookies.toList())
|
||||
|
||||
operator fun get(domainSpec: String): MutableList<Cookie> =
|
||||
cookieMap[domainSpec]?.toMutableList() ?: mutableListOf()
|
||||
operator fun get(domainSpec: String): MutableList<Cookie> = cookieMap[domainSpec]?.toMutableList() ?: mutableListOf()
|
||||
|
||||
fun clear() {
|
||||
cookieMap.clear()
|
||||
|
|
@ -41,22 +46,24 @@ class CommonsCookieStorage(private val preferences: JsonKvStore? = null) {
|
|||
}
|
||||
}
|
||||
|
||||
fun save() =
|
||||
preferences!!.putString(COOKIE_STORE, gson.toJson(this))
|
||||
fun save() = preferences!!.putString(COOKIE_STORE, gson.toJson(this))
|
||||
|
||||
fun contains(domainSpec: String): Boolean =
|
||||
cookieMap.containsKey(domainSpec)
|
||||
fun contains(domainSpec: String): Boolean = cookieMap.containsKey(domainSpec)
|
||||
|
||||
companion object {
|
||||
fun from(map: Map<String, List<Cookie>>) = CommonsCookieStorage().apply {
|
||||
cookieMap.clear()
|
||||
cookieMap.putAll(map)
|
||||
}
|
||||
fun from(map: Map<String, List<Cookie>>) =
|
||||
CommonsCookieStorage().apply {
|
||||
cookieMap.clear()
|
||||
cookieMap.putAll(map)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class CookieStorageTypeAdapter : TypeAdapter<CommonsCookieStorage>() {
|
||||
override fun write(out: JsonWriter, value: CommonsCookieStorage) {
|
||||
override fun write(
|
||||
out: JsonWriter,
|
||||
value: CommonsCookieStorage,
|
||||
) {
|
||||
out.beginObject()
|
||||
value.domains.forEach { domain ->
|
||||
out.name(domain).beginArray()
|
||||
|
|
@ -90,4 +97,4 @@ private class CookieStorageTypeAdapter : TypeAdapter<CommonsCookieStorage>() {
|
|||
endArray()
|
||||
return list
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ class AddEditTagResponse {
|
|||
@SerializedName("tag")
|
||||
@Expose
|
||||
var tag: List<EditTag>? = null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,9 @@ import org.apache.commons.lang3.builder.HashCodeBuilder
|
|||
import org.apache.commons.lang3.builder.ToStringBuilder
|
||||
|
||||
abstract class BaseModel {
|
||||
override fun toString(): String {
|
||||
return ToStringBuilder.reflectionToString(this)
|
||||
}
|
||||
override fun toString(): String = ToStringBuilder.reflectionToString(this)
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return HashCodeBuilder.reflectionHashCode(this)
|
||||
}
|
||||
override fun hashCode(): Int = HashCodeBuilder.reflectionHashCode(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return EqualsBuilder.reflectionEquals(this, other)
|
||||
}
|
||||
override fun equals(other: Any?): Boolean = EqualsBuilder.reflectionEquals(this, other)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,19 @@ package fr.free.nrw.commons.wikidata.model
|
|||
|
||||
import fr.free.nrw.commons.wikidata.json.RuntimeTypeAdapterFactory
|
||||
|
||||
sealed class DataValue(val type: String) {
|
||||
sealed class DataValue(
|
||||
val type: String,
|
||||
) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val polymorphicTypeAdapter =
|
||||
RuntimeTypeAdapterFactory.of(DataValue::class.java, DataValue::type.name)
|
||||
RuntimeTypeAdapterFactory
|
||||
.of(DataValue::class.java, DataValue::type.name)
|
||||
.registerSubtype(EntityId::class.java, EntityId.TYPE)
|
||||
.registerSubtype(ValueString::class.java, ValueString.TYPE)
|
||||
.registerSubtype(GlobeCoordinate_partial::class.java, GlobeCoordinate_partial.TYPE)
|
||||
.registerSubtype(Time_partial::class.java, Time_partial.TYPE)
|
||||
.registerSubtype(Quantity_partial::class.java, Quantity_partial.TYPE)
|
||||
.registerSubtype(GlobeCoordinatePartial::class.java, GlobeCoordinatePartial.TYPE)
|
||||
.registerSubtype(TimePartial::class.java, TimePartial.TYPE)
|
||||
.registerSubtype(QuantityPartial::class.java, QuantityPartial.TYPE)
|
||||
.registerSubtype(MonoLingualText::class.java, MonoLingualText.TYPE)
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +25,9 @@ sealed class DataValue(val type: String) {
|
|||
// },
|
||||
// "type": "wikibase-entityid"
|
||||
// }
|
||||
data class EntityId(val value: WikiBaseEntityValue) : DataValue(TYPE) {
|
||||
data class EntityId(
|
||||
val value: WikiBaseEntityValue,
|
||||
) : DataValue(TYPE) {
|
||||
companion object {
|
||||
const val TYPE = "wikibase-entityid"
|
||||
}
|
||||
|
|
@ -32,7 +37,9 @@ sealed class DataValue(val type: String) {
|
|||
// "value": "SomePicture.jpg",
|
||||
// "type": "string"
|
||||
// }
|
||||
data class ValueString(val value: String) : DataValue(TYPE) {
|
||||
data class ValueString(
|
||||
val value: String,
|
||||
) : DataValue(TYPE) {
|
||||
companion object {
|
||||
const val TYPE = "string"
|
||||
}
|
||||
|
|
@ -47,7 +54,7 @@ sealed class DataValue(val type: String) {
|
|||
// },
|
||||
// "type": "globecoordinate"
|
||||
// }
|
||||
class GlobeCoordinate_partial() : DataValue(TYPE) {
|
||||
class GlobeCoordinatePartial : DataValue(TYPE) {
|
||||
companion object {
|
||||
const val TYPE = "globecoordinate"
|
||||
}
|
||||
|
|
@ -63,7 +70,7 @@ sealed class DataValue(val type: String) {
|
|||
// },
|
||||
// "type": "time"
|
||||
// }
|
||||
class Time_partial() : DataValue(TYPE) {
|
||||
class TimePartial : DataValue(TYPE) {
|
||||
companion object {
|
||||
const val TYPE = "time"
|
||||
}
|
||||
|
|
@ -75,7 +82,7 @@ sealed class DataValue(val type: String) {
|
|||
// "unit": "http://www.wikidata.org/entity/Q828224"
|
||||
// }
|
||||
// }
|
||||
class Quantity_partial() : DataValue(TYPE) {
|
||||
class QuantityPartial : DataValue(TYPE) {
|
||||
companion object {
|
||||
const val TYPE = "quantity"
|
||||
}
|
||||
|
|
@ -87,7 +94,9 @@ sealed class DataValue(val type: String) {
|
|||
// "language": "ko"
|
||||
// }
|
||||
// }
|
||||
class MonoLingualText(val value: WikiBaseMonolingualTextValue) : DataValue(TYPE) {
|
||||
class MonoLingualText(
|
||||
val value: WikiBaseMonolingualTextValue,
|
||||
) : DataValue(TYPE) {
|
||||
companion object {
|
||||
const val TYPE = "monolingualtext"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,5 +23,5 @@ class DepictSearchItem(
|
|||
val pageid: String,
|
||||
val url: String,
|
||||
val label: String,
|
||||
val description: String?
|
||||
val description: String?,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,30 +1,34 @@
|
|||
package fr.free.nrw.commons.wikidata.model
|
||||
|
||||
|
||||
data class EditClaim(val claims: List<Statement_partial>) {
|
||||
|
||||
data class EditClaim(
|
||||
val claims: List<StatementPartial>,
|
||||
) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun from(entityIds: List<String>, propertyName: String): EditClaim {
|
||||
|
||||
val list = mutableListOf<Statement_partial>()
|
||||
fun from(
|
||||
entityIds: List<String>,
|
||||
propertyName: String,
|
||||
): EditClaim {
|
||||
val list = mutableListOf<StatementPartial>()
|
||||
entityIds.forEach {
|
||||
list.add(
|
||||
Statement_partial(
|
||||
mainSnak = Snak_partial(
|
||||
snakType = "value",
|
||||
property = propertyName,
|
||||
dataValue = DataValue.EntityId(
|
||||
WikiBaseEntityValue(
|
||||
entityType = "item",
|
||||
id = it,
|
||||
numericId = it.removePrefix("Q").toLong()
|
||||
)
|
||||
)
|
||||
),
|
||||
StatementPartial(
|
||||
mainSnak =
|
||||
SnakPartial(
|
||||
snakType = "value",
|
||||
property = propertyName,
|
||||
dataValue =
|
||||
DataValue.EntityId(
|
||||
WikiBaseEntityValue(
|
||||
entityType = "item",
|
||||
id = it,
|
||||
numericId = it.removePrefix("Q").toLong(),
|
||||
),
|
||||
),
|
||||
),
|
||||
type = "statement",
|
||||
rank = "preferred"
|
||||
)
|
||||
rank = "preferred",
|
||||
),
|
||||
)
|
||||
}
|
||||
return EditClaim(list)
|
||||
|
|
|
|||
|
|
@ -6,4 +6,10 @@ import com.google.gson.annotations.SerializedName
|
|||
/**
|
||||
* Tag class used when adding wikidata edit tag
|
||||
*/
|
||||
class EditTag(@field:Expose @field:SerializedName("revid") val revid: Int, @field:Expose @field:SerializedName("status") val status: String, @field:Expose @field:SerializedName("actionlogid") val actionlogid: Int, @field:Expose @field:SerializedName("added") val added: List<String>, @field:Expose @field:SerializedName("removed") val removed: List<Any>)
|
||||
class EditTag(
|
||||
@field:Expose @field:SerializedName("revid") val revid: Int,
|
||||
@field:Expose @field:SerializedName("status") val status: String,
|
||||
@field:Expose @field:SerializedName("actionlogid") val actionlogid: Int,
|
||||
@field:Expose @field:SerializedName("added") val added: List<String>,
|
||||
@field:Expose @field:SerializedName("removed") val removed: List<Any>,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class Entities extends MwResponse {
|
|||
@Nullable private Map<String, Label> labels;
|
||||
@Nullable private Map<String, Label> descriptions;
|
||||
@Nullable private Map<String, SiteLink> sitelinks;
|
||||
@Nullable @SerializedName(value = "statements", alternate = "claims") private Map<String, List<Statement_partial>> statements;
|
||||
@Nullable @SerializedName(value = "statements", alternate = "claims") private Map<String, List<StatementPartial>> statements;
|
||||
@Nullable private String missing;
|
||||
|
||||
@NonNull public String id() {
|
||||
|
|
@ -64,7 +64,7 @@ public class Entities extends MwResponse {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, List<Statement_partial>> getStatements() {
|
||||
public Map<String, List<StatementPartial>> getStatements() {
|
||||
return statements;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@ package fr.free.nrw.commons.wikidata.model
|
|||
|
||||
import android.util.SparseArray
|
||||
|
||||
class EnumCodeMap<T>(enumeration: Class<T>) where T : Enum<T>, T : EnumCode {
|
||||
class EnumCodeMap<T>(
|
||||
enumeration: Class<T>,
|
||||
) where T : Enum<T>, T : EnumCode {
|
||||
private val map: SparseArray<T>
|
||||
|
||||
init {
|
||||
map = codeToEnumMap(enumeration)
|
||||
}
|
||||
|
||||
operator fun get(code: Int): T {
|
||||
return map.get(code) ?: throw IllegalArgumentException("code=$code")
|
||||
}
|
||||
operator fun get(code: Int): T = map.get(code) ?: throw IllegalArgumentException("code=$code")
|
||||
|
||||
private fun codeToEnumMap(enumeration: Class<T>): SparseArray<T> {
|
||||
val ret = SparseArray<T>()
|
||||
|
|
@ -21,7 +21,5 @@ class EnumCodeMap<T>(enumeration: Class<T>) where T : Enum<T>, T : EnumCode {
|
|||
return ret
|
||||
}
|
||||
|
||||
fun size(): Int {
|
||||
return map.size()
|
||||
}
|
||||
fun size(): Int = map.size()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,6 @@ package fr.free.nrw.commons.wikidata.model
|
|||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class GetWikidataEditCountResponse(@field:SerializedName("edits") val wikidataEditCount: Int)
|
||||
class GetWikidataEditCountResponse(
|
||||
@field:SerializedName("edits") val wikidataEditCount: Int,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,4 +6,6 @@ import com.google.gson.annotations.SerializedName
|
|||
/**
|
||||
* PageInfo model class with last revision id of the edited Wikidata entity
|
||||
*/
|
||||
class PageInfo(@field:Expose @field:SerializedName("lastrevid") val lastrevid: Long)
|
||||
class PageInfo(
|
||||
@field:Expose @field:SerializedName("lastrevid") val lastrevid: Long,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package fr.free.nrw.commons.wikidata.model
|
||||
|
||||
data class RemoveClaim(val claims: List<ClaimRemoveRequest>) {
|
||||
data class RemoveClaim(
|
||||
val claims: List<ClaimRemoveRequest>,
|
||||
) {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun from(claimIds: List<String>): RemoveClaim {
|
||||
|
|
@ -8,7 +10,7 @@ data class RemoveClaim(val claims: List<ClaimRemoveRequest>) {
|
|||
|
||||
claimIds.forEach {
|
||||
claimsToRemove.add(
|
||||
ClaimRemoveRequest(id = it, remove = "")
|
||||
ClaimRemoveRequest(id = it, remove = ""),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -17,4 +19,7 @@ data class RemoveClaim(val claims: List<ClaimRemoveRequest>) {
|
|||
}
|
||||
}
|
||||
|
||||
data class ClaimRemoveRequest(val id: String, val remove: String)
|
||||
data class ClaimRemoveRequest(
|
||||
val id: String,
|
||||
val remove: String,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ import com.google.gson.annotations.SerializedName
|
|||
},
|
||||
"datatype": "wikibase-item",
|
||||
}*/
|
||||
data class Snak_partial(
|
||||
data class SnakPartial(
|
||||
@SerializedName("snaktype") val snakType: String,
|
||||
val property: String,
|
||||
@SerializedName("datavalue") val dataValue: DataValue
|
||||
@SerializedName("datavalue") val dataValue: DataValue,
|
||||
)
|
||||
|
|
@ -18,11 +18,11 @@ import com.google.gson.annotations.SerializedName
|
|||
}
|
||||
]
|
||||
}*/
|
||||
data class Statement_partial(
|
||||
@SerializedName("mainsnak") val mainSnak: Snak_partial,
|
||||
data class StatementPartial(
|
||||
@SerializedName("mainsnak") val mainSnak: SnakPartial,
|
||||
val type: String,
|
||||
val rank: String,
|
||||
val id: String? = null,
|
||||
val qualifiers: Map<String, List<Snak_partial>> = mapOf(),
|
||||
@SerializedName("qualifiers-order") val qualifiersOrder: List<String> = listOf()
|
||||
val qualifiers: Map<String, List<SnakPartial>> = mapOf(),
|
||||
@SerializedName("qualifiers-order") val qualifiersOrder: List<String> = listOf(),
|
||||
)
|
||||
|
|
@ -6,4 +6,7 @@ import com.google.gson.annotations.SerializedName
|
|||
/**
|
||||
* Wikidata create claim response model class
|
||||
*/
|
||||
class WbCreateClaimResponse(@field:Expose @field:SerializedName("pageinfo") val pageinfo: PageInfo, @field:Expose @field:SerializedName("success") val success: Int)
|
||||
class WbCreateClaimResponse(
|
||||
@field:Expose @field:SerializedName("pageinfo") val pageinfo: PageInfo,
|
||||
@field:Expose @field:SerializedName("success") val success: Int,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ import com.google.gson.annotations.SerializedName
|
|||
data class WikiBaseEntityValue(
|
||||
@SerializedName("entity-type") val entityType: String,
|
||||
val id: String,
|
||||
val numericId: Long
|
||||
val numericId: Long,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package fr.free.nrw.commons.wikidata.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/*"value": {
|
||||
"type": "monolingualtext",
|
||||
"value": {
|
||||
|
|
@ -10,4 +8,7 @@ import com.google.gson.annotations.SerializedName
|
|||
}
|
||||
}*/
|
||||
|
||||
data class WikiBaseMonolingualTextValue(val text: String, val language: String)
|
||||
data class WikiBaseMonolingualTextValue(
|
||||
val text: String,
|
||||
val language: String,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue