protected Object formBackingObject(HttpServletRequest request)
throws Exception {
if (!isFormSubmission(request)) {
String exampleId = request.getParameter("exampleId");
ConstructionExample constructionExample = null;
String typeId = "-1";
if(request.getParameter("typeId") != null)
typeId = request.getParameter("typeId");
else if(request.getAttribute("typeId") != null)
typeId = request.getAttribute("typeId").toString();
request.setAttribute("dangerCategoryList", dangerCategoryManager.getDangerCategorys(null));
if (!StringUtils.isEmpty(exampleId)) {
constructionExample = constructionExampleManager.getConstructionExample(exampleId);
//constructionExampleManager.evict(constructionExample);
} else {
constructionExample = new ConstructionExample();
//generating the unique number of construction
Integer number =constructionExampleManager.getExampleNumberByConstructionObjectId(new Integer(typeId));
constructionExample.setExampleRelativeNumber(number);
}
if (typeId != null) {
// constructionExample.setConstructionType(((ObjectConstruction)objectConstructionManager.getObjectConstruction(typeId)).getConstructionType());
constructionExample.setObjectConstructionId(new Integer(typeId));
}
constructionExampleManager.makeNotNull(constructionExample);
if (request.getParameter("edited") != null) {
request.setAttribute("addition", "?edited=1");
constructionExample.setEdited(true);
}
//checking esciz
if (constructionExample.getWayToDefectEsckiz() == null || constructionExample.getWayToDefectEsckiz().equals("")) {
//retrieving esciz from object construction
ObjectConstruction objectConstruction = objectConstructionManager.getObjectConstruction(constructionExample.getObjectConstructionId().toString());
//esciz for defects
if (objectConstruction.getEsckizBlob() != null && objectConstruction.getWayToEsckiz() != null && !objectConstruction.getWayToEsckiz().equals("")) {
String wayToDefectEskiz = ImageUtil.getUniqueJPEGFile(request);
constructionExample.setWayToDefectEsckiz(wayToDefectEskiz);
objectConstruction.getEsckizBlob();
File file = new File(FileHelper.getCurrentPath(request) + wayToDefectEskiz);
file.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToDefectEskiz);
Blob blob = objectConstruction.getEsckizBlob();
byte[] bufer = new byte[62000];
InputStream inputStream = blob.getBinaryStream();
while (inputStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
inputStream.close();
fileOutputStream.close();
//esciz for power points
String wayToPowerEskiz = ImageUtil.getUniqueJPEGFile(request);
constructionExample.setWayToPowerEsckiz(wayToPowerEskiz);
objectConstruction.getEsckizBlob();
file = new File(FileHelper.getCurrentPath(request) + wayToPowerEskiz);
if (file.exists()) {
file.delete();
}
file.createNewFile();
fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPowerEskiz);
blob = objectConstruction.getEsckizBlob();
byte[] powerBufer = new byte[62000];
inputStream = blob.getBinaryStream();
while (inputStream.read(powerBufer) != -1) {
fileOutputStream.write(powerBufer);
}
inputStream.close();
fileOutputStream.close();
}
}
constructionExample.setDocLocation(request.getParameter("docLocation"));
return constructionExample;
} else {
return super.formBackingObject(request);
}