xslt mapping ui
This commit is contained in:
parent
bd302ab707
commit
ab234a5d32
|
@ -1,6 +1,8 @@
|
|||
package eu.dnetlib.wfs.manager.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -13,7 +15,9 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import eu.dnetlib.common.controller.DnetRestController;
|
||||
import eu.dnetlib.common.mapping.RecordTransformer;
|
||||
import eu.dnetlib.common.mapping.cleaner.CleanerFactory;
|
||||
import eu.dnetlib.common.mapping.xslt.XsltTransformFactory;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
|
@ -24,12 +28,27 @@ public class MappingAjaxController extends DnetRestController {
|
|||
@Autowired
|
||||
private CleanerFactory cleanerFactory;
|
||||
|
||||
@Autowired
|
||||
private XsltTransformFactory xsltFactory;
|
||||
|
||||
@PostMapping(value = "/clean", consumes = {
|
||||
MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE,
|
||||
}, produces = MediaType.APPLICATION_XML_VALUE)
|
||||
public void importResource(@RequestParam final String rule, final HttpServletRequest req, final HttpServletResponse res) throws Exception {
|
||||
public void clean(@RequestParam final String rule, final HttpServletRequest req, final HttpServletResponse res) throws Exception {
|
||||
transform(req, res, this.cleanerFactory.newCleaner(rule));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/xsltTransform", consumes = { MediaType.TEXT_PLAIN_VALUE,
|
||||
MediaType.APPLICATION_XML_VALUE, }, produces = MediaType.APPLICATION_XML_VALUE)
|
||||
public void xsltTransform(@RequestParam final String rule, final HttpServletRequest req, final HttpServletResponse res) throws Exception {
|
||||
transform(req, res, this.xsltFactory.getTransformer(rule, new HashMap<>()));
|
||||
}
|
||||
|
||||
private void transform(final HttpServletRequest req, final HttpServletResponse res, final RecordTransformer<String, String> transformer)
|
||||
throws IOException {
|
||||
|
||||
final String xmlIn = IOUtils.toString(req.getInputStream(), StandardCharsets.UTF_8);
|
||||
final String xmlOut = cleanerFactory.newCleaner(rule).transform(xmlIn);
|
||||
final String xmlOut = transformer.transform(xmlIn);
|
||||
|
||||
res.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
|
||||
|
@ -41,4 +60,5 @@ public class MappingAjaxController extends DnetRestController {
|
|||
res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Invalid record");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,18 +8,17 @@
|
|||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 50%;">
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
|
||||
<mat-label>Input Record</mat-label>
|
||||
<textarea matInput rows="10" formControlName="xmlIn"></textarea>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 50%;">
|
||||
<mat-label>Output Record</mat-label>
|
||||
<textarea matInput rows="10" formControlName="xmlOut" readonly></textarea>
|
||||
</mat-form-field>
|
||||
|
||||
<button mat-stroked-button color="primary" type="submit" [disabled]="!cleanForm.valid">Submit</button>
|
||||
|
||||
<mat-error *ngIf="cleanForm.errors?.['serverError']">
|
||||
{{ cleanForm.errors?.['serverError'] }}
|
||||
<pre>{{ cleanForm.errors?.['serverError'] }}</pre>
|
||||
</mat-error>
|
||||
|
||||
<pre *ngIf="xmlOutput">{{xmlOutput}}</pre>
|
||||
|
||||
</form>
|
||||
|
|
|
@ -18,8 +18,7 @@ export class CleanerTesterComponent {
|
|||
|
||||
cleanForm = new FormGroup({
|
||||
xmlIn: new FormControl('', [Validators.required]),
|
||||
rule: new FormControl('', [Validators.required]),
|
||||
xmlOut: new FormControl('')
|
||||
rule: new FormControl('', [Validators.required])
|
||||
});
|
||||
|
||||
constructor(public client: CleanerTesterClient, public route: ActivatedRoute, public dialog: MatDialog) {
|
||||
|
@ -27,7 +26,7 @@ export class CleanerTesterComponent {
|
|||
}
|
||||
|
||||
clean() {
|
||||
this.client.testCleaning(this.cleanForm.get("rule")?.value!, this.cleanForm.get("xmlIn")?.value!, (data: string) => this.cleanForm.get("xmlOut")?.setValue(data), this.cleanForm);
|
||||
this.client.testCleaning(this.cleanForm.get("rule")?.value!, this.cleanForm.get("xmlIn")?.value!, (data: string) => this.xmlOutput = data, this.cleanForm);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,7 +42,7 @@ export class CleanerTesterClient extends ISClient {
|
|||
|
||||
testCleaning(rule: string, xml: string, onSuccess: Function, relatedForm?: FormGroup): void {
|
||||
var headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
|
||||
this.httpPostWithOptions('/proxy/byType/mapping/clean?rule=' + encodeURIComponent(rule), xml, { headers, responseType: 'text' as 'json' }, onSuccess, relatedForm);
|
||||
this.httpPostWithOptions('/proxy/byType/wf_manager/api/mapping/clean?rule=' + encodeURIComponent(rule), xml, { headers, responseType: 'text' as 'json' }, onSuccess, relatedForm, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,18 +38,19 @@ export class ISClient {
|
|||
});
|
||||
}
|
||||
|
||||
protected httpPostWithOptions(url: string, body: any, options: any, onSuccess: Function, relatedForm?: FormGroup) {
|
||||
protected httpPostWithOptions(url: string, body: any, options: any, onSuccess: Function, relatedForm?: FormGroup, showStrackTrace?: boolean) {
|
||||
this.client.post<void>(url, body, options).subscribe({
|
||||
next: data => onSuccess(data),
|
||||
error: error => this.showError(error, relatedForm)
|
||||
error: error => this.showError(error, relatedForm, showStrackTrace)
|
||||
});
|
||||
}
|
||||
|
||||
protected showError(error: any, form?: FormGroup) {
|
||||
protected showError(error: any, form?: FormGroup, showStrackTrace?: boolean) {
|
||||
|
||||
console.log(error);
|
||||
|
||||
const msg = this.errorMessage(error);
|
||||
const msg = this.errorMessage(error, showStrackTrace);
|
||||
|
||||
if (form) {
|
||||
form.setErrors({ serverError: msg })
|
||||
} else if (this.snackBar) {
|
||||
|
@ -61,9 +62,11 @@ export class ISClient {
|
|||
}
|
||||
}
|
||||
|
||||
protected errorMessage(error: any) {
|
||||
if (error.error && error.error.message) {
|
||||
return error.error.message;
|
||||
protected errorMessage(error: any, showStrackTrace?: boolean) {
|
||||
if (showStrackTrace && error.error) {
|
||||
return error.error.stacktrace ? error.error.stacktrace : JSON.parse(error.error).stacktrace;
|
||||
} else if (error.error) {
|
||||
return error.error.message ? error.error.message : JSON.parse(error.error).message;
|
||||
} else if (error.message) {
|
||||
return error.message;
|
||||
} else {
|
||||
|
|
|
@ -8,18 +8,17 @@
|
|||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 50%;">
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
|
||||
<mat-label>Input Record</mat-label>
|
||||
<textarea matInput rows="10" formControlName="xmlIn"></textarea>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="fill" floatLabel="always" style="width: 50%;">
|
||||
<mat-label>Output Record</mat-label>
|
||||
<textarea matInput rows="10" formControlName="xmlOut" readonly></textarea>
|
||||
</mat-form-field>
|
||||
|
||||
<button mat-stroked-button color="primary" type="submit" [disabled]="!xsltForm.valid">Submit</button>
|
||||
|
||||
<mat-error *ngIf="xsltForm.errors?.['serverError']">
|
||||
{{ xsltForm.errors?.['serverError'] }}
|
||||
<pre>{{ xsltForm.errors?.['serverError'] }}</pre>
|
||||
</mat-error>
|
||||
|
||||
<pre *ngIf="xmlOutput">{{xmlOutput}}</pre>
|
||||
|
||||
</form>
|
||||
|
|
|
@ -18,8 +18,7 @@ export class XsltTesterComponent {
|
|||
|
||||
xsltForm = new FormGroup({
|
||||
xmlIn: new FormControl('', [Validators.required]),
|
||||
rule: new FormControl('', [Validators.required]),
|
||||
xmlOut: new FormControl('')
|
||||
rule: new FormControl('', [Validators.required])
|
||||
});
|
||||
|
||||
constructor(public client: XsltTesterClient, public route: ActivatedRoute, public dialog: MatDialog) {
|
||||
|
@ -27,7 +26,8 @@ export class XsltTesterComponent {
|
|||
}
|
||||
|
||||
transformXslt() {
|
||||
this.client.transformXslt(this.xsltForm.get("rule")?.value!, this.xsltForm.get("xmlIn")?.value!, (data: string) => this.xsltForm.get("xmlOut")?.setValue(data), this.xsltForm);
|
||||
this.xmlOutput = '';
|
||||
this.client.transformXslt(this.xsltForm.get("rule")?.value!, this.xsltForm.get("xmlIn")?.value!, (data: string) => this.xmlOutput = data, this.xsltForm);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ export class XsltTesterClient extends ISClient {
|
|||
|
||||
transformXslt(rule: string, xml: string, onSuccess: Function, relatedForm?: FormGroup): void {
|
||||
var headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
|
||||
this.httpPostWithOptions('/proxy/byType/mapping/transformXslt?rule=' + encodeURIComponent(rule), xml, { headers, responseType: 'text' as 'json' }, onSuccess, relatedForm);
|
||||
this.httpPostWithOptions('/proxy/byType/wf_manager/api/mapping/xsltTransform?rule=' + encodeURIComponent(rule), xml, { headers, responseType: 'text' as 'json' }, onSuccess, relatedForm, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue