Search in sources :

Example 1 with ComponentType

use of io.fixprotocol._2020.orchestra.repository.ComponentType 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 ComponentType

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

the class DocGenerator method generateMembers.

private void generateMembers(final List<Object> members, final STWriter writer) {
    for (final Object member : members) {
        if (member instanceof FieldRefType) {
            final FieldType field = getField(((FieldRefType) member).getId().intValue());
            final ST stField = stGroup.getInstanceOf("fieldMember");
            stField.add("field", field);
            if (((FieldRefType) member).getSupported() == SupportType.SUPPORTED) {
                stField.add("presence", getFieldPresence((FieldRefType) member));
            } else {
                stField.add("presence", supportedMap.get(((FieldRefType) member).getSupported()));
            }
            stField.add("assign", ((FieldRefType) member).getAssign());
            stField.write(writer, templateErrorListener);
        } else if (member instanceof GroupRefType) {
            final GroupType component = getGroup(((GroupRefType) member).getId().intValue());
            final ST stComponent = stGroup.getInstanceOf("componentMember");
            stComponent.add("component", component);
            if (((ComponentRefType) member).getSupported() == SupportType.SUPPORTED) {
                stComponent.add("presence", ((ComponentRefType) member).getPresence().value().toLowerCase());
            } else {
                stComponent.add("presence", supportedMap.get(((ComponentRefType) member).getSupported()));
            }
            stComponent.write(writer, templateErrorListener);
        } else if (member instanceof ComponentRefType) {
            final ComponentType component = getComponent(((ComponentRefType) member).getId().intValue());
            final ST stComponent = stGroup.getInstanceOf("componentMember");
            stComponent.add("component", component);
            if (((ComponentRefType) member).getSupported() == SupportType.SUPPORTED) {
                stComponent.add("presence", ((ComponentRefType) member).getPresence().value().toLowerCase());
            } else {
                stComponent.add("presence", supportedMap.get(((ComponentRefType) member).getSupported()));
            }
            stComponent.write(writer, templateErrorListener);
        }
    }
}
Also used : ST(org.stringtemplate.v4.ST) GroupRefType(io.fixprotocol._2020.orchestra.repository.GroupRefType) ComponentType(io.fixprotocol._2020.orchestra.repository.ComponentType) GroupType(io.fixprotocol._2020.orchestra.repository.GroupType) ComponentRefType(io.fixprotocol._2020.orchestra.repository.ComponentRefType) FieldRefType(io.fixprotocol._2020.orchestra.repository.FieldRefType) FieldType(io.fixprotocol._2020.orchestra.repository.FieldType)

Example 3 with ComponentType

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

the class RepositoryCompressor method compress.

