Project

General

Profile

« Previous | Next » 

Revision b313991f

Added by Andreas Müller over 4 years ago

adapt some classes to new CommonService.getSourcedObjectSByIdInSource and cleanup

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelWebMarkerImport.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
*/
......
28 28
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
29 29
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
30 30

  
31

  
32 31
/**
33 32
 * @author a.mueller
34 33
 * @since 20.03.2008
35
 * @version 1.0
36 34
 */
37 35
@Component
38 36
public class BerlinModelWebMarkerImport extends BerlinModelImportBase {
39
	private static final Logger logger = Logger.getLogger(BerlinModelWebMarkerImport.class);
37

  
38
    private static final long serialVersionUID = 6350956896121390550L;
39
    private static final Logger logger = Logger.getLogger(BerlinModelWebMarkerImport.class);
40 40

  
41 41
	private static int modCount = 2000;
42 42
	private static final String dbTableName = "webMarker";
43 43
	private static final String pluralString = "markers";
44
	
44

  
45 45
	public BerlinModelWebMarkerImport(){
46 46
		super(dbTableName, pluralString);
47 47
	}
48
	
48

  
49 49
	@Override
50 50
	protected String getIdQuery(BerlinModelImportState state) {
51 51
		String result = " SELECT markerId FROM " + getTableName();
......
57 57

  
58 58
	@Override
59 59
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
60
		String strQuery = 
60
		String strQuery =
61 61
			" SELECT *  " +
62 62
            " FROM webMarker INNER JOIN webTableName ON webMarker.TableNameFk = webTableName.TableNameId " +
63 63
            " WHERE (markerId IN ("+ ID_LIST_TOKEN + ") )";
......
65 65
	}
66 66

  
67 67
	@Override
68
	public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
68
	public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, BerlinModelImportState state) {
69 69
		boolean success = true ;
70
	
71
		Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
72
		Set<TaxonBase> taxaToBeSaved = new HashSet<TaxonBase>(); 
73
		
74
		Map<String, DefinedTermBase> definedTermMap = state.getDbCdmDefinedTermMap();
70

  
71
		@SuppressWarnings({ "unchecked", "rawtypes" })
72
        Map<String, TaxonBase> taxonMap = partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
73
		@SuppressWarnings("rawtypes")
74
        Set<TaxonBase> taxaToBeSaved = new HashSet<>();
75

  
76
		@SuppressWarnings("rawtypes")
77
        Map<String, DefinedTermBase> definedTermMap = state.getDbCdmDefinedTermMap();
75 78
		ResultSet rs = partitioner.getResultSet();
76
		
79

  
77 80
		int i = 0;
78 81
		//for each reference
79 82
		try{
......
86 89
					int rIdentifierFk = rs.getInt("RIdentifierFk");
87 90
					String tableName = rs.getString("TableName");
88 91
					Boolean activeFlag = rs.getBoolean("ActiveFlag");
89
					
92

  
90 93
					AnnotatableEntity annotatableEntity;
91 94
					if ("PTaxon".equals(tableName)){
92 95
						TaxonBase<?> taxon = taxonMap.get(String.valueOf(rIdentifierFk));
......
101 104
						logger.warn("Marker for table " + tableName + " not yet implemented.");
102 105
						success = false;
103 106
					}
104
					
105
					
107

  
108

  
106 109
				}catch(Exception ex){
107 110
					logger.error(ex.getMessage());
108 111
					ex.printStackTrace();
......
118 121
		getTaxonService().saveOrUpdate(taxaToBeSaved);
119 122
		return success;
120 123
	}
121
		
124

  
122 125
	@Override
123 126
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
124
		String nameSpace;
125
		Class<?> cdmClass;
127

  
128
	    String nameSpace;
126 129
		Set<String> idSet;
127
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
128
		
130
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
131

  
129 132
		try{
130
			Set<String> taxonIdSet = new HashSet<String>();
133
			Set<String> taxonIdSet = new HashSet<>();
131 134
			while (rs.next()){
132 135
				int tableNameId = rs.getInt("TableNameFk");
133 136
				if (tableNameId != 500){
......
137 140
					handleForeignKey(rs, taxonIdSet, "RIdentifierFk");
138 141
				}
139 142
			}
140
	
143

  
141 144
			//taxon map
142 145
			nameSpace = BerlinModelTaxonImport.NAMESPACE;
143
			cdmClass = TaxonBase.class;
144 146
			idSet = taxonIdSet;
145
			Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
147
			@SuppressWarnings("rawtypes")
148
            Map<String, TaxonBase> taxonMap = getCommonService().getSourcedObjectsByIdInSourceC(TaxonBase.class, idSet, nameSpace);
146 149
			result.put(nameSpace, taxonMap);
147
			
150

  
148 151
		} catch (SQLException e) {
149 152
			throw new RuntimeException(e);
150 153
		}
151 154
		return result;
152 155
	}
153 156

  
154
	private boolean addMarker(AnnotatableEntity annotatableEntity, boolean activeFlag, int markerCategoryFk, Map<String, DefinedTermBase> map ){
157
	private boolean addMarker(AnnotatableEntity annotatableEntity, boolean activeFlag, int markerCategoryFk,
158
	        @SuppressWarnings("rawtypes") Map<String, DefinedTermBase> map ){
155 159
		MarkerType markerType = (MarkerType)map.get("webMarkerCategory_" + markerCategoryFk);
156 160
		if (markerType == null){
157 161
			logger.warn("MarkerType not found: " + markerCategoryFk);
......
161 165
		return true;
162 166

  
163 167
	}
164
	
168

  
165 169
	@Override
166 170
	protected boolean doCheck(BerlinModelImportState state){
167 171
		IOValidator<BerlinModelImportState> validator = new BerlinModelWebMarkerImportValidator();
168 172
		return validator.validate(state);
169 173
	}
170
	
174

  
171 175
	@Override
172 176
	protected boolean isIgnore(BerlinModelImportState state){
173 177
		return ! state.getConfig().isDoMarker();

Also available in: Unified diff