dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24366
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11930: finished event import UI, and other minor fixes
------------------------------------------------------------
revno: 11930
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-09-05 15:09:59 +0200
message:
finished event import UI, and other minor fixes
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultCurrentUserService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/JacksonEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java
dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties
--
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 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java 2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValue.java 2013-09-05 13:09:59 +0000
@@ -148,6 +148,19 @@
return true;
}
+ @Override
+ public String toString()
+ {
+ return "PatientDataValue{" +
+ "dataElement=" + dataElement +
+ ", programStageInstance=" + programStageInstance +
+ ", timestamp=" + timestamp +
+ ", value='" + value + '\'' +
+ ", providedElsewhere=" + providedElsewhere +
+ ", storedBy='" + storedBy + '\'' +
+ '}';
+ }
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultCurrentUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultCurrentUserService.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultCurrentUserService.java 2013-09-05 13:09:59 +0000
@@ -40,7 +40,7 @@
extends AbstractSpringSecurityCurrentUserService
{
private static final String SUPERUSER_AUTHORITY = "ALL";
-
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -51,7 +51,7 @@
{
this.userService = userService;
}
-
+
// -------------------------------------------------------------------------
// CurrentUserService implementation
// -------------------------------------------------------------------------
@@ -74,7 +74,7 @@
return userCredentials.getUser();
}
-
+
public boolean currentUserIsSuper()
{
String username = getCurrentUsername();
@@ -98,7 +98,7 @@
return true;
}
}
-
+
return false;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java 2013-09-04 13:18:44 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/AbstractEventService.java 2013-09-05 13:09:59 +0000
@@ -170,6 +170,7 @@
if ( !assignedToOrganisationUnit )
{
+ System.err.print( "Program is not assigned to this organisation unit." );
return new ImportSummary( ImportStatus.ERROR, "Program is not assigned to this organisation unit." );
}
}
@@ -190,7 +191,7 @@
return new ImportSummary();
}
- private ImportSummary saveSingleEventWithoutRegistration( Program program, OrganisationUnit organisationUnit, Event event, ImportOptions importOptions)
+ private ImportSummary saveSingleEventWithoutRegistration( Program program, OrganisationUnit organisationUnit, Event event, ImportOptions importOptions )
{
try
{
@@ -213,26 +214,16 @@
ProgramStageInstance programStageInstance = null;
- if ( importOptions != null && !importOptions.isDryRun() )
+ String storedBy = getStoredBy( event, importSummary );
+
+ if ( importOptions == null || !importOptions.isDryRun() )
{
programStageInstance = saveEventDate( program, organisationUnit, eventDate,
- event.getCompleted(), event.getCoordinate() );
+ event.getCompleted(), event.getCoordinate(), storedBy );
importSummary.setReference( programStageInstance.getUid() );
}
- String storedBy = event.getStoredBy();
-
- if ( storedBy == null )
- {
- storedBy = currentUserService.getCurrentUsername();
- }
- else if ( storedBy.length() >= 31 )
- {
- importSummary.getConflicts().add( new ImportConflict( "storedBy", storedBy + " is more than 31 characters, using current username instead." ) );
- storedBy = currentUserService.getCurrentUsername();
- }
-
for ( DataValue dataValue : event.getDataValues() )
{
DataElement dataElement = dataElementService.getDataElement( dataValue.getDataElement() );
@@ -246,9 +237,11 @@
{
if ( validateDataElement( dataElement, dataValue.getValue(), importSummary ) )
{
- if ( importOptions != null && !importOptions.isDryRun() )
+ String dataValueStoredBy = dataValue.getStoredBy() != null ? dataValue.getStoredBy() : storedBy;
+
+ if ( importOptions == null || !importOptions.isDryRun() )
{
- saveDataValue( programStageInstance, storedBy, dataElement, dataValue.getValue(), dataValue.getProvidedElsewhere() );
+ saveDataValue( programStageInstance, dataValueStoredBy, dataElement, dataValue.getValue(), dataValue.getProvidedElsewhere() );
}
importSummary.getDataValueCount().incrementImported();
@@ -259,6 +252,25 @@
return importSummary;
}
+ private String getStoredBy( Event event, ImportSummary importSummary )
+ {
+ String storedBy = event.getStoredBy();
+
+ if ( storedBy == null )
+ {
+ storedBy = currentUserService.getCurrentUsername();
+ }
+ else if ( storedBy.length() >= 31 )
+ {
+ if ( importSummary != null )
+ {
+ importSummary.getConflicts().add( new ImportConflict( "storedBy", storedBy + " is more than 31 characters, using current username instead." ) );
+ }
+ storedBy = currentUserService.getCurrentUsername();
+ }
+ return storedBy;
+ }
+
private boolean validateDataElement( DataElement dataElement, String value, ImportSummary importSummary )
{
InputValidationService.Status status = inputValidationService.validateDataElement( dataElement, value );
@@ -284,7 +296,7 @@
}
private ProgramStageInstance saveEventDate( Program program, OrganisationUnit organisationUnit, Date date, Boolean completed,
- Coordinate coordinate )
+ Coordinate coordinate, String storedBy )
{
ProgramStage programStage = program.getProgramStages().iterator().next();
ProgramInstance programInstance = programInstanceService.getProgramInstances( program ).iterator().next();
@@ -312,7 +324,7 @@
{
programStageInstance.setCompleted( completed );
programStageInstance.setCompletedDate( new Date() );
- programStageInstance.setCompletedUser( currentUserService.getCurrentUsername() );
+ programStageInstance.setCompletedUser( storedBy );
}
programStageInstanceService.addProgramStageInstance( programStageInstance );
@@ -461,10 +473,12 @@
Date date = new Date();
+ String storedBy = getStoredBy( event, null );
+
programStageInstance.setDueDate( date );
programStageInstance.setExecutionDate( date );
programStageInstance.setOrganisationUnit( organisationUnit );
- programStageInstance.setCompletedUser( event.getStoredBy() );
+ programStageInstance.setCompletedUser( storedBy );
programStageInstanceService.updateProgramStageInstance( programStageInstance );
@@ -532,6 +546,7 @@
value.setDataElement( patientDataValue.getDataElement().getUid() );
value.setValue( patientDataValue.getValue() );
value.setProvidedElsewhere( patientDataValue.getProvidedElsewhere() );
+ value.setStoredBy( patientDataValue.getStoredBy() );
event.getDataValues().add( value );
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java 2013-09-03 09:40:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DataValue.java 2013-09-05 13:09:59 +0000
@@ -40,7 +40,9 @@
private String dataElement;
- private Boolean providedElsewhere;
+ private Boolean providedElsewhere = false;
+
+ private String storedBy;
public DataValue()
{
@@ -82,6 +84,18 @@
this.providedElsewhere = providedElsewhere;
}
+ @JsonProperty
+ @JacksonXmlProperty( isAttribute = true )
+ public String getStoredBy()
+ {
+ return storedBy;
+ }
+
+ public void setStoredBy( String storedBy )
+ {
+ this.storedBy = storedBy;
+ }
+
@Override
public String toString()
{
@@ -89,6 +103,7 @@
"value='" + value + '\'' +
", dataElement='" + dataElement + '\'' +
", providedElsewhere=" + providedElsewhere +
+ ", storedBy='" + storedBy + '\'' +
'}';
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java 2013-09-04 11:32:31 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/DefaultEventStore.java 2013-09-05 13:09:59 +0000
@@ -132,6 +132,7 @@
dataValue.setValue( rowSet.getString( "pdv_value" ) );
dataValue.setProvidedElsewhere( rowSet.getBoolean( "pdv_providedelsewhere" ) );
dataValue.setDataElement( rowSet.getString( "de_uid" ) );
+ dataValue.setStoredBy( rowSet.getString( "pdv_storedby" ) );
event.getDataValues().add( dataValue );
}
@@ -143,7 +144,7 @@
{
String sql = "select p.uid as p_uid, ps.uid as ps_uid, psi.uid as psi_uid, ou.uid as ou_uid, psi.executiondate as psi_executiondate," +
" psi.completeduser as psi_completeduser, psi.completed as psi_completed," +
- " pdv.value as pdv_value, pdv.providedelsewhere as pdv_providedelsewhere, de.uid as de_uid" +
+ " pdv.value as pdv_value, pdv.storedby as pdv_storedby, pdv.providedelsewhere as pdv_providedelsewhere, de.uid as de_uid" +
" from program p" +
" left join programstage ps on ps.programid=p.programid" +
" left join programstageinstance psi on ps.programstageid=psi.programstageid" +
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/JacksonEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/JacksonEventService.java 2013-09-04 13:18:44 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/JacksonEventService.java 2013-09-05 13:09:59 +0000
@@ -61,25 +61,25 @@
private static ObjectMapper xmlMapper = new XmlMapper();
private static ObjectMapper jsonMapper = new ObjectMapper();
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromXml( InputStream inputStream, Class<?> clazz ) throws IOException
{
return (T) xmlMapper.readValue( inputStream, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromXml( String input, Class<?> clazz ) throws IOException
{
return (T) xmlMapper.readValue( input, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromJson( InputStream inputStream, Class<?> clazz ) throws IOException
{
return (T) jsonMapper.readValue( inputStream, clazz );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private static <T> T fromJson( String input, Class<?> clazz ) throws IOException
{
return (T) jsonMapper.readValue( input, clazz );
@@ -122,13 +122,13 @@
for ( Event event : events.getEvents() )
{
- importSummaries.getImportSummaries().add( saveEvent( event, importOptions ) );
+ importSummaries.addImportSummary( saveEvent( event, importOptions ) );
}
}
catch ( Exception ex )
{
Event event = fromXml( input, Event.class );
- importSummaries.getImportSummaries().add( saveEvent( event, importOptions ) );
+ importSummaries.addImportSummary( saveEvent( event, importOptions ) );
}
notifier.notify( taskId, NotificationLevel.INFO, "Import done", true ).
@@ -177,13 +177,13 @@
for ( Event event : events.getEvents() )
{
- importSummaries.getImportSummaries().add( saveEvent( event, importOptions ) );
+ importSummaries.addImportSummary( saveEvent( event, importOptions ) );
}
}
catch ( Exception ex )
{
Event event = fromJson( input, Event.class );
- importSummaries.getImportSummaries().add( saveEvent( event, importOptions ) );
+ importSummaries.addImportSummary( saveEvent( event, importOptions ) );
}
notifier.notify( taskId, NotificationLevel.INFO, "Import done", true ).
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummaries.java 2013-09-05 13:09:59 +0000
@@ -40,15 +40,30 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "importSummaries", namespace = DxfNamespaces.DXF_2_0 )
+@JacksonXmlRootElement(localName = "importSummaries", namespace = DxfNamespaces.DXF_2_0)
public class ImportSummaries
{
+ private int imported;
+
+ private int updated;
+
+ private int ignored;
+
private List<ImportSummary> importSummaries = new ArrayList<ImportSummary>();
public ImportSummaries()
{
}
+ public void addImportSummary( ImportSummary importSummary )
+ {
+ imported += importSummary.getDataValueCount().getImported();
+ updated += importSummary.getDataValueCount().getUpdated();
+ ignored += importSummary.getDataValueCount().getIgnored();
+
+ importSummaries.add( importSummary );
+ }
+
@JsonProperty
@JacksonXmlElementWrapper( localName = "importSummaryList", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "importSummary", namespace = DxfNamespaces.DXF_2_0 )
@@ -61,4 +76,33 @@
{
this.importSummaries = importSummaries;
}
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public int getImported()
+ {
+ return imported;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public int getUpdated()
+ {
+ return updated;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public int getIgnored()
+ {
+ return ignored;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ImportSummaries{" +
+ "importSummaries=" + importSummaries +
+ '}';
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java 2013-09-05 13:09:59 +0000
@@ -148,4 +148,18 @@
{
this.href = href;
}
+
+ @Override
+ public String toString()
+ {
+ return "ImportSummary{" +
+ "status=" + status +
+ ", description='" + description + '\'' +
+ ", dataValueCount=" + dataValueCount +
+ ", conflicts=" + conflicts +
+ ", dataSetComplete='" + dataSetComplete + '\'' +
+ ", reference='" + reference + '\'' +
+ ", href='" + href + '\'' +
+ '}';
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java 2013-09-05 13:09:59 +0000
@@ -73,14 +73,14 @@
// Implemented methods
// -------------------------------------------------------------------------
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
@Override
public Collection<Program> getByType( int type )
{
return getCriteria( Restrictions.eq( "type", type ) ).list();
}
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
@Override
public Collection<Program> get( int type, OrganisationUnit organisationUnit )
{
@@ -144,7 +144,7 @@
}
@Override
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
public Collection<Program> getProgramsByDisplayOnAllOrgunit( boolean displayOnAllOrgunit, OrganisationUnit orgunit )
{
Criteria criteria = getCriteria();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2013-09-04 07:49:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2013-09-05 13:09:59 +0000
@@ -308,7 +308,7 @@
@RequestMapping(value = { "/assignedPrograms" }, produces = { "application/json", "text/*" })
public void getPrograms( HttpServletResponse response, @RequestParam Map<String, String> parameters,
- @RequestParam(defaultValue = "1") Integer type )
+ @RequestParam(required = false) Integer type )
throws IOException, NotAuthenticatedException
{
User currentUser = currentUserService.getCurrentUser();
@@ -321,10 +321,20 @@
Set<OrganisationUnit> userOrganisationUnits = new HashSet<OrganisationUnit>();
Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
Set<Program> programs = new HashSet<Program>();
- List<Program> userPrograms = new ArrayList<Program>( programService.getProgramsByCurrentUser( Program.SINGLE_EVENT_WITHOUT_REGISTRATION ) );
+ List<Program> userPrograms;
+
+ if ( type == null )
+ {
+ userPrograms = new ArrayList<Program>( programService.getProgramsByCurrentUser() );
+ }
+ else
+ {
+ userPrograms = new ArrayList<Program>( programService.getProgramsByCurrentUser( type ) );
+ }
+
Map<String, List<Program>> programAssociations = new HashMap<String, List<Program>>();
- if ( currentUser.getOrganisationUnits().isEmpty() && currentUser.getUserCredentials().getAllAuthorities().contains( "ALL" ) )
+ if ( currentUserService.currentUserIsSuper() && currentUser.getOrganisationUnits().isEmpty() )
{
userOrganisationUnits.addAll( organisationUnitService.getRootOrganisationUnits() );
}
@@ -350,8 +360,7 @@
for ( OrganisationUnit organisationUnit : userOrganisationUnits )
{
- List<Program> ouPrograms = new ArrayList<Program>(
- programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION, organisationUnit ) );
+ List<Program> ouPrograms = new ArrayList<Program>( programService.getPrograms( organisationUnit ) );
if ( !ouPrograms.isEmpty() )
{
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java 2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java 2013-09-05 13:09:59 +0000
@@ -99,7 +99,6 @@
public static Form fromProgram( Program program )
{
Assert.notNull( program );
- Assert.isTrue( program.getType() == Program.SINGLE_EVENT_WITHOUT_REGISTRATION );
Form form = new Form();
form.setLabel( program.getDisplayName() );
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties 2013-09-05 09:25:02 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/resources/org/hisp/dhis/importexport/i18n_module.properties 2013-09-05 13:09:59 +0000
@@ -281,6 +281,7 @@
import_summary=Import summary
data_set_completed_on=Data set completed on
import_count=Import count
+import_total_count=Import total count
imported=Imported
updated=Updated
ignored=Ignored