mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fix issue where Wikidata edits were not happening (#1682)
* Added logs to debug wikidata edits * Minor changes in logs
This commit is contained in:
parent
306f23d1e2
commit
b2a150a3ae
10 changed files with 55 additions and 9 deletions
|
|
@ -24,6 +24,7 @@ import static android.content.Intent.EXTRA_STREAM;
|
|||
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_CAMERA;
|
||||
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY;
|
||||
import static fr.free.nrw.commons.upload.UploadService.EXTRA_SOURCE;
|
||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
|
||||
|
||||
public class ContributionController {
|
||||
|
||||
|
|
@ -91,6 +92,7 @@ public class ContributionController {
|
|||
}
|
||||
|
||||
public void handleImagePicked(int requestCode, Intent data, boolean isDirectUpload, String wikiDataEntityId) {
|
||||
Timber.d("Is direct upload %s and the Wikidata entity ID is %s", isDirectUpload, wikiDataEntityId);
|
||||
FragmentActivity activity = fragment.getActivity();
|
||||
Timber.d("handleImagePicked() called with onActivityResult()");
|
||||
Intent shareIntent = new Intent(activity, ShareActivity.class);
|
||||
|
|
@ -119,7 +121,7 @@ public class ContributionController {
|
|||
try {
|
||||
shareIntent.putExtra("isDirectUpload", isDirectUpload);
|
||||
if (wikiDataEntityId != null && !wikiDataEntityId.equals("")) {
|
||||
shareIntent.putExtra("wikiDataEntityId", wikiDataEntityId);
|
||||
shareIntent.putExtra(WIKIDATA_ENTITY_ID_PREF, wikiDataEntityId);
|
||||
}
|
||||
activity.startActivity(shareIntent);
|
||||
} catch (SecurityException e) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import timber.log.Timber;
|
|||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
|
||||
|
||||
public class NearbyListFragment extends DaggerFragment {
|
||||
private Bundle bundleForUpdates; // Carry information from activity about changed nearby places and current location
|
||||
|
|
@ -146,7 +147,7 @@ public class NearbyListFragment extends DaggerFragment {
|
|||
if (resultCode == RESULT_OK) {
|
||||
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
|
||||
requestCode, resultCode, data);
|
||||
controller.handleImagePicked(requestCode, data, true, directPrefs.getString("WikiDataEntityId", null));
|
||||
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
|
||||
} else {
|
||||
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
|
||||
requestCode, resultCode, data);
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;
|
|||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
|
||||
|
||||
public class NearbyMapFragment extends DaggerFragment {
|
||||
|
||||
|
|
@ -711,7 +712,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
|
||||
fabCamera.setOnClickListener(view -> {
|
||||
if (fabCamera.isShown()) {
|
||||
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
|
||||
Timber.d("Camera button tapped. Place: %s", place.toString());
|
||||
storeSharedPrefs();
|
||||
directUpload.initiateCameraUpload();
|
||||
}
|
||||
|
|
@ -719,7 +720,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
|
||||
fabGallery.setOnClickListener(view -> {
|
||||
if (fabGallery.isShown()) {
|
||||
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
|
||||
Timber.d("Gallery button tapped. Place: %s", place.toString());
|
||||
storeSharedPrefs();
|
||||
directUpload.initiateGalleryUpload();
|
||||
}
|
||||
|
|
@ -731,7 +732,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
editor.putString("Title", place.getName());
|
||||
editor.putString("Desc", place.getLongDescription());
|
||||
editor.putString("Category", place.getCategory());
|
||||
editor.putString("WikiDataEntityId", place.getWikiDataEntityId());
|
||||
editor.putString(WIKIDATA_ENTITY_ID_PREF, place.getWikiDataEntityId());
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
|
@ -767,7 +768,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
if (resultCode == RESULT_OK) {
|
||||
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
|
||||
requestCode, resultCode, data);
|
||||
controller.handleImagePicked(requestCode, data, true, directPrefs.getString("WikiDataEntityId", null));
|
||||
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
|
||||
} else {
|
||||
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
|
||||
requestCode, resultCode, data);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.util.Map;
|
|||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class Place {
|
||||
|
||||
|
|
@ -58,10 +59,12 @@ public class Place {
|
|||
@Nullable
|
||||
public String getWikiDataEntityId() {
|
||||
if (!hasWikidataLink()) {
|
||||
Timber.d("Wikidata entity ID is null for place with sitelink %s", siteLinks.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
String wikiDataLink = siteLinks.getWikidataLink().toString();
|
||||
Timber.d("Wikidata entity is %s", wikiDataLink);
|
||||
return wikiDataLink.replace("http://www.wikidata.org/entity/", "");
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +97,18 @@ public class Place {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Place(%s@%s)", name, location);
|
||||
return "Place{" +
|
||||
"name='" + name + '\'' +
|
||||
", label='" + label + '\'' +
|
||||
", longDescription='" + longDescription + '\'' +
|
||||
", secondaryImageUrl='" + secondaryImageUrl + '\'' +
|
||||
", location='" + location + '\'' +
|
||||
", category='" + category + '\'' +
|
||||
", image='" + image + '\'' +
|
||||
", secondaryImage=" + secondaryImage +
|
||||
", distance='" + distance + '\'' +
|
||||
", siteLinks='" + siteLinks.toString() + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -58,6 +58,15 @@ public class Sitelinks implements Parcelable {
|
|||
return Uri.parse(sanitisedStringUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Sitelinks{" +
|
||||
"wikipediaLink='" + wikipediaLink + '\'' +
|
||||
", commonsLink='" + commonsLink + '\'' +
|
||||
", wikidataLink='" + wikidataLink + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
private Sitelinks(Sitelinks.Builder builder) {
|
||||
this.wikidataLink = builder.wikidataLink;
|
||||
this.wikipediaLink = builder.wikipediaLink;
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ import android.support.design.widget.FloatingActionButton;
|
|||
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.DUPLICATE_PROCEED;
|
||||
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
|
||||
import static fr.free.nrw.commons.upload.FileUtils.getSHA1;
|
||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;
|
||||
|
||||
/**
|
||||
* Activity for the title/desc screen after image is selected. Also starts processing image
|
||||
|
|
@ -325,6 +326,8 @@ public class ShareActivity
|
|||
if (intent.hasExtra("isDirectUpload")) {
|
||||
Timber.d("This was initiated by a direct upload from Nearby");
|
||||
isNearbyUpload = true;
|
||||
wikiDataEntityId = intent.getStringExtra(WIKIDATA_ENTITY_ID_PREF);
|
||||
Timber.d("Received wikiDataEntityId from contribution controller %s", wikiDataEntityId);
|
||||
}
|
||||
mimeType = intent.getType();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.accounts.Account;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
|
|
@ -98,6 +99,7 @@ public class UploadController {
|
|||
public void startUpload(String title, Uri mediaUri, String description, String mimeType, String source, String decimalCoords, String wikiDataEntityId, ContributionUploadProgress onComplete) {
|
||||
Contribution contribution;
|
||||
|
||||
Timber.d("Wikidata entity ID received from Share activity is %s", wikiDataEntityId);
|
||||
//TODO: Modify this to include coords
|
||||
Account currentAccount = sessionManager.getCurrentAccount();
|
||||
if(currentAccount == null) {
|
||||
|
|
@ -124,6 +126,7 @@ public class UploadController {
|
|||
* @param contribution the contribution object
|
||||
* @param onComplete the progress tracker
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
|
||||
//Set creator, desc, and license
|
||||
if (TextUtils.isEmpty(contribution.getCreator())) {
|
||||
|
|
|
|||
|
|
@ -259,8 +259,10 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
|
||||
String resultStatus = uploadResult.getResultStatus();
|
||||
if (!resultStatus.equals("Success")) {
|
||||
Timber.d("Contribution upload failed. Wikidata entity won't be edited");
|
||||
showFailedNotification(contribution);
|
||||
} else {
|
||||
Timber.d("Contribution upload success. Initiating Wikidata edit for entity id %s", contribution.getWikiDataEntityId());
|
||||
wikidataEditService.createClaimWithLogging(contribution.getWikiDataEntityId(), filename);
|
||||
contribution.setFilename(uploadResult.getCanonicalFilename());
|
||||
contribution.setImageUrl(uploadResult.getImageUrl());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
package fr.free.nrw.commons.wikidata;
|
||||
|
||||
public class WikidataConstants {
|
||||
public static final String WIKIDATA_ENTITY_ID_PREF = "WikiDataEntityId";
|
||||
}
|
||||
|
|
@ -48,10 +48,16 @@ public class WikidataEditService {
|
|||
* @param fileName
|
||||
*/
|
||||
public void createClaimWithLogging(String wikidataEntityId, String fileName) {
|
||||
if(wikidataEntityId == null
|
||||
|| fileName == null) {
|
||||
if(wikidataEntityId == null) {
|
||||
Timber.d("Skipping creation of claim as Wikidata entity ID is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if(fileName == null) {
|
||||
Timber.d("Skipping creation of claim as fileName entity ID is null");
|
||||
return;
|
||||
}
|
||||
|
||||
editWikidataProperty(wikidataEntityId, fileName);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue