Skip to content

Commit b2a150a

Browse files
Vivek Maskaramisaochan
Vivek Maskara
authored andcommitted
Fix issue where Wikidata edits were not happening (#1682)
* Added logs to debug wikidata edits * Minor changes in logs
1 parent 306f23d commit b2a150a

10 files changed

+55
-9
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_CAMERA;
2525
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY;
2626
import static fr.free.nrw.commons.upload.UploadService.EXTRA_SOURCE;
27+
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
2728

2829
public class ContributionController {
2930

@@ -91,6 +92,7 @@ public void startGalleryPick() {
9192
}
9293

9394
public void handleImagePicked(int requestCode, Intent data, boolean isDirectUpload, String wikiDataEntityId) {
95+
Timber.d("Is direct upload %s and the Wikidata entity ID is %s", isDirectUpload, wikiDataEntityId);
9496
FragmentActivity activity = fragment.getActivity();
9597
Timber.d("handleImagePicked() called with onActivityResult()");
9698
Intent shareIntent = new Intent(activity, ShareActivity.class);
@@ -119,7 +121,7 @@ public void handleImagePicked(int requestCode, Intent data, boolean isDirectUplo
119121
try {
120122
shareIntent.putExtra("isDirectUpload", isDirectUpload);
121123
if (wikiDataEntityId != null && !wikiDataEntityId.equals("")) {
122-
shareIntent.putExtra("wikiDataEntityId", wikiDataEntityId);
124+
shareIntent.putExtra(WIKIDATA_ENTITY_ID_PREF, wikiDataEntityId);
123125
}
124126
activity.startActivity(shareIntent);
125127
} catch (SecurityException e) {

app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import static android.app.Activity.RESULT_OK;
3737
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
38+
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
3839

3940
public class NearbyListFragment extends DaggerFragment {
4041
private Bundle bundleForUpdates; // Carry information from activity about changed nearby places and current location
@@ -146,7 +147,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
146147
if (resultCode == RESULT_OK) {
147148
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
148149
requestCode, resultCode, data);
149-
controller.handleImagePicked(requestCode, data, true, directPrefs.getString("WikiDataEntityId", null));
150+
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
150151
} else {
151152
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
152153
requestCode, resultCode, data);

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
import static android.app.Activity.RESULT_OK;
6565
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
66+
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
6667

6768
public class NearbyMapFragment extends DaggerFragment {
6869

@@ -711,15 +712,15 @@ private void passInfoToSheet(Place place) {
711712

712713
fabCamera.setOnClickListener(view -> {
713714
if (fabCamera.isShown()) {
714-
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
715+
Timber.d("Camera button tapped. Place: %s", place.toString());
715716
storeSharedPrefs();
716717
directUpload.initiateCameraUpload();
717718
}
718719
});
719720

720721
fabGallery.setOnClickListener(view -> {
721722
if (fabGallery.isShown()) {
722-
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
723+
Timber.d("Gallery button tapped. Place: %s", place.toString());
723724
storeSharedPrefs();
724725
directUpload.initiateGalleryUpload();
725726
}
@@ -731,7 +732,7 @@ void storeSharedPrefs() {
731732
editor.putString("Title", place.getName());
732733
editor.putString("Desc", place.getLongDescription());
733734
editor.putString("Category", place.getCategory());
734-
editor.putString("WikiDataEntityId", place.getWikiDataEntityId());
735+
editor.putString(WIKIDATA_ENTITY_ID_PREF, place.getWikiDataEntityId());
735736
editor.apply();
736737
}
737738

@@ -767,7 +768,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
767768
if (resultCode == RESULT_OK) {
768769
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
769770
requestCode, resultCode, data);
770-
controller.handleImagePicked(requestCode, data, true, directPrefs.getString("WikiDataEntityId", null));
771+
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
771772
} else {
772773
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
773774
requestCode, resultCode, data);

app/src/main/java/fr/free/nrw/commons/nearby/Place.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import fr.free.nrw.commons.R;
1212
import fr.free.nrw.commons.location.LatLng;
13+
import timber.log.Timber;
1314

1415
public class Place {
1516

@@ -58,10 +59,12 @@ public void setDistance(String distance) {
5859
@Nullable
5960
public String getWikiDataEntityId() {
6061
if (!hasWikidataLink()) {
62+
Timber.d("Wikidata entity ID is null for place with sitelink %s", siteLinks.toString());
6163
return null;
6264
}
6365

6466
String wikiDataLink = siteLinks.getWikidataLink().toString();
67+
Timber.d("Wikidata entity is %s", wikiDataLink);
6568
return wikiDataLink.replace("http://www.wikidata.org/entity/", "");
6669
}
6770

@@ -94,7 +97,18 @@ public int hashCode() {
9497

9598
@Override
9699
public String toString() {
97-
return String.format("Place(%s@%s)", name, location);
100+
return "Place{" +
101+
"name='" + name + '\'' +
102+
", label='" + label + '\'' +
103+
", longDescription='" + longDescription + '\'' +
104+
", secondaryImageUrl='" + secondaryImageUrl + '\'' +
105+
", location='" + location + '\'' +
106+
", category='" + category + '\'' +
107+
", image='" + image + '\'' +
108+
", secondaryImage=" + secondaryImage +
109+
", distance='" + distance + '\'' +
110+
", siteLinks='" + siteLinks.toString() + '\'' +
111+
'}';
98112
}
99113

100114
/**

app/src/main/java/fr/free/nrw/commons/nearby/Sitelinks.java

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ private static Uri sanitiseString(String stringUrl) {
5858
return Uri.parse(sanitisedStringUrl);
5959
}
6060

61+
@Override
62+
public String toString() {
63+
return "Sitelinks{" +
64+
"wikipediaLink='" + wikipediaLink + '\'' +
65+
", commonsLink='" + commonsLink + '\'' +
66+
", wikidataLink='" + wikidataLink + '\'' +
67+
'}';
68+
}
69+
6170
private Sitelinks(Sitelinks.Builder builder) {
6271
this.wikidataLink = builder.wikidataLink;
6372
this.wikipediaLink = builder.wikipediaLink;

app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.DUPLICATE_PROCEED;
6969
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
7070
import static fr.free.nrw.commons.upload.FileUtils.getSHA1;
71+
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
7172

7273
/**
7374
* Activity for the title/desc screen after image is selected. Also starts processing image
@@ -325,6 +326,8 @@ private void receiveImageIntent() {
325326
if (intent.hasExtra("isDirectUpload")) {
326327
Timber.d("This was initiated by a direct upload from Nearby");
327328
isNearbyUpload = true;
329+
wikiDataEntityId = intent.getStringExtra(WIKIDATA_ENTITY_ID_PREF);
330+
Timber.d("Received wikiDataEntityId from contribution controller %s", wikiDataEntityId);
328331
}
329332
mimeType = intent.getType();
330333
}

app/src/main/java/fr/free/nrw/commons/upload/UploadController.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.free.nrw.commons.upload;
22

3+
import android.annotation.SuppressLint;
34
import android.accounts.Account;
45
import android.content.ComponentName;
56
import android.content.ContentResolver;
@@ -98,6 +99,7 @@ public void cleanup() {
9899
public void startUpload(String title, Uri mediaUri, String description, String mimeType, String source, String decimalCoords, String wikiDataEntityId, ContributionUploadProgress onComplete) {
99100
Contribution contribution;
100101

102+
Timber.d("Wikidata entity ID received from Share activity is %s", wikiDataEntityId);
101103
//TODO: Modify this to include coords
102104
Account currentAccount = sessionManager.getCurrentAccount();
103105
if(currentAccount == null) {
@@ -124,6 +126,7 @@ public void startUpload(String title, Uri mediaUri, String description, String m
124126
* @param contribution the contribution object
125127
* @param onComplete the progress tracker
126128
*/
129+
@SuppressLint("StaticFieldLeak")
127130
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
128131
//Set creator, desc, and license
129132
if (TextUtils.isEmpty(contribution.getCreator())) {

app/src/main/java/fr/free/nrw/commons/upload/UploadService.java

+2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,10 @@ private void uploadContribution(Contribution contribution) {
259259

260260
String resultStatus = uploadResult.getResultStatus();
261261
if (!resultStatus.equals("Success")) {
262+
Timber.d("Contribution upload failed. Wikidata entity won't be edited");
262263
showFailedNotification(contribution);
263264
} else {
265+
Timber.d("Contribution upload success. Initiating Wikidata edit for entity id %s", contribution.getWikiDataEntityId());
264266
wikidataEditService.createClaimWithLogging(contribution.getWikiDataEntityId(), filename);
265267
contribution.setFilename(uploadResult.getCanonicalFilename());
266268
contribution.setImageUrl(uploadResult.getImageUrl());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fr.free.nrw.commons.wikidata;
2+
3+
public class WikidataConstants {
4+
public static final String WIKIDATA_ENTITY_ID_PREF = "WikiDataEntityId";
5+
}

app/src/main/java/fr/free/nrw/commons/wikidata/WikidataEditService.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ public WikidataEditService(Context context,
4848
* @param fileName
4949
*/
5050
public void createClaimWithLogging(String wikidataEntityId, String fileName) {
51-
if(wikidataEntityId == null
52-
|| fileName == null) {
51+
if(wikidataEntityId == null) {
52+
Timber.d("Skipping creation of claim as Wikidata entity ID is null");
5353
return;
5454
}
55+
56+
if(fileName == null) {
57+
Timber.d("Skipping creation of claim as fileName entity ID is null");
58+
return;
59+
}
60+
5561
editWikidataProperty(wikidataEntityId, fileName);
5662
}
5763

0 commit comments

Comments
 (0)