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:
Sean Mac Gillicuddy 2020-03-24 13:35:49 +00:00
commit d5b62befc9
5 changed files with 30 additions and 17 deletions

View file

@ -70,6 +70,7 @@ public class Contribution extends Media {
public String decimalCoords; public String decimalCoords;
public boolean isMultiple; public boolean isMultiple;
public String wikiDataEntityId; public String wikiDataEntityId;
public String wikiItemName;
private String p18Value; private String p18Value;
public Uri contentProviderUri; public Uri contentProviderUri;
public String dateCreatedSource; public String dateCreatedSource;
@ -121,6 +122,7 @@ public class Contribution extends Media {
state = in.readInt(); state = in.readInt();
transferred = in.readLong(); transferred = in.readLong();
isMultiple = in.readInt() == 1; isMultiple = in.readInt() == 1;
wikiItemName = in.readString();
} }
@Override @Override
@ -131,6 +133,7 @@ public class Contribution extends Media {
parcel.writeInt(state); parcel.writeInt(state);
parcel.writeLong(transferred); parcel.writeLong(transferred);
parcel.writeInt(isMultiple ? 1 : 0); parcel.writeInt(isMultiple ? 1 : 0);
parcel.writeString(wikiItemName);
} }
public void setDateCreatedSource(String dateCreatedSource) { public void setDateCreatedSource(String dateCreatedSource) {
@ -279,6 +282,10 @@ public class Contribution extends Media {
return wikiDataEntityId; return wikiDataEntityId;
} }
public String getWikiItemName() {
return wikiItemName;
}
/** /**
* When the corresponding wikidata entity is known as in case of nearby uploads, it can be set * When the corresponding wikidata entity is known as in case of nearby uploads, it can be set
* using the setter method * using the setter method
@ -288,6 +295,10 @@ public class Contribution extends Media {
this.wikiDataEntityId = wikiDataEntityId; this.wikiDataEntityId = wikiDataEntityId;
} }
public void setWikiItemName(String wikiItemName) {
this.wikiItemName = wikiItemName;
}
public String getP18Value() { public String getP18Value() {
return p18Value; return p18Value;
} }

View file

@ -168,6 +168,7 @@ public class UploadModel {
CommonsApplication.DEFAULT_EDIT_SUMMARY, selectedDepictions, item.gpsCoords.getDecimalCoords()); CommonsApplication.DEFAULT_EDIT_SUMMARY, selectedDepictions, item.gpsCoords.getDecimalCoords());
if (item.place != null) { if (item.place != null) {
contribution.setWikiDataEntityId(item.place.getWikiDataEntityId()); 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 // 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); contribution.setP18Value(item.place.pic);
} }

View file

@ -296,8 +296,11 @@ public class UploadService extends HandlerService<Contribution> {
p18Value); p18Value);
} }
} }
wikidataEditService.createClaimWithLogging(contribution.getWikiDataEntityId(), canonicalFilename, Timber.d("Contribution upload success. Initiating Wikidata edit for"
p18Value); + " 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, wikidataEditService.createLabelforWikidataEntity(contribution.getWikiDataEntityId(), canonicalFilename,
(Map) contribution.getCaptions()); (Map) contribution.getCaptions());
contribution.setFilename(canonicalFilename); contribution.setFilename(canonicalFilename);

View file

@ -83,7 +83,7 @@ public class WikidataEditService {
* @param p18Value pic attribute of Wikidata item * @param p18Value pic attribute of Wikidata item
>>>>>>> origin/master >>>>>>> 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) { if (wikidataEntityId == null) {
Timber.d("Skipping creation of claim as Wikidata entity ID is null"); Timber.d("Skipping creation of claim as Wikidata entity ID is null");
return; return;
@ -104,7 +104,7 @@ public class WikidataEditService {
return; return;
} }
editWikidataProperty(wikidataEntityId, fileName); editWikidataProperty(wikidataEntityId, wikiItemName, fileName);
//editWikiBaseDepictsProperty(wikidataEntityId, fileName); //editWikiBaseDepictsProperty(wikidataEntityId, fileName);
} }
@ -118,7 +118,7 @@ public class WikidataEditService {
* @param fileName * @param fileName
*/ */
@SuppressLint("CheckResult") @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("Upload successful with wiki data entity id as %s", wikidataEntityId);
Timber.d("Attempting to edit Wikidata property %s", wikidataEntityId); Timber.d("Attempting to edit Wikidata property %s", wikidataEntityId);
@ -134,13 +134,12 @@ public class WikidataEditService {
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .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"); Timber.e(throwable, "Error occurred while making claim");
ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure)); ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure));
}); });
} }
/** /**
* Edits the wikibase entity by adding DEPICTS property. * Edits the wikibase entity by adding DEPICTS property.
* Adding DEPICTS property requires call to the wikibase API to set tag against the entity. * 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 (revisionId != null) {
if (wikidataEditListener != null) { if (wikidataEditListener != null) {
wikidataEditListener.onSuccessfulWikidataEdit(); wikidataEditListener.onSuccessfulWikidataEdit();
} }
showSuccessToast(); showSuccessToast(wikiItemName);
} else { } else {
Timber.d("Unable to make wiki data edit for entity %s", wikidataEntityId); Timber.d("Unable to make wiki data edit for entity %s", wikidataEntityId);
ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure)); 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 * Show a success toast when the edit is made successfully
*/ */
private void showSuccessToast() { private void showSuccessToast(String wikiItemName) {
String caption = directKvStore.getString("Title", "");
String successStringTemplate = context.getString(R.string.successful_wikidata_edit); 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); ViewUtil.showLongToast(context, successMessage);
} }

View file

@ -37,19 +37,19 @@ class WikidataEditServiceTest {
@Test @Test
fun noClaimsWhenEntityIdIsNull() { fun noClaimsWhenEntityIdIsNull() {
wikidataEditService!!.createClaimWithLogging(null, "Test.jpg","") wikidataEditService!!.createClaimWithLogging(null, null,"Test.jpg","")
verifyZeroInteractions(wikidataClient!!) verifyZeroInteractions(wikidataClient!!)
} }
@Test @Test
fun noClaimsWhenFileNameIsNull() { fun noClaimsWhenFileNameIsNull() {
wikidataEditService!!.createClaimWithLogging("Q1", null,"") wikidataEditService!!.createClaimWithLogging("Q1", "Test", null,"")
verifyZeroInteractions(wikidataClient!!) verifyZeroInteractions(wikidataClient!!)
} }
@Test @Test
fun noClaimsWhenP18IsNotEmpty() { fun noClaimsWhenP18IsNotEmpty() {
wikidataEditService!!.createClaimWithLogging("Q1", "Test.jpg","Previous.jpg") wikidataEditService!!.createClaimWithLogging("Q1", "Test","Test.jpg","Previous.jpg")
verifyZeroInteractions(wikidataClient!!) verifyZeroInteractions(wikidataClient!!)
} }
@ -57,7 +57,7 @@ class WikidataEditServiceTest {
fun noClaimsWhenLocationIsNotCorrect() { fun noClaimsWhenLocationIsNotCorrect() {
`when`(directKvStore!!.getBoolean("Picture_Has_Correct_Location", true)) `when`(directKvStore!!.getBoolean("Picture_Has_Correct_Location", true))
.thenReturn(false) .thenReturn(false)
wikidataEditService!!.createClaimWithLogging("Q1", "Test.jpg","") wikidataEditService!!.createClaimWithLogging("Q1", "","Test.jpg","")
verifyZeroInteractions(wikidataClient!!) verifyZeroInteractions(wikidataClient!!)
} }
@ -69,7 +69,7 @@ class WikidataEditServiceTest {
.thenReturn(Observable.just(1L)) .thenReturn(Observable.just(1L))
`when`(wikidataClient!!.addEditTag(anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())) `when`(wikidataClient!!.addEditTag(anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
.thenReturn(Observable.just(mock(AddEditTagResponse::class.java))) .thenReturn(Observable.just(mock(AddEditTagResponse::class.java)))
wikidataEditService!!.createClaimWithLogging("Q1", "Test.jpg","") wikidataEditService!!.createClaimWithLogging("Q1", "Test","Test.jpg","")
verify(wikidataClient!!, times(1)) verify(wikidataClient!!, times(1))
.createClaim(ArgumentMatchers.anyString(), ArgumentMatchers.anyString()) .createClaim(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())
} }