mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Snak_partial.kt & Statement_partial.kt: refactored to remove underscores in class names to meet ktLint standard
This commit is contained in:
		
							parent
							
								
									e07442418f
								
							
						
					
					
						commit
						4717ce0a58
					
				
					 13 changed files with 46 additions and 46 deletions
				
			
		|  | @ -10,7 +10,7 @@ import fr.free.nrw.commons.wikidata.WikidataProperties | |||
| import fr.free.nrw.commons.wikidata.model.DataValue | ||||
| import fr.free.nrw.commons.wikidata.model.DepictSearchItem | ||||
| import fr.free.nrw.commons.wikidata.model.Entities | ||||
| import fr.free.nrw.commons.wikidata.model.Statement_partial | ||||
| import fr.free.nrw.commons.wikidata.model.StatementPartial | ||||
| import io.reactivex.Single | ||||
| import java.util.Locale | ||||
| import javax.inject.Inject | ||||
|  | @ -111,7 +111,7 @@ class DepictsClient | |||
|         /** | ||||
|          * returns list of id ex. "Q2323" from Statement_partial | ||||
|          */ | ||||
|         private fun List<Statement_partial>?.toIds(): List<String> = | ||||
|         private fun List<StatementPartial>?.toIds(): List<String> = | ||||
|             this | ||||
|                 ?.map { it.mainSnak.dataValue } | ||||
|                 ?.filterIsInstance<DataValue.EntityId>() | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| package fr.free.nrw.commons.upload.depicts | ||||
| 
 | ||||
| import com.google.gson.annotations.SerializedName | ||||
| import fr.free.nrw.commons.wikidata.model.Statement_partial | ||||
| import fr.free.nrw.commons.wikidata.model.StatementPartial | ||||
| 
 | ||||
| data class Claims( | ||||
|     @SerializedName(value = "claims") | ||||
|     val claims: Map<String, List<Statement_partial>> = emptyMap(), | ||||
|     val claims: Map<String, List<StatementPartial>> = emptyMap(), | ||||
| ) | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ import fr.free.nrw.commons.wikidata.WikidataProperties.IMAGE | |||
| import fr.free.nrw.commons.wikidata.WikidataProperties.INSTANCE_OF | ||||
| import fr.free.nrw.commons.wikidata.model.DataValue | ||||
| import fr.free.nrw.commons.wikidata.model.Entities | ||||
| import fr.free.nrw.commons.wikidata.model.Statement_partial | ||||
| import fr.free.nrw.commons.wikidata.model.StatementPartial | ||||
| import kotlinx.parcelize.Parcelize | ||||
| import java.math.BigInteger | ||||
| import java.security.MessageDigest | ||||
|  | @ -78,14 +78,14 @@ data class DepictedItem constructor( | |||
|     override fun hashCode(): Int = name.hashCode() | ||||
| } | ||||
| 
 | ||||
| private fun List<Statement_partial>?.toIds(): List<String> = | ||||
| private fun List<StatementPartial>?.toIds(): List<String> = | ||||
|     this | ||||
|         ?.map { it.mainSnak.dataValue } | ||||
|         ?.filterIsInstance<DataValue.EntityId>() | ||||
|         ?.map { it.value.id } | ||||
|         ?: emptyList() | ||||
| 
 | ||||
| private val List<Statement_partial>?.primaryImageValue: DataValue.ValueString? | ||||
| private val List<StatementPartial>?.primaryImageValue: DataValue.ValueString? | ||||
|     get() = this?.firstOrNull()?.mainSnak?.dataValue as? DataValue.ValueString | ||||
| 
 | ||||
| operator fun Entities.Entity.get(property: WikidataProperties) = statements?.get(property.propertyName) | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| 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 io.reactivex.Observable | ||||
| import javax.inject.Inject | ||||
|  | @ -20,7 +20,7 @@ class WikidataClient | |||
|          * @return revisionID of the edit | ||||
|          */ | ||||
|         fun setClaim( | ||||
|             claim: Statement_partial?, | ||||
|             claim: StatementPartial?, | ||||
|             tags: String?, | ||||
|         ): Observable<Long> = | ||||
|             csrfToken() | ||||
|  |  | |||
|  | @ -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())); | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,9 +12,9 @@ sealed class DataValue( | |||
|                 .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) | ||||
|     } | ||||
| 
 | ||||
|  | @ -54,7 +54,7 @@ sealed class DataValue( | |||
|     //    }, | ||||
|     //    "type": "globecoordinate" | ||||
|     //    } | ||||
|     class GlobeCoordinate_partial : DataValue(TYPE) { | ||||
|     class GlobeCoordinatePartial : DataValue(TYPE) { | ||||
|         companion object { | ||||
|             const val TYPE = "globecoordinate" | ||||
|         } | ||||
|  | @ -70,7 +70,7 @@ sealed class DataValue( | |||
|     //    }, | ||||
|     //    "type": "time" | ||||
|     //    } | ||||
|     class Time_partial : DataValue(TYPE) { | ||||
|     class TimePartial : DataValue(TYPE) { | ||||
|         companion object { | ||||
|             const val TYPE = "time" | ||||
|         } | ||||
|  | @ -82,7 +82,7 @@ sealed class DataValue( | |||
|     //        "unit": "http://www.wikidata.org/entity/Q828224" | ||||
|     //    } | ||||
|     //    } | ||||
|     class Quantity_partial : DataValue(TYPE) { | ||||
|     class QuantityPartial : DataValue(TYPE) { | ||||
|         companion object { | ||||
|             const val TYPE = "quantity" | ||||
|         } | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| package fr.free.nrw.commons.wikidata.model | ||||
| 
 | ||||
| data class EditClaim( | ||||
|     val claims: List<Statement_partial>, | ||||
|     val claims: List<StatementPartial>, | ||||
| ) { | ||||
|     companion object { | ||||
|         @JvmStatic | ||||
|  | @ -9,12 +9,12 @@ data class EditClaim( | |||
|             entityIds: List<String>, | ||||
|             propertyName: String, | ||||
|         ): EditClaim { | ||||
|             val list = mutableListOf<Statement_partial>() | ||||
|             val list = mutableListOf<StatementPartial>() | ||||
|             entityIds.forEach { | ||||
|                 list.add( | ||||
|                     Statement_partial( | ||||
|                     StatementPartial( | ||||
|                         mainSnak = | ||||
|                             Snak_partial( | ||||
|                             SnakPartial( | ||||
|                                 snakType = "value", | ||||
|                                 property = propertyName, | ||||
|                                 dataValue = | ||||
|  |  | |||
|  | @ -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; | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -15,7 +15,7 @@ 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, | ||||
|  | @ -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(), | ||||
|     val qualifiers: Map<String, List<SnakPartial>> = mapOf(), | ||||
|     @SerializedName("qualifiers-order") val qualifiersOrder: List<String> = listOf(), | ||||
| ) | ||||
|  | @ -10,8 +10,8 @@ import fr.free.nrw.commons.upload.structure.depictions.DepictedItem | |||
| import fr.free.nrw.commons.wikidata.model.DataValue | ||||
| import fr.free.nrw.commons.wikidata.model.DepictSearchItem | ||||
| import fr.free.nrw.commons.wikidata.model.Entities | ||||
| 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.WikiBaseEntityValue | ||||
| import java.util.Date | ||||
| 
 | ||||
|  | @ -104,23 +104,23 @@ fun wikiBaseEntityValue( | |||
| ) = WikiBaseEntityValue(entityType, id, numericId) | ||||
| 
 | ||||
| fun statement( | ||||
|     mainSnak: Snak_partial = snak(), | ||||
|     mainSnak: SnakPartial = snak(), | ||||
|     rank: String = "rank", | ||||
|     type: String = "type", | ||||
| ) = Statement_partial(mainSnak, type, rank) | ||||
| ) = StatementPartial(mainSnak, type, rank) | ||||
| 
 | ||||
| fun snak( | ||||
|     snakType: String = "type", | ||||
|     property: String = "property", | ||||
|     dataValue: DataValue = valueString(""), | ||||
| ) = Snak_partial(snakType, property, dataValue) | ||||
| ) = SnakPartial(snakType, property, dataValue) | ||||
| 
 | ||||
| fun valueString(value: String) = DataValue.ValueString(value) | ||||
| 
 | ||||
| fun entity( | ||||
|     labels: Map<String, String> = emptyMap(), | ||||
|     descriptions: Map<String, String> = emptyMap(), | ||||
|     statements: Map<String, List<Statement_partial>>? = emptyMap(), | ||||
|     statements: Map<String, List<StatementPartial>>? = emptyMap(), | ||||
|     id: String = "id", | ||||
| ) = mock<Entities.Entity>().apply { | ||||
|     val mockedLabels = labels.mockLabels() | ||||
|  |  | |||
|  | @ -12,8 +12,8 @@ import fr.free.nrw.commons.upload.structure.depictions.DepictedItem | |||
| import fr.free.nrw.commons.wikidata.model.DataValue | ||||
| import fr.free.nrw.commons.wikidata.model.DepictSearchResponse | ||||
| import fr.free.nrw.commons.wikidata.model.Entities | ||||
| 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.WikiBaseEntityValue | ||||
| import io.reactivex.Single | ||||
| import org.junit.Before | ||||
|  | @ -67,12 +67,12 @@ class DepictsClientTest { | |||
|         whenever(binding2.id).thenReturn("2") | ||||
|         val entities = mock<Entities>() | ||||
|         val entity = mock<Entities.Entity>() | ||||
|         val statementPartial = mock<Statement_partial>() | ||||
|         val statementPartial = mock<StatementPartial>() | ||||
|         whenever(depictsInterface.getEntities("1|2")).thenReturn(Single.just(entities)) | ||||
|         whenever(entities.entities()).thenReturn(mapOf("en" to entity)) | ||||
|         whenever(entity.statements).thenReturn(mapOf("P31" to listOf(statementPartial))) | ||||
|         whenever(statementPartial.mainSnak).thenReturn( | ||||
|             Snak_partial( | ||||
|             SnakPartial( | ||||
|                 "test", | ||||
|                 "P31", | ||||
|                 DataValue.EntityId( | ||||
|  | @ -165,10 +165,10 @@ class DepictsClientTest { | |||
|     fun `Test mapToDepictItem when description is empty and P31 exists`() { | ||||
|         val entities = mock<Entities>() | ||||
|         val entity = mock<Entities.Entity>() | ||||
|         val statementPartial = mock<Statement_partial>() | ||||
|         val statementPartial = mock<StatementPartial>() | ||||
|         whenever(entity.statements).thenReturn(mapOf("P31" to listOf(statementPartial))) | ||||
|         whenever(statementPartial.mainSnak).thenReturn( | ||||
|             Snak_partial( | ||||
|             SnakPartial( | ||||
|                 "test", | ||||
|                 "P31", | ||||
|                 DataValue.EntityId( | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ package fr.free.nrw.commons.wikidata | |||
| import com.google.gson.Gson | ||||
| import com.nhaarman.mockitokotlin2.whenever | ||||
| import fr.free.nrw.commons.wikidata.model.PageInfo | ||||
| 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 fr.free.nrw.commons.wikidata.mwapi.MwQueryResult | ||||
|  | @ -48,8 +48,8 @@ class WikidataClientTest { | |||
|         whenever(response.pageinfo).thenReturn(pageInfo) | ||||
|         `when`(wikidataInterface!!.postSetClaim(anyString(), anyString(), anyString())) | ||||
|             .thenReturn(Observable.just(response)) | ||||
|         whenever(gson!!.toJson(any(Statement_partial::class.java))).thenReturn("claim") | ||||
|         val request = mock(Statement_partial::class.java) | ||||
|         whenever(gson!!.toJson(any(StatementPartial::class.java))).thenReturn("claim") | ||||
|         val request = mock(StatementPartial::class.java) | ||||
| 
 | ||||
|         val claim = | ||||
|             wikidataClient!! | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 tristan81
						tristan81