Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 3526 Unlike "Items" tab, "child classes" tab does not display description nor image thumbnail #3619

Merged
merged 8 commits into from
Apr 10, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class Binding {
@SerializedName("subclassLabel")
@Expose
private SubclassLabel subclassLabel;

@SerializedName("subclassDescription")
@Expose
private SubclassDescription subclassDescription;
/**
* No args constructor for use in serialization
*
Expand All @@ -26,10 +28,11 @@ public Binding() {
* @param subclassLabel
* @param subclass
*/
public Binding(Subclass subclass, SubclassLabel subclassLabel) {
public Binding(Subclass subclass, SubclassLabel subclassLabel, SubclassDescription subclassDescription) {
super();
this.subclass = subclass;
this.subclassLabel = subclassLabel;
this.subclassDescription = subclassDescription;
}

public Subclass getSubclass() {
Expand All @@ -44,8 +47,16 @@ public SubclassLabel getSubclassLabel() {
return subclassLabel;
}

public SubclassDescription getSubclassDescription(){
return subclassDescription;
}

public void setSubclassLabel(SubclassLabel subclassLabel) {
this.subclassLabel = subclassLabel;
}

public void setSubclassDescription(SubclassDescription subclassDescription) {
this.subclassDescription = subclassDescription;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package fr.free.nrw.commons.depictions.SubClass.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

/**
* Model class for parsing SparqlQueryResponse
*/
public class SubclassDescription {

@SerializedName("type")
@Expose
private String type;
@SerializedName("value")
@Expose
private String value;
@SerializedName("xml:lang")
@Expose
private String xmlLang;

/**
* No args constructor for use in serialization
*
*/
public SubclassDescription() {
}

/**
*
* @param value
* @param xmlLang
* @param type
*/
public SubclassDescription(String type, String value, String xmlLang) {
super();
this.type = type;
this.value = value;
this.xmlLang = xmlLang;
}

public String getType() {
return type;
}

/**
* returns type
*/
public void setType(String type) {
this.type = type;
}

/**
* gets value of the depiction
*/
public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

/**
* get language in which the depiction was requested
*/
public String getXmlLang() {
return xmlLang;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.google.gson.Gson;

import fr.free.nrw.commons.depictions.SubClass.models.SubclassDescription;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -242,7 +243,13 @@ public Observable<ArrayList<DepictedItem>> getChildQIDs(String qid) throws IOExc
String label = binding.getSubclassLabel().getValue();
String entityId = binding.getSubclass().getValue();
entityId = entityId.substring(entityId.lastIndexOf("/") + 1);
subItems.add(new DepictedItem(label, "", "", false,entityId ));
String description = "";
SubclassDescription subclassDescription = binding.getSubclassDescription();
if (subclassDescription != null
&& subclassDescription.getXmlLang() != null) {
description = subclassDescription.getValue();
}
subItems.add(new DepictedItem(label, description, "", false, entityId));
Timber.e(label);
}
}
Expand Down Expand Up @@ -288,7 +295,13 @@ public Observable<ArrayList<DepictedItem>> getParentQIDs(String qid) throws IOEx
if (parentClass.get("value") != null) {
String entityId = parentClass.getString("value");
entityId = entityId.substring(entityId.lastIndexOf("/") + 1);
subItems.add(new DepictedItem(labelString, "", "", false, entityId));
String description = "";
if (!object.isNull("parentClassDescription")) {
JSONObject parentClassDescription = (JSONObject) object
.get("parentClassDescription");
description = parentClassDescription.getString("value");
}
subItems.add(new DepictedItem(labelString, description, "", false, entityId));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/resources/queries/parentclasses_query.rq
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SELECT ?parentClass ?parentClassLabel WHERE {
SELECT ?parentClass ?parentClassLabel ?parentClassDescription WHERE {
wd:${QID} wdt:P279 ?parentClass.
SERVICE wikibase:label { bd:serviceParam wikibase:language ${LANG}. }
}
2 changes: 1 addition & 1 deletion app/src/main/resources/queries/subclasses_query.rq
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SELECT ?subclass ?subclassLabel WHERE {
SELECT ?subclass ?subclassLabel ?subclassDescription WHERE {
?subclass wdt:P279 wd:${QID}.
SERVICE wikibase:label { bd:serviceParam wikibase:language ${LANG}. }
}