private boolean compress(InputStream is, OutputStream os, Predicate<? super MessageType> messagePredicate) {
    try {
        final Repository inRepository = unmarshal(is);
        final Categories categories = inRepository.getCategories();
        isCategoryInSection.setCategories(categories.getCategory());
        final Repository outRepository = new Repository();
        inRepository.copyTo(null, outRepository, AttributeCopyStrategy.INSTANCE);
        final ElementOrRefinementContainer metadata = (ElementOrRefinementContainer) inRepository.getMetadata().clone();
        final List<JAXBElement<SimpleLiteral>> literals = metadata.getAny();
        final ObjectFactory objectFactory = new ObjectFactory();
        final SimpleLiteral contributor = new SimpleLiteral();
        contributor.getContent().add("RepositoryCompressor");
        literals.add(objectFactory.createContributor(contributor));
        outRepository.setMetadata(metadata);
        if (categories != null) {
            outRepository.setCategories((Categories) categories.clone());
        }
        final Sections sections = inRepository.getSections();
        if (sections != null) {
            outRepository.setSections((Sections) sections.clone());
        }
        final Datatypes datatypes = inRepository.getDatatypes();
        if (datatypes != null) {
            outRepository.setDatatypes((Datatypes) datatypes.clone());
        }
        final Actors actors = inRepository.getActors();
        if (actors != null) {
            outRepository.setActors((Actors) actors.clone());
        }
        final Components components = inRepository.getComponents();
        if (components != null) {
            final Components inComponents = (Components) components.clone();
            componentList = inComponents.getComponent();
        }
        final Groups groups = inRepository.getGroups();
        if (groups != null) {
            final Groups inGroups = (Groups) groups.clone();
            groupList = inGroups.getGroup();
        }
        final Messages messages = inRepository.getMessages();
        final List<MessageType> messageList;
        if (messages != null) {
            final Messages inMessages = (Messages) messages.clone();
            messageList = inMessages.getMessage();
        } else {
            messageList = Collections.emptyList();
        }
        final List<MessageType> filteredMessages = messageList.stream().filter(messagePredicate).collect(Collectors.toList());
        filteredMessages.forEach(m -> walk(m.getStructure().getComponentRefOrGroupRefOrFieldRef()));
        final List<BigInteger> distinctFieldIds = fieldIdList.stream().distinct().collect(Collectors.toList());
        final Fields inFields = (Fields) inRepository.getFields().clone();
        final List<FieldType> fieldsWithFlow = inFields.getField().stream().filter(f -> distinctFieldIds.contains(f.getId())).collect(Collectors.toList());
        final Fields outFields = new Fields();
        outFields.getField().addAll(fieldsWithFlow);
        outRepository.setFields(outFields);
        final List<String> typeList = fieldsWithFlow.stream().map(FieldType::getType).distinct().collect(Collectors.toList());
        final CodeSets inCodeSets = (CodeSets) inRepository.getCodeSets().clone();
        final List<CodeSetType> codeSetsWithFlow = inCodeSets.getCodeSet().stream().filter(cs -> typeList.contains(cs.getName())).collect(Collectors.toList());
        final CodeSets outCodeSets = new CodeSets();
        outCodeSets.getCodeSet().addAll(codeSetsWithFlow);
        outRepository.setCodeSets(outCodeSets);
        final List<BigInteger> distinctComponentsIds = componentIdList.stream().distinct().collect(Collectors.toList());
        final List<ComponentType> componentsWithFlow = componentList.stream().filter(c -> distinctComponentsIds.contains(c.getId())).collect(Collectors.toList());
        final Components outComponents = new Components();
        outComponents.getComponent().addAll(componentsWithFlow);
        outRepository.setComponents(outComponents);
        final List<BigInteger> distinctGroupIds = groupIdList.stream().distinct().collect(Collectors.toList());
        final List<GroupType> groupWithFlow = groupList.stream().filter(c -> distinctGroupIds.contains(c.getId())).collect(Collectors.toList());
        final Groups outGroups = new Groups();
        outGroups.getGroup().addAll(groupWithFlow);
        outRepository.setGroups(outGroups);
        final Messages outMessages = new Messages();
        outMessages.getMessage().addAll(filteredMessages);
        outRepository.setMessages(outMessages);
        marshal(outRepository, os);
        return true;
    } catch (JAXBException e) {
        logger.fatal("RepositoryCompressor failed", e);
        return false;
    }
}
Also used : ComponentType(io.fixprotocol._2020.orchestra.repository.ComponentType) ElementOrRefinementContainer(org.purl.dc.terms.ElementOrRefinementContainer) Sections(io.fixprotocol._2020.orchestra.repository.Sections) Marshaller(javax.xml.bind.Marshaller) Components(io.fixprotocol._2020.orchestra.repository.Components) Options(org.apache.commons.cli.Options) CategoryType(io.fixprotocol._2020.orchestra.repository.CategoryType) GroupRefType(io.fixprotocol._2020.orchestra.repository.GroupRefType) HelpFormatter(org.apache.commons.cli.HelpFormatter) ArrayList(java.util.ArrayList) DefaultParser(org.apache.commons.cli.DefaultParser) BiPredicate(java.util.function.BiPredicate) CodeSets(io.fixprotocol._2020.orchestra.repository.CodeSets) MessageType(io.fixprotocol._2020.orchestra.repository.MessageType) Groups(io.fixprotocol._2020.orchestra.repository.Groups) Fields(io.fixprotocol._2020.orchestra.repository.Fields) CommandLine(org.apache.commons.cli.CommandLine) BigInteger(java.math.BigInteger) ObjectFactory(org.purl.dc.elements._1.ObjectFactory) Datatypes(io.fixprotocol._2020.orchestra.repository.Datatypes) Repository(io.fixprotocol._2020.orchestra.repository.Repository) JAXBContext(javax.xml.bind.JAXBContext) Option(org.apache.commons.cli.Option) SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral) ComponentRefType(io.fixprotocol._2020.orchestra.repository.ComponentRefType) OutputStream(java.io.OutputStream) Unmarshaller(javax.xml.bind.Unmarshaller) Actors(io.fixprotocol._2020.orchestra.repository.Actors) Predicate(java.util.function.Predicate) JAXBElement(javax.xml.bind.JAXBElement) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) File(java.io.File) Categories(io.fixprotocol._2020.orchestra.repository.Categories) List(java.util.List) Logger(org.apache.logging.log4j.Logger) FieldRefType(io.fixprotocol._2020.orchestra.repository.FieldRefType) CodeSetType(io.fixprotocol._2020.orchestra.repository.CodeSetType) ParseException(org.apache.commons.cli.ParseException) FieldType(io.fixprotocol._2020.orchestra.repository.FieldType) Messages(io.fixprotocol._2020.orchestra.repository.Messages) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) GroupType(io.fixprotocol._2020.orchestra.repository.GroupType) Components(io.fixprotocol._2020.orchestra.repository.Components) ObjectFactory(org.purl.dc.elements._1.ObjectFactory) Sections(io.fixprotocol._2020.orchestra.repository.Sections) Groups(io.fixprotocol._2020.orchestra.repository.Groups) SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral) Datatypes(io.fixprotocol._2020.orchestra.repository.Datatypes) MessageType(io.fixprotocol._2020.orchestra.repository.MessageType) CodeSetType(io.fixprotocol._2020.orchestra.repository.CodeSetType) ComponentType(io.fixprotocol._2020.orchestra.repository.ComponentType) Messages(io.fixprotocol._2020.orchestra.repository.Messages) CodeSets(io.fixprotocol._2020.orchestra.repository.CodeSets) Categories(io.fixprotocol._2020.orchestra.repository.Categories) JAXBException(javax.xml.bind.JAXBException) Actors(io.fixprotocol._2020.orchestra.repository.Actors) JAXBElement(javax.xml.bind.JAXBElement) FieldType(io.fixprotocol._2020.orchestra.repository.FieldType) Repository(io.fixprotocol._2020.orchestra.repository.Repository) Fields(io.fixprotocol._2020.orchestra.repository.Fields) GroupType(io.fixprotocol._2020.orchestra.repository.GroupType) ElementOrRefinementContainer(org.purl.dc.terms.ElementOrRefinementContainer) BigInteger(java.math.BigInteger)

Aggregations

ComponentRefType (io.fixprotocol._2020.orchestra.repository.ComponentRefType)3 ComponentType (io.fixprotocol._2020.orchestra.repository.ComponentType)3 FieldRefType (io.fixprotocol._2020.orchestra.repository.FieldRefType)3 FieldType (io.fixprotocol._2020.orchestra.repository.FieldType)3 GroupRefType (io.fixprotocol._2020.orchestra.repository.GroupRefType)3 GroupType (io.fixprotocol._2020.orchestra.repository.GroupType)3 Actors (io.fixprotocol._2020.orchestra.repository.Actors)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 MessageType (io.fixprotocol._2020.orchestra.repository.MessageType)2 Repository (io.fixprotocol._2020.orchestra.repository.Repository)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBElement (javax.xml.bind.JAXBElement)2