1
package org.hisp.dhis.importexport.mapping;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import java.util.HashMap;
33
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
34
import org.hisp.dhis.period.Period;
35
import org.hisp.dhis.system.util.LoggingHashMap;
38
* @author Lars Helge Overland
39
* @version $Id: NameMappingUtil.java 5727 2008-09-18 17:48:54Z larshelg $
41
public class NameMappingUtil
43
private static ThreadLocal<Map<Object, String>> categoryMap = new ThreadLocal<Map<Object, String>>();
44
private static ThreadLocal<Map<Object, String>> categoryOptionMap = new ThreadLocal<Map<Object, String>>();
45
private static ThreadLocal<Map<Object, String>> categoryComboMap = new ThreadLocal<Map<Object, String>>();
46
private static ThreadLocal<Map<Object, DataElementCategoryOptionCombo>> categoryOptionComboMap = new ThreadLocal<Map<Object, DataElementCategoryOptionCombo>>();
47
private static ThreadLocal<Map<Object, String>> dataElementMap = new ThreadLocal<Map<Object, String>>();
48
private static ThreadLocal<Map<Object, String>> dataElementGroupMap = new ThreadLocal<Map<Object, String>>();
49
private static ThreadLocal<Map<Object, String>> indicatorMap = new ThreadLocal<Map<Object, String>>();
50
private static ThreadLocal<Map<Object, String>> indicatorGroupMap = new ThreadLocal<Map<Object, String>>();
51
private static ThreadLocal<Map<Object, String>> indicatorTypeMap = new ThreadLocal<Map<Object, String>>();
52
private static ThreadLocal<Map<Object, String>> dataDictionaryMap = new ThreadLocal<Map<Object,String>>();
53
private static ThreadLocal<Map<Object, Period>> periodMap = new ThreadLocal<Map<Object, Period>>();
54
private static ThreadLocal<Map<Object, String>> dataSetMap = new ThreadLocal<Map<Object,String>>();
55
private static ThreadLocal<Map<Object, String>> organisationUnitMap = new ThreadLocal<Map<Object, String>>();
56
private static ThreadLocal<Map<Object, String>> organisationUnitGroupMap = new ThreadLocal<Map<Object, String>>();
57
private static ThreadLocal<Map<Object, String>> organisationUnitGroupSetMap = new ThreadLocal<Map<Object, String>>();
58
private static ThreadLocal<Map<Object, String>> reportTableMap = new ThreadLocal<Map<Object,String>>();
59
private static ThreadLocal<Map<Object, String>> dataElementAggregationOperatorMap = new ThreadLocal<Map<Object,String>>();
61
// -------------------------------------------------------------------------
63
// -------------------------------------------------------------------------
65
public static void clearMapping()
68
categoryOptionMap.remove();
69
categoryComboMap.remove();
70
categoryOptionComboMap.remove();
71
dataElementMap.remove();
72
dataElementGroupMap.remove();
73
indicatorMap.remove();
74
indicatorGroupMap.remove();
75
indicatorTypeMap.remove();
76
dataDictionaryMap.remove();
79
organisationUnitMap.remove();
80
organisationUnitGroupMap.remove();
81
organisationUnitGroupSetMap.remove();
82
reportTableMap.remove();
83
dataElementAggregationOperatorMap.remove();
86
// -------------------------------------------------------------------------
88
// -------------------------------------------------------------------------
91
* Adds a map entry with DataElementCategory identifier as key and name as value.
93
public static void addCategoryMapping( Object categoryId, String categoryName )
95
put( categoryMap, categoryId, categoryName );
99
* Returns a Map with all DataElementCategory identifier and name entries.
101
public static Map<Object, String> getCategoryMap()
103
return categoryMap.get() != null ? new HashMap<Object, String>( categoryMap.get() ) : new HashMap<Object, String>();
106
// -------------------------------------------------------------------------
108
// -------------------------------------------------------------------------
111
* Adds a map entry with DataElementCategoryOption identifier as key and name as value.
113
public static void addCategoryOptionMapping( Object categoryOptionId, String categoryOptionName )
115
put( categoryOptionMap, categoryOptionId, categoryOptionName );
119
* Returns a Map with all DataElementCategoryOption identifier and name entries.
121
public static Map<Object, String> getCategoryOptionMap()
123
return categoryOptionMap.get() != null ? new HashMap<Object, String>( categoryOptionMap.get() ) : new HashMap<Object, String>();
126
// -------------------------------------------------------------------------
128
// -------------------------------------------------------------------------
131
* Adds a map entry with DataElementCategoryCombo identifier as key and name as value.
133
public static void addCategoryComboMapping( Object categoryComboId, String categoryComboName )
135
put( categoryComboMap, categoryComboId, categoryComboName );
139
* Returns a Map with all DataElementCategoryCombo identifier and name entries.
141
public static Map<Object, String> getCategoryComboMap()
143
return categoryComboMap.get() != null ? new HashMap<Object, String>( categoryComboMap.get() ) : new HashMap<Object, String>();
146
// -------------------------------------------------------------------------
147
// CategoryOptionCombo
148
// -------------------------------------------------------------------------
151
* Adds a map entry with DataElementCategoryOptionCombo identifier as key
152
* and the DataElementCategoryOptionCombo as value.
154
public static void addCategoryOptionComboMapping( Object categoryOptionComboId, DataElementCategoryOptionCombo categoryOptionCombo )
156
Map<Object, DataElementCategoryOptionCombo> map = categoryOptionComboMap.get();
160
map = new HashMap<Object, DataElementCategoryOptionCombo>();
163
if ( !map.containsKey( categoryOptionComboId ) )
165
map.put( categoryOptionComboId, categoryOptionCombo );
167
categoryOptionComboMap.set( map );
172
* Returns a Map with all DataElementCategoryOption identifier and
173
* DataElementCategoryOptionCombo entries.
175
public static Map<Object, DataElementCategoryOptionCombo> getCategoryOptionComboMap()
177
return categoryOptionComboMap.get() != null ? new HashMap<Object, DataElementCategoryOptionCombo>( categoryOptionComboMap.get() ) : new HashMap<Object, DataElementCategoryOptionCombo>();
180
// -------------------------------------------------------------------------
182
// -------------------------------------------------------------------------
185
* Adds a map entry with DataElement identifier as key and name as value.
187
public static void addDataElementMapping( Object dataElementId, String dataElementName )
189
put( dataElementMap, dataElementId, dataElementName );
193
* Returns a map with all DataElement identifier and name entries.
195
public static Map<Object, String> getDataElementMap()
197
return dataElementMap.get() != null ? new HashMap<Object, String>( dataElementMap.get() ) : new HashMap<Object, String>();
200
// -------------------------------------------------------------------------
202
// -------------------------------------------------------------------------
205
* Adds a map entry with DataElementGroup identifier as key and name as value.
207
public static void addDataElementGroupMapping( Object groupId, String groupName )
209
put( dataElementGroupMap, groupId, groupName );
213
* Returns a map with all DataElementGroup identifier and name entries.
215
public static Map<Object, String> getDataElementGroupMap()
217
return dataElementGroupMap.get() != null ? new HashMap<Object, String>( dataElementGroupMap.get() ) : new HashMap<Object, String>();
220
// -------------------------------------------------------------------------
222
// -------------------------------------------------------------------------
225
* Adds a map entry with Indicator identifier as key and name as value.
227
public static void addIndicatorMapping( Object indicatorId, String indicatorName )
229
put( indicatorMap, indicatorId, indicatorName );
233
* Returns a map with all Indicator identifier and name entries.
235
public static Map<Object, String> getIndicatorMap()
237
return indicatorMap.get() != null ? new HashMap<Object, String>( indicatorMap.get() ) : new HashMap<Object, String>();
240
// -------------------------------------------------------------------------
242
// -------------------------------------------------------------------------
245
* Adds a map entry with IndicatorGroup identifier as key and name as value.
247
public static void addIndicatorGroupMapping( Object groupId, String groupName )
249
put( indicatorGroupMap, groupId, groupName );
253
* Returns a map with all Indicator identifier and name entries.
255
public static Map<Object, String> getIndicatorGroupMap()
257
return indicatorGroupMap.get() != null ? new HashMap<Object, String>( indicatorGroupMap.get() ) : new HashMap<Object, String>();
260
// -------------------------------------------------------------------------
262
// -------------------------------------------------------------------------
265
* Adds a map entry with IndicatorType identifier as key and name as value.
267
public static void addIndicatorTypeMapping( Object typeId, String typeName )
269
put( indicatorTypeMap, typeId, typeName );
273
* Returns a map with all IndicatorType identifier and name entries.
275
public static Map<Object, String> getIndicatorTypeMap()
277
return indicatorTypeMap.get() != null ? new HashMap<Object, String>( indicatorTypeMap.get() ) : new HashMap<Object, String>();
280
// -------------------------------------------------------------------------
282
// -------------------------------------------------------------------------
285
* Adds a map entry with DataDictionary identifier as key and name as value.
287
public static void addDataDictionaryMapping( Object dictionaryId, String dictionaryName )
289
put( dataDictionaryMap, dictionaryId, dictionaryName );
293
* Returns a map with all DataDictionary identifier and name entries.
295
public static Map<Object, String> getDataDictionaryMap()
297
return dataDictionaryMap.get() != null ? new HashMap<Object, String>( dataDictionaryMap.get() ) : new HashMap<Object, String>();
300
// -------------------------------------------------------------------------
302
// -------------------------------------------------------------------------
305
* Adds a map entry with Period identifier as key and the period as value.
307
public static void addPeriodMapping( Object periodId, Period period )
309
Map<Object, Period> map = periodMap.get();
313
map = new HashMap<Object, Period>();
316
map.put( periodId, period );
318
periodMap.set( map );
322
* Returns a map with all Period identifier and period entries.
324
public static Map<Object, Period> getPeriodMap()
326
return periodMap.get() != null ? new HashMap<Object, Period>( periodMap.get() ) : new HashMap<Object, Period>();
329
// -------------------------------------------------------------------------
331
// -------------------------------------------------------------------------
334
* Adds a map entry with DataSet identifier as key and name as value.
336
public static void addDataSetMapping( Object dataSetId, String dataSetName )
338
put( dataSetMap, dataSetId, dataSetName );
342
* Returns a map with all DataSet identifier and name entries.
344
public static Map<Object, String> getDataSetMap()
346
return dataSetMap.get() != null ? new HashMap<Object, String>( dataSetMap.get() ) : new HashMap<Object, String>();
349
// -------------------------------------------------------------------------
351
// -------------------------------------------------------------------------
354
* Adds a map entry with OrganisationUnit identifier as key and name as value.
356
public static void addOrganisationUnitMapping( Object organisationUnitId, String organisationUnitName )
358
put( organisationUnitMap, organisationUnitId, organisationUnitName );
362
* Returns a map with all OrganisationUnit identifier and name entries.
364
public static Map<Object, String> getOrganisationUnitMap()
366
return organisationUnitMap.get() != null ? new HashMap<Object, String>( organisationUnitMap.get() ) : new HashMap<Object, String>();
369
// -------------------------------------------------------------------------
370
// OrganisationUnitGroup
371
// -------------------------------------------------------------------------
374
* Adds a map entry with OrganisationUnitGroup identifier as key and name as value.
376
public static void addOrganisationUnitGroupMapping( Object groupId, String groupName )
378
put( organisationUnitGroupMap, groupId, groupName );
382
* Returns a map with all OrganisationUnitGroup identifier and name entries.
384
public static Map<Object, String> getOrganisationUnitGroupMap()
386
return organisationUnitGroupMap.get() != null ? new HashMap<Object, String>( organisationUnitGroupMap.get() ) : new HashMap<Object, String>();
389
// -------------------------------------------------------------------------
390
// OrganisationUnitGroupSet
391
// -------------------------------------------------------------------------
394
* Adds a map entry with OrganisationUnitGroupSet identifier as key and name as value.
396
public static void addGroupSetMapping( Object groupSetId, String groupSetName )
398
put( organisationUnitGroupSetMap, groupSetId, groupSetName );
402
* Returns a map with all OrganisationUnitGroupSet identifier and name entries.
404
public static Map<Object, String> getGroupSetMap()
406
return organisationUnitGroupSetMap.get() != null ? new HashMap<Object, String>( organisationUnitGroupSetMap.get() ) : new HashMap<Object, String>();
409
// -------------------------------------------------------------------------
411
// -------------------------------------------------------------------------
414
* Adds a map entry with ReportTable identifier as key and name as value.
416
public static void addReportTableMapping( Object reportTableId, String reportTableName )
418
put( reportTableMap, reportTableId, reportTableName );
422
* Returns a map with all ReportTable identifier and name entries.
424
public static Map<Object, String> getReportTableMap()
426
return reportTableMap.get() != null ? new HashMap<Object, String>( reportTableMap.get() ) : new HashMap<Object, String>();
429
// -------------------------------------------------------------------------
431
// -------------------------------------------------------------------------
433
public static void addDataElementAggregationOperatorMapping( Object dataElementId, String aggregationOperator )
435
put( dataElementAggregationOperatorMap, dataElementId, aggregationOperator );
438
public static Map<Object, String> getDataElementAggregationOperatorMap()
440
return dataElementAggregationOperatorMap.get() != null ? new LoggingHashMap<Object, String>( dataElementAggregationOperatorMap.get() ) : new HashMap<Object, String>();
443
// -------------------------------------------------------------------------
444
// Supportive methods
445
// -------------------------------------------------------------------------
447
private static void put( ThreadLocal<Map<Object, String>> threadLocal, Object key, String value )
449
Map<Object, String> map = threadLocal.get();
453
map = new HashMap<Object, String>();
456
if ( !map.containsKey( key ) )
458
map.put( key, value );
460
threadLocal.set( map );