nf.setMaximumFractionDigits(2);
defectText += defectParameter.getParameter() + " - " + nf.format(defectParameter.getParameterValue()) + " " + defectParameter.getParameter().getMeasure() + "<br/>";
extraComment += "<br>" + defectParameter.getParameter() + " - " + nf.format(defectParameter.getParameterValue()) + " " + defectParameter.getParameter().getMeasure();
}
defectText += "<br/>" + constructionDefect.getComment() + "<br/>";
DefectPhoto defectPhoto = new DefectPhoto();
if (constructionDefect.getPhotoBlob() != null) {
defectPhoto.setPhotoBlob(constructionDefect.getPhotoBlob());
defectPhoto.setWayToPhoto(constructionDefect.getWayToPhoto());
defectPhoto.setPhotoRefference("Фото " + (l + 1) + "." + (k + 1) + "." + (s + 1));
defectPhoto.setExtraComment(extraComment);
defectPhotoList.add(defectPhoto);
} else {
defectPhoto.setPhotoRefference("-");
}
//defect cell
newRowInnerDefect = tableInnerDefectRow.replaceAll("%defect_name%", defectText);
//defect photo cell
newRowInnerDefect = newRowInnerDefect.replaceAll("%defect_photo%", defectPhoto.getPhotoRefference());
resultInnerDefect += newRowInnerDefect;
}
newRowDefectBuilder = new StringBuilder(newRowDefect);
ReportUtil.replaceAllLabel(newRowDefectBuilder, "%rowsInnerDefects%", resultInnerDefect);
newRowDefect = newRowDefectBuilder.toString();
}
}
//construction example danger category
String exampleDangerCategory = "";
if (constructionExample.getDangerCategory() != null) {
exampleDangerCategory = constructionExample.getDangerCategory().toString();
}
newRowDefect = newRowDefect.replaceAll("%example_danger%", exampleDangerCategory);
resultDefect += newRowDefect;
}
newDefectBlockBuilder = new StringBuilder(newDefectBlock);
ReportUtil.replaceAllLabel(newDefectBlockBuilder, "%rowsDefects%", resultDefect);
newDefectBlock = newDefectBlockBuilder.toString();
newDefectBlockBuilder = new StringBuilder(newDefectBlock);
tableDefectRow = ReportUtil.extractBookmarkForTable(newDefectBlockBuilder, "zone_defects_table_rows", "%zoneRowsDefects%");
newDefectBlock = newDefectBlockBuilder.toString();
resultDefect = "";
List constructionDefectZones = constructionDefectManager.getConstructionDefectZonesBuConstrType(constructionType.getConstructionTypeId().toString(), buildingObjectId, FileHelper.getCurrentPath(request));
num = 0;
for (int k = 0; k < constructionDefectZones.size(); k++) {
ConstructionDefectZone constructionDefectZone = (ConstructionDefectZone) constructionDefectZones.get(k);
List examplesList = constructionDefectManager.getExamplesByDefect(constructionDefectZone.getUniqueForExamples(), FileHelper.getCurrentPath(request));
String examples = "";
for (int g = 0; g < examplesList.size(); g++) {
ConstructionExample constructionExample = constructionExampleManager.getConstructionExample(examplesList.get(g).toString());
if (constructionExample.getExampleName() == null || constructionExample.getExampleName().trim().equals("")) {
examples += constructionExample.getExampleRelativeNumber();
} else {
examples += constructionExample.getExampleName();
}
if (g != examplesList.size() - 1) {
examples += "; ";
}
}
num++;
String defectText = constructionDefectZone.getDefectType() + "<br/>" + constructionDefectZone.getDefectVarity() + "<br/>";
List defectParameters = constructionDefectZone.getDefectParameters();
for (int m = 0; m < defectParameters.size(); m++) {
DefectParameterZone defectParameter = (DefectParameterZone) defectParameters.get(m);
nf.setMaximumFractionDigits(2);
defectText += "<br>" + defectParameter.getParameter() + " : " + nf.format(defectParameter.getParameterValue()) + "-" + nf.format(defectParameter.getParameterValueSecond()) + " " + defectParameter.getParameter().getMeasure();
}
defectText += "<br/>" + constructionDefectZone.getComment() + "<br/>";
newRowDefect = tableDefectRow.replaceAll("%num%", String.valueOf(num));
newRowDefect = newRowDefect.replaceAll("%defect_zone%", defectText);
newRowDefect = newRowDefect.replaceAll("%examples%", examples);
resultDefect += newRowDefect;
}
newDefectBlockBuilder = new StringBuilder(newDefectBlock);
ReportUtil.replaceAllLabel(newDefectBlockBuilder, "%zoneRowsDefects%", resultDefect);
newDefectBlock = newDefectBlockBuilder.toString();
//power table filling
newDefectBlockBuilder = new StringBuilder(newDefectBlock);
String tableStrengthRow = ReportUtil.extractBookmarkForTable(newDefectBlockBuilder, "strength_table_rows", "%rowsStrengths%");
newDefectBlock = newDefectBlockBuilder.toString();
String resultStrength = "";
String newRowStrength = "";
constructionVarities = buildingObjectManager.getObjectConstructionsByTypeId(buildingObjectId, constructionType.getConstructionTypeId().toString());
num = 0;
for (int k = 0; k < constructionExamples.size(); k++) {
ConstructionExample constructionExample = (ConstructionExample) constructionExamples.get(k);
if (constructionExample.getStrengthPoints().size() != 0) {
num++;
newRowStrength = tableStrengthRow.replaceAll("%strength_number%", String.valueOf(num));
newRowStrength = newRowStrength.replaceAll("%strength_point%", constructionExample.getExampleName() != null ? constructionExample.getExampleName() : String.valueOf(constructionExample.getExampleRelativeNumber()));
List strengthPoints = constructionExample.getStrengthPoints();
//filling inner table
StringBuilder newRowStrengthBuilder = new StringBuilder(newRowStrength);
String tableStrengthInnerRow = ReportUtil.extractBookmarkForTableInTable(newRowStrengthBuilder, "strength_table_inner_rows", "%rowsStrengthsInner%");
newRowStrength = newRowStrengthBuilder.toString();
String resultStrengthInner = "";
String newRowStrengthInner = "";
for (int i = 0; i < strengthPoints.size(); i++) {
Strength strength = (Strength) strengthPoints.get(i);
newRowStrengthInner = tableStrengthInnerRow.replaceAll("%strength_marking%", strength.getPointRelativeNumber().toString());
newRowStrengthInner = newRowStrengthInner.replaceAll("%strength_value%", String.valueOf(strength.getStrengthValue()));
resultStrengthInner += newRowStrengthInner;
}
newRowStrengthBuilder = new StringBuilder(newRowStrength);
ReportUtil.replaceAllLabel(newRowStrengthBuilder, "%rowsStrengthsInner%", resultStrengthInner);
newRowStrength = newRowStrengthBuilder.toString();
resultStrength += newRowStrength;
}
}
newDefectBlockBuilder = new StringBuilder(newDefectBlock);
if (!"".equals(resultStrength)) {
ReportUtil.replaceAllLabel(newDefectBlockBuilder, "%rowsStrengths%", resultStrength);
} else {
//removing tables head from report, because it's empty
//ReportUtil.extractBookmarkForTable(newDefectBlockBuilder, "main_strength_table", "");
}
newDefectBlock = newDefectBlockBuilder.toString();
//defect rreason table filling
newDefectBlockBuilder = new StringBuilder(newDefectBlock);
String tableReasonRow = ReportUtil.extractBookmarkForTable2(newDefectBlockBuilder, "common_reason_table_rows", "%rowsReasons%");
newDefectBlock = newDefectBlockBuilder.toString();
String resultReason = "";
String newRowReason = "";
StringBuilder newReasonRowBuilder = new StringBuilder();
String tableReasonInnerRow = "";
List reasonList = reasonManager.getReasonsForConstrcutionsInObject(constructionType.getConstructionTypeId().toString(), buildingObjectId);
List otherReasonList = reasonManager.getOtherReasonsForConstrcutionsInObject(constructionType.getConstructionTypeId().toString(), buildingObjectId);
reasonList.addAll(otherReasonList);
for (int i = 0; i < reasonList.size(); i++) {
newRowReason = tableReasonRow;
newReasonRowBuilder = new StringBuilder(newRowReason);
tableReasonInnerRow = ReportUtil.extractBookmarkForTableInTableFirstColumn(newReasonRowBuilder, "defect_description_reason_table_rows", "%rowsReasonsInner%");
String resultReasonInner = "";
String newRowReasonInner = "";
List defectList;
Reason reason = new Reason();
String otherReason = "";
boolean standartReason = false;
if (reasonList.get(i) instanceof Reason) {
reason = (Reason) reasonList.get(i);
defectList = constructionDefectManager.getConstructionDefectsForReason(reason.getReasonId().toString(), constructionType.getConstructionTypeId().toString(), buildingObjectId);
standartReason = true;
} else {
standartReason = false;
otherReason = (String) reasonList.get(i);
defectList = constructionDefectManager.getConstructionDefectsForOtherReason(otherReason, constructionType.getConstructionTypeId().toString(), buildingObjectId);
}
//TODO find out how to get maximum if one parameter is maximum and the other one is small and make it by sql query
double maxParameter = 0;
Integer currentDefectTypeId = null;
Integer currentDefectVarityId = null;
List finalDefectList = new ArrayList();
ConstructionDefect curConstructionDefect = defectList.size() != 0 ? (ConstructionDefect) defectList.get(0) : null;
for (int j = 0; j < defectList.size(); j++) {
ConstructionDefect constructionDefect = (ConstructionDefect) defectList.get(j);
if ((!constructionDefect.getDefectType().getDefectTypeId().equals(currentDefectTypeId) || !constructionDefect.getDefectVarity().getVarityId().equals(currentDefectVarityId))) {
currentDefectTypeId = constructionDefect.getDefectType().getDefectTypeId();
currentDefectVarityId = constructionDefect.getDefectVarity().getVarityId();
finalDefectList.add(curConstructionDefect);
curConstructionDefect = constructionDefect;
maxParameter = 0;
}
List parameterList = constructionDefect.getDefectParameters();
for (int k = 0; k < parameterList.size(); k++) {
DefectParameter defectParameter = (DefectParameter) parameterList.get(k);
if (maxParameter < defectParameter.getParameterValue()) {
maxParameter = defectParameter.getParameterValue();
}
}
}
defectList = finalDefectList;
for (int j = 0; j < defectList.size(); j++) {
ConstructionDefect constructionDefect = (ConstructionDefect) defectList.get(j);
//constructiondefect
ConstructionExample constructionExample = constructionExampleManager.getConstructionExample(constructionDefect.getExampleId().toString());
String defectText = constructionDefect.getDefectType().toString() + " " + constructionDefect.getDefectVarity() + " <br/>";
List parameterList = constructionDefect.getDefectParameters();
for (int k = 0; k < parameterList.size(); k++) {
DefectParameter defectParameter = (DefectParameter) parameterList.get(k);
defectText += defectParameter.getParameter() + " - " + nf.format(defectParameter.getParameterValue()) + " " + defectParameter.getParameter().getMeasure() + "<br/>";
}
newRowReasonInner = tableReasonInnerRow.replaceAll("%defect_name%", defectText);
newRowReasonInner = newRowReasonInner.replaceAll("%defect_category%", constructionDefect.getDangerCategory().toString());
resultReasonInner += newRowReasonInner;
}
ReportUtil.replaceAllLabel(newReasonRowBuilder, "%rowsReasonsInner%", resultReasonInner);
newRowReason = newReasonRowBuilder.toString();
if (standartReason) {
newRowReason = newRowReason.replaceAll("%defect_reason%", reason.toString());
} else {
newRowReason = newRowReason.replaceAll("%defect_reason%", otherReason);
}
resultReason += newRowReason;
}
newDefectBlockBuilder = new StringBuilder(newDefectBlock);
if (!"".equals(resultReason)) {
ReportUtil.replaceAllLabel(newDefectBlockBuilder, "%rowsReasons%", resultReason);
} else {
//removing tables head from report, because it's empty
ReportUtil.extractBookmarkForTable(newDefectBlockBuilder, "main_strength_table", "");
}
//defining construction type condition
String tableCondition = ReportUtil.extractBookmarkForTable(newDefectBlockBuilder, "common_condition_table", "%rowsCondition%");
newDefectBlock = newDefectBlockBuilder.toString();
String resultCondition = "";
String newRowCondition = "";
Integer bNumber = buildingObjectManager.getObjectConstructionTypeExampleByCategory(buildingObjectId, constructionType.getConstructionTypeId().toString(), "B");
Integer aNumber = buildingObjectManager.getObjectConstructionTypeExampleByCategory(buildingObjectId, constructionType.getConstructionTypeId().toString(), "A");
Integer commonNumber = buildingObjectManager.getObjectConstructionTypeExampleNum(buildingObjectId, constructionType.getConstructionTypeId().toString());
Integer cNumber = new Integer(commonNumber - bNumber - aNumber);
double aPercent = (aNumber.floatValue() / commonNumber.floatValue()) * 100;
double bPercent = (bNumber.floatValue() / commonNumber.floatValue()) * 100;
double cPercent = (cNumber.floatValue() / commonNumber.floatValue()) * 100;
newRowCondition = tableCondition.replaceAll("%construction_type%", constructionType.toString());
StringBuilder newRowConditionBuilder = new StringBuilder(newRowCondition);
//filling inner table
String tableConditionInner = ReportUtil.extractBookmarkForTableInTable(newRowConditionBuilder, "private_condition_table", "%rowsConditionInner%");
newRowCondition = newRowConditionBuilder.toString();
String resultConditionInner = "";
String newRowConditionInner = "";
if (aPercent > 0) {
newRowConditionInner = tableConditionInner.replaceAll("%condition_danger%", "Неработоспособное состояние");
newRowConditionInner = newRowConditionInner.replaceAll("%condition_number%", aNumber + "/" + aPercent + "%");
resultConditionInner += newRowConditionInner;
}
if (bPercent > 0) {
newRowConditionInner = tableConditionInner.replaceAll("%condition_danger%", "Ограниченно работоспособное состояние");
newRowConditionInner = newRowConditionInner.replaceAll("%condition_number%", bNumber + "/" + bPercent + "%");
resultConditionInner += newRowConditionInner;
}
if (cPercent > 0) {
newRowConditionInner = tableConditionInner.replaceAll("%condition_danger%", "Работоспособное состояние");
newRowConditionInner = newRowConditionInner.replaceAll("%condition_number%", cNumber + "/" + cPercent + "%");
resultConditionInner += newRowConditionInner;
}
newRowConditionBuilder = new StringBuilder(newRowCondition);
ReportUtil.replaceAllLabel(newRowConditionBuilder, "%rowsConditionInner%", resultConditionInner);
newRowCondition = newRowConditionBuilder.toString();
resultCondition += newRowCondition;
newDefectBlockBuilder = new StringBuilder(newDefectBlock);
ReportUtil.replaceAllLabel(newDefectBlockBuilder, "%rowsCondition%", resultCondition);
ReportUtil.replaceAllLabel(newDefectBlockBuilder, "%cond_construction_type%", constructionType.toString());
newDefectBlock = newDefectBlockBuilder.toString();
resultConstructionDefectBlock += newDefectBlock;
}
ReportUtil.replaceAllLabel(template, "%defectBlocks%", resultConstructionDefectBlock);
// //adding recomendations
String tableRecomendation = ReportUtil.extractBookmark(template, "recomendation_table", "%rowsRecomendation%");
String resultRecomendation = "";
String newRowRecomendation = "";
for (int l = 0; l < objectConstructionTypes.size(); l++) {
ConstructionType constructionType = (ConstructionType) objectConstructionTypes.get(l);
//getting recomendations
List defectRecomendationList = defectRecomendationManager.getRecomendationsForConstructionType(constructionType.getConstructionTypeId().toString(), buildingObjectId);
String recomendationText = "";
if (defectRecomendationList.size() != 0) {
recomendationText += constructionType.toString() + "<br>";
for (int i = 0; i < defectRecomendationList.size(); i++) {
DefectRecomendation defectRecomendation = (DefectRecomendation) defectRecomendationList.get(i);
recomendationText += "- " + defectRecomendation.getContent() + "<br/>";
}
newRowRecomendation = tableRecomendation.replaceAll("%recomendation_body%", recomendationText);
// ReportUtil.replaceAllLabel(template, "%recomendation_body%", recomendationText);
resultRecomendation += newRowRecomendation.replaceAll("%recomendation_construction_type%", constructionType.toString());
}
}
ReportUtil.replaceAllLabel(template, "%rowsRecomendation%", resultRecomendation);
if (defectPhotoList.size() > 0) {
ReportUtil.extractBookmarkForImageList(template, "defect_illustration", "%illustrations%");
String resultPhoto = "";
String newRowPhoto = "";
for (int i = 0; i < defectPhotoList.size(); i++) {
DefectPhoto defectPhoto = (DefectPhoto) defectPhotoList.get(i);
File filePhoto = new File(defectPhoto.getWayToPhoto());
if (filePhoto.exists()) {
filePhoto.delete();
}
filePhoto.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(defectPhoto.getWayToPhoto());
Blob blob = defectPhoto.getPhotoBlob();
byte[] bufer = new byte[62000];
InputStream inputStream = blob.getBinaryStream();
while (inputStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
inputStream.close();
fileOutputStream.close();
Image image = Image.getInstance(defectPhoto.getWayToPhoto());
newRowPhoto = ReportUtil.createPhoto("defect_illustration", image.height(), image.width(), defectPhoto.getWayToPhoto());
newRowPhoto += "\n<p class=3DMsoNormal align=3Dcenter style=3D'text-align:center'>" + (defectPhoto.getPhotoRefference() + ". " + defectPhoto.getExtraComment()) + "</p>\n";
ReportUtil.insertImage(defectPhoto.getWayToPhoto(), defectPhoto.getPhotoBlob().getBytes(1, (int) defectPhoto.getPhotoBlob().length()), template);
resultPhoto += newRowPhoto;
}
ReportUtil.replaceAllLabel(template, "%illustrations%", resultPhoto);
} else {