Project

General

Profile

« Previous | Next » 

Revision bff8d9fe

Added by Andreas Müller over 5 years ago

ref #1444 cleanup erms import code

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/erms/ErmsNotesSourcesImport.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
34 34
 */
35 35
@Component
36 36
public class ErmsNotesSourcesImport extends ErmsImportBase<CommonTaxonName> {
37
	@SuppressWarnings("unused")
37
    private static final long serialVersionUID = -5197101648269924453L;
38

  
39
    @SuppressWarnings("unused")
38 40
	private static final Logger logger = Logger.getLogger(ErmsNotesSourcesImport.class);
39
	
40
	
41

  
42

  
41 43
//************************** VARIABLES ********************************************
42
	
44

  
43 45
	private static String pluralString = "note sources";
44 46
	private static String dbTableName = "notes_sources";
45 47
	private static final Class<?> cdmTargetClass = DescriptionElementSource.class;
46 48

  
47
	private DbImportMapping<?,?> mapping;
49
	private DbImportMapping<ErmsImportState, ErmsImportConfigurator> mapping;
50

  
51
//******************************************* CONSTRUCTOR *******************************
48 52

  
49
	
50
//******************************************* CONSTRUCTOR *******************************	
51
	
52 53
	/**
53
	 * @param dbTableName 
54
	 * @param dbTableName
54 55
	 * @param pluralString
55 56
	 * @param dbTableName
56 57
	 */
......
58 59
		super(pluralString, dbTableName, cdmTargetClass);
59 60
	}
60 61

  
61

  
62
	/* (non-Javadoc)
63
	 * @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getRecordQuery(eu.etaxonomy.cdm.io.erms.ErmsImportConfigurator)
64
	 */
65 62
	@Override
66 63
	protected String getRecordQuery(ErmsImportConfigurator config) {
67
		String strQuery = 
68
			" SELECT * " + 
64
		String strQuery =
65
			" SELECT * " +
69 66
			" FROM vernaculars_sources " +
70 67
			" WHERE vernacular_id IN (" + ID_LIST_TOKEN + ") AND " +
71 68
					" source_id IN (" + ID_LIST_TOKEN + ")";
......
74 71

  
75 72
	@Override
76 73
	protected String getIdQuery() {
77
		String strQuery = 
78
			" SELECT vernacular_id, source_id " + 
79
			" FROM vernaculars_sources " 
74
		String strQuery =
75
			" SELECT vernacular_id, source_id " +
76
			" FROM vernaculars_sources "
80 77
			;
81 78
		return strQuery;
82 79
	}
83
	
80

  
84 81
	@Override
85
	protected DbImportMapping<?,?> getMapping() {
82
	protected DbImportMapping<ErmsImportState, ErmsImportConfigurator> getMapping() {
86 83
		if (mapping == null){
87
			mapping = new DbImportMapping();
88
			String vernacularNamespace = ErmsVernacularImport.VERNACULAR_NAMESPACE;
89
			String referenceNamespace = ErmsReferenceImport.REFERENCE_NAMESPACE;
84
			mapping = new DbImportMapping<>();
85
			String vernacularNamespace = ErmsImportBase.VERNACULAR_NAMESPACE;
86
			String referenceNamespace = ErmsImportBase.REFERENCE_NAMESPACE;
90 87
			mapping.addMapper(DbImportDescriptionElementSourceCreationMapper.NewInstance("vernacular_id", vernacularNamespace, "source_id", referenceNamespace ));
91 88
		}
92 89
		return mapping;
93 90
	}
94 91

  
95 92
	@Override
96
	public Map getRelatedObjectsForPartition(ResultSet rs, ErmsImportState state) {
93
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, ErmsImportState state) {
97 94
		String nameSpace;
98 95
		Class<?> cdmClass;
99 96
		Set<String> idSet;
100
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
101
		
97
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
98

  
102 99
		try{
103 100
			Set<String> vernacularIdSet = new HashSet<String>();
104 101
			Set<String> sourceIdSet = new HashSet<String>();
......
106 103
				handleForeignKey(rs, vernacularIdSet, "vernacular_id");
107 104
				handleForeignKey(rs, sourceIdSet, "source_id");
108 105
			}
109
			
106

  
110 107
			//vernacular map
111
			nameSpace = ErmsVernacularImport.VERNACULAR_NAMESPACE;
108
			nameSpace = ErmsImportBase.VERNACULAR_NAMESPACE;
112 109
			cdmClass = CommonTaxonName.class;
113 110
			idSet = vernacularIdSet;
114 111
			Map<String, CommonTaxonName> vernacularMap = (Map<String, CommonTaxonName>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
115 112
			result.put(nameSpace, vernacularMap);
116
			
117
			
113

  
114

  
118 115
			//reference map
119
			nameSpace = ErmsReferenceImport.REFERENCE_NAMESPACE;
116
			nameSpace = ErmsImportBase.REFERENCE_NAMESPACE;
120 117
			cdmClass = Reference.class;
121 118
			idSet = sourceIdSet;
122
			Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
119
			@SuppressWarnings("unchecked")
120
            Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
123 121
			result.put(nameSpace, referenceMap);
124
	
122

  
125 123
		} catch (SQLException e) {
126 124
			throw new RuntimeException(e);
127 125
		}
128 126
		return result;
129 127
	}
130
	
128

  
131 129
	@Override
132 130
	protected boolean doCheck(ErmsImportState state) {
133 131
		IOValidator<ErmsImportState> validator = new ErmsNoteSourceImportValidator();
134 132
		return validator.validate(state);
135 133
	}
136
	
134

  
137 135
	@Override
138 136
	protected boolean isIgnore(ErmsImportState state) {
139 137
		boolean isDo = state.getConfig().isDoVernaculars() && state.getConfig().isDoVernaculars();

Also available in: Unified diff