Update "validation-panel-table" with custom values

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
Isabelle
Posts: 168
Joined: Fri Jan 20, 2017 1:11 pm

Update "validation-panel-table" with custom values

Post by Isabelle »

Hello,

We use oxygen 27 and we want to add customs elements in the validation panel (validation-panel-table).

We have our own validation rules (functional rules) and we want to add errors to your existing validation panel.

In our sdk application, we have extended ValidationProblemsFilter api and it works fine.
We have override filterValidationProblems method and add our class in WSEditor like this
wsEditor.addValidationProblemsFilter(validationProblemsFilter);

I have found the WebappDocumentValidator api, and I retrieve correctly the existing xsd errors with documentValidator.getValidationTask().call();

But how can I add our functional errors into your validator ?

Thanks
Regards,
Isabelle
cosminef
Site Admin
Posts: 215
Joined: Wed Aug 30, 2023 2:33 pm

Re: Update "validation-panel-table" with custom values

Post by cosminef »

Hello,

You can use the method: ro.sync.exml.workspace.api.editor.validation.ValidationProblems.addValidationProblems(ValidationProblems) [1] to add validation problems.
Another way to add validation problems is to use a Schematron schema into your framework [2].

If none of these proposals suit you, please provide us with more details about what you want to achieve/use case.

[1] https://www.oxygenxml.com/InstData/Edit ... nProblems)
[2] https://www.oxygenxml.com/doc/versions/ ... chema.html
Cosmin Eftenie
www.oxygenxml.com
Isabelle
Posts: 168
Joined: Fri Jan 20, 2017 1:11 pm

Re: Update "validation-panel-table" with custom values

Post by Isabelle »

Hello Cosmin,

Thank you for your reply.
Can you show me an example of ValidationProblems use ?
How can I retrieve this element ? From WSEditor ?
Thanks.

Regards,
Isabelle
cosminef
Site Admin
Posts: 215
Joined: Wed Aug 30, 2023 2:33 pm

Re: Update "validation-panel-table" with custom values

Post by cosminef »

Hello,

We have a sample plugin [1] in this regard.
In sample code [2], a filter is demonstrated that removes all validation problems with a SEVERITY_WARN level from the list.

To add a validation error with SEVERITY_ERROR level, you can use something like this:

Code: Select all

DocumentPositionedInfo newProblem = new DocumentPositionedInfo(DocumentPositionedInfo.SEVERITY_ERROR, "This is a custom error");
problemsList.add(newProblem);
and to see the custom error, you need to test it on an invalid document with validation errors; if the document is valid, the errors will not appear.

Best,
Cosmin

[1] https://github.com/oxygenxml/web-author ... ems-filter
[2] https://github.com/oxygenxml/web-author ... ilter.java
Cosmin Eftenie
www.oxygenxml.com
Isabelle
Posts: 168
Joined: Fri Jan 20, 2017 1:11 pm

Re: Update "validation-panel-table" with custom values

Post by Isabelle »

Hello,

I still have issue with your solution.
To do our own validation, we need the AuthorDocumentModel.
To implement your solution I have done this :

Code: Select all

public class CustomWorkspaceAccessPluginExtension implements WorkspaceAccessPluginExtension {

    @Override
    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
        WebappPluginWorkspace workspace = (WebappPluginWorkspace) pluginWorkspaceAccess;
        EditorChangeListener.init(pluginWorkspaceAccess);

        workspace.addEditingSessionLifecycleListener(new WebappEditingSessionLifecycleListener() {

            @Override
            public void editingSessionStarted(String sessionId, AuthorDocumentModel documentModel) {
                EditorChangeListener.getInstance().openingDocument(documentModel);                
            }
        });

        workspace.addEditorChangeListener(EditorChangeListener.getInstance(), PluginWorkspace.MAIN_EDITING_AREA);
    }
}

Code: Select all

public class EditorChangeListener extends WSEditorChangeListener {

    private static EditorChangeListener instance;

    private final StandalonePluginWorkspace workspace;
    private AuthorDocumentModel authorDocumentModel;
    private Validation validation;

    private EditorChangeListener(StandalonePluginWorkspace workspace) {
        this.workspace = workspace;
    }

    public static void init(StandalonePluginWorkspace workspace) {
        instance = new EditorChangeListener(workspace);
    }

    public static EditorChangeListener getInstance() {
        return instance;
    }

    public void openingDocument(AuthorDocumentModel document) {
        authorDocumentModel = document;
    }

    @Override
    public void editorOpened(URL url) {
        super.editorOpened(url);

        validation = new Validation(authorDocumentModel);

        final WSEditor editorAccess = workspace.getCurrentEditorAccess(PluginWorkspace.MAIN_EDITING_AREA);
        if (editorAccess != null) {
            editorAccess.addValidationProblemsFilter(brexValidation);
        }
    }

    public BrexValidation getBrexValidation() {
        return brexValidation;
    }

    public StandalonePluginWorkspace getWorkspace() {
        return workspace;
    }
}

Code: Select all

public final class Validation extends ValidationProblemsFilter {
   
        private final AuthorDocumentModel authorDocumentModel;
	private List<DocumentPositionedInfo> lastBusinessRulesErrorList = null;

    public Validation(AuthorDocumentModel authorDocumentModel) {
        this.authorDocumentModel = authorDocumentModel;        
    }

