Jira Plugin: Adding an IssueType to an IssueType scheme in Java

I create an IssueType in Java. Now I want to add that IssueType to the current IssueTypeScheme of the project.

I foudn this: https://bitbucket.org/topmanage/tm-project-templates/src/6a3f0467bf1c51406fd5f7018d85d142cd8d5dbb/src/main/java/com/topmanage/jiraplugins/projecttemplates/ProjectCloner.java?at=master&fileviewer=file-view-default

But I don’t understand whats happaning there. Isn’t there an easier way?

Thx,
Harald

My solution:

            for (final Project p : projectManager.getProjects()) {
                    final FieldConfigScheme scheme = issueTypeSchemeManager.getConfigScheme(p);
                    if (!scheme.getAssociatedIssueTypes().contains(issueType)) {
                        final OptionSet options = optionSetManager.getOptionsForConfig(scheme.getOneAndOnlyConfig());
                        options.addOption(IssueFieldConstants.ISSUE_TYPE, issueType.getId());
                        issueTypeSchemeManager.update(scheme, options.getOptionIds());
                    }
            }