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
| public String[] downloadFormsPack(int instrumentID) throws DocumentManagementException
{
cat.info("DocumentManagementBean: 'downloadFormsPack' starts...\n");
Connection connection = null;
String eptForms[] = {new String(), new String(), new String(), new String(), new String(), new String()};
byte[] buf = new byte[64 * 1024];
PreparedStatement stmt = null;
ResultSet eptFormsSet = null;
try
{
connection = getJDBCConnection();
File file = File.createTempFile("epf" + instrumentID, "tmp");
File keywordsFile = File.createTempFile("kxfm" + instrumentID, "tmp");
File activityFile = File.createTempFile("axfm" + instrumentID, "tmp");
stmt = connection.prepareStatement("" +
"SELECT EPT_FORMS, \n" +
" EPT_FORMS_NAME, \n" +
" ACTIVITYCODE_FORM, \n" +
" KEYWORDS_FORM \n" +
"FROM EPSS_INSTRUMENT, EPSS_ACTIVITYCODE_FORM, EPSS_KEYWORDS_FORM\n" +
"WHERE ACTIVITYCODE_ID=\n" +
" (SELECT MAX(ACTIVITYCODE_ID) FROM EPSS_ACTIVITYCODE_FORM) \n" +
"AND KEYWORDS_ID=\n" +
" (SELECT MAX(KEYWORDS_ID) FROM EPSS_KEYWORDS_FORM)\n" +
"AND INSTRUMENT_ID = ?");
stmt.setInt(1, instrumentID);
eptFormsSet = stmt.executeQuery();
eptFormsSet.next();
BLOB blob = ((OracleResultSet) eptFormsSet).getBLOB(1);
OutputStream fileStream = new FileOutputStream(file);
InputStream blobStream = blob.getBinaryStream();
try
{
int numRead = 0;
while((numRead = blobStream.read(buf)) >= 0)
{
fileStream.write(buf, 0, numRead);
}
}
finally
{
try
{
fileStream.close();
}
catch(Exception e)
{
}
try
{
blobStream.close();
}
catch(Exception e)
{
}
}
//get ActivityCodes form
blob = ((OracleResultSet) eptFormsSet).getBLOB(3);
fileStream = new FileOutputStream(activityFile);
blobStream = blob.getBinaryStream();
try
{
int numRead = 0;
while ((numRead = blobStream.read(buf)) >= 0)
{
fileStream.write(buf, 0, numRead);
}
}
finally
{
try
{
fileStream.close();
}
catch (Exception e) {
}
try
{
blobStream.close();
}
catch (Exception e) {
}
}
//get Keywords Form
blob = ((OracleResultSet) eptFormsSet).getBLOB(4);
fileStream = new FileOutputStream(keywordsFile);
blobStream = blob.getBinaryStream();
try
{
int numRead = 0;
while ((numRead = blobStream.read(buf)) >= 0)
{
fileStream.write(buf, 0, numRead);
}
}
finally
{
try
{
fileStream.close();
}
catch (Exception e) {
}
try
{
blobStream.close();
}
catch (Exception e) {
}
}
String eptFormName = eptFormsSet.getString(2);
String filepath = file.getAbsolutePath().toString();
String activityFormName = "ActivityCodes.xfm";
String activityFormPath = activityFile.getAbsolutePath().toString();
String keywordsFormName = "Keywords.xfm";
String keywordsFormPath = keywordsFile.getAbsolutePath().toString();
eptForms[0] = filepath;
eptForms[1] = eptFormName;
eptForms[2] = activityFormPath;
eptForms[3] = activityFormName;
eptForms[4] = keywordsFormPath;
eptForms[5] = keywordsFormName;
if(blob.isOpen()) blob.close();
return eptForms;
}
catch(Exception dbe)
{
cat.error("DocumentManagementBean: Exception in downloadFormsPack");
cat.error("Message: " + (dbe.getMessage()));
cat.error("Exception Details: ", dbe);
throw new DocumentManagementException();
}
finally
{
try
{
eptFormsSet.close();
}
catch(Exception e)
{
}
try
{
stmt.close();
}
catch(Exception e)
{
}
try
{
closeJDBCConnection(connection);
}
catch(Exception e)
{
}
cat.info("DocumentManagementBean: 'downloadFormsPack' exits...\n");
}
}//end of downloadFormsPack |
Partager