Added tag index download

This commit is contained in:
Juan Miguel Boyero Corral 2011-05-09 17:11:29 +02:00
parent be3d8a308e
commit 1604c83aa5
4 changed files with 67 additions and 22 deletions

View File

@ -142,7 +142,8 @@ public class DataBaseHelper {
if(t != null) {
o = new TestTag(id,
t.getQstCod(),
ent.getString("tagTxt"));
ent.getString("tagTxt"),
ent.getInt("tagInd"));
} else {
o = null;
}
@ -157,7 +158,8 @@ public class DataBaseHelper {
} else if(table.equals(Global.DB_TABLE_TEST_QUESTION_TAGS)) {
o = new TestTag(ent.getInt("tagCod"),
ent.getInt("qstCod"),
null);
null,
ent.getInt("tagInd"));
}
return o;
@ -285,9 +287,8 @@ public class DataBaseHelper {
/**
* Inserts a test tag in database
* @param t Test tag to be inserted
* @param qstCod Test question code to be referenced
*/
public void insertTestTag(TestTag t, int qstCod)
public void insertTestTag(TestTag t)
{
Entity ent = new Entity(Global.DB_TABLE_TEST_TAGS);
@ -296,8 +297,9 @@ public class DataBaseHelper {
ent.save();
ent = new Entity(Global.DB_TABLE_TEST_QUESTION_TAGS);
ent.setValue("qstCod", qstCod);
ent.setValue("qstCod", t.getQstCod());
ent.setValue("tagCod", t.getId());
ent.setValue("tagInd", t.getTagInd());
ent.save();
}
@ -428,9 +430,8 @@ public class DataBaseHelper {
* Updates a test tag in database
* @param prev Test tag to be updated
* @param actual Updated test tag
* @param qstCod Test question code to be referenced
*/
public void updateTestTag(TestTag prev, TestTag actual, int qstCod)
public void updateTestTag(TestTag prev, TestTag actual)
{
List<Entity> rows = db.getEntityList(Global.DB_TABLE_TEST_TAGS, "id = " + prev.getId());
Entity ent = rows.get(0);
@ -441,7 +442,8 @@ public class DataBaseHelper {
ent = new Entity(Global.DB_TABLE_TEST_QUESTION_TAGS);
ent.setValue("tagCod", actual.getId());
ent.setValue("qstCod", qstCod);
ent.setValue("qstCod", actual.getQstCod());
ent.setValue("tagInd", actual.getTagInd());
ent.save();
}

View File

@ -35,22 +35,30 @@ public class TestTag extends Model {
* Tag text
*/
private String tagTxt;
/**
* Tag index
*/
private int tagInd;
private static PropertyInfo PI_id = new PropertyInfo();
private static PropertyInfo PI_tagText = new PropertyInfo();
private static PropertyInfo PI_tagInd = new PropertyInfo();
private static PropertyInfo[] PI_PROP_ARRAY =
{
PI_id,
PI_tagText
PI_tagText,
PI_tagInd
};
/**
* Constructor
* @param id tag id
* @param tagTxt Tag text
* @param tagInd Tag index
*/
public TestTag(int id, String tagTxt) {
public TestTag(int id, String tagTxt, int tagInd) {
super(id);
this.tagTxt = tagTxt;
this.tagInd = tagInd;
}
/**
@ -58,11 +66,13 @@ public class TestTag extends Model {
* @param id tag id
* @param qstCod question id
* @param tagTxt Tag text
* @param tagInd Tag index
*/
public TestTag(int id, int qstCod, String tagTxt) {
public TestTag(int id, int qstCod, String tagTxt, int tagInd) {
super(id);
this.qstCod = qstCod;
this.tagTxt = tagTxt;
this.tagInd = tagInd;
}
/**
@ -97,6 +107,22 @@ public class TestTag extends Model {
this.qstCod = qstCod;
}
/**
* Gets tag index
* @return Tag index
*/
public int getTagInd() {
return tagInd;
}
/**
* Sets tag index
* @param tagInd Tag index
*/
public void setTagInd(int tagInd) {
this.tagInd = tagInd;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@ -105,6 +131,8 @@ public class TestTag extends Model {
final int prime = 31;
int result = super.hashCode();
result = prime * result + qstCod;
result = prime * result + tagInd;
result = prime * result + ((tagTxt == null) ? 0 : tagTxt.hashCode());
return result;
}
@ -113,8 +141,8 @@ public class TestTag extends Model {
*/
@Override
public String toString() {
return "TestTag [qstCod=" + qstCod + ", tagTxt=" + tagTxt
+ ", getId()=" + getId() + "]";
return "TestTag [qstCod=" + qstCod + ", tagTxt=" + tagTxt + ", tagInd="
+ tagInd + ", getId()=" + getId() + "]";
}
/* (non-Javadoc)
@ -126,6 +154,7 @@ public class TestTag extends Model {
{
case 0 : object = this.getId();break;
case 1 : object = tagTxt;break;
case 2 : object = tagInd;break;
}
return object;
@ -135,7 +164,7 @@ public class TestTag extends Model {
* @see org.ksoap2.serialization.KvmSerializable#getPropertyCount()
*/
public int getPropertyCount() {
return 2;
return 3;
}
/* (non-Javadoc)
@ -151,6 +180,10 @@ public class TestTag extends Model {
propertyInfo.type = PropertyInfo.STRING_CLASS;
propertyInfo.name = "tagTxt";
break;
case 2:
propertyInfo.type = PropertyInfo.INTEGER_CLASS;
propertyInfo.name = "tagInd";
break;
}
}
@ -162,6 +195,7 @@ public class TestTag extends Model {
{
case 0 : this.setId((Integer)obj); break;
case 1 : tagTxt = (String)obj; break;
case 2 : tagInd = (Integer)obj; break;
}
}

View File

@ -24,6 +24,8 @@ import java.security.NoSuchAlgorithmException;
import org.ksoap2.SoapFault;
import org.xmlpull.v1.XmlPullParserException;
import android.os.Bundle;
import es.ugr.swad.swadroid.modules.Module;
/**
@ -32,6 +34,15 @@ import es.ugr.swad.swadroid.modules.Module;
*/
public class TestsMake extends Module {
/* (non-Javadoc)
* @see es.ugr.swad.swadroid.modules.Module#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see es.ugr.swad.swadroid.modules.Module#requestService()
*/
@ -39,7 +50,6 @@ public class TestsMake extends Module {
protected void requestService() throws NoSuchAlgorithmException,
IOException, XmlPullParserException, SoapFault,
IllegalAccessException, InstantiationException {
// TODO Auto-generated method stub
}
@ -48,7 +58,6 @@ public class TestsMake extends Module {
*/
@Override
protected void connect() {
// TODO Auto-generated method stub
}
@ -57,7 +66,6 @@ public class TestsMake extends Module {
*/
@Override
protected void postConnect() {
// TODO Auto-generated method stub
}

View File

@ -111,7 +111,7 @@ public class TestsQuestionsDownload extends Module {
SoapObject pii = (SoapObject)tagsListObject.getProperty(i);
Integer tagCod = new Integer(pii.getProperty("tagCode").toString());
String tagTxt = pii.getProperty("tagText").toString();
TestTag tag = new TestTag(tagCod, 0, tagTxt);
TestTag tag = new TestTag(tagCod, 0, tagTxt, 0);
tagsList.add(tag);
if(isDebuggable)
@ -180,13 +180,14 @@ public class TestsQuestionsDownload extends Module {
SoapObject pii = (SoapObject)questionTagsListObject.getProperty(i);
Integer qstCod = new Integer(pii.getProperty("questionCode").toString());
Integer tagCod = new Integer(pii.getProperty("tagCode").toString());
//Integer tagIndex = new Integer(pii.getProperty("tagIndex").toString());
TestTag tag = tagsList.get(tagsList.indexOf(new TestTag(tagCod, "")));
Integer tagIndex = new Integer(pii.getProperty("tagIndex").toString());
TestTag tag = tagsList.get(tagsList.indexOf(new TestTag(tagCod, "", 0)));
tag.setQstCod(qstCod);
tag.setTagInd(tagIndex);
//If it's a new tag, insert in database
if(!tagsListDB.contains(tag)) {
dbHelper.insertTestTag(tag, qstCod);
dbHelper.insertTestTag(tag);
tagsListDB.add(tag);
questionTagsListDB.add(new PairTable<Integer, Integer>(Global.DB_TABLE_TEST_QUESTION_TAGS,
tag.getQstCod(), tag.getId()));
@ -194,7 +195,7 @@ public class TestsQuestionsDownload extends Module {
//If it's an updated tag, update it's rows in database
} else if(!questionTagsListDB.contains(tag)) {
TestTag old = (TestTag) tagsListDB.get(tagsListDB.indexOf(tag));
dbHelper.updateTestTag(old, tag, qstCod);
dbHelper.updateTestTag(old, tag);
questionTagsListDB.add(new PairTable<Integer, Integer>(Global.DB_TABLE_TEST_QUESTION_TAGS,
tag.getQstCod(), tag.getId()));
}