diff --git a/bindings-generator/pom.xml b/bindings-generator/pom.xml index 9eae5e7..457f28d 100644 --- a/bindings-generator/pom.xml +++ b/bindings-generator/pom.xml @@ -11,7 +11,7 @@ com.vmware.vcloud vcd-api-tooling-parent - 9.7 + 10.0.0 ${project.artifactId} :: Bindings generation utility Provides custom API bindings generation beyond what can be accomplished with xjc and OpenAPI diff --git a/pom.xml b/pom.xml index 4d93571..f9c8c6b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ 4.0.0 com.vmware.vcloud vcd-api-tooling-parent - 9.7 + 10.0.0 pom ${project.artifactId} :: vCloud Director REST API tooling parent Parent project housing tools and utilities to process vCloud Director APIs and build bindings diff --git a/vcd-bindings-maven-plugin/pom.xml b/vcd-bindings-maven-plugin/pom.xml index e703ad0..cc557dd 100644 --- a/vcd-bindings-maven-plugin/pom.xml +++ b/vcd-bindings-maven-plugin/pom.xml @@ -12,7 +12,7 @@ com.vmware.vcloud vcd-api-tooling-parent - 9.7 + 10.0.0 ${project.artifactId} :: Maven plugin wrapper for bindings generation utility diff --git a/vcd-xjc-plugins/pom.xml b/vcd-xjc-plugins/pom.xml index 2421c71..cb26e1b 100644 --- a/vcd-xjc-plugins/pom.xml +++ b/vcd-xjc-plugins/pom.xml @@ -10,7 +10,7 @@ com.vmware.vcloud vcd-api-tooling-parent - 9.7 + 10.0.0 jar ${project.artifactId} :: Custom plugins for XML to Java Compilation @@ -37,4 +37,16 @@ + + + + maven-compiler-plugin + + utf8 + 1.8 + 1.8 + + + + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/ContentType.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/ContentType.java index 8c3fcd4..8ea8ca4 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/ContentType.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/ContentType.java @@ -4,7 +4,7 @@ * #%L * vcd-xjc-plugins :: Custom plugins for XML to Java Compilation * %% - * Copyright (C) 2018 VMware, Inc. + * Copyright (C) 2018 - 2021 VMware, Inc. * %% * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -45,3 +45,4 @@ public @interface ContentType { String value(); } + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/MultiSite.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/MultiSite.java new file mode 100644 index 0000000..94805ce --- /dev/null +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/MultiSite.java @@ -0,0 +1,80 @@ +package com.vmware.vcloud.api.annotation; + +/*- + * #%L + * vcd-xjc-plugins :: Custom plugins for XML to Java Compilation + * %% + * Copyright (C) 2018 - 2021 VMware, Inc. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.xml.bind.JAXBElement; + +import com.vmware.vcloud.api.rest.version.ApiVersion; + + +/** + * Indicates that a handler method can handle multi-site requests. A list of collection field names + * to be merged in the result body can be optionally specified. A custom response builder class can + * also be optionallyspecified to handle aggregation of the federated responses. If neither is + * specified, default aggregation implementation will be applied to the results. + */ +@Inherited +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface MultiSite { + + /** + * Specifies the list of collection names in a {@link JAXBElement} type that should be merged to + * create a multi-site response. i.e. the contents of independent response objects from multiple + * associated Org endpoints will be merged into a single collection in the response object + */ + String[] mergeCollections() default {}; + + /** + * Specifies a custom class to use to build a multi-site response object. If none specified, a + * default multi-site response builder will be used to construct a multi-site response for the + * request. Any mrgeCollections value is ignored if a custom response builder is specified + */ + Class customResponseBuilder() default Object.class; + + /** + * Specifies an {@link ApiVersion.Alias} to add support for multi-site request fanout. If none + * specified, a default {@code ApiVersion.Alias.MULTI_SITE} is used + */ + ApiVersion.Alias addedIn() default ApiVersion.Alias.MULTI_SITE; + + /** + * Specifies an {@link ApiVersion.Alias} to remove support for multi-site request fanout. If + * none specified, a default {@code ApiVersion.Alias.FUTURE} is used + */ + ApiVersion.Alias removedIn() default ApiVersion.Alias.FUTURE; +} + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/Restricted.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/Restricted.java new file mode 100644 index 0000000..a21aa53 --- /dev/null +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/Restricted.java @@ -0,0 +1,47 @@ +package com.vmware.vcloud.api.annotation; + +/*- + * #%L + * vcd-xjc-plugins :: Custom plugins for XML to Java Compilation + * %% + * Copyright (C) 2018 - 2021 VMware, Inc. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation denotes that the annotated field is potentially restricted. Before writing out or + * reading in this field, the API framework should determine if the caller is allowed to see/use the + * field. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.FIELD }) +public @interface Restricted { + +} + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/Supported.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/Supported.java index ef9b15e..d498d99 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/Supported.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/annotation/Supported.java @@ -4,7 +4,7 @@ * #%L * vcd-xjc-plugins :: Custom plugins for XML to Java Compilation * %% - * Copyright (C) 2018 VMware, Inc. + * Copyright (C) 2018 - 2021 VMware, Inc. * %% * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -36,28 +36,27 @@ /** * This annotation denotes when the specific feature was introduced to the - * REST-API and if and when it was removed.

- * - * A feature is present starting from {@link #addedIn()} version inclusive, to - * {@link #removedIn()} exclusive.

- * - * This annotation is added automatically to the JAXB generated classes. + * REST-API and if and when it was removed. This annotation is added + * automatically to the JAXB generated classes. + *

+ * The feature is present starting from {@link #addedIn()} version inclusive, to + * {@link #removedIn()} exclusive. + *

*/ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE }) public @interface Supported { + public static final String VCLOUD_LEGACY_FILTER_PARAM = "vcloud_legacy"; + /** - * Version in which the feature was added, inclusive. - * - * @return a version string + * Version in which the feature was added. */ String addedIn(); /** - * Version in which the feature was removed, exclusive. - * - * @return a version string + * Version in which the feature was removed. */ String removedIn() default ""; } + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/enums/EnumValidator.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/enums/EnumValidator.java index 146ad7d..ba14d79 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/enums/EnumValidator.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/enums/EnumValidator.java @@ -49,3 +49,4 @@ public interface EnumValidator extends Serializable { */ void validate(String key, T value); } + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/enums/NameVersionHolder.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/enums/NameVersionHolder.java index 9de9f68..56b5ba3 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/enums/NameVersionHolder.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/enums/NameVersionHolder.java @@ -93,3 +93,4 @@ protected T validateValue(String key, T value) { return value; } } + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/JAXBElementConverter.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/JAXBElementConverter.java new file mode 100644 index 0000000..baf772e --- /dev/null +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/JAXBElementConverter.java @@ -0,0 +1,138 @@ +package com.vmware.vcloud.api.http.converters; + +/*- + * #%L + * vcd-xjc-plugins :: Custom plugins for XML to Java Compilation + * %% + * Copyright (C) 2018 - 2021 VMware, Inc. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import javax.xml.bind.JAXBElement; + + +/** + * Converts an xsd-generated type into a {@link JAXBElement} wrapped representation + */ +public class JAXBElementConverter { + + private static class ObjectFactoryInvocation { + final Object objectFactory; + final Method factoryMethod; + + ObjectFactoryInvocation(Object objectFactory, Method factoryMethod) { + this.objectFactory = objectFactory; + this.factoryMethod = factoryMethod; + } + + public JAXBElement convert(Object value) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + return (JAXBElement) factoryMethod.invoke(objectFactory, value); + } + } + + + private final List objectFactories; + + private static final ConcurrentMap, ObjectFactoryInvocation> jaxbFactoryMethods = + new ConcurrentHashMap<>(); + + public JAXBElementConverter(final List objectFactories) { + this.objectFactories = new ArrayList<>(objectFactories); + } + + /** + * Locates the factory method from among the {@code ObjectFactory}s this instance was seeded + * with and converts the payload into its {@link JAXBElement} wrapped representation + * + * @param value + * xsd-generated type object to be wrapped within a {@link JAXBElement} + * @return {@link JAXBElement} wrapped representation + * + * @throws IllegalAccessException + * if there was an error invoking the factory method. + * @throws IllegalArgumentException + * if factory method to rejected the argument. + * @throws NullPointerException + * They payload to be converted has no applicable factory method to effect the + * conversion. + * @throws InvocationTargetException + * if there was an error invoking the factory method. + */ + public JAXBElement convertToJAXBElement(Object value) throws IllegalAccessException, + IllegalArgumentException, + NullPointerException, + InvocationTargetException { + + final ObjectFactoryInvocation jaxbConverter = getJAXBFactoryMethodInfo(value.getClass()); + final JAXBElement result = jaxbConverter.convert(value); + return result; + } + + /** + * For a payload type locate the {@code ObjectFactory} and the {@link Method} on that factory + * that will effect the conversion + *

+ * The pair is wrapped in an {@link ObjectFactoryInvocation} object and cached for quicker + * lookups in the future + * + * @param elementCls + * - xsd-generated type's {@link Class} + * + * @return {@link ObjectFactoryInvocation} whose {@link ObjectFactoryInvocation#convert(Object) + * convert} method can be invoked to get the {@link JAXBElement} + */ + private ObjectFactoryInvocation getJAXBFactoryMethodInfo(Class elementCls) { + return jaxbFactoryMethods.computeIfAbsent(elementCls, this::getConverter); + } + + private ObjectFactoryInvocation getConverter(Class elementCls) { + for (Object factory : objectFactories) { + Method[] methods = factory.getClass().getMethods(); + for (Method m : methods) { + Class[] pTypes = m.getParameterTypes(); + Class pType = null; + if (pTypes != null && pTypes.length == 1) { + pType = pTypes[0]; + } else { + continue; + } + + Class type = m.getReturnType(); + if (elementCls.equals(pType) && JAXBElement.class.isAssignableFrom(type)) { + return new ObjectFactoryInvocation(factory, m); + } + } + } + + return null; + } +} + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/JAXBElementMixIn.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/JAXBElementMixIn.java index 06db0f8..a20a925 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/JAXBElementMixIn.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/JAXBElementMixIn.java @@ -51,4 +51,3 @@ public abstract class JAXBElementMixIn { public abstract Object getValue(); } - diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/QNameMixin.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/QNameMixin.java new file mode 100644 index 0000000..4ad2251 --- /dev/null +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/QNameMixin.java @@ -0,0 +1,75 @@ +package com.vmware.vcloud.api.http.converters; + +/*- + * #%L + * vcd-xjc-plugins :: Custom plugins for XML to Java Compilation + * %% + * Copyright (C) 2018 - 2021 VMware, Inc. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import javax.xml.namespace.QName; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * A Jackson Mixin to assist in parsing {@link QName} from its string representation + *

+ * {@link QName}, which primarily consists of a {@code namespace URI} and a {@code localpart}, is + * serialized in {@code json} representation of our legacy API types as per the most commonly + * accepted way of representing it as defined by James + * Clark..
+ * Parsing such a string can be accomplished by {@link QName#valueOf(String)} method. + *

+ * {@link ObjectMapper}'s order of preference causes {@link QName#QName(String)} single argument + * constructor to be preferred over this method over a similar single argument factory method (which + * would be {@code QName#valueOf(String)}. As a result, a single string, that is formatted as above, + * is interpreted as a {@code QName} that is comprised solely of the {@code localpart} instead of + * potentially both, {@code namespace URI} and {@code localpart}. + *

+ * This mixin instructs the {@link ObjectMapper} to ignore that constructor and instead use the + * {@link QName#valueOf(String) valueOf method} as a factory method to parse the incoming string. + *

+ * De-serializing the payload is handled by {@link QName#toString()} method + *

+ * Ref:Official + * Jackson MixIn Annotations Documentation + * + * @see QName#toString() + * @see QName#valueOf(String) + */ +public abstract class QNameMixin { + + @JsonIgnore + public QNameMixin(String localPart) {} + + @JsonCreator + public static QName valueOf(String qNameAsString) { + return QName.valueOf(qNameAsString); + } + +} + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/QueryResultJsonRecords.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/QueryResultJsonRecords.java new file mode 100644 index 0000000..84cb574 --- /dev/null +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/http/converters/QueryResultJsonRecords.java @@ -0,0 +1,120 @@ +package com.vmware.vcloud.api.http.converters; + +/*- + * #%L + * vcd-xjc-plugins :: Custom plugins for XML to Java Compilation + * %% + * Copyright (C) 2018 - 2021 VMware, Inc. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +import java.lang.reflect.Method; +import java.util.List; + +/** + * Wrapper to provide access to OpenAPI query results. + * + * @since 9.7 + */ +public class QueryResultJsonRecords { + + private static final String TOTAL_METHOD = "getResultTotal"; + private static final String COUNT_METHOD = "getPageCount"; + private static final String PAGE_METHOD = "getPage"; + private static final String PAGE_SIZE_METHOD = "getPageSize"; + private static final String VALUES_METHOD = "getValues"; + + private final int resultTotal; + private final int pageCount; + private final int page; + private final int pageSize; + private final List values; + + public QueryResultJsonRecords(Object openApiResults) { + try { + this.resultTotal = getInt(openApiResults, TOTAL_METHOD); + this.pageCount = getInt(openApiResults, COUNT_METHOD); + this.page = getInt(openApiResults, PAGE_METHOD); + this.pageSize = getInt(openApiResults, PAGE_SIZE_METHOD); + this.values = getList(openApiResults, VALUES_METHOD); + } catch (SecurityException | ReflectiveOperationException e) { + throw new IllegalArgumentException("Unable to create JSON record from provided object", e); + } + } + + private int getInt(Object object, String methodName) throws ReflectiveOperationException, SecurityException { + final Object invokeMethod = invokeMethod(object, methodName); + if (!(invokeMethod instanceof Integer)) { + throwException(object, methodName); + } + + return (int) invokeMethod; + } + + @SuppressWarnings("unchecked") + private List getList(Object object, String methodName) throws ReflectiveOperationException, SecurityException { + final Object invokeMethod = invokeMethod(object, methodName); + if (!(invokeMethod instanceof List)) { + throwException(object, methodName); + } + + return (List) invokeMethod; + } + + private void throwException(Object object, String methodName) throws ReflectiveOperationException { + throw new ReflectiveOperationException("Unexpected return type from " + methodName + " on " + object.getClass().getSimpleName()); + } + + /** + * Invokes {@code methodName} on the provided {@link Object} and returns + * the result. + */ + private Object invokeMethod(Object object, String methodName) throws ReflectiveOperationException, SecurityException { + final Method method = object.getClass().getMethod(methodName); + final Object result = method.invoke(object); + return result; + } + + public int getResultTotal() { + return resultTotal; + } + + public int getPageCount() { + return pageCount; + } + + public int getPage() { + return page; + } + + public int getPageSize() { + return pageSize; + } + + public List getValues() { + return values; + } + +} + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersion.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersion.java index 4b29169..9e26295 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersion.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersion.java @@ -178,7 +178,8 @@ public enum ApiVersion { VERSION_28_0("28.0", true), /** Introduced in product version Trifecta (9.0) **/ - VERSION_29_0("29.0"), + @Deprecated + VERSION_29_0("29.0", true), /** Introduced in product version Ulysses (9.1) **/ VERSION_30_0("30.0"), @@ -186,9 +187,12 @@ public enum ApiVersion { /** Introduced in product version Vulcan (9.5) **/ VERSION_31_0("31.0"), - /** Introduced in product version Wellington **/ + /** Introduced in product version Wellington (9.7) **/ VERSION_32_0("32.0"), + /** Introduced in product version Xendi **/ + VERSION_33_0("33.0"), + /** Larger than all versions. Keep last! */ VERSION_MAX(""); @@ -196,10 +200,10 @@ public enum ApiVersion { * This enum will help manage all API version alias mappings. */ public enum Alias { - MIN_SUPPORTED(ApiVersion.VERSION_20_0), + MIN_SUPPORTED(ApiVersion.VERSION_27_0), OBJECT_EXTENSIBILITY(ApiVersion.VERSION_16_0), VM_AFFINITY_RULES(ApiVersion.VERSION_20_0), - MAX_SUPPORTED(ApiVersion.VERSION_32_0), + MAX_SUPPORTED(ApiVersion.VERSION_33_0), VAPP_AUTO_NATURE(ApiVersion.VERSION_22_0), VDC_ADOPT_RP(ApiVersion.VERSION_22_0), PERSIST_TABLE_ACCESS(ApiVersion.VERSION_22_0), @@ -246,6 +250,7 @@ public enum Alias { SITE_ORG_ASSOCIATIONS_QUERY(ApiVersion.VERSION_31_0), ORG_VDC_NETWORKING(ApiVersion.VERSION_32_0), CPOM(ApiVersion.VERSION_32_0), + CPOM_PROVIDER(ApiVersion.VERSION_33_0), GENERIC_VDC_TYPE(ApiVersion.VERSION_32_0), VC_NONE_NETWORK(ApiVersion.VERSION_32_0), PREFERENCES(ApiVersion.VERSION_32_0), @@ -260,7 +265,19 @@ public enum Alias { NSXT_EDGE_DNS(ApiVersion.VERSION_32_0), CREATE_BLANK_VM(ApiVersion.VERSION_32_0), INSTANTIATE_VM_TEMPLATE(ApiVersion.VERSION_32_0), - SECURITY_CONTEXT_CACHE_IN_DB(ApiVersion.VERSION_32_0), + VAPP_LOCALID_VM_QUERY(ApiVersion.VERSION_33_0), + NSXT_SERVICES(ApiVersion.VERSION_33_0), + VM_SIZING_POLICY(ApiVersion.VERSION_33_0), + AUTH_HEADERS_LOGIN_ONLY(ApiVersion.VERSION_33_0), + VM_REAPPLY_COMPUTE_POLICY(ApiVersion.VERSION_33_0), + VDC_MAX_COMPUTE_POLICY_CREATE(ApiVersion.VERSION_33_0), + VC_RESOURCE_POOLS(ApiVersion.VERSION_33_0), + ALLOW_ACTIVITY_ACCESS_IN_MAINT_MODE(ApiVersion.VERSION_33_0), + API_EXPLORER_VIEW(ApiVersion.VERSION_33_0), + AUDIT_TRAIL(ApiVersion.VERSION_33_0), + SECURITY_CONTEXT_CACHE_IN_DB(ApiVersion.VERSION_33_0), + INCLUDE_API_VERSION_IN_AUTH_LOCATION(ApiVersion.VERSION_33_0), + VDC_COMPUTE_POLICIES(ApiVersion.VERSION_33_0), ; private final ApiVersion mapping; @@ -332,6 +349,15 @@ public static ApiVersion fromValue(String v) { return ApiVersionCacheHelper.instance.getValue(v); } + public static boolean isValidApiVersion(String v) { + if (!ApiVersionCacheHelper.instance.isCached(v)) { + if (!ApiVersionCacheHelper.instance.isAliasCached(v)) { + return false; + } + } + return true; + } + /** * Checks if the version is in the range supported by s. * @@ -372,6 +398,18 @@ public boolean isAtLeast(final ApiVersion version) { return this.compareTo(version) >= 0; } + /** + * Tests if this {@code ApiVersion} is greater than the given one. + * + * @param version + * the version to compare this version to + * @return true if this {@code ApiVersion} is greater than or equal to {@code version}, false + * otherwise + */ + public boolean isGreaterThan(final ApiVersion version) { + return this.compareTo(version) > 0; + } + /** * Tests if this {@code ApiVersion} is less than or equal to the given one. * @@ -384,6 +422,18 @@ public boolean isAtMost(final ApiVersion version) { return this.compareTo(version) <= 0; } + /** + * Tests if this {@code ApiVersion} is less than the given one. + * + * @param version + * the version to compare this version to + * @return true if this {@code ApiVersion} is less than {@code version}, false + * otherwise + */ + public boolean isLessThan(final ApiVersion version) { + return this.compareTo(version) < 0; + } + /** * @return {@code true} if this version falls within the supported range * of the {@link Supported} annotation (including if no range is provided) @@ -447,4 +497,3 @@ public static List getRangeAbove(final ApiVersion minApiVersion) { } } - diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersionCacheHelper.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersionCacheHelper.java index 8732069..0ce4f91 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersionCacheHelper.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersionCacheHelper.java @@ -4,7 +4,7 @@ * #%L * vcd-xjc-plugins :: Custom plugins for XML to Java Compilation * %% - * Copyright (C) 2018 VMware, Inc. + * Copyright (C) 2018 - 2021 VMware, Inc. * %% * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -110,3 +110,4 @@ Set getAllKeys() { } } } + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersionGenerator.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersionGenerator.java index bbfdca8..44033e9 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersionGenerator.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/ApiVersionGenerator.java @@ -112,3 +112,4 @@ private static void writeSerializedConfiguration(byte[] serlializedConfiguration fileOutputStream.close(); } } + diff --git a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/Supported.java b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/Supported.java index d90dfcc..2636ddf 100644 --- a/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/Supported.java +++ b/vcd-xjc-plugins/src/main/java/com/vmware/vcloud/api/rest/version/Supported.java @@ -46,3 +46,4 @@ public interface Supported { */ ApiVersion getRemovedIn(); } +