Changes to support better data extraction from answers when generating OpenXML document

This commit is contained in:
Ioannis Kalyvas 2018-10-19 12:59:54 +03:00
parent b7193d2dda
commit 2c2133bb28
6 changed files with 108 additions and 54 deletions

View File

@ -1,9 +1,13 @@
package eu.eudat.logic.utilities.documents.word;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
import eu.eudat.logic.utilities.documents.types.TextStyle;
import eu.eudat.logic.utilities.interfaces.ApplierWithValue;
import eu.eudat.models.data.components.commons.datafield.CheckBoxData;
import eu.eudat.models.data.components.commons.datafield.ComboBoxData;
import eu.eudat.models.data.user.components.datasetprofile.Field;
import eu.eudat.models.data.user.components.datasetprofile.FieldSet;
import eu.eudat.models.data.user.components.datasetprofile.Section;
@ -139,9 +143,13 @@ public class WordBuilder {
fields.forEach(field -> {
if (visibilityRuleService.isElementVisible(field.getId())) {
if (!createListing) {
XWPFParagraph paragraph = addParagraphContent(field.getValue() == null ? "" : field.getValue(), mainDocumentPart, ParagraphStyle.TEXT, numId);
try {
XWPFParagraph paragraph = addParagraphContent(this.formatter(field), mainDocumentPart, ParagraphStyle.TEXT, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
@ -180,4 +188,38 @@ public class WordBuilder {
}
}
public String formatter(Field field) throws IOException {
switch (field.getViewStyle().getRenderStyle()) {
case "combobox": {
String comboboxType = ((ComboBoxData) field.getData()).getType();
if (comboboxType.equals("autocomplete")) {
ObjectMapper mapper = new ObjectMapper();
if (field.getValue() == null) return null;
Map<String, String> map = mapper.readValue(field.getValue(), new TypeReference<Map<String, String>>() {
});
return map.get("label");
} else if (comboboxType.equals("wordlist")) {
ObjectMapper mapper = new ObjectMapper();
if (field.getValue() == null) return null;
Map<String, String> map = mapper.readValue(field.getValue(), new TypeReference<Map<String, String>>() {
});
return map.get("label");
}
}
case "booleanDecision":
if (field.getValue() != null && field.getValue().equals("true")) return "Yes";
else return "No";
case "radiobox":
return field.getValue();
case "checkBox":
CheckBoxData data = (CheckBoxData) field.getData();
return data.getLabel();
case "freetext":
return field.getValue();
case "textarea":
return field.getValue();
}
return null;
}
}

View File

@ -1,7 +1,7 @@
<div [formGroup]="form">
<mat-form-field>
<mat-select formControlName="value" [required]="field.validationRequired">
<mat-option *ngFor="let opt of field.data.options" [value]="opt.value">{{opt.label}}</mat-option>
<mat-option *ngFor="let opt of field.data.options" [value]="assign(opt)">{{opt.label}}</mat-option>
</mat-select>
<mat-error *ngIf="form.get('value').errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>

View File

@ -17,4 +17,13 @@ export class DynamicFieldDropdownComponent implements OnInit {
ngOnInit() {
}
assign(item: any) {
if (!item) { return null; }
return this.transform(item);
}
transform(item: any) {
if (typeof item === 'string') { return JSON.parse(item); } else { return JSON.stringify(item); }
}
}

View File

@ -12,7 +12,8 @@
<div *ngSwitchCase="'freetext'">
<mat-form-field>
<input matInput formControlName="value" placeholder="{{field.data.label}}" [required]="field.validationRequired">
<mat-error *ngIf="form.get('value')['errors'] && form.get('value')['errors']['required']">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="form.get('value')['errors'] && form.get('value')['errors']['required']">{{'GENERAL.VALIDATION.REQUIRED'
| translate}}</mat-error>
</mat-form-field>
</div>
@ -24,7 +25,6 @@
<div *ngIf="this.field.data.type === 'wordlist'">
<app-df-dropdown [form]="form" [field]="field"></app-df-dropdown>
</div>
</div>
<div *ngSwitchCase="'checkBox'" class="checkbox">
@ -33,12 +33,16 @@
<div *ngSwitchCase="'textarea'">
<mat-form-field>
<textarea matInput formControlName="value" matTextareaAutosize matAutosizeMinRows="2" matAutosizeMaxRows="10" [required]="field.validationRequired">
<textarea matInput formControlName="value" matTextareaAutosize matAutosizeMinRows="2" matAutosizeMaxRows="10"
[required]="field.validationRequired">
</textarea>
<button mat-button *ngIf="!form.get('value').disabled && form.get('value').value" matSuffix mat-icon-button aria-label="Clear" (click)="this.form.patchValue({'value': ''})">
<button mat-button *ngIf="!form.get('value').disabled && form.get('value').value" matSuffix mat-icon-button
aria-label="Clear" (click)="this.form.patchValue({'value': ''})">
<mat-icon>close</mat-icon>
</button>
<mat-error *ngIf="form.get('value')['errors'] && form.get('value')['errors']['required']">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="form.get('value')['errors'] && form.get('value')['errors']['required']">{{'GENERAL.VALIDATION.REQUIRED'
| translate}}</mat-error>
</mat-form-field>
</div>