dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35816
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18336: Import, centralized method
------------------------------------------------------------
revno: 18336
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-02-19 17:52:45 +0100
message:
Import, centralized method
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.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 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2015-02-19 16:52:45 +0000
@@ -420,6 +420,8 @@
Collection<OrganisationUnit> getOrganisationUnitsBetweenByStatusLastUpdated( boolean status, Date lastUpdated, int first, int max );
+ Map<String, OrganisationUnit> getUuidOrganisationUnitMap();
+
/**
* Retrieves all the org units within the distance from center location.
*
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-02-19 16:52:45 +0000
@@ -726,6 +726,21 @@
}
@Override
+ public Map<String, OrganisationUnit> getUuidOrganisationUnitMap()
+ {
+ Map<String, OrganisationUnit> map = new HashMap<>();
+
+ Collection<OrganisationUnit> organisationUnits = getAllOrganisationUnits();
+
+ for ( OrganisationUnit organisationUnit : organisationUnits )
+ {
+ map.put( organisationUnit.getUuid(), organisationUnit );
+ }
+
+ return map;
+ }
+
+ @Override
public boolean isInUserHierarchy( OrganisationUnit organisationUnit )
{
User user = currentUserService.getCurrentUser();
@@ -910,7 +925,7 @@
return levelMap;
}
-
+
@Override
public int getNumberOfOrganisationUnits()
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-02-19 09:18:17 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-02-19 16:52:45 +0000
@@ -28,7 +28,26 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.csvreader.CsvReader;
+import static com.google.common.collect.Sets.newHashSet;
+import static org.apache.commons.lang3.StringUtils.trimToNull;
+import static org.hisp.dhis.common.IdentifiableProperty.UUID;
+import static org.hisp.dhis.system.notification.NotificationLevel.ERROR;
+import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
+import static org.hisp.dhis.system.util.ConversionUtils.wrap;
+import static org.hisp.dhis.system.util.DateUtils.getDefaultDate;
+import static org.hisp.dhis.system.util.DateUtils.parseDate;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.amplecode.quick.BatchHandler;
import org.amplecode.quick.BatchHandlerFactory;
import org.amplecode.staxwax.factory.XMLFactory;
@@ -46,14 +65,14 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.dxf2.common.IdSchemes;
+import org.hisp.dhis.dxf2.common.ImportOptions;
+import org.hisp.dhis.dxf2.common.JacksonUtils;
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
import org.hisp.dhis.dxf2.importsummary.ImportCount;
import org.hisp.dhis.dxf2.importsummary.ImportStatus;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
-import org.hisp.dhis.dxf2.common.ImportOptions;
import org.hisp.dhis.dxf2.pdfform.PdfDataEntryFormUtil;
-import org.hisp.dhis.dxf2.common.IdSchemes;
-import org.hisp.dhis.dxf2.common.JacksonUtils;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.importexport.ImportStrategy;
@@ -75,26 +94,7 @@
import org.hisp.dhis.user.CurrentUserService;
import org.springframework.beans.factory.annotation.Autowired;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static com.google.common.collect.Sets.newHashSet;
-import static org.apache.commons.lang3.StringUtils.trimToNull;
-import static org.hisp.dhis.common.IdentifiableProperty.UUID;
-import static org.hisp.dhis.system.notification.NotificationLevel.ERROR;
-import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
-import static org.hisp.dhis.system.util.ConversionUtils.wrap;
-import static org.hisp.dhis.system.util.DateUtils.getDefaultDate;
-import static org.hisp.dhis.system.util.DateUtils.parseDate;
+import com.csvreader.CsvReader;
/**
* @author Lars Helge Overland
@@ -625,7 +625,7 @@
//----------------------------------------------------------------------
Map<String, DataElement> dataElementMap = identifiableObjectManager.getIdMap( DataElement.class, dataElementIdScheme );
- Map<String, OrganisationUnit> orgUnitMap = orgUnitIdScheme == UUID ? getUuidOrgUnitMap() : identifiableObjectManager.getIdMap( OrganisationUnit.class, orgUnitIdScheme );
+ Map<String, OrganisationUnit> orgUnitMap = getOrgUnitMap( orgUnitIdScheme );
Map<String, DataElementCategoryOptionCombo> categoryOptionComboMap = identifiableObjectManager.getIdMap( DataElementCategoryOptionCombo.class, idScheme );
Map<String, Period> periodMap = new HashMap<>();
@@ -930,17 +930,10 @@
summary.setDataSetComplete( DateUtils.getMediumDateString( completeDate ) );
}
- private Map<String, OrganisationUnit> getUuidOrgUnitMap()
+ private Map<String, OrganisationUnit> getOrgUnitMap( IdentifiableProperty orgUnitIdScheme )
{
- Map<String, OrganisationUnit> orgUnitMap = new HashMap<>();
-
- Collection<OrganisationUnit> allOrganisationUnits = organisationUnitService.getAllOrganisationUnits();
-
- for ( OrganisationUnit organisationUnit : allOrganisationUnits )
- {
- orgUnitMap.put( organisationUnit.getUuid(), organisationUnit );
- }
-
- return orgUnitMap;
+ return UUID.equals( orgUnitIdScheme ) ?
+ organisationUnitService.getUuidOrganisationUnitMap() :
+ identifiableObjectManager.getIdMap( OrganisationUnit.class, orgUnitIdScheme );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2015-02-17 06:00:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2015-02-19 16:52:45 +0000
@@ -262,7 +262,7 @@
{
in = new ClassPathResource( "datavalueset/dataValueSetBcode.xml" ).getInputStream();
- ImportOptions options = new ImportOptions( CODE, CODE, false, true, NEW_AND_UPDATES, false );
+ ImportOptions options = new ImportOptions( CODE, CODE, CODE, false, true, NEW_AND_UPDATES, false );
ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
@@ -289,7 +289,7 @@
{
in = new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream();
- ImportOptions options = new ImportOptions( UID, UID, true, true, NEW_AND_UPDATES, false );
+ ImportOptions options = new ImportOptions( UID, UID, UID, true, true, NEW_AND_UPDATES, false );
ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
@@ -307,7 +307,7 @@
{
in = new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream();
- ImportOptions options = new ImportOptions( UID, UID, false, true, UPDATES, false );
+ ImportOptions options = new ImportOptions( UID, UID, UID, false, true, UPDATES, false );
ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );