dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08174
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1918: Fix login error with password containing number.
------------------------------------------------------------
revno: 1918
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: cbhis-mobile
timestamp: Tue 2010-10-05 16:14:30 +0700
message:
Fix login error with password containing number.
Make relation of Program_DB and ProgramStage_DB in RMS
Add "Delete Program"
Add "Delete Activity"
added:
DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ProgramStageRecordFilter.java
DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ProgramStageRecordStore.java
modified:
DHISMobile/.mtj
DHISMobile/build.properties
DHISMobile/src/org/hisp/dhis/mobile/reporting/connection/ConnectionManager.java
DHISMobile/src/org/hisp/dhis/mobile/reporting/db/AbstractModelFilter.java
DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ActivityRecordStore.java
DHISMobile/src/org/hisp/dhis/mobile/reporting/gui/DHISMIDlet.java
DHISMobile/src/org/hisp/dhis/mobile/reporting/model/Activity.java
DHISMobile/src/org/hisp/dhis/mobile/reporting/model/ProgramStage.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/UserResource.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/parser/FormParser.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'DHISMobile/.mtj'
--- DHISMobile/.mtj 2010-09-24 14:08:46 +0000
+++ DHISMobile/.mtj 2010-10-05 09:14:30 +0000
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<mtjMetadata jad="DHISMobile.jad" version="1.2.1.v201006161022">
- <device group="Sun Java(TM) Wireless Toolkit 2.5.2_01 for CLDC" name="AmharicColorPhone"/>
+ <device group="Sun Java(TM) Wireless Toolkit 2.5.2_01 for CLDC" name="DefaultColorPhone"/>
<signing projectSpecific="false" signProject="false">
<alias/>
</signing>
<configurations>
- <configuration active="true" name="AmharicColorPhone">
- <device group="Sun Java(TM) Wireless Toolkit 2.5.2_01 for CLDC" name="AmharicColorPhone"/>
+ <configuration active="true" name="DefaultColorPhone">
+ <device group="Sun Java(TM) Wireless Toolkit 2.5.2_01 for CLDC" name="DefaultColorPhone"/>
<symbolSet name="AmharicColorPhone">
+ <symbol name="screen.isColor" value="true"/>
<symbol name="MMAPI" value="1.1"/>
- <symbol name="screen.isColor" value="true"/>
<symbol name="screen.bitDepth" value="8"/>
<symbol name="JSR82" value="1.1"/>
<symbol name="JSR226" value="1.0"/>
@@ -18,8 +18,8 @@
<symbol name="SATSA-PKI" value="1.0"/>
<symbol name="CLDC" value="1.1"/>
<symbol name="JSR179" value="1.0"/>
+ <symbol name="WMA" value="2.0"/>
<symbol name="SATSA-JCRMI" value="1.0"/>
- <symbol name="WMA" value="2.0"/>
<symbol name="J2ME-WS" value="1.0"/>
<symbol name="screen.width" value="240"/>
<symbol name="JSR238" value="1.0"/>
=== modified file 'DHISMobile/build.properties'
--- DHISMobile/build.properties 2010-09-24 14:08:46 +0000
+++ DHISMobile/build.properties 2010-10-05 09:14:30 +0000
@@ -1,34 +1,6 @@
# MTJ Build Properties
-AmharicColorPhone.includes=src/org/hisp/dhis/mobile/reporting/connection/Base64.java\
-,src/org/hisp/dhis/mobile/reporting/connection/BasicAuth.java\
-,src/org/hisp/dhis/mobile/reporting/connection/ConnectionManager.java\
-,src/org/hisp/dhis/mobile/reporting/db/AbstractModelComparator.java\
-,src/org/hisp/dhis/mobile/reporting/db/AbstractModelFilter.java\
-,src/org/hisp/dhis/mobile/reporting/db/ActivityRecordFilter.java\
-,src/org/hisp/dhis/mobile/reporting/db/ActivityRecordStore.java\
-,src/org/hisp/dhis/mobile/reporting/db/ModelRecordStore.java\
-,src/org/hisp/dhis/mobile/reporting/db/SettingsRecordStore.java\
-,src/org/hisp/dhis/mobile/reporting/db/ValueRecordStore.java\
-,src/org/hisp/dhis/mobile/reporting/gui/CalendarCanvas.java\
-,src/org/hisp/dhis/mobile/reporting/gui/CalendarWidget.java\
-,src/org/hisp/dhis/mobile/reporting/gui/DHISMIDlet.java\
-,src/org/hisp/dhis/mobile/reporting/gui/SplashScreen.java\
-,src/org/hisp/dhis/mobile/reporting/image/dhis2_logo.PNG\
-,src/org/hisp/dhis/mobile/reporting/model/AbstractModel.java\
-,src/org/hisp/dhis/mobile/reporting/model/AbstractModelList.java\
-,src/org/hisp/dhis/mobile/reporting/model/Activity.java\
-,src/org/hisp/dhis/mobile/reporting/model/ActivityPlan.java\
-,src/org/hisp/dhis/mobile/reporting/model/ActivityValue.java\
-,src/org/hisp/dhis/mobile/reporting/model/Beneficiary.java\
-,src/org/hisp/dhis/mobile/reporting/model/DataElement.java\
-,src/org/hisp/dhis/mobile/reporting/model/DataSet.java\
-,src/org/hisp/dhis/mobile/reporting/model/DataSetValue.java\
-,src/org/hisp/dhis/mobile/reporting/model/DataValue.java\
-,src/org/hisp/dhis/mobile/reporting/model/ISerializable.java\
-,src/org/hisp/dhis/mobile/reporting/model/Period.java\
-,src/org/hisp/dhis/mobile/reporting/model/Program.java\
-,src/org/hisp/dhis/mobile/reporting/model/ProgramStage.java\
-,src/org/hisp/dhis/mobile/reporting/model/Task.java\
+DefaultColorPhone.includes=src\
+,res\
-AmharicColorPhone.excludes=\
+DefaultColorPhone.excludes=\
=== modified file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/connection/ConnectionManager.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/connection/ConnectionManager.java 2010-09-24 14:08:46 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/connection/ConnectionManager.java 2010-10-05 09:14:30 +0000
@@ -1,6 +1,8 @@
package org.hisp.dhis.mobile.reporting.connection;
import com.jcraft.jzlib.ZInputStream;
+import com.sun.midp.io.Base64;
+
import java.io.*;
import java.util.Vector;
import javax.microedition.io.*;
@@ -119,8 +121,10 @@
// set HTTP basic authentication
if (userName != null && password != null) {
- conn.setRequestProperty("Authorization",
- "Basic " + BasicAuth.encode(userName,password));
+// conn.setRequestProperty("Authorization",
+// "Basic " + BasicAuth.encode(userName,password));
+ byte[] auth = (userName+":"+password).getBytes();
+ conn.setRequestProperty( "Authorization", "Basic " + Base64.encode( auth, 0, auth.length ));
}
}
=== modified file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/db/AbstractModelFilter.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/db/AbstractModelFilter.java 2010-09-24 14:08:46 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/db/AbstractModelFilter.java 2010-10-05 09:14:30 +0000
@@ -34,7 +34,7 @@
.recordToAbstractModel(suspect);
matches = abstractModel.getId() == model.getId()
&& abstractModel.getName().equalsIgnoreCase(model.getName());
-
+ close();
return matches;
}
=== modified file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ActivityRecordStore.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ActivityRecordStore.java 2010-09-24 14:08:46 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ActivityRecordStore.java 2010-10-05 09:14:30 +0000
@@ -103,7 +103,8 @@
}
return recordId;
}
- public void save() {
+
+ public void save() {
clear();
=== added file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ProgramStageRecordFilter.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ProgramStageRecordFilter.java 1970-01-01 00:00:00 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ProgramStageRecordFilter.java 2010-10-05 09:14:30 +0000
@@ -0,0 +1,71 @@
+package org.hisp.dhis.mobile.reporting.db;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+import javax.microedition.rms.RecordFilter;
+
+/**
+ * @author Tran Ng Minh Luan
+ *
+ */
+public class ProgramStageRecordFilter implements RecordFilter
+{
+ public static final String filterByProgramId = "filterByProgramId";
+
+ private int progId;
+
+ private String filter;
+
+
+
+ public ProgramStageRecordFilter( String filter )
+ {
+ this.filter = filter;
+ }
+
+
+ public int getProgId()
+ {
+ return progId;
+ }
+
+
+ public void setProgId( int progId )
+ {
+ this.progId = progId;
+ }
+
+
+ public boolean matches( byte[] candidate )
+ {
+ DataInputStream dis = new DataInputStream( new ByteArrayInputStream( candidate ) );
+
+ try
+ {
+ //skip ID and Name
+ dis.readInt();
+ dis.readUTF();
+ //end
+ if(this.filter.equals( filterByProgramId )){
+ if(dis.readInt() == this.progId){
+ return true;
+ }else{
+ return false;
+ }
+ }else{
+ System.out.println("lack of filter");
+ return false;
+ }
+
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ return false;
+ }
+
+ }
+
+}
=== added file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ProgramStageRecordStore.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ProgramStageRecordStore.java 1970-01-01 00:00:00 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/db/ProgramStageRecordStore.java 2010-10-05 09:14:30 +0000
@@ -0,0 +1,47 @@
+package org.hisp.dhis.mobile.reporting.db;
+
+import javax.microedition.rms.RecordEnumeration;
+import javax.microedition.rms.RecordStore;
+import javax.microedition.rms.RecordStoreException;
+
+
+/**
+ * @author Tran Ng Minh Luan
+ *
+ */
+public class ProgramStageRecordStore
+{
+ public static final String PROGRAMSTAGE_DB = "PROGRAMSTAGE";
+
+ private String dbName;
+
+ public ProgramStageRecordStore() {
+ this.dbName = ModelRecordStore.PROGRAM_STAGE_DB;
+ }
+
+ public void deleteProgStageOfProgId(int progId) throws RecordStoreException {
+ RecordStore rs = null;
+ RecordEnumeration re = null;
+ ProgramStageRecordFilter rf = new ProgramStageRecordFilter(ProgramStageRecordFilter.filterByProgramId);
+ rf.setProgId(progId);
+ try {
+ rs = RecordStore.openRecordStore(dbName, true);
+ re = rs.enumerateRecords(rf, null, false);
+ while (re.hasNextElement()) {
+ rs.deleteRecord( re.nextRecordId());
+ System.out.println("one progstage deleted");
+ }
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ System.out.println(e.getMessage());
+ }
+ finally {
+ if (re != null)
+ re.destroy();
+ if (rs != null)
+ rs.closeRecordStore();
+ rf = null;
+ }
+ }
+}
=== modified file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/gui/DHISMIDlet.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/gui/DHISMIDlet.java 2010-09-24 14:08:46 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/gui/DHISMIDlet.java 2010-10-05 09:14:30 +0000
@@ -9,6 +9,7 @@
import org.hisp.dhis.mobile.reporting.connection.ConnectionManager;
import org.hisp.dhis.mobile.reporting.db.ActivityRecordStore;
import org.hisp.dhis.mobile.reporting.db.ModelRecordStore;
+import org.hisp.dhis.mobile.reporting.db.ProgramStageRecordStore;
import org.hisp.dhis.mobile.reporting.db.SettingsRecordStore;
import org.hisp.dhis.mobile.reporting.model.AbstractModel;
import org.hisp.dhis.mobile.reporting.model.Activity;
@@ -64,6 +65,7 @@
private List servicesList;
private List maintenanceList;
private List deleteList;
+ private List deleteProgList;
private List mainMenuList;
private List dsDnldList;
private List prDnldList;
@@ -214,7 +216,16 @@
deleteDataSet(model);
switchDisplayable(null, getMaintenanceList());
}
- }
+ }
+ else if(displayable == deleteProgList)
+ {
+ if(command == List.SELECT_COMMAND){
+ AbstractModel model = (AbstractModel) programsVector.elementAt(((List) getDeleteProgList()).getSelectedIndex());
+ deleteProgramsAndProgramStages(model);
+ }else if(command == deleteBakCmd){
+ switchDisplayable( null, getMaintenanceList() );
+ }
+ }
else if (displayable == dsDnldList)
{
if (command == List.SELECT_COMMAND)
@@ -1044,6 +1055,7 @@
if( activity == null || programStage == null )
{
+ form.deleteAll();
form.append("The requested form is not available");
}
else
@@ -1099,11 +1111,17 @@
if (rec != null){
prStage = new ProgramStage();
prStage.deSerialize(rec);
+ getActivityDetailForm().setTitle("Details");
+ System.out.println(prStage);
+ getActivityDetailForm().append( "Service: " + prStage.getName()
+ + "\nName: " + selectedActivity.getBeneficiary().getFullName()
+ + "\nDue date: " + Period.formatDailyPeriod(selectedActivity.getDueDate()));
}
- getActivityDetailForm().setTitle("Details");
- getActivityDetailForm().append( "Service: " + prStage.getName()
- + "\nName: " + selectedActivity.getBeneficiary().getFullName()
- + "\nDue date: " + Period.formatDailyPeriod(selectedActivity.getDueDate()));
+ else{
+ getActivityDetailForm().deleteAll();
+ getActivityDetailForm().append( "There is no details" );
+
+ }
} catch (RecordStoreException rse) {
@@ -1165,8 +1183,8 @@
}
else if (__selectedString.equals("Delete Program"))
{
- populatePrograms(getDeleteList());
- switchDisplayable(null, getDeleteList());
+ populatePrograms(getDeleteProgList());
+ switchDisplayable(null, getDeleteProgList());
}
else if(__selectedString.equals("Download Activity Plan"))
{
@@ -1179,7 +1197,12 @@
}
else if (__selectedString.equals("Delete Activity Plan"))
{
- deleteActivityPlan();
+ getWaitForm().deleteAll();
+ getWaitForm().setTitle("Deleting Activity Plan");
+ getWaitForm().append("Please wait........");
+ switchDisplayable(null, getWaitForm());
+
+ deleteActivityPlan();
}
}
}
@@ -1324,7 +1347,22 @@
}
return errorAlert;
}
-
+
+ /**
+ * Returns an initiliazed instance of deleteProgList component.
+ *
+ * @return the initialized component instance
+ */
+ public List getDeleteProgList() {
+ if (deleteProgList == null) {
+ deleteProgList = new List("Please select", Choice.IMPLICIT);
+ deleteProgList.addCommand(getDeleteBakCmd());
+ deleteProgList.setCommandListener(this);
+ }
+ return deleteProgList;
+ }
+
+
/**
* Returns an initiliazed instance of deleteList component.
*
@@ -1352,7 +1390,7 @@
* deleteList component.
*/
public void deleteListAction() {
-
+
}
/**
@@ -1486,7 +1524,26 @@
private void populatePrograms(List list)
{
- System.out.println("I will try to delete programs here");
+ programsVector.removeAllElements();
+ ModelRecordStore modelRecordStore = null;
+ Vector programs = null;
+ try {
+ modelRecordStore = new ModelRecordStore(ModelRecordStore.PROGRAM_DB);
+ programs = modelRecordStore.getAllRecord();
+ } catch (RecordStoreException rse) {
+ rse.printStackTrace();
+ }
+
+ list.deleteAll();
+ if(programs!=null){
+ for (int i = 0; i < programs.size(); i++) {
+ AbstractModel prog = (AbstractModel) programs.elementAt(i);
+ list.insert(i, prog.getName(), null);
+ programsVector.addElement(prog);
+ }
+ }
+
+ switchDisplayable( null, getDeleteProgList() );
}
private void loadDataSets(List list)
@@ -1557,7 +1614,19 @@
private void deleteActivityPlan()
{
- System.out.println("should delete activity plan");
+ new Thread(new Runnable()
+ {
+
+ public void run() {
+ ActivityRecordStore activityRs = new ActivityRecordStore();
+ activityRs.clear();
+ switchDisplayable( null, getMaintenanceList() );
+ }
+ }
+
+ ).start();
+
+
}
private void downloadActivityPlan()
@@ -1598,6 +1667,7 @@
dataSetsVector = dataSets;
if (dataSets == null) {
+ getDsDnldList().deleteAll();
getDsDnldList().append("No Datasets available", null);
} else {
getDsDnldList().deleteAll();
@@ -1689,13 +1759,12 @@
programRecordStore.AddRecord(model.serialize());
Vector prStgs = program.getProgramStages();
-
for(int i=0; i<prStgs.size(); i++)
{
- ProgramStage prStg = (ProgramStage) prStgs.elementAt(i);
- programStageRecordStore.AddRecord( prStg.serialize() );
+ ProgramStage prStg = (ProgramStage) prStgs.elementAt(i);
+ prStg.setProgramId( model.getId() );
+ programStageRecordStore.AddRecord( prStg.serialize() );
}
-
} catch (IOException ex) {
// ex.printStackTrace();
getErrorAlert().setTitle("Download Status");
@@ -1723,7 +1792,7 @@
ActivityRecordStore activityRecordStore = new ActivityRecordStore();
activityRecordStore.setActivityVector(activityPlan.getActivities());
- activityRecordStore.save();
+ activityRecordStore.save();
getSuccessAlert().setTitle("Download Status");
getSuccessAlert().setString("SUCCESS");
@@ -1886,6 +1955,22 @@
} catch (RecordStoreException rse) {
}
}
+
+ private void deleteProgramsAndProgramStages(AbstractModel model){
+ ModelRecordStore progRecord = null;
+ ProgramStageRecordStore progStageRecord = null;
+ try {
+ progRecord = new ModelRecordStore(ModelRecordStore.PROGRAM_DB);
+ progStageRecord = new ProgramStageRecordStore();
+ //Delete ProgramStages have programId = model.getId();
+ progStageRecord.deleteProgStageOfProgId( model.getId() );
+ //Delete Program has id = model.getId();
+ progRecord.deleteRecord(model);
+ //should refresh deleteProgList here and show it again
+ switchDisplayable( null, getMaintenanceList() );
+ } catch (RecordStoreException rse) {
+ }
+ }
public DateField getDailyPeriodDateField() {
if (dailyPeriodDateField == null) {
=== modified file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/model/Activity.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/model/Activity.java 2010-09-24 14:08:46 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/model/Activity.java 2010-10-05 09:14:30 +0000
@@ -111,7 +111,7 @@
}
- public void deSerialize(DataInputStream din) throws IOException {
+ public void deSerialize(DataInputStream din) throws IOException {
this.setDueDate(new Date(din.readLong()));
this.beneficiary.deSerialize(din);
=== modified file 'DHISMobile/src/org/hisp/dhis/mobile/reporting/model/ProgramStage.java'
--- DHISMobile/src/org/hisp/dhis/mobile/reporting/model/ProgramStage.java 2010-09-24 14:08:46 +0000
+++ DHISMobile/src/org/hisp/dhis/mobile/reporting/model/ProgramStage.java 2010-10-05 09:14:30 +0000
@@ -8,10 +8,23 @@
import java.util.Vector;
public class ProgramStage extends AbstractModel {
-
+ private int programId;
+
private Vector dataElements = new Vector();
- public Vector getDataElements() {
+
+
+ public int getProgramId()
+ {
+ return programId;
+ }
+
+ public void setProgramId( int programId )
+ {
+ this.programId = programId;
+ }
+
+ public Vector getDataElements() {
return dataElements;
}
@@ -20,12 +33,13 @@
}
public byte[] serialize() throws IOException
- {
+ {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(bout);
-
+
dout.writeInt(this.getId());
- dout.writeUTF(this.getName());
+ dout.writeUTF(this.getName());
+ dout.writeInt( this.programId );
dout.writeInt(dataElements.size());
for(int i=0; i<dataElements.size(); i++)
@@ -43,10 +57,14 @@
{
ByteArrayInputStream bin = new ByteArrayInputStream(data);
DataInputStream din = new DataInputStream(bin);
-
+
this.setId( din.readInt() ) ;
this.setName( din.readUTF() );
+ //ignore programId
+ din.readInt();
+ //end
+
int size = din.readInt();
for(int i=0; i<size; i++)
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/UserResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/UserResource.java 2010-08-26 14:59:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/UserResource.java 2010-10-05 09:14:30 +0000
@@ -47,7 +47,7 @@
if ( units.isEmpty() )
{
- return Response.status( Status.NOT_FOUND ).build();
+ return Response.status( Status.NO_CONTENT ).build();
}
else if ( units.size() > 1 )
{
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/parser/FormParser.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/parser/FormParser.java 2010-08-26 14:59:39 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/parser/FormParser.java 2010-10-05 09:14:30 +0000
@@ -80,15 +80,15 @@
String name = parser.getName();
String text = parser.nextText();
- if ( name.equals( "deId" ) )
+ if ( name.equals( "id" ) )
{
de.setId( Integer.valueOf( text ).intValue() );
}
- else if ( name.equals( "deName" ) )
+ else if ( name.equals( "name" ) )
{
de.setName( text );
}
- else if ( name.equals( "deType" ) )
+ else if ( name.equals( "type" ) )
{
if ( text.equals( "int" ) )
de.setType( DataElement.TYPE_INT );