ConstructionExample constructionExample = (ConstructionExample) command;
boolean isNew = (constructionExample.getExampleId() == null);
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
ObjectConstruction objectConstruction = objectConstructionManager.getObjectConstruction(constructionExample.getObjectConstructionId().toString());
objectConstruction.getConstructionExamples().remove(constructionExample);
objectConstructionManager.saveObjectConstruction(objectConstruction);
saveMessage(request, getText("constructionExample.deleted", locale));
} else {
Integer dangerId = constructionExample.getDangerCategory().getDangerCategoryId();
if (!dangerId.equals(new Integer(-1))) {
constructionExample.setDangerCategory(dangerCategoryManager.getDangerCategory(dangerId.toString()));
} else {
constructionExample.setDangerCategory(null);
}
ObjectConstruction objectConstruction = objectConstructionManager.getObjectConstruction(constructionExample.getObjectConstructionId().toString());
objectConstructionManager.evict(objectConstruction);
constructionExample.setConstructionType(objectConstruction.getConstructionType());
if (constructionExample.getWayToPowerEsckiz() != null && !constructionExample.getWayToPowerEsckiz().equals("") && (new File(FileHelper.getCurrentPath(request) + constructionExample.getWayToDefectEsckiz())).exists()) {
constructionExample.setDefectEsckizBlob(Hibernate.createBlob(new FileInputStream(FileHelper.getCurrentPath(request) + constructionExample.getWayToDefectEsckiz())));
}
if (constructionExample.getWayToPowerEsckiz() != null && !constructionExample.getWayToPowerEsckiz().equals("") && (new File(FileHelper.getCurrentPath(request) + constructionExample.getWayToPowerEsckiz())).exists()) {
constructionExample.setPowerEsckizBlob(Hibernate.createBlob(new FileInputStream(FileHelper.getCurrentPath(request) + constructionExample.getWayToPowerEsckiz())));
}
//restoring construction examples associations
if (!isNew) {
ConstructionExample oldConstructionExample = constructionExampleManager.getConstructionExample(constructionExample.getExampleId().toString());
constructionExample.setExampleDefects(oldConstructionExample.getExampleDefects());
constructionExample.setConstructionType(oldConstructionExample.getConstructionType());
constructionExample.setStrengthPoints(oldConstructionExample.getStrengthPoints());
constructionExample.setDefectEsckizBlob(oldConstructionExample.getDefectEsckizBlob());
constructionExample.setWayToDefectEsckiz(oldConstructionExample.getWayToDefectEsckiz());
constructionExample.setWayToPowerEsckiz(oldConstructionExample.getWayToPowerEsckiz());
constructionExample.setPowerEsckizBlob(oldConstructionExample.getPowerEsckizBlob());
constructionExampleManager.evict(oldConstructionExample);
}
if (isNew) {
constructionExample.setBuildObjectId(objectConstruction.getObjectId());
objectConstruction.addConstructionExample(constructionExample);
objectConstructionManager.saveObjectConstruction(objectConstruction);
} else {
System.out.println("editing example"+constructionExample.getExampleId());
constructionExampleManager.saveConstructionExample(constructionExample);
}