added correct management with removed and updated groups and group types
This commit is contained in:
parent
f580072057
commit
5a2919a0f3
|
@ -788,7 +788,7 @@ public class DataBaseHelper {
|
||||||
}else{
|
}else{
|
||||||
ent = new Entity(tableName);
|
ent = new Entity(tableName);
|
||||||
}
|
}
|
||||||
if(tableName.equals(Global.DB_TABLE_GROUPS)){
|
if(tableName.compareTo(Global.DB_TABLE_GROUPS) == 0){
|
||||||
Group g = (Group) currentModel;
|
Group g = (Group) currentModel;
|
||||||
ent.setValue("id", g.getId());
|
ent.setValue("id", g.getId());
|
||||||
ent.setValue("groupName", g.getGroupName());
|
ent.setValue("groupName", g.getGroupName());
|
||||||
|
@ -800,7 +800,7 @@ public class DataBaseHelper {
|
||||||
ent.save();
|
ent.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tableName.equals(Global.DB_TABLE_GROUP_TYPES)){
|
if(tableName.compareTo(Global.DB_TABLE_GROUP_TYPES) == 0){
|
||||||
GroupType gt = (GroupType) currentModel;
|
GroupType gt = (GroupType) currentModel;
|
||||||
ent.setValue("id", gt.getId());
|
ent.setValue("id", gt.getId());
|
||||||
ent.setValue("groupTypeName", gt.getGroupTypeName());
|
ent.setValue("groupTypeName", gt.getGroupTypeName());
|
||||||
|
@ -875,7 +875,11 @@ public class DataBaseHelper {
|
||||||
boolean returnValue = true;
|
boolean returnValue = true;
|
||||||
if(rows.isEmpty()) {
|
if(rows.isEmpty()) {
|
||||||
insertEntity(Global.DB_TABLE_GROUPS,g);
|
insertEntity(Global.DB_TABLE_GROUPS,g);
|
||||||
|
} else { //already exits a group with the given code. just update
|
||||||
|
insertEntity(Global.DB_TABLE_GROUPS,g,rows.get(0));
|
||||||
|
|
||||||
|
}
|
||||||
|
//update all the relationship
|
||||||
Entity ent;
|
Entity ent;
|
||||||
|
|
||||||
long groupCode = g.getId();
|
long groupCode = g.getId();
|
||||||
|
@ -885,7 +889,7 @@ public class DataBaseHelper {
|
||||||
//it should not insert/modify rows in the relationship table if the course does not exists
|
//it should not insert/modify rows in the relationship table if the course does not exists
|
||||||
if(course != null){
|
if(course != null){
|
||||||
if(rows.isEmpty()){
|
if(rows.isEmpty()){
|
||||||
PairTable<Long,Long> pair = new PairTable(Global.DB_TABLE_GROUPS_COURSES,courseCode,g.getId());
|
PairTable<Long,Long> pair = new PairTable(Global.DB_TABLE_GROUPS_COURSES,g.getId(),courseCode);
|
||||||
insertPairTable(pair);
|
insertPairTable(pair);
|
||||||
}else{
|
}else{
|
||||||
rows.get(0).setValue("crsCod", courseCode);
|
rows.get(0).setValue("crsCod", courseCode);
|
||||||
|
@ -904,22 +908,14 @@ public class DataBaseHelper {
|
||||||
if(rows.isEmpty()){
|
if(rows.isEmpty()){
|
||||||
Pair<String,String> params = selectParamsPairTable(Global.DB_TABLE_GROUPS_GROUPTYPES);
|
Pair<String,String> params = selectParamsPairTable(Global.DB_TABLE_GROUPS_GROUPTYPES);
|
||||||
insertPairTable(new PairTable<Long,Long>(Global.DB_TABLE_GROUPS_GROUPTYPES,groupTypeCode,groupCode));
|
insertPairTable(new PairTable<Long,Long>(Global.DB_TABLE_GROUPS_GROUPTYPES,groupTypeCode,groupCode));
|
||||||
/*ent = new Entity(Global.DB_TABLE_GROUPS_GROUPTYPES);
|
|
||||||
ent.setValue("grpCod", groupCode);
|
|
||||||
ent.setValue("grpTypCod", groupTypeCode[0]);
|
|
||||||
ent.save();*/
|
|
||||||
}else{
|
}else{
|
||||||
PairTable<Integer,Integer> prev = new PairTable(Global.DB_TABLE_GROUPS_GROUPTYPES,rows.get(0).getValue("grpTypCod"),rows.get(0).getValue("grpCod"));
|
PairTable<Integer,Integer> prev = new PairTable(Global.DB_TABLE_GROUPS_GROUPTYPES,rows.get(0).getValue("grpTypCod"),rows.get(0).getValue("grpCod"));
|
||||||
PairTable<Integer,Integer> current = new PairTable(Global.DB_TABLE_GROUPS_GROUPTYPES,groupTypeCode,groupCode);
|
PairTable<Integer,Integer> current = new PairTable(Global.DB_TABLE_GROUPS_GROUPTYPES,groupTypeCode,groupCode);
|
||||||
updatePairTable(prev,current);
|
updatePairTable(prev,current);
|
||||||
//rows.get(0).setValue("grpTypCod", groupTypeCode[0]);
|
|
||||||
//rows.get(0).save();
|
|
||||||
}
|
}
|
||||||
/*}else returnValue = false;*/
|
/*}else returnValue = false;*/
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
} else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -937,6 +933,62 @@ public class DataBaseHelper {
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean insertCollection(String table,List<Model> currentModels, long...courseCode){
|
||||||
|
boolean result = true;
|
||||||
|
List<Model> modelsDB = getAllRows(table);
|
||||||
|
List<Model> newModels = new ArrayList<Model>();
|
||||||
|
List<Model> obsoleteModel = new ArrayList<Model>();
|
||||||
|
List<Model> modifiedModel = new ArrayList<Model>();
|
||||||
|
|
||||||
|
newModels.addAll(currentModels);
|
||||||
|
newModels.removeAll(modelsDB);
|
||||||
|
|
||||||
|
obsoleteModel.addAll(modelsDB);
|
||||||
|
obsoleteModel.removeAll(currentModels);
|
||||||
|
|
||||||
|
modifiedModel.addAll(currentModels);
|
||||||
|
modifiedModel.removeAll(newModels);
|
||||||
|
modifiedModel.removeAll(obsoleteModel);
|
||||||
|
|
||||||
|
if(table.compareTo(Global.DB_TABLE_GROUP_TYPES) == 0){
|
||||||
|
for(int i = 0; i < obsoleteModel.size(); ++i){
|
||||||
|
long code = obsoleteModel.get(i).getId();
|
||||||
|
removeAllRow(table,"id", code);
|
||||||
|
removeAllRow(Global.DB_TABLE_GROUPS_GROUPTYPES,"grpTypCod", code);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < newModels.size(); ++i){
|
||||||
|
Model model = newModels.get(i);
|
||||||
|
insertEntity(table,model);
|
||||||
|
}
|
||||||
|
List<Entity> rows;
|
||||||
|
for(int i = 0; i < modifiedModel.size(); ++i){
|
||||||
|
Model m = modifiedModel.get(i);
|
||||||
|
rows = db.getEntityList(table, "id="+ m.getId());
|
||||||
|
insertEntity(table,m,rows.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(table.compareTo(Global.DB_TABLE_GROUPS) == 0){
|
||||||
|
for(int i = 0; i < obsoleteModel.size(); ++i){
|
||||||
|
long code = obsoleteModel.get(i).getId();
|
||||||
|
removeAllRow(table,"id", code);
|
||||||
|
removeAllRow(Global.DB_TABLE_GROUPS_GROUPTYPES,"grpCod", code);
|
||||||
|
removeAllRow(Global.DB_TABLE_GROUPS_COURSES,"grpCod",code);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < newModels.size(); ++i){
|
||||||
|
Model model = newModels.get(i);
|
||||||
|
insertGroup((Group) model, courseCode[0]);
|
||||||
|
}
|
||||||
|
List<Entity> rows;
|
||||||
|
for(int i = 0; i < modifiedModel.size(); ++i){
|
||||||
|
Model model = modifiedModel.get(i);
|
||||||
|
insertGroup((Group) model, courseCode[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts the rollcall data of a student to a practice session in database
|
* Inserts the rollcall data of a student to a practice session in database
|
||||||
* @param l User code of student
|
* @param l User code of student
|
||||||
|
|
|
@ -106,7 +106,9 @@ public class GroupTypes extends Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO remove obsolete groups
|
dbHelper.insertCollection(Global.DB_TABLE_GROUP_TYPES, groupsSWAD);
|
||||||
|
|
||||||
|
/* //TODO remove obsolete groups
|
||||||
for(int i = 0; i < groupsSWAD.size(); ++i){
|
for(int i = 0; i < groupsSWAD.size(); ++i){
|
||||||
GroupType g = (GroupType) groupsSWAD.get(i);
|
GroupType g = (GroupType) groupsSWAD.get(i);
|
||||||
//boolean isAdded = dbHelper.insertGroup(g,Global.getSelectedCourseCode());
|
//boolean isAdded = dbHelper.insertGroup(g,Global.getSelectedCourseCode());
|
||||||
|
@ -114,7 +116,7 @@ public class GroupTypes extends Module {
|
||||||
if(!dbHelper.insertGroupType(g)){
|
if(!dbHelper.insertGroupType(g)){
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
//Request finalized without errors
|
//Request finalized without errors
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,15 +131,16 @@ public class Groups extends Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbHelper.insertCollection(Global.DB_TABLE_GROUPS, groupsSWAD, courseCode);
|
||||||
//TODO remove obsolete groups
|
//TODO remove obsolete groups
|
||||||
for(int i = 0; i < groupsSWAD.size(); ++i){
|
/*for(int i = 0; i < groupsSWAD.size(); ++i){
|
||||||
Group g = (Group) groupsSWAD.get(i);
|
Group g = (Group) groupsSWAD.get(i);
|
||||||
//boolean isAdded = dbHelper.insertGroup(g,Global.getSelectedCourseCode());
|
//boolean isAdded = dbHelper.insertGroup(g,Global.getSelectedCourseCode());
|
||||||
//if(!isAdded){
|
//if(!isAdded){
|
||||||
if(!dbHelper.insertGroup(g,Global.getSelectedCourseCode())){
|
if(!dbHelper.insertGroup(g,Global.getSelectedCourseCode())){
|
||||||
dbHelper.updateGroup(g.getId(), Global.getSelectedCourseCode(), g);
|
dbHelper.updateGroup(g.getId(), Global.getSelectedCourseCode(), g);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
//Request finalized without errors
|
//Request finalized without errors
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class MyGroupsManager extends MenuExpandableListActivity {
|
||||||
groupTypesRequested = true;
|
groupTypesRequested = true;
|
||||||
if(dbHelper.getAllRows(Global.DB_TABLE_GROUP_TYPES, "courseCode = " + courseCode , "groupTypeName").size() > 0){
|
if(dbHelper.getAllRows(Global.DB_TABLE_GROUP_TYPES, "courseCode = " + courseCode , "groupTypeName").size() > 0){
|
||||||
//If there are not group types, either groups. Therefore, there is no need to request groups
|
//If there are not group types, either groups. Therefore, there is no need to request groups
|
||||||
Intent activity = new Intent(getBaseContext(),GroupTypes.class);
|
Intent activity = new Intent(getBaseContext(),Groups.class);
|
||||||
activity.putExtra("courseCode", courseCode);
|
activity.putExtra("courseCode", courseCode);
|
||||||
startActivityForResult(activity,Global.GROUPS_REQUEST_CODE);
|
startActivityForResult(activity,Global.GROUPS_REQUEST_CODE);
|
||||||
}else
|
}else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user