1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
| package tdms.formBeans;
import java.io.IOException;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;
import org.hibernate.Session;
import tdms.dto.Company;
import tdms.dto.DocFormat;
import tdms.dto.DocType;
import tdms.dto.Document;
import tdms.dto.Family;
import tdms.dto.Location;
import tdms.dto.User;
import tdms.net.MyFTPClient;
import tdms.tree.FamilyTree;
import tdms.utils.Misc;
/**
*
* @struts.form
* name="editDocFormBean"
* type="tdms.formBeans.EditDocFormBean"
*/
public class EditDocFormBean extends ActionForm
{
private static final long serialVersionUID = 1L;
private int docId;
private int docApprover1;
private int docApprover2;
private int docApprover3;
private boolean docBook;
private String docComments;
private int docCompanies[];
private int docDistriPolicy;
private int docFamily;
private int docFormat;
private String docKeyword;
private int docLocations[];
private String docName;
private String docProjectName;
private String docReportTitle;
private String docShortProjectName;
private String docShortReportTitle;
private String docSummary;
private String docTemplateVersion;
private int docType;
private float docVersion;
private String docVersionModif;
private int day;
private int month;
private int year;
private FormFile iuFile;
private FormFile srcFile;
private FormFile ndaFile;
/* Uploaded file accessors */
public FormFile getIuFile() { return iuFile; }
public FormFile getSrcFile() { return srcFile; }
public FormFile getNdaFile() { return ndaFile; }
public void setIuFile(FormFile f) { if (f.getFileSize() != 0) iuFile = f; }
public void setSrcFile(FormFile f) { if (f.getFileSize() != 0) srcFile = f; }
public void setNdaFile(FormFile f) { if (f.getFileSize() != 0) ndaFile = f; }
public String getIuFileName() {
return iuFile == null ? "" : iuFile.getFileName();
}
public String getSrcFileName() {
return srcFile == null ? "" : srcFile.getFileName();
}
public String getNdaFileName() {
return ndaFile == null ? "" : ndaFile.getFileName();
}
/* Regular getters */
public int getDocId() { return docId; }
public int getDocApprover1() { return docApprover1; }
public int getDocApprover2() { return docApprover2; }
public int getDocApprover3() { return docApprover3; }
public boolean isDocBook() { return docBook; }
public String getDocComments() { return docComments; }
public int[] getDocCompanies() { return docCompanies; }
public int getDocDistriPolicy() { return docDistriPolicy; }
public int getDocFamily() { return docFamily; }
public int getDocFormat() { return docFormat; }
public String getDocKeyword() { return docKeyword; }
public int[] getDocLocations() { return docLocations; }
public String getDocName() { return docName; }
public String getDocProjectName() { return docProjectName; }
public String getDocReportTitle() { return docReportTitle; }
public String getDocShortProjectName() { return docShortProjectName; }
public String getDocShortReportTitle() { return docShortReportTitle; }
public String getDocSummary() { return docSummary; }
public String getDocTemplateVersion() { return docTemplateVersion; }
public int getDocType() { return docType; }
public float getDocVersion() { return docVersion; }
public String getDocVersionModif() { return docVersionModif; }
public int getDay() { return day; }
public int getMonth() { return month; }
public int getYear() { return year; }
/* Regular setters */
public void setDocId (int i) { docId = i; }
public void setDocApprover1 (int i) { docApprover1 = i; }
public void setDocApprover2 (int i) { docApprover2 = i; }
public void setDocApprover3 (int i) { docApprover3 = i; }
public void setDocBook (boolean b) { docBook = b; }
public void setDocComments (String s) { docComments = s; }
public void setDocCompanies (int[] t) { docCompanies = t; }
public void setDocDistriPolicy (int i) { docDistriPolicy = i; }
public void setDocFamily (int i) { docFamily = i; }
public void setDocFormat (int i) { docFormat = i; }
public void setDocLocations (int[] t) { docLocations = t; }
public void setDocName (String s) { docName = s; }
public void setDocKeyword (String s) { docKeyword = s; }
public void setDocProjectName (String s) { docProjectName = s; }
public void setDocReportTitle (String s) { docReportTitle = s; }
public void setDocShortProjectName (String s) { docShortProjectName = s; }
public void setDocShortReportTitle (String s) { docShortReportTitle = s; }
public void setDocSummary (String s) { docSummary = s; }
public void setDocTemplateVersion (String s) { docTemplateVersion = s;}
public void setDocType (int i) { docType = i; }
public void setDocVersion (float f) { docVersion = f; }
public void setDocVersionModif (String s) { docVersionModif = s; }
public void setDay (int i) { day = i; }
public void setMonth (int i) { month = i; }
public void setYear (int i) { year = i; }
/* Validates the form when posted */
public ActionErrors validate (ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
if ("submit".equals(request.getParameter("action")))
{
if (docLocations == null || docLocations.length == 0)
errors.add ("docLocations", new ActionMessage ("errors.required", "Location"));
if (docApprover1 == 0)
errors.add ("docApprover1", new ActionMessage ("errors.required", "Approver1"));
if (docApprover2 == 0)
errors.add ("docApprover2", new ActionMessage ("errors.required", "Approver2"));
if (docVersion == 0)
errors.add ("docVersion", new ActionMessage ("errors.required", "Version"));
if (Misc.isMissing (docName))
errors.add ("docName", new ActionMessage ("errors.required", "Document name"));
if (srcFile == null)
errors.add ("srcFile", new ActionMessage ("errors.fileMissing"));
if (iuFile == null)
errors.add ("iuFile", new ActionMessage ("errors.fileMissing"));
if (ndaFile == null)
errors.add ("ndaFile", new ActionMessage ("errors.fileMissing"));
}
return errors;
}
/**
* Load a EditDocFormBean from the database
* @param session db connection
* @param id identifier of the document
*/
public void load (Session session, int id)
{
Document d = Document.get (session, id);
/* Load attributes */
docId = id;
docBook = d.isDocBook();
docComments = d.getDocComment();
docDistriPolicy = d.getDocDistriPolicy();
docKeyword = d.getDocKeyword();
docName = d.getDocName();
docProjectName = d.getDocProjectName();
docReportTitle = d.getDocReportTitle();
docShortProjectName = d.getDocShortProjectName();
docShortReportTitle = d.getDocShortReportTitle();
docSummary = d.getDocSummary();
docTemplateVersion = d.getDocTemplateVersion();
docVersion = d.getDocVersion();
docVersionModif = d.getDocVersionModif();
/* Relations */
docApprover1 = d.getDocApprover1().getId();
docApprover2 = d.getDocApprover2() == null ? 0 : d.getDocApprover2().getId();
docApprover3 = d.getDocApprover3() == null ? 0 : d.getDocApprover3().getId();
docFamily = d.getDocFamily().getId();
docFormat = d.getDocFormat().getId();
docType = d.getDocType().getId();
/* Load document date */
Calendar cal = Calendar.getInstance();
cal.setTime (d.getDocDate());
day = cal.get (Calendar.DAY_OF_MONTH);
month = cal.get (Calendar.MONTH) + 1;
year = cal.get (Calendar.YEAR);
/* Load allowed companies */
if (d.getDocCompanies().size() > 0)
{
int i = 0;
Set s = d.getDocCompanies();
docCompanies = new int[s.size()];
Iterator it = s.iterator();
while (it.hasNext())
docCompanies[i++] = ((Company)it.next()).getId();
}
/* Load locations */
if (d.getDocLocations().size() > 0)
{
int i = 0;
Set s = d.getDocLocations();
docLocations = new int[s.size()];
Iterator it = s.iterator();
while (it.hasNext())
docLocations[i++] = ((Location)it.next()).getId();
}
/* Load files */
MyFTPClient ftp = new MyFTPClient();
try
{
ftp.connect();
srcFile = ftp.getDocFile (id, docName, MyFTPClient.DOC_SRC);
iuFile = ftp.getDocFile (id, docName, MyFTPClient.DOC_IU);
ndaFile = ftp.getDocFile (id, docName, MyFTPClient.DOC_NDA);
ftp.disconnect();
}
catch (IOException e) { System.err.println ("Pb getting file " + e.getMessage()); }
}
/**
* Store a ReleaseAppr3FormBean into the database
* @param session db connection
* @throws Exception
*/
public void store (Session session) throws Exception
{
Document d = Document.get (session, docId);
/* Save document attributes */
d.setDocBook (docBook);
d.setDocComment (docComments);
d.setDocDistriPolicy (docDistriPolicy);
d.setDocKeyword (docKeyword);
d.setDocName (docName);
d.setDocProjectName (docProjectName);
d.setDocReportTitle (docReportTitle);
d.setDocShortProjectName (docShortProjectName);
d.setDocShortReportTitle (docShortReportTitle);
d.setDocSummary (docSummary);
d.setDocTemplateVersion (docTemplateVersion);
d.setDocVersion (docVersion);
d.setDocVersionModif (docVersionModif);
/* Save relations */
d.setDocApprover1 (User.get (session, docApprover1));
d.setDocApprover2 (User.get (session, docApprover2));
d.setDocApprover3 (User.get (session, docApprover3));
d.setDocFamily (Family.get (session, docFamily));
d.setDocFormat (DocFormat.get (session, docFormat));
d.setDocType (DocType.get (session, docType));
/* Save companies */
Set k = d.getDocCompanies();
if (docCompanies != null)
for (int i=0; i<docCompanies.length; i++)
k.add (Company.get (session, docCompanies[i]));
/* Save locations */
Set l = d.getDocLocations();
for (int i=0; i<docLocations.length; i++)
l.add (Location.get (session, docLocations[i]));
/* Save document date */
Calendar cal = Calendar.getInstance();
cal.set (year, month-1, day);
d.setDocDate (cal.getTime());
/* Save to database */
d.store (session);
/* Update family tree */
FamilyTree.updateRemoteTree();
/* Store files */
MyFTPClient ftp = new MyFTPClient();
try
{
ftp.connect();
ftp.sendDocFile (srcFile, d.getDocId(), d.getDocName(), MyFTPClient.DOC_SRC);
ftp.sendDocFile (iuFile, d.getDocId(), d.getDocName(), MyFTPClient.DOC_IU);
ftp.sendDocFile (ndaFile, d.getDocId(), d.getDocName(), MyFTPClient.DOC_NDA);
System.err.println ("Stored file : " + d.getDocId());
ftp.disconnect();
}
catch (IOException e) { System.err.println ("Pb uploading file : " + e.getMessage()); }
}
} |