Changeset 5781
- Timestamp:
- Dec 11, 2019, 12:34:23 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/TMASpecimenImporter.java
r5779 r5781 22 22 import net.sf.basedb.core.Sample; 23 23 import net.sf.basedb.core.StringParameterType; 24 import net.sf.basedb.core.Type;25 24 import net.sf.basedb.core.plugin.GuiContext; 26 25 import net.sf.basedb.core.plugin.InteractivePlugin; … … 29 28 import net.sf.basedb.core.plugin.Request; 30 29 import net.sf.basedb.core.plugin.Response; 31 import net.sf.basedb.core.query.Expressions;32 import net.sf.basedb.core.query.Hql;33 import net.sf.basedb.core.query.Restrictions;34 30 import net.sf.basedb.plugins.AbstractFlatFileImporter; 31 import net.sf.basedb.plugins.batchimport.IdMethod; 32 import net.sf.basedb.plugins.batchimport.PropertyIdMethod; 35 33 import net.sf.basedb.plugins.util.Parameters; 36 34 import net.sf.basedb.reggie.Reggie; … … 39 37 import net.sf.basedb.reggie.dao.ReggieItem; 40 38 import net.sf.basedb.reggie.dao.Subtype; 39 import net.sf.basedb.util.Enumeration; 41 40 import net.sf.basedb.util.parser.ConfigureByExample; 42 41 import net.sf.basedb.util.parser.FlatFileParser; … … 65 64 private static final PluginParameter<String> caseColumnMapping = new PluginParameter<String>( 66 65 "caseColumnMapping", 67 "Case ",68 "Mapping that picks the name o fthe Case from the data columns. This " +66 "Case ID", 67 "Mapping that picks the name or external id for the Case from the data columns. This " + 69 68 "parameter is required. " + 70 "Example: \\Case \\",69 "Example: \\Case ID\\", 71 70 requiredColumnMapping 72 71 ); … … 156 155 // ------------------------------------ 157 156 157 protected IdMethod[] getIdMethods() 158 { 159 return new IdMethod[] { PropertyIdMethod.NAME, PropertyIdMethod.EXTERNAL_ID }; 160 } 161 162 /** 163 Get the id method to use for finding cases. This implementation 164 searches the methods returned by {@link #getIdMethods()} 165 */ 166 protected IdMethod getIdMethod(String method) 167 { 168 for (IdMethod im : getIdMethods()) 169 { 170 if (im.getMethod().equals(method)) 171 { 172 return im; 173 } 174 } 175 return PropertyIdMethod.NAME; 176 } 177 158 178 @Override 159 179 public RequestInformation getRequestInformation(GuiContext context, String command) … … 199 219 return; 200 220 } 221 222 // Check that a mapping has been provided for the selected idMethod 223 IdMethod idMethod = getIdMethod((String)request.getParameterValue("idMethod")); 224 if (idMethod == null) 225 { 226 response.setError("Unknown method for item identification: " + 227 request.getParameterValue("idMethod"), null); 228 return; 229 } 201 230 202 231 // Check the mapping expressions … … 208 237 storeValue(wrapper, request, ri.getParameter(Parameters.LOGFILE_PARAMETER)); 209 238 storeValue(wrapper, request, excelSheetParameter); 239 storeValue(wrapper, request, ri.getParameter("idMethod")); 210 240 211 241 storeValue(wrapper, request, dataHeaderRegexpParameter); … … 245 275 private DbControl dc; 246 276 private FlatFileParser ffp; 277 private IdMethod idMethod; 247 278 private ItemQuery<Sample> caseQuery; 248 279 private Mapper caseMapper; … … 262 293 this.dc = sc.newDbControl(); 263 294 this.dryRun = job.getJob().isDryRun(); 295 this.idMethod = getIdMethod(job.getValue("idMethod")); 264 296 this.caseQuery = Sample.getQuery(); 265 297 Subtype.CASE.addFilter(dc, caseQuery); 266 298 caseQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); 267 caseQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("caseName")));299 idMethod.prepareQuery(dc, caseQuery); 268 300 if (ffp.getExcelSheet() != null) 269 301 { … … 275 307 protected void beginData() 276 308 { 277 caseMapper = NotNullMapper.wrap("Case nameis null", getMapper(ffp, job.getValue("caseColumnMapping"), null, null));309 caseMapper = NotNullMapper.wrap("Case ID is null", getMapper(ffp, job.getValue("caseColumnMapping"), null, null)); 278 310 tmaBlockMapper = NotNullMapper.wrap("TMABlock is null", getMapper(ffp, job.getValue("tmaBlockColumnMapping"), null, null)); 279 311 tmaBlockPosMapper = NotNullMapper.wrap("TMABlockPos is null", getMapper(ffp, job.getValue("tmaBlockPosColumnMapping"), null, null)); … … 287 319 throws BaseException 288 320 { 289 String caseName = caseMapper.getString(data); 290 caseQuery.setParameter("caseName", caseName, Type.STRING); 291 List<Sample> cases = caseQuery.list(dc); 321 String caseId = caseMapper.getString(data); 322 List<Sample> cases = idMethod.find(dc, caseQuery, caseId); 292 323 if (cases.size() > 1) 293 324 { 294 throw new InvalidDataException("Found " + cases.size() + " cases with the same name (" + caseName + ").");325 throw new InvalidDataException("Found " + cases.size() + " cases [" + idMethod + "=" + caseId + "]"); 295 326 } 296 327 else if (cases.size() == 0) 297 328 { 298 throw new ItemNotFoundException("Case[ name=" + caseName+ "]");329 throw new ItemNotFoundException("Case[" + idMethod + "=" + caseId + "]"); 299 330 } 300 331 … … 380 411 parameters.add(Parameters.dryRunParameter(null, null, null)); 381 412 413 Enumeration<String, String> idMethods = new Enumeration<String, String>(); 414 idMethods.add(null, null); 415 idMethods.add(PropertyIdMethod.NAME.getMethod(), PropertyIdMethod.NAME.getTitle()); 416 idMethods.add(PropertyIdMethod.EXTERNAL_ID.getMethod(), PropertyIdMethod.EXTERNAL_ID.getTitle()); 417 PluginParameter<String> idMethodParameter = new PluginParameter<String>( 418 "idMethod", 419 "Case identification method", 420 "The method to use for finding existing cases. The plug-in can use either the " + 421 "SCAN-B ID or the Release ID.", 422 new StringParameterType(null, null, true, 1, 0, 0, idMethods) 423 ); 424 parameters.add(idMethodParameter); 425 426 382 427 // Parser regular expressions 383 428 parameters.add(parserSection);
Note: See TracChangeset
for help on using the changeset viewer.