    @Override
    public void filterValidationProblems(ValidationProblems validationProblems) {
        super.filterValidationProblems(validationProblems);
        
        List<DocumentPositionedInfo> documentPositionedInfoList = validationProblems.getProblemsList();
        if (documentPositionedInfoList == null) {
            documentPositionedInfoList = new ArrayList<>();
        }

        lastBusinessRulesErrorList = getBusinessRulesErrorList();
        documentPositionedInfoList.addAll(lastBusinessRulesErrorList);

        validationProblems.setProblemsList(documentPositionedInfoList);
    }

    public Map<String, Integer> validateEntireDocument() {
        lastBusinessRulesErrorList = getBusinessRulesErrorList();

        WSEditor wsEditorAccess = EditorChangeListener.getInstance().getWorkspace().getCurrentEditorAccess(PluginWorkspace.MAIN_EDITING_AREA);
        wsEditorAccess.checkValid();

        return new HashMap<>();
    }

    private List<DocumentPositionedInfo> getBusinessRulesErrorList() {
        List<DocumentPositionedInfo> businessRulesErrorList = new ArrayList<>();
        // launch business rule validation based on authorDocumentModel information.
        
        return businessRulesErrorList;
    }
}
When we call validation from toolbar, we use this

Code: Select all

@WebappCompatible
@WebappRestSafe
public class ValidationOperation extends AuthorOperationWithResult {

    @Override
    public String doOperation(AuthorDocumentModel authorDocumentModel, ArgumentsMap argumentsMap) throws IllegalArgumentException, AuthorOperationException {
        try {
            final BrexValidation validation = EditorChangeListener.getInstance().getBrexValidation();
           validation.validateEntireDocument();
            return "validation_ok";
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
And I get an error because wsEditorAccess.checkValid(); is not available for web app.
How can I launch a document validation in JAVA ?
Thanks,

Regards,
Isabelle
mihaela
Posts: 512
Joined: Wed May 20, 2009 2:40 pm

Re: Update "validation-panel-table" with custom values

Post by mihaela »

Hello,

When the automatic validation is performed in Web Author, the filterValidationProblems method is called. Here is how you should implement this method so that your problems appear in the in the Validation view, on each automatic validation:

Code: Select all

@Override
    public void filterValidationProblems(ValidationProblems validationProblems) {
           validationProblems.addValidationProblems(new ValidationProblems(getBusinessRulesErrorList(), ValidationProblems.VALIDATION_AUTOMATIC));
    }


Since your errors will be collected and rendered at each automatic validation, I think there is no need to add your own operation on the toolbar to trigger the validation. If I am wrong, please give us more details about your use case.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Isabelle
Posts: 168
Joined: Fri Jan 20, 2017 1:11 pm

Re: Update "validation-panel-table" with custom values

Post by Isabelle »

Hello,

We have to show a report validation in a modal.
Adding our own errors in your validation panel is only a part of our need.

That is why we need to add our own operation on the toolbar to trigger the validation.

Regards,
Isabelle
mihaela
Posts: 512
Joined: Wed May 20, 2009 2:40 pm

Re: Update "validation-panel-table" with custom values

Post by mihaela »

Hello,
Your operation should use the following code to obtain all the validation errors:

Code: Select all

AuthorDocumentModel authorDocumentModel = docModel.getAuthorDocumentModel();
WebappDocumentValidator documentValidator = authorDocumentModel.getDocumentValidator();
Callable<List<DocumentPositionedInfo>> validationTask = documentValidator.getValidationTask();
List<DocumentPositionedInfo> dpis = validationTask.call();
Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Isabelle
Posts: 168
Joined: Fri Jan 20, 2017 1:11 pm

Re: Update "validation-panel-table" with custom values

Post by Isabelle »

Hello,

I can add our functional errors in your validationProblems.
But regarding validation-panel-table panel, it is not refreshed.

Here is my use case :
  • I click on my toolbar button to launch the validation manualy
  • Our code uses the method documentValidator.getValidationTask().call(); to launch filterValidationProblems(ValidationProblems validationProblems)
  • In method filterValidationProblems(ValidationProblems validationProblems) we add our own functional errors to validationProblems [validationProblems.addValidationProblems(new ValidationProblems(lastBusinessRulesErrorList, ValidationProblems.VALIDATION_AUTOMATIC));]
  • Our modal is well display with all the required informaions
But the validation-panel-table panel does not refresh and I don't see our functional errors.
I have to update the document (the value of an attribute for exemple) and then the panel is well refreshed with all errors.

Is it possible to force the refresh of the validation-panel-table panel ?
Thanks,

Regrads,
Isabelle
mihaela
Posts: 512
Joined: Wed May 20, 2009 2:40 pm

Re: Update "validation-panel-table" with custom values

Post by mihaela »

Hello,

I understand that you want to trigger an automatic validation when your toolbar action is invoked, so that the Validation View to present the newly added custom validation problems.
There is no API to trigger an automatic validation, this happens only when the document is changed.

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
mihaela
Posts: 512
Joined: Wed May 20, 2009 2:40 pm

Re: Update "validation-panel-table" with custom values

Post by mihaela »

Hello,

Here is another idea: you can implement your own view that lists all the custom validation problems.
In this way you do not depend on the automatic validation.

Here is a a sample side-view implementation:
https://github.com/oxygenxml/web-author ... ments-view

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply