Juan Hernandez has submitted this change and it was merged.
Change subject: codegen: Avoid calculation of singulars and plurals
......................................................................
codegen: Avoid calculation of singulars and plurals
Currently the code generator assumes that there is a semantic
relationship between the names of XML schema complex type that represent
collections and entities: the name of the entity is the plural of the
name of the collection. To handle this it uses rules to calculate the
plurals from singulars, and the other way around. But for some
collections and entities simple calculation of plural and singular
(adding or removing a trailing "s") doesn't work. For example:
SchedulingPolicies -> SchedulingPolicy
Another example is the following, which has been introduced in the
server side:
KatelloErrata -> KatelloErratum
The code generator also assumes that the names of the XML schema complex
types match the URL segments. This doesn't always work. For example,
with the recent addition of external providers to the server side there
are URL segments like this one:
/externalhostproviders/{externalhostprovider:id}/hosts
The XML complex type corresponding to this "hosts" collection is
"ExternalHost", and not "Host" as the existing rules expect.
We have been handling these situations adding exceptions in the code of
the generator, and implementing more robust rules for calculations of
plurals and singulars, but this doesn't scale well, and it is prone to
unexcpected failures. To avoid these issues in a more systematic way
this patch modifies the generator so that it will extract the required
information from the XML schema and the RSDL instead of making
calculations.
The core of this change is the introduction of a tree data structure
that stores the links extracted from the RSDL, so that it is easy to
find from one node its children and parents. This data structure is used
to decide if a location corresponds to a collection, entity or action,
and combined with querying the XML schema to extract the type names.
Change-Id: I7b27061d436e524683dbed81c5521eed51e8c2f0
Signed-off-by: Juan Hernandez <juan.hernandez(a)redhat.com>
---
M generator/src/main/java/org/ovirt/engine/sdk/generator/Main.java
D generator/src/main/java/org/ovirt/engine/sdk/generator/common/AbstractCodegen.java
A generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/Action.java
A generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/BrokerRules.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/CodeHolder.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/Collection.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/CollectionExceptions.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/Documentation.java
A generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/Location.java
A generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/LocationRules.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/Resource.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/RsdlCodegen.java
A generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/SchemaRules.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/SubCollection.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/SubResource.java
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/CollectionAddTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/CollectionGetDisksTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/CollectionGetNotSearchableTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/CollectionGetSearchableTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/CollectionListNotSearchableTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/CollectionListSearchableTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/ResourceActionTemplate
M generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/ResourceTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/ResourceUpdateTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubCollectionAddTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubCollectionGetTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubCollectionListTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubCollectionListWithParamsTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubCollectionTemplate
D
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubResourceActionTemplate
D
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubResourceActionTemplate.java
D
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubResourceCollectionActionTemplate
D
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubResourceCollectionActionTemplate.java
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubResourceDeleteWithUrlParamsAndBodyTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubResourceDeleteWithUrlParamsTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubResourceTemplate
M
generator/src/main/java/org/ovirt/engine/sdk/generator/rsdl/templates/SubResourceUpdateTemplate
M generator/src/main/java/org/ovirt/engine/sdk/generator/utils/CollectionsUtils.java
D generator/src/main/java/org/ovirt/engine/sdk/generator/utils/StringUtils.java
A generator/src/main/java/org/ovirt/engine/sdk/generator/utils/Tree.java
D generator/src/main/java/org/ovirt/engine/sdk/generator/utils/TypeUtils.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/utils/UrlUtils.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/xsd/XsdCodegen.java
M generator/src/main/java/org/ovirt/engine/sdk/generator/xsd/XsdData.java
44 files changed, 1,201 insertions(+), 1,423 deletions(-)
Approvals:
Juan Hernandez: Verified; Looks good to me, approved
--
To view, visit
https://gerrit.ovirt.org/37868
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7b27061d436e524683dbed81c5521eed51e8c2f0
Gerrit-PatchSet: 5
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernandez(a)redhat.com>
Gerrit-Reviewer: Juan Hernandez <juan.hernandez(a)redhat.com>
Gerrit-Reviewer: Martin Peřina <mperina(a)redhat.com>
Gerrit-Reviewer: Moti Asayag <masayag(a)redhat.com>
Gerrit-Reviewer: automation(a)ovirt.org