Search in sources :

Example 11 with Archetype

use of com.nedap.archie.aom.Archetype in project archetype-languageserver by nedap.

the class ADL14ConvertingStorage method convert.

public void convert(String documentUri) {
    ADL14Converter adl14Converter = new ADL14Converter(BuiltinReferenceModels.getMetaModels(), configuration);
    adl14Converter.setExistingRepository(repository);
    Archetype archetype = adl14Files.get(documentUri);
    // find all parent archetypes that must also be converted for this to properly work
    List<Archetype> toConvert = getAllToConvertIncludingParents(archetype);
    ADL2ConversionResultList converted = adl14Converter.convert(toConvert);
    for (ADL2ConversionResult result : converted.getConversionResults()) {
        if (result.getException() != null) {
            textService.pushDiagnostics(new TextDocumentIdentifier(documentUri), result.getException());
        } else {
            String newPath = documentUri.substring(0, documentUri.lastIndexOf("/")) + "/adl2/" + result.getArchetypeId() + ".adls";
            textService.writeFile(newPath, "ADL2 conversion of " + result.getArchetypeId(), ADLArchetypeSerializer.serialize(result.getArchetype()));
        }
    }
}
Also used : ADL14Converter(com.nedap.archie.adl14.ADL14Converter) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) Archetype(com.nedap.archie.aom.Archetype) ADL2ConversionResultList(com.nedap.archie.adl14.ADL2ConversionResultList) ADL2ConversionResult(com.nedap.archie.adl14.ADL2ConversionResult)

Example 12 with Archetype

use of com.nedap.archie.aom.Archetype in project archetype-languageserver by nedap.

the class BroadcastingArchetypeRepository method extractADL14Info.

private void extractADL14Info(TextDocumentItem textDocumentItem) {
    adl14Storage.addFile(textDocumentItem);
    // make sure any ADL 2 things get removed here!
    ADL14SymbolExtractor adlSymbolExtractor = new ADL14SymbolExtractor();
    try {
        DocumentInformation documentInformation = adlSymbolExtractor.extractSymbols(textDocumentItem.getUri(), textDocumentItem.getText());
        symbolsByUri.put(textDocumentItem.getUri(), documentInformation);
        if (documentInformation.getArchetypeId() != null) {
            documentsByArchetypeId.put(documentInformation.getArchetypeId(), textDocumentItem);
        }
        resolveDocumentLinks();
        Archetype archetype = adl14Storage.getArchetype(new TextDocumentIdentifier(textDocumentItem.getUri()));
        if (archetype != null) {
            String language = archetype.getOriginalLanguage() != null ? archetype.getOriginalLanguage().getCodeString() : null;
            if (language == null) {
                language = "en";
            }
            SymbolNameFromTerminologyHelper.giveNames(documentInformation.getSymbols(), archetype, language);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return;
}
Also used : ADL14SymbolExtractor(com.nedap.openehr.lsp.symbolextractor.adl14.ADL14SymbolExtractor) Archetype(com.nedap.archie.aom.Archetype) DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) IOException(java.io.IOException)

Example 13 with Archetype

use of com.nedap.archie.aom.Archetype in project archetype-languageserver by nedap.

the class BroadcastingArchetypeRepository method extractADL2Info.

private void extractADL2Info(TextDocumentItem textDocumentItem) {
    try {
        ADL2SymbolExtractor adl2SymbolExtractor = new ADL2SymbolExtractor();
        DocumentInformation documentInformation = adl2SymbolExtractor.extractSymbols(textDocumentItem.getUri(), textDocumentItem.getText());
        symbolsByUri.put(textDocumentItem.getUri(), documentInformation);
        if (documentInformation.getArchetypeId() != null) {
            documentsByArchetypeId.put(documentInformation.getArchetypeId(), textDocumentItem);
        }
        if (documentInformation.getErrors().hasNoErrors()) {
            ADLParser adlParser = new ADLParser(BuiltinReferenceModels.getMetaModels());
            // no console output please :)
            adlParser.setLogEnabled(false);
            Archetype archetype = null;
            try {
                archetype = adlParser.parse(textDocumentItem.getText());
                addArchetype(archetype);
                // perform incremental compilation here
                invalidateAndRecompileArchetypes(archetype);
                ValidationResult result = getValidationResult(archetype.getArchetypeId().toString());
                Archetype archetypeForTerms = archetype;
                if (result != null && result.getFlattened() != null) {
                    archetypeForTerms = result.getFlattened();
                }
                String language = archetype.getOriginalLanguage() != null ? archetype.getOriginalLanguage().getCodeString() : null;
                if (language == null) {
                    language = "en";
                }
                documentInformation.setHoverInfo(new ArchetypeHoverInfo(documentInformation, archetype, archetypeForTerms, language));
                SymbolNameFromTerminologyHelper.giveNames(documentInformation.getSymbols(), archetypeForTerms, language);
            // diagnostics will now be pushed from within the invalidateArchetypesAndRecompile method
            } catch (ADLParseException e) {
                // this should have been checked in the previous step. But still, it could happen.
                textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), e.getErrors());
            } catch (Exception ex) {
                // this particular exce[tion is a parse error, usually when extracting JSON. be sure to post taht
                textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), ex);
            }
        } else {
            textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), documentInformation.getErrors());
        }
    } catch (IOException e) {
        // shouldn't happen, ever, just in memory processing
        throw new RuntimeException(e);
    }
}
Also used : ADLParser(com.nedap.archie.adlparser.ADLParser) ADL2SymbolExtractor(com.nedap.openehr.lsp.symbolextractor.ADL2SymbolExtractor) Archetype(com.nedap.archie.aom.Archetype) DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) IOException(java.io.IOException) ValidationResult(com.nedap.archie.archetypevalidator.ValidationResult) ArchetypeHoverInfo(com.nedap.openehr.lsp.document.ArchetypeHoverInfo) ADLParseException(com.nedap.archie.adlparser.ADLParseException) IOException(java.io.IOException) ADLParseException(com.nedap.archie.adlparser.ADLParseException)

Aggregations

Archetype (com.nedap.archie.aom.Archetype)13 ValidationResult (com.nedap.archie.archetypevalidator.ValidationResult)5 DocumentInformation (com.nedap.openehr.lsp.document.DocumentInformation)4 ArchetypeModelObject (com.nedap.archie.aom.ArchetypeModelObject)3 CAttribute (com.nedap.archie.aom.CAttribute)3 CObject (com.nedap.archie.aom.CObject)3 ArrayList (java.util.ArrayList)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 ADLParseException (com.nedap.archie.adlparser.ADLParseException)2 OperationalTemplate (com.nedap.archie.aom.OperationalTemplate)2 Flattener (com.nedap.archie.flattener.Flattener)2 PathSegment (com.nedap.archie.paths.PathSegment)2 MetaModels (com.nedap.archie.rminfo.MetaModels)2 AQLRuntimeException (com.nedap.healthcare.aqlparser.exception.AQLRuntimeException)2 AQLUnsupportedFeatureException (com.nedap.healthcare.aqlparser.exception.AQLUnsupportedFeatureException)2 AQLValidationException (com.nedap.healthcare.aqlparser.exception.AQLValidationException)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 JAXBException (javax.xml.bind.JAXBException)2