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;
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() {
00051 Vector tableList = new Vector();
00052 Vector itemList=new Vector();
00053 itemList.addElement("Serial No");
00054 itemList.addElement("Uploaded by");
00055 itemList.addElement("Date");
00056 itemList.addElement("Category");
00057 itemList.addElement("Reason");
00058 itemList.addElement("Barrel Assignment");
00059 itemList.addElement("Reason");
00060 itemList.addElement("Comments");
00061 tableList.addElement(itemList);
00062 if(snList.size()==0) return tableList;
00063
00064 try {
00065 for(int i=0;i<snList.size();i++) {
00066 itemList = new Vector();
00067 String testno = (String)snList.elementAt(i);
00068 SignoffData signoffData = new SignoffData((String)snList.elementAt(i));
00069 itemList.addElement(signoffData.getString(ModuleSignoffData.SERIALNO));
00070 System.out.println("Extracting signoff info for module "+signoffData.getString(ModuleSignoffData.SERIALNO)+" ("+Integer.toString(i+1)+" out of "+snList.size()+")");
00071 SCTDBTestInfoHolder testInfo = GeneralUtilities.getTestInfo(testno);
00072 itemList.addElement(testInfo.get(SCTDBTestInfoHolder.LOCATION));
00073 itemList.addElement(testInfo.get(SCTDBTestInfoHolder.DATE));
00074 itemList.addElement(signoffData.getString(ModuleSignoffData.CATEGORY));
00075 String failReason = signoffData.getString(ModuleSignoffData.FAILREASON);
00076 if(failReason==null) itemList.addElement("n/a");
00077 else itemList.addElement(failReason);
00078 String barrelA = signoffData.getString(ModuleSignoffData.BARREL).toUpperCase();
00079 if(barrelA.equals("6")) barrelA="Barrel 6 ONLY";
00080 itemList.addElement(barrelA);
00081 String b56Reason = signoffData.getString(ModuleSignoffData.B56REASON);
00082 if(b56Reason==null) itemList.addElement("n/a");
00083 else itemList.addElement(b56Reason);
00084 itemList.addElement(signoffData.getString(ModuleSignoffData.COMMENT));
00085 tableList.addElement(itemList);
00086 }
00087 }catch(Exception e){System.err.println("Exception "+e.toString());}
00088 return tableList;
00089 }
00090
00091 public Vector getQualityTable() {
00092 Vector tableList = new Vector();
00093 Vector itemList=new Vector();
00094 itemList.addElement("Serial No");
00095 itemList.addElement("Uploaded by");
00096 itemList.addElement("Date");
00097 itemList.addElement("IV Category");
00098 itemList.addElement("IV comment");
00099 itemList.addElement("Elec Category");
00100 itemList.addElement("Elec comment");
00101 itemList.addElement("Elec spec Settings");
00102 itemList.addElement("SCurve Category");
00103 itemList.addElement("SCurve comment");
00104 tableList.addElement(itemList);
00105 if(snList.size()==0) return tableList;
00106
00107 try {
00108 for(int i=0;i<snList.size();i++) {
00109 itemList = new Vector();
00110 String testno = (String)snList.elementAt(i);
00111 System.out.println("Extracting quality data for test number "+testno+" (test "+Integer.toString(i+1)+" out of "+snList.size()+")");
00112 SignoffData signoffData = new SignoffData(testno);
00113 itemList.addElement(signoffData.getString(ModuleSignoffData.SERIALNO));
00114 SCTDBTestInfoHolder testInfo = GeneralUtilities.getTestInfo(testno);
00115 itemList.addElement(testInfo.get(SCTDBTestInfoHolder.LOCATION));
00116 itemList.addElement(testInfo.get(SCTDBTestInfoHolder.DATE));
00117 itemList.addElement( (signoffData.getString(ModuleSignoffData.IVCATEGORY)!=null) ? signoffData.getString(ModuleSignoffData.IVCATEGORY) : "Not known");
00118 itemList.addElement( (signoffData.getString(ModuleSignoffData.IVCOMMENT)!=null) ? signoffData.getString(ModuleSignoffData.IVCOMMENT) : "None");
00119 itemList.addElement( (signoffData.getString(ModuleSignoffData.ELECTRICALCATEGORY)!=null) ? signoffData.getString(ModuleSignoffData.ELECTRICALCATEGORY) : "Unknown");
00120 itemList.addElement( (signoffData.getString(ModuleSignoffData.ELECTRICALCOMMENT)!=null) ? signoffData.getString(ModuleSignoffData.ELECTRICALCOMMENT) : "None");
00121 itemList.addElement( (signoffData.getString(ModuleSignoffData.ELEC_SPECIAL_SETTING)!=null) ? signoffData.getString(ModuleSignoffData.ELEC_SPECIAL_SETTING) : "None");
00122 itemList.addElement( (signoffData.getString(ModuleSignoffData.SCURVECATEGORY)!=null) ? signoffData.getString(ModuleSignoffData.SCURVECATEGORY) : "Ok");
00123 itemList.addElement( (signoffData.getString(ModuleSignoffData.SCURVECOMMENT)!=null) ? signoffData.getString(ModuleSignoffData.SCURVECOMMENT) : "None");
00124 tableList.addElement(itemList);
00125 }
00126 }catch(Exception e){System.err.println("Exception "+e.toString());}
00127 return tableList;
00128 }
00129 public Vector getTestNoList() {
00130 return snList;
00131 }
00132
00133
00134
00135 public String getString(String location,int index, boolean isHTML) {
00136 if(!signoffDataHash.containsKey(location)) return "None uploaded";
00137 String value=null;
00138 if((value=((SignoffData)signoffDataHash.get(location)).getString(index))!=null) {
00139 if(isHTML) value = value.replaceAll("[\\n\\r]+","<br>");
00140 switch(index) {
00141 case ModuleSignoffData.IVCATEGORY:
00142 case ModuleSignoffData.ELECTRICALCATEGORY:
00143 case ModuleSignoffData.SCURVECATEGORY:
00144 if(value.matches(".*GOOD|Good.*")) value="<font color=green>"+value+"</font>";
00145 else value="<font color=red>"+value+"</font>";
00146 break;
00147 default:
00148 }
00149 }
00150 return (value==null) ? "None uploaded" : value;
00151 }
00152
00153
00154
00155 public String getString(int index, boolean isHTML) {
00156 String value=null;
00157 if(signoffDataHash.size()!=1) return null;
00158 for (java.util.Enumeration e = signoffDataHash.keys() ; e.hasMoreElements() ;) {
00159 String location = (String)e.nextElement();
00160 value=((SignoffData)signoffDataHash.get(location)).getString(index);
00161 if(isHTML) value = value.replaceAll("\\n","<br>");
00162 }
00163 return value;
00164 }
00165
00166 public boolean qualityInfoIsPresent() {
00167 if(signoffDataHash.size()==0) return false;
00168 for (java.util.Enumeration e = signoffDataHash.keys() ; e.hasMoreElements() ;) {
00169 String location = (String)e.nextElement();
00170 String value;
00171 if((value=((SignoffData)signoffDataHash.get(location)).getString(ModuleSignoffData.IVCATEGORY))==null) return false;
00172 }
00173 return true;
00174 }
00175
00176 public Hashtable getSignoffDataHash() {
00177 return signoffDataHash;
00178 }
00179 public void setParameter(String location, int index, String value) {
00180 if(!signoffDataHash.containsKey(location)) signoffDataHash.put(location, new SignoffData());
00181 ((SignoffData)signoffDataHash.get(location)).put(keywords[index],value);
00182 }
00183 public String getUploaderInfo(String location) {
00184 if(!signoffDataHash.containsKey(location)) return null;
00185 return ((SignoffData)signoffDataHash.get(location)).getUploaderInfo();
00186 }
00187
00188
00189 public String writeUploadFiles(String sn, String location) {
00190 String userInitials=null;
00191 if(!signoffDataHash.containsKey(location)) return null;
00192 SignoffData signoffData = (SignoffData)signoffDataHash.get(location);
00193 try {
00194 userPrompt thisPrompt = new userPrompt(null,"","Your initials", GeneralUtilities.getNameList(location));
00195 thisPrompt.pack();
00196 thisPrompt.setVisible(true);
00197 userInitials = thisPrompt.getValidatedText();
00198 if (userInitials.equals("None")) return null;
00199 } catch(Exception e1){System.out.println("ERROR retrieving list of users from SCTDB: "+e1.toString()); return null;}
00200 try {
00201 return ProdDatabase.BarrelUtilities.writeUploadFile(sn,signoffData.writeUploadDataFile(sn),userInitials, location,signoffType);
00202 }catch(Exception e) {System.out.println("FAILED to create upload file: "+e.toString()); return null;}
00203 }
00204
00205
00206 }