Search in sources :

Example 1 with CategoryType

use of io.fixprotocol._2020.orchestra.repository.CategoryType in project fix-orchestra by FIXTradingCommunity.

the class DocGenerator method generate.

/**
 * Generates documentation
 *
 * @throws Exception if input cannot be read or output cannot be written to a file
 */
public void generate() throws Exception {
    this.repository = unmarshal(inputStream);
    // Implementation note: consideration was given to supporting "jar:file:" scheme, but the
    // supporting FileSystem is not guaranteed to be installed.
    pathManager = getPathManager(outputRootDir);
    final Path baseOutputPath = pathManager.makeRootPath(outputRootDir);
    createCss(baseOutputPath);
    generateMain(baseOutputPath, getTitle());
    generateMetadata(baseOutputPath, repository, repository.getMetadata().getAny());
    final Path datatypesOutputPath = pathManager.makeDirectory(baseOutputPath.resolve("datatypes"));
    generateDatatypeList(datatypesOutputPath, repository.getDatatypes().getDatatype());
    repository.getDatatypes().getDatatype().forEach(d -> {
        try {
            generateDatatype(datatypesOutputPath, d);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    final Path fieldsOutputPath = pathManager.makeDirectory(baseOutputPath.resolve("fields"));
    final List<FieldType> sortedFieldList = repository.getFields().getField().stream().sorted(Comparator.comparing(FieldType::getName)).collect(Collectors.toList());
    generateFieldsList(fieldsOutputPath, sortedFieldList);
    repository.getFields().getField().forEach(f -> {
        try {
            generateFieldDetail(fieldsOutputPath, f);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    final List<CodeSetType> allCodeSets = repository.getCodeSets().getCodeSet();
    generateCodeSetList(datatypesOutputPath, allCodeSets.stream().sorted(Comparator.comparing(CodeSetType::getName)).collect(Collectors.toList()));
    repository.getCodeSets().getCodeSet().forEach(cs -> {
        try {
            generateCodeSetDetail(datatypesOutputPath, cs);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    final Path messagesDocPath = pathManager.makeDirectory(baseOutputPath.resolve("messages"));
    final Path messagesImgPath = pathManager.makeDirectory(messagesDocPath.resolve("img"));
    final Optional<Categories> optCategories = Optional.ofNullable(repository.getCategories());
    final List<CategoryType> sortedCategoryList = optCategories.orElse(new Categories()).getCategory().stream().filter(c -> c.getComponentType() == CatComponentTypeT.MESSAGE).sorted((o1, o2) -> {
        final String sectionValue1 = o1.getSection() != null ? o1.getSection() : "";
        final String sectionValue2 = o2.getSection() != null ? o2.getSection() : "";
        int retv = sectionValue1.compareTo(sectionValue2);
        if (retv == 0) {
            retv = o1.getName().compareTo(o2.getName());
        }
        return retv;
    }).collect(Collectors.toList());
    generateCategories(messagesDocPath, "Message Categories", sortedCategoryList);
    final List<MessageType> sortedMessageList = repository.getMessages().getMessage().stream().sorted(Comparator.comparing(MessageType::getName).thenComparing(MessageType::getScenario)).collect(Collectors.toList());
    final Optional<Actors> actors = Optional.ofNullable(repository.getActors());
    final List<ActorType> actorList = actors.orElse(new Actors()).getActorOrFlow().stream().filter(af -> af instanceof ActorType).map(af -> (ActorType) af).collect(Collectors.toList());
    generateActorsList(messagesDocPath, actorList);
    actorList.forEach(a -> {
        try {
            generateActorDetail(messagesDocPath, messagesImgPath, a);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    final List<FlowType> flowList = actors.orElse(new Actors()).getActorOrFlow().stream().filter(af -> af instanceof FlowType).map(af -> (FlowType) af).collect(Collectors.toList());
    generateFlowsList(messagesDocPath, flowList);
    flowList.forEach(f -> {
        try {
            generateFlowDetail(messagesDocPath, f);
            generateMessageListByFlow(messagesDocPath, f, sortedMessageList);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    generateAllMessageList(messagesDocPath, sortedMessageList);
    sortedCategoryList.forEach(c -> {
        try {
            generateMessageListByCategory(messagesDocPath, c, sortedMessageList);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    final List<ComponentType> componentList = repository.getComponents().getComponent();
    final List<ComponentType> sortedComponentList = componentList.stream().sorted(Comparator.comparing(ComponentType::getName).thenComparing(ComponentType::getScenario)).collect(Collectors.toList());
    generateAllComponentsList(messagesDocPath, sortedComponentList);
    componentList.forEach(c -> {
        try {
            generateComponentDetail(messagesDocPath, c);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    final List<GroupType> groupList = repository.getGroups().getGroup();
    final List<GroupType> sortedGroupList = groupList.stream().sorted(Comparator.comparing(GroupType::getName).thenComparing(GroupType::getScenario)).collect(Collectors.toList());
    generateAllGroupsList(messagesDocPath, sortedGroupList);
    groupList.forEach(c -> {
        try {
            generateGroupDetail(messagesDocPath, c);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    repository.getMessages().getMessage().forEach(m -> {
        try {
            generateMessageDetail(messagesDocPath, messagesImgPath, m);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    });
    pathManager.close();
}
Also used : ComponentType(io.fixprotocol._2020.orchestra.repository.ComponentType) STWriter(org.stringtemplate.v4.STWriter) STMessage(org.stringtemplate.v4.misc.STMessage) GroupRefType(io.fixprotocol._2020.orchestra.repository.GroupRefType) FieldRuleType(io.fixprotocol._2020.orchestra.repository.FieldRuleType) MessageType(io.fixprotocol._2020.orchestra.repository.MessageType) STGroup(org.stringtemplate.v4.STGroup) Map(java.util.Map) ValidationEventHandler(javax.xml.bind.ValidationEventHandler) Path(java.nio.file.Path) Repository(io.fixprotocol._2020.orchestra.repository.Repository) SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral) ComponentRefType(io.fixprotocol._2020.orchestra.repository.ComponentRefType) SupportType(io.fixprotocol._2020.orchestra.repository.SupportType) FlowType(io.fixprotocol._2020.orchestra.repository.FlowType) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Categories(io.fixprotocol._2020.orchestra.repository.Categories) PresenceT(io.fixprotocol._2020.orchestra.repository.PresenceT) ValidationEvent(javax.xml.bind.ValidationEvent) List(java.util.List) ST(org.stringtemplate.v4.ST) FieldRefType(io.fixprotocol._2020.orchestra.repository.FieldRefType) StateMachineType(io.fixprotocol._2020.orchestra.repository.StateMachineType) CodeSetType(io.fixprotocol._2020.orchestra.repository.CodeSetType) FieldType(io.fixprotocol._2020.orchestra.repository.FieldType) Writer(java.io.Writer) Optional(java.util.Optional) CodeType(io.fixprotocol._2020.orchestra.repository.CodeType) STGroupFile(org.stringtemplate.v4.STGroupFile) NoIndentWriter(org.stringtemplate.v4.NoIndentWriter) HashMap(java.util.HashMap) CategoryType(io.fixprotocol._2020.orchestra.repository.CategoryType) Datatype(io.fixprotocol._2020.orchestra.repository.Datatype) ResponseType(io.fixprotocol._2020.orchestra.repository.ResponseType) JAXBContext(javax.xml.bind.JAXBContext) PrintStream(java.io.PrintStream) Unmarshaller(javax.xml.bind.Unmarshaller) Files(java.nio.file.Files) Actors(io.fixprotocol._2020.orchestra.repository.Actors) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) MessageRefType(io.fixprotocol._2020.orchestra.repository.MessageRefType) FileInputStream(java.io.FileInputStream) STErrorListener(org.stringtemplate.v4.STErrorListener) File(java.io.File) Responses(io.fixprotocol._2020.orchestra.repository.MessageType.Responses) ActorType(io.fixprotocol._2020.orchestra.repository.ActorType) CatComponentTypeT(io.fixprotocol._2020.orchestra.repository.CatComponentTypeT) Comparator(java.util.Comparator) InputStream(java.io.InputStream) GroupType(io.fixprotocol._2020.orchestra.repository.GroupType) CategoryType(io.fixprotocol._2020.orchestra.repository.CategoryType) MessageType(io.fixprotocol._2020.orchestra.repository.MessageType) Path(java.nio.file.Path) CodeSetType(io.fixprotocol._2020.orchestra.repository.CodeSetType) ComponentType(io.fixprotocol._2020.orchestra.repository.ComponentType) Categories(io.fixprotocol._2020.orchestra.repository.Categories) Actors(io.fixprotocol._2020.orchestra.repository.Actors) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) FieldType(io.fixprotocol._2020.orchestra.repository.FieldType) ActorType(io.fixprotocol._2020.orchestra.repository.ActorType) GroupType(io.fixprotocol._2020.orchestra.repository.GroupType) FlowType(io.fixprotocol._2020.orchestra.repository.FlowType)

Example 2 with CategoryType

use of io.fixprotocol._2020.orchestra.repository.CategoryType in project fix-orchestra by FIXTradingCommunity.

the class DocGenerator method generateMessageListByCategory.

private void generateMessageListByCategory(final Path messagesDocPath, final CategoryType category, final List<MessageType> messageList) throws Exception {
    final ST st = stGroup.getInstanceOf("messages");
    final List<MessageType> filteredMessageList = messageList.stream().filter(m -> category.getName().equals(m.getCategory())).collect(Collectors.toList());
    st.add("messages", filteredMessageList);
    st.add("title", String.format("%s Messages", category.getName()));
    final Path path = messagesDocPath.resolve(String.format("%sMessages.html", category.getName()));
    try (final STWriterWrapper writer = getWriter(path)) {
        st.write(writer, templateErrorListener);
    }
}
Also used : ComponentType(io.fixprotocol._2020.orchestra.repository.ComponentType) STWriter(org.stringtemplate.v4.STWriter) STMessage(org.stringtemplate.v4.misc.STMessage) GroupRefType(io.fixprotocol._2020.orchestra.repository.GroupRefType) FieldRuleType(io.fixprotocol._2020.orchestra.repository.FieldRuleType) MessageType(io.fixprotocol._2020.orchestra.repository.MessageType) STGroup(org.stringtemplate.v4.STGroup) Map(java.util.Map) ValidationEventHandler(javax.xml.bind.ValidationEventHandler) Path(java.nio.file.Path) Repository(io.fixprotocol._2020.orchestra.repository.Repository) SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral) ComponentRefType(io.fixprotocol._2020.orchestra.repository.ComponentRefType) SupportType(io.fixprotocol._2020.orchestra.repository.SupportType) FlowType(io.fixprotocol._2020.orchestra.repository.FlowType) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) Categories(io.fixprotocol._2020.orchestra.repository.Categories) PresenceT(io.fixprotocol._2020.orchestra.repository.PresenceT) ValidationEvent(javax.xml.bind.ValidationEvent) List(java.util.List) ST(org.stringtemplate.v4.ST) FieldRefType(io.fixprotocol._2020.orchestra.repository.FieldRefType) StateMachineType(io.fixprotocol._2020.orchestra.repository.StateMachineType) CodeSetType(io.fixprotocol._2020.orchestra.repository.CodeSetType) FieldType(io.fixprotocol._2020.orchestra.repository.FieldType) Writer(java.io.Writer) Optional(java.util.Optional) CodeType(io.fixprotocol._2020.orchestra.repository.CodeType) STGroupFile(org.stringtemplate.v4.STGroupFile) NoIndentWriter(org.stringtemplate.v4.NoIndentWriter) HashMap(java.util.HashMap) CategoryType(io.fixprotocol._2020.orchestra.repository.CategoryType) Datatype(io.fixprotocol._2020.orchestra.repository.Datatype) ResponseType(io.fixprotocol._2020.orchestra.repository.ResponseType) JAXBContext(javax.xml.bind.JAXBContext) PrintStream(java.io.PrintStream) Unmarshaller(javax.xml.bind.Unmarshaller) Files(java.nio.file.Files) Actors(io.fixprotocol._2020.orchestra.repository.Actors) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) MessageRefType(io.fixprotocol._2020.orchestra.repository.MessageRefType) FileInputStream(java.io.FileInputStream) STErrorListener(org.stringtemplate.v4.STErrorListener) File(java.io.File) Responses(io.fixprotocol._2020.orchestra.repository.MessageType.Responses) ActorType(io.fixprotocol._2020.orchestra.repository.ActorType) CatComponentTypeT(io.fixprotocol._2020.orchestra.repository.CatComponentTypeT) Comparator(java.util.Comparator) InputStream(java.io.InputStream) GroupType(io.fixprotocol._2020.orchestra.repository.GroupType) Path(java.nio.file.Path) ST(org.stringtemplate.v4.ST) MessageType(io.fixprotocol._2020.orchestra.repository.MessageType)

Aggregations

ActorType (io.fixprotocol._2020.orchestra.repository.ActorType)2 Actors (io.fixprotocol._2020.orchestra.repository.Actors)2 CatComponentTypeT (io.fixprotocol._2020.orchestra.repository.CatComponentTypeT)2 Categories (io.fixprotocol._2020.orchestra.repository.Categories)2 CategoryType (io.fixprotocol._2020.orchestra.repository.CategoryType)2 CodeSetType (io.fixprotocol._2020.orchestra.repository.CodeSetType)2 CodeType (io.fixprotocol._2020.orchestra.repository.CodeType)2 ComponentRefType (io.fixprotocol._2020.orchestra.repository.ComponentRefType)2 ComponentType (io.fixprotocol._2020.orchestra.repository.ComponentType)2 Datatype (io.fixprotocol._2020.orchestra.repository.Datatype)2 FieldRefType (io.fixprotocol._2020.orchestra.repository.FieldRefType)2 FieldRuleType (io.fixprotocol._2020.orchestra.repository.FieldRuleType)2 FieldType (io.fixprotocol._2020.orchestra.repository.FieldType)2 FlowType (io.fixprotocol._2020.orchestra.repository.FlowType)2 GroupRefType (io.fixprotocol._2020.orchestra.repository.GroupRefType)2 GroupType (io.fixprotocol._2020.orchestra.repository.GroupType)2 MessageRefType (io.fixprotocol._2020.orchestra.repository.MessageRefType)2 MessageType (io.fixprotocol._2020.orchestra.repository.MessageType)2 Responses (io.fixprotocol._2020.orchestra.repository.MessageType.Responses)2 PresenceT (io.fixprotocol._2020.orchestra.repository.PresenceT)2