mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge remote-tracking branch 'origin/master' into structured-data
# Conflicts: # app/src/main/java/fr/free/nrw/commons/upload/UploadService.java # app/src/main/java/fr/free/nrw/commons/wikidata/WikidataEditService.java
This commit is contained in:
commit
d5b62befc9
5 changed files with 30 additions and 17 deletions
|
|
@ -70,6 +70,7 @@ public class Contribution extends Media {
|
|||
public String decimalCoords;
|
||||
public boolean isMultiple;
|
||||
public String wikiDataEntityId;
|
||||
public String wikiItemName;
|
||||
private String p18Value;
|
||||
public Uri contentProviderUri;
|
||||
public String dateCreatedSource;
|
||||
|
|
@ -121,6 +122,7 @@ public class Contribution extends Media {
|
|||
state = in.readInt();
|
||||
transferred = in.readLong();
|
||||
isMultiple = in.readInt() == 1;
|
||||
wikiItemName = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -131,6 +133,7 @@ public class Contribution extends Media {
|
|||
parcel.writeInt(state);
|
||||
parcel.writeLong(transferred);
|
||||
parcel.writeInt(isMultiple ? 1 : 0);
|
||||
parcel.writeString(wikiItemName);
|
||||
}
|
||||
|
||||
public void setDateCreatedSource(String dateCreatedSource) {
|
||||
|
|
@ -279,6 +282,10 @@ public class Contribution extends Media {
|
|||
return wikiDataEntityId;
|
||||
}
|
||||
|
||||
public String getWikiItemName() {
|
||||
return wikiItemName;
|
||||
}
|
||||
|
||||
/**
|
||||
* When the corresponding wikidata entity is known as in case of nearby uploads, it can be set
|
||||
* using the setter method
|
||||
|
|
@ -288,6 +295,10 @@ public class Contribution extends Media {
|
|||
this.wikiDataEntityId = wikiDataEntityId;
|
||||
}
|
||||
|
||||
public void setWikiItemName(String wikiItemName) {
|
||||
this.wikiItemName = wikiItemName;
|
||||
}
|
||||
|
||||
public String getP18Value() {
|
||||
return p18Value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ public class UploadModel {
|
|||
CommonsApplication.DEFAULT_EDIT_SUMMARY, selectedDepictions, item.gpsCoords.getDecimalCoords());
|
||||
if (item.place != null) {
|
||||
contribution.setWikiDataEntityId(item.place.getWikiDataEntityId());
|
||||
contribution.setWikiItemName(item.place.getName());
|
||||
// If item already has an image, we need to know it. We don't want to override existing image later
|
||||
contribution.setP18Value(item.place.pic);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -296,8 +296,11 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
p18Value);
|
||||
}
|
||||
}
|
||||
wikidataEditService.createClaimWithLogging(contribution.getWikiDataEntityId(), canonicalFilename,
|
||||
p18Value);
|
||||
Timber.d("Contribution upload success. Initiating Wikidata edit for"
|
||||
+ " entity id %s if necessary (if P18 is null). P18 value is %s",
|
||||
contribution.getWikiDataEntityId(), contribution.getP18Value());
|
||||
wikidataEditService.createClaimWithLogging(contribution.getWikiDataEntityId(), contribution.getWikiItemName(), canonicalFilename, contribution.getP18Value());
|
||||
|
||||
wikidataEditService.createLabelforWikidataEntity(contribution.getWikiDataEntityId(), canonicalFilename,
|
||||
(Map) contribution.getCaptions());
|
||||
contribution.setFilename(canonicalFilename);
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class WikidataEditService {
|
|||
* @param p18Value pic attribute of Wikidata item
|
||||
>>>>>>> origin/master
|
||||
*/
|
||||
public void createClaimWithLogging(String wikidataEntityId, String fileName, @NonNull String p18Value) {
|
||||
public void createClaimWithLogging(String wikidataEntityId, String wikiItemName, String fileName, @NonNull String p18Value) {
|
||||
if (wikidataEntityId == null) {
|
||||
Timber.d("Skipping creation of claim as Wikidata entity ID is null");
|
||||
return;
|
||||
|
|
@ -104,7 +104,7 @@ public class WikidataEditService {
|
|||
return;
|
||||
}
|
||||
|
||||
editWikidataProperty(wikidataEntityId, fileName);
|
||||
editWikidataProperty(wikidataEntityId, wikiItemName, fileName);
|
||||
//editWikiBaseDepictsProperty(wikidataEntityId, fileName);
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ public class WikidataEditService {
|
|||
* @param fileName
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
private void editWikidataProperty(String wikidataEntityId, String fileName) {
|
||||
private void editWikidataProperty(String wikidataEntityId, String wikiItemName, String fileName) {
|
||||
Timber.d("Upload successful with wiki data entity id as %s", wikidataEntityId);
|
||||
Timber.d("Attempting to edit Wikidata property %s", wikidataEntityId);
|
||||
|
||||
|
|
@ -134,13 +134,12 @@ public class WikidataEditService {
|
|||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(revisionId -> handleClaimResult(wikidataEntityId, String.valueOf(revisionId)), throwable -> {
|
||||
.subscribe(revisionId -> handleClaimResult(wikidataEntityId, wikiItemName, String.valueOf(revisionId)), throwable -> {
|
||||
Timber.e(throwable, "Error occurred while making claim");
|
||||
ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edits the wikibase entity by adding DEPICTS property.
|
||||
* Adding DEPICTS property requires call to the wikibase API to set tag against the entity.
|
||||
|
|
@ -215,12 +214,12 @@ public class WikidataEditService {
|
|||
});
|
||||
}
|
||||
|
||||
private void handleClaimResult(String wikidataEntityId, String revisionId) {
|
||||
private void handleClaimResult(String wikidataEntityId, String wikiItemName, String revisionId) {
|
||||
if (revisionId != null) {
|
||||
if (wikidataEditListener != null) {
|
||||
wikidataEditListener.onSuccessfulWikidataEdit();
|
||||
}
|
||||
showSuccessToast();
|
||||
showSuccessToast(wikiItemName);
|
||||
} else {
|
||||
Timber.d("Unable to make wiki data edit for entity %s", wikidataEntityId);
|
||||
ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure));
|
||||
|
|
@ -231,10 +230,9 @@ public class WikidataEditService {
|
|||
/**
|
||||
* Show a success toast when the edit is made successfully
|
||||
*/
|
||||
private void showSuccessToast() {
|
||||
String caption = directKvStore.getString("Title", "");
|
||||
private void showSuccessToast(String wikiItemName) {
|
||||
String successStringTemplate = context.getString(R.string.successful_wikidata_edit);
|
||||
@SuppressLint({"StringFormatInvalid", "LocalSuppress"}) String successMessage = String.format(Locale.getDefault(), successStringTemplate, caption);
|
||||
String successMessage = String.format(Locale.getDefault(), successStringTemplate, wikiItemName);
|
||||
ViewUtil.showLongToast(context, successMessage);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,19 +37,19 @@ class WikidataEditServiceTest {
|
|||
|
||||
@Test
|
||||
fun noClaimsWhenEntityIdIsNull() {
|
||||
wikidataEditService!!.createClaimWithLogging(null, "Test.jpg","")
|
||||
wikidataEditService!!.createClaimWithLogging(null, null,"Test.jpg","")
|
||||
verifyZeroInteractions(wikidataClient!!)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noClaimsWhenFileNameIsNull() {
|
||||
wikidataEditService!!.createClaimWithLogging("Q1", null,"")
|
||||
wikidataEditService!!.createClaimWithLogging("Q1", "Test", null,"")
|
||||
verifyZeroInteractions(wikidataClient!!)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noClaimsWhenP18IsNotEmpty() {
|
||||
wikidataEditService!!.createClaimWithLogging("Q1", "Test.jpg","Previous.jpg")
|
||||
wikidataEditService!!.createClaimWithLogging("Q1", "Test","Test.jpg","Previous.jpg")
|
||||
verifyZeroInteractions(wikidataClient!!)
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ class WikidataEditServiceTest {
|
|||
fun noClaimsWhenLocationIsNotCorrect() {
|
||||
`when`(directKvStore!!.getBoolean("Picture_Has_Correct_Location", true))
|
||||
.thenReturn(false)
|
||||
wikidataEditService!!.createClaimWithLogging("Q1", "Test.jpg","")
|
||||
wikidataEditService!!.createClaimWithLogging("Q1", "","Test.jpg","")
|
||||
verifyZeroInteractions(wikidataClient!!)
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ class WikidataEditServiceTest {
|
|||
.thenReturn(Observable.just(1L))
|
||||
`when`(wikidataClient!!.addEditTag(anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(mock(AddEditTagResponse::class.java)))
|
||||
wikidataEditService!!.createClaimWithLogging("Q1", "Test.jpg","")
|
||||
wikidataEditService!!.createClaimWithLogging("Q1", "Test","Test.jpg","")
|
||||
verify(wikidataClient!!, times(1))
|
||||
.createClaim(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue