From 8e845590a8218dda19a954718cbc363a1a54b1f1 Mon Sep 17 00:00:00 2001 From: Kevin Ruland Date: Thu, 16 Feb 2012 19:25:28 +0000 Subject: [PATCH] We cannot use the designation directly in the search. For some manufacturers (CTI), the designation provided in the burn file is not at all consistent with the designation stored in the thrustcurve.org main database. Instead we pull out what looks like the common name using a regular expression and use that. --- .../TCMissingMotorDownloadAction.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java b/android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java index c64bb02d4..ce580e958 100644 --- a/android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java +++ b/android/src/net/sf/openrocket/android/thrustcurve/TCMissingMotorDownloadAction.java @@ -1,12 +1,16 @@ package net.sf.openrocket.android.thrustcurve; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.sf.openrocket.android.util.AndroidLogWrapper; import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder; public class TCMissingMotorDownloadAction extends TCQueryAction { + private final static String DESIGNATION_REGEX_STRING = "(Micro Maxx|Micro Maxx II|1/4A|1/2A|[A-O][0-9]*)"; + public static TCMissingMotorDownloadAction newInstance( Set missingMotors ) { TCMissingMotorDownloadAction frag = new TCMissingMotorDownloadAction(); frag.task = frag.new Downloader(missingMotors); @@ -16,16 +20,31 @@ public class TCMissingMotorDownloadAction extends TCQueryAction { private class Downloader extends TCQueryAction.TCQueryTask { private Set missingMotors; + private Pattern designation_pattern = null; private Downloader( Set missingMotors ) { this.missingMotors = missingMotors; + try { + designation_pattern = Pattern.compile(DESIGNATION_REGEX_STRING); + } catch ( Exception ex ) { + AndroidLogWrapper.e(TCMissingMotorDownloadAction.class, "Exception in pattern compile {}", ex); + } } private void downloadMissingMotor( ThrustCurveMotorPlaceholder motor ) { try { + SearchRequest request = new SearchRequest(); request.setManufacturer(motor.getManufacturer()); - request.setDesignation(motor.getDesignation()); + String designation = motor.getDesignation(); + if ( designation_pattern != null ) { + Matcher m = designation_pattern.matcher(designation); + if ( m.find() ) { + designation = m.group(); + } + } + AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "using designation {}", designation); + request.setCommon_name(designation); handler.post( new UpdateMessage("Looking for " + motor.getManufacturer() + " " + motor.getDesignation())); @@ -69,11 +88,11 @@ public class TCMissingMotorDownloadAction extends TCQueryAction { @Override protected String doInBackground(Void... arg0) { + for ( ThrustCurveMotorPlaceholder motor : missingMotors ) { AndroidLogWrapper.d(TCMissingMotorDownloadAction.class, "Motor: {}", motor); downloadMissingMotor(motor); } - dismiss(); return null; }