00001 package ProdDatabase;
00002
00003
00004
00005 import java.io.*;
00006 import java.util.Hashtable;
00007 import java.util.Vector;
00008 import Preferences.PreferencesInterface;
00009 import guiUtilities.userPrompt;
00010 import guiUtilities.DaveUtils;
00011
00012 public class SignoffDataInterface implements ModuleSignoffData {
00013
00014 Hashtable signoffDataHash;
00015 private String location;
00016 String signoffType;
00017 String finalSignoffInfo;
00018 Vector snList, selectedSNList;
00019
00020 public SignoffDataInterface(String serialNo, String location, String signoffType) {
00021 this.signoffType=signoffType;
00022 try {
00023 signoffDataHash = GeneralUtilities.getSignoffDataTestNo(serialNo, location, signoffType);
00024 if(!signoffDataHash.containsKey(location)) return;
00025 String testno = (String)signoffDataHash.get(location);
00026 Vector rawData = GeneralUtilities.getRawData(testno);
00027 if(rawData.size()>0) signoffDataHash.put(location,new SignoffData(GeneralUtilities.getUploaderInfo(testno),(String)rawData.elementAt(1)));
00028 }catch(Exception e){System.out.println("FAILED to download signoff data: "+e.toString());}
00029 }
00030 public SignoffDataInterface(String serialNo, String signoffType) {
00031 this.signoffType=signoffType;
00032 try {
00033 signoffDataHash = GeneralUtilities.getSignoffDataTestNo(serialNo,signoffType);
00034
00035 for (java.util.Enumeration e = signoffDataHash.keys() ; e.hasMoreElements() ;) {
00036 String location = (String)e.nextElement();
00037 String testno = (String)signoffDataHash.get(location);
00038 Vector rawData = GeneralUtilities.getRawData(testno);
00039 if(rawData.size()>0) signoffDataHash.put(location,new SignoffData(GeneralUtilities.getUploaderInfo(testno),(String)rawData.elementAt(1)));
00040 else signoffDataHash.remove(location);
00041 }
00042 }catch(Exception e){System.out.println("FAILED to download signoff data: "+e.toString());}
00043 }
00044 public SignoffDataInterface(String sn1, String sn2, String currLocation, String institute, String signoffType, boolean latestOnly) {
00045 try {
00046 snList = GeneralUtilities.getSignoffDataTestNos(sn1,sn2,currLocation, institute, signoffType, latestOnly);
00047 }catch(Exception e){System.out.println("FAILED to download signoff data: "+e.toString());}
00048 }
00049
00050 public Vector getSignoffTable(int category, int barrel) {
00051 String[] cats = {"GOOD","PASS","PASS2","SPARE","FAIL"};
00052 String[] barrels = {"ANY","56","6"};
00053 Vector tableList = new Vector();
00054 Vector itemList=new Vector();
00055 selectedSNList = new Vector();
00056 itemList.addElement("Serial No");
00057 itemList.addElement("Uploaded by");
00058 itemList.addElement("Date");
00059 itemList.addElement("Category");
00060 itemList.addElement("Reason");
00061 itemList.addElement("Barrel Assignment");
00062 itemList.addElement("Reason");
00063 itemList.addElement("Comments");
00064 tableList.addElement(itemList);
00065 if(snList.size()==0) return tableList;
00066
00067 try {
00068 for(int i=0;i<snList.size();i++) {
00069 itemList = new Vector();
00070 String testno = (String)snList.elementAt(i);
00071 SignoffData signoffData = new SignoffData((String)snList.elementAt(i));
00072 System.out.println("Extracting signoff info for module "+signoffData.getString(ModuleSignoffData.SERIALNO)+" ("+Integer.toString(i+1)+" out of "+snList.size()+")");
00073 String thisCategory = signoffData.getString(ModuleSignoffData.CATEGORY);
00074 String barrelA = signoffData.getString(ModuleSignoffData.BARREL).toUpperCase();
00075 if(category>0 && !thisCategory.equals(cats[category-1])) continue;
00076 if(barrel>0 && !barrelA.equals(barrels[barrel-1])) continue;
00077 itemList.addElement(signoffData.getString(ModuleSignoffData.SERIALNO));
00078
00079 SCTDBTestInfoHolder testInfo = GeneralUtilities.getTestInfo(testno);
00080 itemList.addElement(testInfo.get(SCTDBTestInfoHolder.LOCATION));
00081 itemList.addElement(testInfo.get(SCTDBTestInfoHolder.DATE));
00082 itemList.addElement(thisCategory);
00083 String failReason = signoffData.getString(ModuleSignoffData.FAILREASON);
00084 if(failReason==null) itemList.addElement("n/a");
00085 else itemList.addElement(failReason);
00086
00087 if(barrelA.equals("6")) barrelA="Barrel 6 ONLY";
00088 itemList.addElement(barrelA);
00089 String b56Reason = signoffData.getString(ModuleSignoffData.B56REASON);
00090 if(b56Reason==null) itemList.addElement("n/a");
00091 else itemList.addElement(b56Reason);
00092 itemList.addElement(signoffData.getString(ModuleSignoffData.COMMENT));
00093 tableList.addElement(itemList);
00094 selectedSNList.addElement(testno);
00095 }
00096 }catch(Exception e){System.err.println("Exception "+e.toString());}
00097 return tableList;
00098 }
00099
00100 public Vector getQualityTable() {
00101 Vector tableList = new Vector();
00102 Vector itemList=new Vector();
00103 itemList.addElement("Serial No");
00104 itemList.addElement("Uploaded by");
00105 itemList.addElement("Date");
00106 itemList.addElement("IV Category");
00107 itemList.addElement("IV comment");
00108 itemList.addElement("Elec Category");
00109 itemList.addElement("Elec comment");
00110 itemList.addElement("Elec spec Settings");
00111 itemList.addElement("SCurve Category");
00112 itemList.addElement("SCurve comment");
00113 tableList.addElement(itemList);
00114 if(snList.size()==0) return tableList;
00115
00116 try {
00117 for(int i=0;i<snList.size();i++) {
00118 itemList = new Vector();
00119 String testno = (String)snList.elementAt(i);
00120 System.out.println("Extracting quality data for test number "+testno+" (test "+Integer.toString(i+1)+" out of "+snList.size()+")");
00121 SignoffData signoffData = new SignoffData(testno);
00122 itemList.addElement(signoffData.getString(ModuleSignoffData.SERIALNO));
00123 SCTDBTestInfoHolder testInfo = GeneralUtilities.getTestInfo(testno);
00124 itemList.addElement(testInfo.get(SCTDBTestInfoHolder.LOCATION));
00125 itemList.addElement(testInfo.get(SCTDBTestInfoHolder.DATE));
00126 itemList.addElement( (signoffData.getString(ModuleSignoffData.IVCATEGORY)!=null) ? signoffData.getString(ModuleSignoffData.IVCATEGORY) : "Not known");
00127 itemList.addElement( (signoffData.getString(ModuleSignoffData.IVCOMMENT)!=null) ? signoffData.getString(ModuleSignoffData.IVCOMMENT) : "None");
00128 itemList.addElement( (signoffData.getString(ModuleSignoffData.ELECTRICALCATEGORY)!=null) ? signoffData.getString(ModuleSignoffData.ELECTRICALCATEGORY) : "Unknown");
00129 itemList.addElement( (signoffData.getString(ModuleSignoffData.ELECTRICALCOMMENT)!=null) ? signoffData.getString(ModuleSignoffData.ELECTRICALCOMMENT) : "None");
00130 itemList.addElement( (signoffData.getString(ModuleSignoffData.ELEC_SPECIAL_SETTING)!=null) ? signoffData.getString(ModuleSignoffData.ELEC_SPECIAL_SETTING) : "None");
00131 itemList.addElement( (signoffData.getString(ModuleSignoffData.SCURVECATEGORY)!=null) ? signoffData.getString(ModuleSignoffData.SCURVECATEGORY) : "Ok");
00132 itemList.addElement( (signoffData.getString(ModuleSignoffData.SCURVECOMMENT)!=null) ? signoffData.getString(ModuleSignoffData.SCURVECOMMENT) : "None");
00133 tableList.addElement(itemList);
00134 }
00135 }catch(Exception e){System.err.println("Exception "+e.toString());}
00136 return tableList;
00137 }
00138 public Vector getTestNoList() {
00139 return snList;
00140 }
00141 public Vector getSelectedTestNoList() {
00142 return selectedSNList;
00143 }
00144
00145
00146
00147 public String getString(String location,int index, boolean isHTML) {
00148 if(!signoffDataHash.containsKey(location)) return "None uploaded";
00149 String value=null;
00150 if((value=((SignoffData)signoffDataHash.get(location)).getString(index))!=null) {
00151 if(isHTML) value = value.replaceAll("[\\n\\r]+","<br>");
00152 switch(index) {
00153 case ModuleSignoffData.IVCATEGORY:
00154 case ModuleSignoffData.ELECTRICALCATEGORY:
00155 case ModuleSignoffData.SCURVECATEGORY:
00156 if(value.matches(".*GOOD|Good.*")) value="<font color=green>"+value+"</font>";
00157 else value="<font color=red>"+value+"</font>";
00158 break;
00159 default:
00160 }
00161 }
00162 return (value==null) ? "None uploaded" : value;
00163 }
00164
00165
00166
00167 public String getString(int index, boolean isHTML) {
00168 String value=null;
00169 if(signoffDataHash.size()!=1) return null;
00170 for (java.util.Enumeration e = signoffDataHash.keys() ; e.hasMoreElements() ;) {
00171 String location = (String)e.nextElement();
00172 value=((SignoffData)signoffDataHash.get(location)).getString(index);
00173 if(isHTML) value = value.replaceAll("\\n","<br>");
00174 }
00175 return value;
00176 }
00177
00178 public boolean qualityInfoIsPresent() {
00179 if(signoffDataHash.size()==0) return false;
00180 for (java.util.Enumeration e = signoffDataHash.keys() ; e.hasMoreElements() ;) {
00181 String location = (String)e.nextElement();
00182 String value;
00183 if((value=((SignoffData)signoffDataHash.get(location)).getString(ModuleSignoffData.IVCATEGORY))==null) return false;
00184 }
00185 return true;
00186 }
00187
00188 public Hashtable getSignoffDataHash() {
00189 return signoffDataHash;
00190 }
00191 public void setParameter(String location, int index, String value) {
00192 if(!signoffDataHash.containsKey(location)) signoffDataHash.put(location, new SignoffData());
00193 ((SignoffData)signoffDataHash.get(location)).put(keywords[index],value);
00194 }
00195 public String getUploaderInfo(String location) {
00196 if(!signoffDataHash.containsKey(location)) return null;
00197 return ((SignoffData)signoffDataHash.get(location)).getUploaderInfo();
00198 }
00199
00200
00201 public String writeUploadFiles(String sn, String location) {
00202 String userInitials=null;
00203 if(!signoffDataHash.containsKey(location)) return null;
00204 SignoffData signoffData = (SignoffData)signoffDataHash.get(location);
00205 try {
00206 userPrompt thisPrompt = new userPrompt(null,"","Your initials", GeneralUtilities.getNameList(location));
00207 thisPrompt.pack();
00208 thisPrompt.setVisible(true);
00209 userInitials = thisPrompt.getValidatedText();
00210 if (userInitials.equals("None")) return null;
00211 } catch(Exception e1){System.out.println("ERROR retrieving list of users from SCTDB: "+e1.toString()); return null;}
00212 try {
00213 return ProdDatabase.BarrelUtilities.writeUploadFile(sn,signoffData.writeUploadDataFile(sn),userInitials, location,signoffType);
00214 }catch(Exception e) {System.out.println("FAILED to create upload file: "+e.toString()); return null;}
00215 }
00216
00217
00218 }