ucInsertAttachmentContent
Purpose
Applies To
Attachment Methods
Signature
public Attachment ucInsertAttachmentContent(
Connection dbConn,
Attachment attachment)
Notes
Example
public Attachment ucInsertAttachmentContent(Connection dbConn,Attachment attach){
boolean toBeStoredInternal = attach.getToBeStoredInternal();
if (!toBeStoredInternal) {
String attachId = attach.getAttachmentId();
String problemId = String.valueOf(attach.getProblemId());
String zeros = "00000000";
String zeroId = zeros.substring(problemId.length()) + problemId;
String millions = zeroId.substring(0, 2);
String thousands = zeroId.substring(2, 5);
String rootDir = "";
rootDir = Z.config.getConfigValue("ATTACHMENT_ROOT_DIR");
//String rootDir = "C:/Documents and Settings/...";
if (rootDir == null) {
rootDir = System.getProperty("java.io.tmpdir");
}
String attachDir = rootDir + "/" + millions + "/"
+ thousands + "/" + problemId + "/" + attachId;
String fileName = attach.getFileName();
try {
String extIdent = attach.getExternalAttachmentIdent();
File inputFile = new File(attach.getPath());
File outputDir = null;
File outputFile = null;
boolean status = false;
outputDir = new File(attachDir);
// Create the output directory
if (!outputDir.exists()) {
outputDir.mkdirs();
}
if (outputDir.exists()) {
outputFile = new File(attachDir, fileName);
}
Z.log.writeToLog(Z.log.INFO,
"THE File is : " + outputFile.getAbsolutePath());
if (inputFile != null && outputFile != null) {
status = this.copyFile(inputFile, outputFile);
}
if (status) {
attach.setExternalAttachmentIdent(outputFile.getAbsolutePath());
attach.setStoredInExternalSystem(true);
attach.setToBeStoredInternal(false);
attach.setStoredLocal("N");
}
}
catch (Exception e) {
ErrorWriter.write(e, ErrorWriter.LOG);
}
}
return attach;
}