diff --git a/.idea/compiler.xml b/.idea/compiler.xml index e9c5688c..ee47ce8d 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -9,8 +9,8 @@ - + diff --git a/delivery-sdk-generators/src/main/java/kontent/ai/delivery/generators/CodeGenerator.java b/delivery-sdk-generators/src/main/java/kontent/ai/delivery/generators/CodeGenerator.java index 84c4fde9..2f82b9b8 100644 --- a/delivery-sdk-generators/src/main/java/kontent/ai/delivery/generators/CodeGenerator.java +++ b/delivery-sdk-generators/src/main/java/kontent/ai/delivery/generators/CodeGenerator.java @@ -8,6 +8,7 @@ import javax.lang.model.element.Modifier; import java.io.File; import java.io.IOException; +import java.io.Serializable; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; @@ -15,7 +16,8 @@ import java.util.concurrent.ExecutionException; /** - * Generates java source files using the Kontent.ai Type listing endpoint in the Delivery API + * Generates java source files using the Kontent.ai Type listing endpoint in the + * Delivery API */ public class CodeGenerator { @@ -29,16 +31,18 @@ public class CodeGenerator { /** * Constructs the CodeGenerator - * @param projectId the project id from your Kontent.ai account + * + * @param projectId the project id from your Kontent.ai account * @param packageName the package to place the generated models under - * @param outputDir the source root to place the generated models - * @throws UnsupportedOperationException when a there is a problem with the outputDir + * @param outputDir the source root to place the generated models + * @throws UnsupportedOperationException when a there is a problem with the + * outputDir */ public CodeGenerator(String projectId, String packageName, File outputDir) { this.projectId = projectId; this.packageName = packageName; this.outputDir = outputDir; - if (!outputDir.exists() && !outputDir.mkdirs()){ + if (!outputDir.exists() && !outputDir.mkdirs()) { throw new UnsupportedOperationException( String.format("Unable to create directory %s", outputDir.getAbsolutePath())); } @@ -49,32 +53,45 @@ public CodeGenerator(String projectId, String packageName, File outputDir) { } /** - * Returns a list of specifications of the sources representing the types in your Kontent.ai account + * Returns a list of specifications of the sources representing the types in + * your Kontent.ai account + * * @return A list of specifications - * @throws ExecutionException when a problem occurs communicating with the Kontent.ai API - * @throws InterruptedException when a problem occurs communicating with the Kontent.ai API + * @throws ExecutionException when a problem occurs communicating with the + * Kontent.ai API + * @throws InterruptedException when a problem occurs communicating with the + * Kontent.ai API */ public List generateSources() throws ExecutionException, InterruptedException { return generateSources(new DeliveryClient(projectId)); } /** - * Returns a list of specifications of the sources representing the types in your Kontent.ai account. - * The provided {@link DeliveryClient} param is useful for testing, however in most environments, the default + * Returns a list of specifications of the sources representing the types in + * your Kontent.ai account. + * The provided {@link DeliveryClient} param is useful for testing, however in + * most environments, the default * {@link #generateSources()} method should suffice. + * * @param client A DeliveryClient instance to use to generate the sources. * @return A list of specifications - * @throws ExecutionException when a problem occurs communicating with the Kontent.ai API - * @throws InterruptedException when a problem occurs communicating with the Kontent.ai API + * @throws ExecutionException when a problem occurs communicating with the + * Kontent.ai API + * @throws InterruptedException when a problem occurs communicating with the + * Kontent.ai API */ public List generateSources(DeliveryClient client) throws ExecutionException, InterruptedException { return generateSources(client.getTypes().toCompletableFuture().get().getTypes()); } /** - * Returns a list of specifications of the sources representing the types in your Kontent.ai account. - * The provided List of {@link ContentType} param is useful for testing, however in most environments, the default - * {@link #generateSources()} method should generally be the only method invoking this. + * Returns a list of specifications of the sources representing the types in + * your Kontent.ai account. + * The provided List of {@link ContentType} param is useful for testing, however + * in most environments, the default + * {@link #generateSources()} method should generally be the only method + * invoking this. + * * @param types A List of ContentType to generate the sources from * @return A list of specifications */ @@ -87,9 +104,12 @@ public List generateSources(List types) { } /** - * Returns a specification of the source representing this type in your Kontent.ai account. - * Invoking this directly may be useful for testing, however in most environments, the default + * Returns a specification of the source representing this type in your + * Kontent.ai account. + * Invoking this directly may be useful for testing, however in most + * environments, the default * {@link #generateSources()} method should suffice. + * * @param type A ContentType to generate the source from * @return A specification */ @@ -100,113 +120,109 @@ public JavaFile generateSource(ContentType type) { for (Map.Entry element : type.getElements().entrySet()) { TypeName typeName = null; - //Get the TypeName + // Get the TypeName switch (element.getValue().getType()) { - case "text" : - case "rich_text" : - case "url_slug" : - case "custom" : + case "text": + case "rich_text": + case "url_slug": + case "custom": typeName = ClassName.get(String.class); break; - case "number" : + case "number": typeName = ClassName.get(Double.class); break; - case "multiple_choice" : + case "multiple_choice": typeName = ParameterizedTypeName.get( ClassName.get(JAVA_UTIL_PACKAGE, "List"), ClassName.get(DELIVERY_PACKAGE, "Option")); break; - case "date_time" : + case "date_time": typeName = ClassName.get(ZonedDateTime.class); break; - case "asset" : + case "asset": typeName = ParameterizedTypeName.get( ClassName.get(JAVA_UTIL_PACKAGE, "List"), ClassName.get(DELIVERY_PACKAGE, "Asset")); break; - case "modular_content" : + case "modular_content": typeName = ParameterizedTypeName.get( ClassName.get(JAVA_UTIL_PACKAGE, "List"), ClassName.get(DELIVERY_PACKAGE, "ContentItem")); break; - case "taxonomy" : + case "taxonomy": typeName = ParameterizedTypeName.get( ClassName.get(JAVA_UTIL_PACKAGE, "List"), ClassName.get(DELIVERY_PACKAGE, "Taxonomy")); break; - default : + default: break; } if (typeName != null) { - //Add the field + // Add the field String fieldName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, element.getKey()); - Class annoClass = element.getValue().getType() == "modular_content" ? - ContentItemMapping.class : ElementMapping.class; + Class annoClass = element.getValue().getType() == "modular_content" ? ContentItemMapping.class + : ElementMapping.class; fieldSpecs.add( FieldSpec.builder(typeName, fieldName) .addAnnotation( AnnotationSpec.builder(annoClass) .addMember("value", "$S", element.getKey()) .build()) - .build() - ); - //Add the getter + .build()); + // Add the getter String getterName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "get_" + element.getKey()); methodSpecs.add( MethodSpec.methodBuilder(getterName) .addModifiers(Modifier.PUBLIC) .returns(typeName) .addStatement("return $N", fieldName) - .build() - ); - //Add the setter + .build()); + // Add the setter String setterName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "set_" + element.getKey()); methodSpecs.add( MethodSpec.methodBuilder(setterName) .addModifiers(Modifier.PUBLIC) .addParameter(typeName, fieldName) .addStatement("this.$N = $N", fieldName, fieldName) - .build() - ); + .build()); } } - //Add the System element + // Add the System element fieldSpecs.add(FieldSpec.builder(ClassName.get(System.class), SYSTEM).build()); methodSpecs.add( MethodSpec.methodBuilder("getSystem") .addModifiers(Modifier.PUBLIC) .returns(ClassName.get(System.class)) .addStatement("return $N", SYSTEM) - .build() - ); + .build()); methodSpecs.add( MethodSpec.methodBuilder("setSystem") .addModifiers(Modifier.PUBLIC) .addParameter(ClassName.get(System.class), SYSTEM) .addStatement("this.$N = $N", SYSTEM, SYSTEM) - .build() - ); + .build()); - //Create the class + // Create the class TypeSpec.Builder typeSpecBuilder = TypeSpec .classBuilder(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, type.getSystem().getCodename())) .addModifiers(Modifier.PUBLIC) .addJavadoc("This code was generated by a " + "delivery-sdk-generators tool\n") .addJavadoc("\n") - .addJavadoc("Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.\n") + .addJavadoc( + "Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.\n") .addJavadoc("For further modifications of the class, create a separate file and extend this class.\n") .addAnnotation(AnnotationSpec.builder(ContentItemMapping.class) .addMember("value", "$S", type.getSystem().getCodename()) .build()); - //Add the fields + // Add the fields for (FieldSpec fieldSpec : fieldSpecs) { typeSpecBuilder.addField(fieldSpec); } - //Add the methods + // Add the methods for (MethodSpec methodSpec : methodSpecs) { typeSpecBuilder.addMethod(methodSpec); } @@ -217,12 +233,16 @@ public JavaFile generateSource(ContentType type) { } /** - * Writes the provided specifications to the outputDir provided in the constructor. This is generally called - * after a call to {@link #generateSources()}, but is separated in case you need to make modifications to your + * Writes the provided specifications to the outputDir provided in the + * constructor. This is generally called + * after a call to {@link #generateSources()}, but is separated in case you need + * to make modifications to your * specifications before writing. + * * @param sources A list of specifications - * @throws IOException when a problem occurs writing the source files, note some source may have been written when - * this is thrown + * @throws IOException when a problem occurs writing the source files, note some + * source may have been written when + * this is thrown */ public void writeSources(List sources) throws IOException { for (JavaFile source : sources) { @@ -231,9 +251,12 @@ public void writeSources(List sources) throws IOException { } /** - * Writes the provided specification to the outputDir provided in the constructor. This is generally called - * after a call to {@link #generateSources()}, but is separated in case you need to make modifications to your + * Writes the provided specification to the outputDir provided in the + * constructor. This is generally called + * after a call to {@link #generateSources()}, but is separated in case you need + * to make modifications to your * specification before writing. + * * @param source A specification * @throws IOException when a problem occurs writing the source files */ @@ -241,4 +264,3 @@ public void writeSource(JavaFile source) throws IOException { source.writeTo(outputDir); } } - diff --git a/delivery-sdk-generators/src/test/java/kontent/ai/delivery/generators/CodeGeneratorTest.java b/delivery-sdk-generators/src/test/java/kontent/ai/delivery/generators/CodeGeneratorTest.java index 20ec69f2..07a7943a 100644 --- a/delivery-sdk-generators/src/test/java/kontent/ai/delivery/generators/CodeGeneratorTest.java +++ b/delivery-sdk-generators/src/test/java/kontent/ai/delivery/generators/CodeGeneratorTest.java @@ -21,12 +21,25 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.List; +import java.util.concurrent.ExecutionException; public class CodeGeneratorTest extends LocalServerTestBase { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); + // @Test + // public void testTrial() throws ExecutionException, InterruptedException, IOException { + // DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); + + // File outputDir = new File("C:\\tmp\\models"); + // Assert.assertTrue(outputDir.exists() && outputDir.isDirectory()); + // CodeGenerator codeGenerator = + // new CodeGenerator("975bf280-fd91-488c-994c-2f04416e5ee3","kontent.ai.delivery.sample.dancinggoat.models", outputDir); + // List sources = codeGenerator.generateSources(client); + // codeGenerator.writeSources(sources); + // } + @Test public void testGenerator() throws Exception { String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c"; diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/Asset.java b/delivery-sdk/src/main/java/kontent/ai/delivery/Asset.java index 369622d4..4b7eeb1b 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/Asset.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/Asset.java @@ -1,62 +1,64 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Object model for Asset elements - */ -@lombok.Data -@lombok.ToString -@lombok.EqualsAndHashCode -@lombok.NoArgsConstructor -@lombok.AllArgsConstructor -@lombok.Builder -@lombok.Getter -@lombok.Setter -public class Asset { - - @JsonProperty("name") - String name; - - @JsonProperty("type") - String type; - - @JsonProperty("size") - Integer size; - - @JsonProperty("description") - String description; - - @JsonProperty("url") - String url; - - @JsonProperty("width") - String width; - - @JsonProperty("height") - String height; +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; + +/** + * Object model for Asset elements + */ +@lombok.Data +@lombok.ToString +@lombok.EqualsAndHashCode +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor +@lombok.Builder +@lombok.Getter +@lombok.Setter +public class Asset { + + @JsonProperty("name") + String name; + + @JsonProperty("type") + String type; + + @JsonProperty("size") + Integer size; + + @JsonProperty("description") + String description; + + @JsonProperty("url") + String url; + + @JsonProperty("width") + String width; + + @JsonProperty("height") + String height; } \ No newline at end of file diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/ContentItem.java b/delivery-sdk/src/main/java/kontent/ai/delivery/ContentItem.java index 78e0901d..c720ed60 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/ContentItem.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/ContentItem.java @@ -1,212 +1,213 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * Object model description of a single content item object. - * - * @see - * Kontent.ai API reference - Content item object - */ -@lombok.Data -@lombok.NoArgsConstructor -@lombok.AllArgsConstructor -@lombok.Builder -@lombok.EqualsAndHashCode(exclude = {"linkedItemProvider", "stronglyTypedContentItemConverter"}) -@lombok.ToString(exclude = {"linkedItemProvider", "stronglyTypedContentItemConverter"}) -public class ContentItem { - - /** - * {@link System} attributes of the content item. - * - * @param system New value for System attributes of this content item. - * @return The System attributes of this content item. - */ - @JsonProperty("system") - System system; - - /** - * Content type elements in the content item. These are keyed by the codename of the element. - *

- * Note: The order of the {@link Element} objects might not match the order in the Kontent.ai UI. - * - * @return Map of this ContentItem's {@link Element} objects. - */ - @JsonProperty("elements") - Map elements; - - @JsonIgnore - LinkedItemProvider linkedItemProvider; - - @JsonIgnore - private StronglyTypedContentItemConverter stronglyTypedContentItemConverter; - - /** - * Content type elements in the content item. These are keyed by the codename of the element. - *

- * Note: The order of the {@link Element} objects might not match the order in the Kontent.ai UI. - * - * @param elements New value for this ContentItem's {@link Element} objects. - */ - public void setElements(Map elements) { - this.elements = elements; - elements.forEach((s, element) -> element.setParent(this)); - } - - /** - * Convenience method to get the value of a Text or Rich text element without traversing the Elements map. - * - * @param codename The element codename to retrieve the String rendering of from this ContentItem. - * @return The value of the element. Returns null if the element does not exist, or if it is not a - * {@link TextElement} or {@link RichTextElement}. - */ - public String getString(String codename) { - Element element = elements.get(codename); - if (element == null) { - return null; - } - if (!(element instanceof TextElement)) { - return null; - } - return ((TextElement) element).getValue(); - } - - /** - * Convenience method to get the value of an Assets element without traversing the Elements map. - * - * @param codename The element codename to get the Asset list of from this ContentItem. - * @return A list of {@link Asset} objects. Returns an empty collection if the element does not exist, or - * if it is not an {@link AssetsElement}. - */ - public List getAssets(String codename) { - Element element = elements.get(codename); - if (element == null) { - return Collections.emptyList(); - } - if (!(element instanceof AssetsElement)) { - return Collections.emptyList(); - } - return ((AssetsElement) element).getValue(); - } - - /** - * Convenience method to retrieve the ContentItem from linked items. - * - * @param codename The {@link ContentItem} codename of the linked item. - * @return The {@link ContentItem}. Returns null if it was not included in the response. - */ - public ContentItem getLinkedItem(String codename) { - //This shouldn't happen if this is de-serialized from Jackson, but protecting against the NPE for unexpected - //usages. - if (linkedItemProvider == null) { - return null; - } - return linkedItemProvider.getLinkedItems().get(codename); - } - - /** - * Returns a new instance of T by mapping fields to elements in this content item. Element fields are mapped - * by automatically CamelCasing and checking for equality, unless otherwise annotated by an {@link ElementMapping} - * annotation. T must have a default constructor and have standard setter methods. - * When passing in Object.class, the type returned will be an instance of the class registered with the - * {@link DeliveryClient} that is annotated with {@link ContentItemMapping} that matches the - * {@link System#type} of this ContentItem (however still returned as type Object). - *

- * If {@link Object} is passed in, the {@link StronglyTypedContentItemConverter} will cast this ContentItem to a - * type that is mapped this ContentItem's {@link System#type} from a previous registration via the registration has - * been done, then this same instance of ContentItem will be returned. Invoking {@link #castToDefault()} is the - * same as invoking this method with {@link Object}. - * - * @param tClass The class which a new instance should be returned from using this ContentItem. - * @param The type of class which will be returned. - * @return An instance of T with data mapped from this {@link ContentItem}. - * @see DeliveryClient#registerType(Class) - * @see DeliveryClient#registerType(String, Class) - * @see ContentItemMapping - * @see ElementMapping - * @see StronglyTypedContentItemConverter - */ - public T castTo(Class tClass) { - return stronglyTypedContentItemConverter.convert(this, linkedItemProvider.getLinkedItems(), tClass); - } - - /** - * Returns a new instance by mapping fields to elements in this content item. Element fields are mapped - * by automatically CamelCasing and checking for equality, unless otherwise annotated by an {@link ElementMapping} - * annotation. The type returned will be an instance of the class registered with the {@link DeliveryClient} that - * is annotated with {@link ContentItemMapping} that matches the {@link System#type} of this ContentItem - * (however still returned as type Object). - *

- * If no registration has been done, then this same instance of ContentItem will be returned. - * - * @return An instance with data mapped from this {@link ContentItem}. - * @see #castTo(Class) - * @see DeliveryClient#registerType(Class) - * @see DeliveryClient#registerType(String, Class) - * @see ContentItemMapping - * @see ElementMapping - * @see StronglyTypedContentItemConverter - */ - public Object castToDefault() { - return this.castTo(Object.class); - } - - /** - * Returns a new instance by mapping fields to elements in this content item. Element fields are mapped - * by automatically CamelCasing and checking for equality, unless otherwise annotated by an {@link ElementMapping} - * annotation. The type returned will be an instance of the class registered with the {@link DeliveryClient} that - * that matches the {@link System#type} provided. - *

- * If no registration has been done, then this same instance of ContentItem will be returned. - * - * @param contentItemSystemType The contentItemSystemType to match this ContentItem too. - * @return An instance with data mapped from this {@link ContentItem}. - * @see #castTo(Class) - * @see DeliveryClient#registerType(Class) - * @see DeliveryClient#registerType(String, Class) - * @see ContentItemMapping - * @see ElementMapping - * @see StronglyTypedContentItemConverter - */ - public Object castTo(String contentItemSystemType) { - return stronglyTypedContentItemConverter.convert( - this, linkedItemProvider.getLinkedItems(), contentItemSystemType); - } - - void setLinkedItemProvider(LinkedItemProvider linkedItemProvider) { - this.linkedItemProvider = linkedItemProvider; - } - - void setStronglyTypedContentItemConverter(StronglyTypedContentItemConverter stronglyTypedContentItemConverter) { - this.stronglyTypedContentItemConverter = stronglyTypedContentItemConverter; - } -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * Object model description of a single content item object. + * + * @see + * Kontent.ai API reference - Content item object + */ +@lombok.Data +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor +@lombok.Builder +@lombok.EqualsAndHashCode(exclude = {"linkedItemProvider", "stronglyTypedContentItemConverter"}) +@lombok.ToString(exclude = {"linkedItemProvider", "stronglyTypedContentItemConverter"}) +public class ContentItem { + + /** + * {@link System} attributes of the content item. + * + * @param system New value for System attributes of this content item. + * @return The System attributes of this content item. + */ + @JsonProperty("system") + System system; + + /** + * Content type elements in the content item. These are keyed by the codename of the element. + *

+ * Note: The order of the {@link Element} objects might not match the order in the Kontent.ai UI. + * + * @return Map of this ContentItem's {@link Element} objects. + */ + @JsonProperty("elements") + Map elements; + + @JsonIgnore + LinkedItemProvider linkedItemProvider; + + @JsonIgnore + private StronglyTypedContentItemConverter stronglyTypedContentItemConverter; + + /** + * Content type elements in the content item. These are keyed by the codename of the element. + *

+ * Note: The order of the {@link Element} objects might not match the order in the Kontent.ai UI. + * + * @param elements New value for this ContentItem's {@link Element} objects. + */ + public void setElements(Map elements) { + this.elements = elements; + elements.forEach((s, element) -> element.setParent(this)); + } + + /** + * Convenience method to get the value of a Text or Rich text element without traversing the Elements map. + * + * @param codename The element codename to retrieve the String rendering of from this ContentItem. + * @return The value of the element. Returns null if the element does not exist, or if it is not a + * {@link TextElement} or {@link RichTextElement}. + */ + public String getString(String codename) { + Element element = elements.get(codename); + if (element == null) { + return null; + } + if (!(element instanceof TextElement)) { + return null; + } + return ((TextElement) element).getValue(); + } + + /** + * Convenience method to get the value of an Assets element without traversing the Elements map. + * + * @param codename The element codename to get the Asset list of from this ContentItem. + * @return A list of {@link Asset} objects. Returns an empty collection if the element does not exist, or + * if it is not an {@link AssetsElement}. + */ + public List getAssets(String codename) { + Element element = elements.get(codename); + if (element == null) { + return Collections.emptyList(); + } + if (!(element instanceof AssetsElement)) { + return Collections.emptyList(); + } + return ((AssetsElement) element).getValue(); + } + + /** + * Convenience method to retrieve the ContentItem from linked items. + * + * @param codename The {@link ContentItem} codename of the linked item. + * @return The {@link ContentItem}. Returns null if it was not included in the response. + */ + public ContentItem getLinkedItem(String codename) { + //This shouldn't happen if this is de-serialized from Jackson, but protecting against the NPE for unexpected + //usages. + if (linkedItemProvider == null) { + return null; + } + return linkedItemProvider.getLinkedItems().get(codename); + } + + /** + * Returns a new instance of T by mapping fields to elements in this content item. Element fields are mapped + * by automatically CamelCasing and checking for equality, unless otherwise annotated by an {@link ElementMapping} + * annotation. T must have a default constructor and have standard setter methods. + * When passing in Object.class, the type returned will be an instance of the class registered with the + * {@link DeliveryClient} that is annotated with {@link ContentItemMapping} that matches the + * {@link System#type} of this ContentItem (however still returned as type Object). + *

+ * If {@link Object} is passed in, the {@link StronglyTypedContentItemConverter} will cast this ContentItem to a + * type that is mapped this ContentItem's {@link System#type} from a previous registration via the registration has + * been done, then this same instance of ContentItem will be returned. Invoking {@link #castToDefault()} is the + * same as invoking this method with {@link Object}. + * + * @param tClass The class which a new instance should be returned from using this ContentItem. + * @param The type of class which will be returned. + * @return An instance of T with data mapped from this {@link ContentItem}. + * @see DeliveryClient#registerType(Class) + * @see DeliveryClient#registerType(String, Class) + * @see ContentItemMapping + * @see ElementMapping + * @see StronglyTypedContentItemConverter + */ + public T castTo(Class tClass) { + return stronglyTypedContentItemConverter.convert(this, linkedItemProvider.getLinkedItems(), tClass); + } + + /** + * Returns a new instance by mapping fields to elements in this content item. Element fields are mapped + * by automatically CamelCasing and checking for equality, unless otherwise annotated by an {@link ElementMapping} + * annotation. The type returned will be an instance of the class registered with the {@link DeliveryClient} that + * is annotated with {@link ContentItemMapping} that matches the {@link System#type} of this ContentItem + * (however still returned as type Object). + *

+ * If no registration has been done, then this same instance of ContentItem will be returned. + * + * @return An instance with data mapped from this {@link ContentItem}. + * @see #castTo(Class) + * @see DeliveryClient#registerType(Class) + * @see DeliveryClient#registerType(String, Class) + * @see ContentItemMapping + * @see ElementMapping + * @see StronglyTypedContentItemConverter + */ + public Object castToDefault() { + return this.castTo(Object.class); + } + + /** + * Returns a new instance by mapping fields to elements in this content item. Element fields are mapped + * by automatically CamelCasing and checking for equality, unless otherwise annotated by an {@link ElementMapping} + * annotation. The type returned will be an instance of the class registered with the {@link DeliveryClient} that + * that matches the {@link System#type} provided. + *

+ * If no registration has been done, then this same instance of ContentItem will be returned. + * + * @param contentItemSystemType The contentItemSystemType to match this ContentItem too. + * @return An instance with data mapped from this {@link ContentItem}. + * @see #castTo(Class) + * @see DeliveryClient#registerType(Class) + * @see DeliveryClient#registerType(String, Class) + * @see ContentItemMapping + * @see ElementMapping + * @see StronglyTypedContentItemConverter + */ + public Object castTo(String contentItemSystemType) { + return stronglyTypedContentItemConverter.convert( + this, linkedItemProvider.getLinkedItems(), contentItemSystemType); + } + + void setLinkedItemProvider(LinkedItemProvider linkedItemProvider) { + this.linkedItemProvider = linkedItemProvider; + } + + void setStronglyTypedContentItemConverter(StronglyTypedContentItemConverter stronglyTypedContentItemConverter) { + this.stronglyTypedContentItemConverter = stronglyTypedContentItemConverter; + } +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/ContentItemResponse.java b/delivery-sdk/src/main/java/kontent/ai/delivery/ContentItemResponse.java index 3c272d0b..1747940b 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/ContentItemResponse.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/ContentItemResponse.java @@ -1,128 +1,129 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; -import java.util.Map; - -/** - * Content item listing response from an invocation of {@link DeliveryClient#getItem(String)}, or - * {@link DeliveryClient#getItem(String, List)}. - * - * @see - * Kontent.ai API reference - Content item object - * @see - * Kontent.ai API reference - View a content item - * @see ContentItem - * @see DeliveryClient#getItem(String) - * @see DeliveryClient#getItem(String, List) - */ -@lombok.Getter -@lombok.ToString(exclude = "stronglyTypedContentItemConverter") -@lombok.EqualsAndHashCode(exclude = "stronglyTypedContentItemConverter") -@lombok.NoArgsConstructor -@lombok.AllArgsConstructor -@lombok.Builder -public class ContentItemResponse implements LinkedItemProvider { - - /** - * The {@link ContentItem} returned by this ContentItemResponse. - * - * @see - * Kontent.ai API reference - Content item object - * @see - * Kontent.ai API reference - View a content item - * @return The {@link ContentItem} of this ContentItemResponse. - */ - @JsonProperty("item") - ContentItem item; - - /** - * A map of content items used in linked item and Rich text elements. - * - * @see - * Kontent.ai API reference - Linked items - * @see - * Kontent.ai API reference - Content item object - * @see - * Kontent.ai API reference - View a content item - * @return The linked {@link ContentItem}s referenced in this response. - */ - @JsonProperty("modular_content") - Map linkedItems; - - @JsonIgnore - private StronglyTypedContentItemConverter stronglyTypedContentItemConverter; - - /** - * Returns a new instance of T by mapping fields to elements in this response's {@link #getItem()}. Element fields - * are mapped by automatically CamelCasing and checking for equality, unless otherwise annotated by an - * {@link ElementMapping} annotation. T must have a default constructor and have standard setter methods. When - * passing in Object.class, the type returned will be an instance of the class registered with the - * {@link DeliveryClient} that is annotated with {@link ContentItemMapping} that matches the - * {@link System#type} of this ContentItem (however still returned as type Object). - *

- * If {@link Object} is passed in, the {@link StronglyTypedContentItemConverter} will cast this ContentItem to a - * type that is mapped this ContentItem's {@link System#type} from a previous registration via the - * {@link DeliveryClient#registerType(Class)} or {@link DeliveryClient#registerType(String, Class)} methods. If no - * registration has been done, then this same instance of ContentItem will be returned. - * - * @param tClass The class which a new instance should be returned from using this ContentItem. - * @param The type of class which will be returned. - * @return An instance of T with data mapped from the {@link ContentItem} in this response. - * @see DeliveryClient#registerType(Class) - * @see DeliveryClient#registerType(String, Class) - * @see ContentItemMapping - * @see ElementMapping - * @see StronglyTypedContentItemConverter - */ - public T castTo(Class tClass) { - return stronglyTypedContentItemConverter.convert(item, this.getLinkedItems(), tClass); - } - - void setItem(ContentItem item) { - this.item = item; - item.setLinkedItemProvider(this); - } - - void setLinkedItems(Map linkedItems) { - this.linkedItems = linkedItems; - linkedItems.values().forEach(contentItem -> contentItem.setLinkedItemProvider(this)); - } - - ContentItemResponse setStronglyTypedContentItemConverter(StronglyTypedContentItemConverter stronglyTypedContentItemConverter) { - this.stronglyTypedContentItemConverter = stronglyTypedContentItemConverter; - item.setStronglyTypedContentItemConverter(stronglyTypedContentItemConverter); - if (linkedItems != null) { - for (ContentItem linkedItem : linkedItems.values()) { - linkedItem.setStronglyTypedContentItemConverter(stronglyTypedContentItemConverter); - } - } - return this; - } -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * Content item listing response from an invocation of {@link DeliveryClient#getItem(String)}, or + * {@link DeliveryClient#getItem(String, List)}. + * + * @see + * Kontent.ai API reference - Content item object + * @see + * Kontent.ai API reference - View a content item + * @see ContentItem + * @see DeliveryClient#getItem(String) + * @see DeliveryClient#getItem(String, List) + */ +@lombok.Getter +@lombok.ToString(exclude = "stronglyTypedContentItemConverter") +@lombok.EqualsAndHashCode(exclude = "stronglyTypedContentItemConverter") +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor +@lombok.Builder +public class ContentItemResponse implements LinkedItemProvider { + + /** + * The {@link ContentItem} returned by this ContentItemResponse. + * + * @see + * Kontent.ai API reference - Content item object + * @see + * Kontent.ai API reference - View a content item + * @return The {@link ContentItem} of this ContentItemResponse. + */ + @JsonProperty("item") + ContentItem item; + + /** + * A map of content items used in linked item and Rich text elements. + * + * @see + * Kontent.ai API reference - Linked items + * @see + * Kontent.ai API reference - Content item object + * @see + * Kontent.ai API reference - View a content item + * @return The linked {@link ContentItem}s referenced in this response. + */ + @JsonProperty("modular_content") + Map linkedItems; + + @JsonIgnore + private StronglyTypedContentItemConverter stronglyTypedContentItemConverter; + + /** + * Returns a new instance of T by mapping fields to elements in this response's {@link #getItem()}. Element fields + * are mapped by automatically CamelCasing and checking for equality, unless otherwise annotated by an + * {@link ElementMapping} annotation. T must have a default constructor and have standard setter methods. When + * passing in Object.class, the type returned will be an instance of the class registered with the + * {@link DeliveryClient} that is annotated with {@link ContentItemMapping} that matches the + * {@link System#type} of this ContentItem (however still returned as type Object). + *

+ * If {@link Object} is passed in, the {@link StronglyTypedContentItemConverter} will cast this ContentItem to a + * type that is mapped this ContentItem's {@link System#type} from a previous registration via the + * {@link DeliveryClient#registerType(Class)} or {@link DeliveryClient#registerType(String, Class)} methods. If no + * registration has been done, then this same instance of ContentItem will be returned. + * + * @param tClass The class which a new instance should be returned from using this ContentItem. + * @param The type of class which will be returned. + * @return An instance of T with data mapped from the {@link ContentItem} in this response. + * @see DeliveryClient#registerType(Class) + * @see DeliveryClient#registerType(String, Class) + * @see ContentItemMapping + * @see ElementMapping + * @see StronglyTypedContentItemConverter + */ + public T castTo(Class tClass) { + return stronglyTypedContentItemConverter.convert(item, this.getLinkedItems(), tClass); + } + + void setItem(ContentItem item) { + this.item = item; + item.setLinkedItemProvider(this); + } + + void setLinkedItems(Map linkedItems) { + this.linkedItems = linkedItems; + linkedItems.values().forEach(contentItem -> contentItem.setLinkedItemProvider(this)); + } + + ContentItemResponse setStronglyTypedContentItemConverter(StronglyTypedContentItemConverter stronglyTypedContentItemConverter) { + this.stronglyTypedContentItemConverter = stronglyTypedContentItemConverter; + item.setStronglyTypedContentItemConverter(stronglyTypedContentItemConverter); + if (linkedItems != null) { + for (ContentItem linkedItem : linkedItems.values()) { + linkedItem.setStronglyTypedContentItemConverter(stronglyTypedContentItemConverter); + } + } + return this; + } +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/DateTimeElement.java b/delivery-sdk/src/main/java/kontent/ai/delivery/DateTimeElement.java index 9d54fed6..a4a135d2 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/DateTimeElement.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/DateTimeElement.java @@ -1,60 +1,61 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.time.ZonedDateTime; - -/** - * Object model for Date & time elements. - * - * @see Asset - * @see - * Kontent.ai API reference - Date time - * @see - * Kontent.ai API reference - Content item object - */ -@lombok.Getter -@lombok.Setter -@lombok.ToString(callSuper = true) -@lombok.EqualsAndHashCode(callSuper = true) -public class DateTimeElement extends Element { - - static final String TYPE_VALUE = "date_time"; - - /** - * The value of a Date & time element is a string in the ISO 8601 format. If empty, the value is null. - * - * @param value New value of the {@link ZonedDateTime} of this element. - * @return A {@link ZonedDateTime} instance representing the original ISO 8601 string. - */ - @JsonProperty("value") - ZonedDateTime value; - - public DateTimeElement() { - setType(TYPE_VALUE); - } -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.time.ZonedDateTime; + +/** + * Object model for Date & time elements. + * + * @see Asset + * @see + * Kontent.ai API reference - Date time + * @see + * Kontent.ai API reference - Content item object + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString(callSuper = true) +@lombok.EqualsAndHashCode(callSuper = true) +public class DateTimeElement extends Element { + + static final String TYPE_VALUE = "date_time"; + + /** + * The value of a Date & time element is a string in the ISO 8601 format. If empty, the value is null. + * + * @param value New value of the {@link ZonedDateTime} of this element. + * @return A {@link ZonedDateTime} instance representing the original ISO 8601 string. + */ + @JsonProperty("value") + ZonedDateTime value; + + public DateTimeElement() { + setType(TYPE_VALUE); + } +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/Element.java b/delivery-sdk/src/main/java/kontent/ai/delivery/Element.java index bcb2be35..bef3964e 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/Element.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/Element.java @@ -1,108 +1,109 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; - -import java.util.List; - -/** - * Parent object model of individual elements - *

- * When retrieving content items or content types, you get an elements collection as a part of the retrieved item or - * type. - */ -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -@JsonSubTypes({ - @JsonSubTypes.Type(value = TextElement.class, name = TextElement.TYPE_VALUE), - @JsonSubTypes.Type(value = RichTextElement.class, name = RichTextElement.TYPE_VALUE), - @JsonSubTypes.Type(value = MultipleChoiceElement.class, name = MultipleChoiceElement.TYPE_VALUE), - @JsonSubTypes.Type(value = NumberElement.class, name = NumberElement.TYPE_VALUE), - @JsonSubTypes.Type(value = DateTimeElement.class, name = DateTimeElement.TYPE_VALUE), - @JsonSubTypes.Type(value = AssetsElement.class, name = AssetsElement.TYPE_VALUE), - @JsonSubTypes.Type(value = LinkedItem.class, name = LinkedItem.TYPE_VALUE), - @JsonSubTypes.Type(value = TaxonomyElement.class, name = TaxonomyElement.TYPE_VALUE), - @JsonSubTypes.Type(value = UrlSlugElement.class, name = UrlSlugElement.TYPE_VALUE), - @JsonSubTypes.Type(value = CustomElement.class, name = CustomElement.TYPE_VALUE) -}) -@lombok.Getter -@lombok.Setter -@lombok.ToString(exclude = "parent") -@lombok.EqualsAndHashCode(exclude = "parent") -@lombok.NoArgsConstructor -public abstract class Element { - - /** - * Type of the element - *

- * Valid values: text, rich_text, number, multiple_choice, date_time, asset, modular_content - * ({@link LinkedItem}), taxonomy, url_slug. - * - * @param type the type of element - * @return the codename for this element type - */ - @JsonProperty("type") - String type; - - /** - * Display name of the element - * - * @param name the name of this element - * @return the display name of this element - */ - @JsonProperty("name") - String name; - - /** - * The codename for this element - *

- * Note: This is only populated when querying an individual content type element. - * - * @param codeName the codename of this element - * @return codename for this content type element as defined in a content type - * @see DeliveryClient#getContentTypeElement(String, String) - * @see DeliveryClient#getContentTypeElement(String, String, List) - */ - @JsonProperty("codename") - String codeName; - - /** - * A reference to the parent ContentItem to this element. - * - * @param parent the parent to this - * @return the parent to this - */ - @JsonIgnore - ContentItem parent; - - /** - * Returns the value of the element. - * @return The value of the element. - */ - public abstract T getValue(); -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import java.io.Serializable; +import java.util.List; + +/** + * Parent object model of individual elements + *

+ * When retrieving content items or content types, you get an elements collection as a part of the retrieved item or + * type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonSubTypes({ + @JsonSubTypes.Type(value = TextElement.class, name = TextElement.TYPE_VALUE), + @JsonSubTypes.Type(value = RichTextElement.class, name = RichTextElement.TYPE_VALUE), + @JsonSubTypes.Type(value = MultipleChoiceElement.class, name = MultipleChoiceElement.TYPE_VALUE), + @JsonSubTypes.Type(value = NumberElement.class, name = NumberElement.TYPE_VALUE), + @JsonSubTypes.Type(value = DateTimeElement.class, name = DateTimeElement.TYPE_VALUE), + @JsonSubTypes.Type(value = AssetsElement.class, name = AssetsElement.TYPE_VALUE), + @JsonSubTypes.Type(value = LinkedItem.class, name = LinkedItem.TYPE_VALUE), + @JsonSubTypes.Type(value = TaxonomyElement.class, name = TaxonomyElement.TYPE_VALUE), + @JsonSubTypes.Type(value = UrlSlugElement.class, name = UrlSlugElement.TYPE_VALUE), + @JsonSubTypes.Type(value = CustomElement.class, name = CustomElement.TYPE_VALUE) +}) +@lombok.Getter +@lombok.Setter +@lombok.ToString(exclude = "parent") +@lombok.EqualsAndHashCode(exclude = "parent") +@lombok.NoArgsConstructor +public abstract class Element { + + /** + * Type of the element + *

+ * Valid values: text, rich_text, number, multiple_choice, date_time, asset, modular_content + * ({@link LinkedItem}), taxonomy, url_slug. + * + * @param type the type of element + * @return the codename for this element type + */ + @JsonProperty("type") + String type; + + /** + * Display name of the element + * + * @param name the name of this element + * @return the display name of this element + */ + @JsonProperty("name") + String name; + + /** + * The codename for this element + *

+ * Note: This is only populated when querying an individual content type element. + * + * @param codeName the codename of this element + * @return codename for this content type element as defined in a content type + * @see DeliveryClient#getContentTypeElement(String, String) + * @see DeliveryClient#getContentTypeElement(String, String, List) + */ + @JsonProperty("codename") + String codeName; + + /** + * A reference to the parent ContentItem to this element. + * + * @param parent the parent to this + * @return the parent to this + */ + @JsonIgnore + ContentItem parent; + + /** + * Returns the value of the element. + * @return The value of the element. + */ + public abstract T getValue(); +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/Image.java b/delivery-sdk/src/main/java/kontent/ai/delivery/Image.java index 6d7fb4d3..e5c62883 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/Image.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/Image.java @@ -1,72 +1,74 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Object model for Image elements - *

- * Images associated with rich text elements - * - * @see RichTextElement - */ -@lombok.Getter -@lombok.Setter -@lombok.ToString -@lombok.EqualsAndHashCode -@lombok.NoArgsConstructor -public class Image { - - /** - * ID of the image - * - * @param imageId Sets the imageId of this - * @return This imageId - */ - @JsonProperty("image_id") - String imageId; - - /** - * Description of the image - *

- * Used for the alt attribute of an <img> tag. - * - * @param description Sets the description of this - * @return The image description of this - */ - @JsonProperty("description") - String description; - - /** - * Absolute URL for the image - * - * @param url Sets the url of this - * @return An absolute URL image hosted by Kontent.ai - */ - @JsonProperty("url") - String url; - -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; + +/** + * Object model for Image elements + *

+ * Images associated with rich text elements + * + * @see RichTextElement + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode +@lombok.NoArgsConstructor +public class Image { + + /** + * ID of the image + * + * @param imageId Sets the imageId of this + * @return This imageId + */ + @JsonProperty("image_id") + String imageId; + + /** + * Description of the image + *

+ * Used for the alt attribute of an <img> tag. + * + * @param description Sets the description of this + * @return The image description of this + */ + @JsonProperty("description") + String description; + + /** + * Absolute URL for the image + * + * @param url Sets the url of this + * @return An absolute URL image hosted by Kontent.ai + */ + @JsonProperty("url") + String url; + +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/Link.java b/delivery-sdk/src/main/java/kontent/ai/delivery/Link.java index 969f1a7c..a57a095f 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/Link.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/Link.java @@ -1,72 +1,74 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Object model for Link elements - *

- * Links associated with rich text elements - * - * @see RichTextElement - */ -@lombok.Getter -@lombok.Setter -@lombok.ToString -@lombok.EqualsAndHashCode -@lombok.NoArgsConstructor -public class Link { - - /** - * Content type of the content item - * - * @param type Sets the type of this. - * @return The content item type codename. - */ - @JsonProperty("type") - String type; - - /** - * Display name of the element - * - * @param codename Sets the codename of this. - * @return The codename of the link element. - */ - @JsonProperty("codename") - String codename; - - /** - * URL slug of the content item - *

- * Empty string if the content item's type does not use a URL slug element - * - * @param urlSlug Sets the urlSlug of this. - * @return URL slug of the content item. - */ - @JsonProperty("url_slug") - String urlSlug; - -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; + +/** + * Object model for Link elements + *

+ * Links associated with rich text elements + * + * @see RichTextElement + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode +@lombok.NoArgsConstructor +public class Link { + + /** + * Content type of the content item + * + * @param type Sets the type of this. + * @return The content item type codename. + */ + @JsonProperty("type") + String type; + + /** + * Display name of the element + * + * @param codename Sets the codename of this. + * @return The codename of the link element. + */ + @JsonProperty("codename") + String codename; + + /** + * URL slug of the content item + *

+ * Empty string if the content item's type does not use a URL slug element + * + * @param urlSlug Sets the urlSlug of this. + * @return URL slug of the content item. + */ + @JsonProperty("url_slug") + String urlSlug; + +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/NameValuePair.java b/delivery-sdk/src/main/java/kontent/ai/delivery/NameValuePair.java index d62214fa..f0cfc206 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/NameValuePair.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/NameValuePair.java @@ -1,37 +1,37 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.io.Serializable; - -@Data -@AllArgsConstructor -public class NameValuePair implements Serializable { - private String name; - private String value; -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.io.Serializable; + +@Data +@AllArgsConstructor +public class NameValuePair { + private String name; + private String value; +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/Option.java b/delivery-sdk/src/main/java/kontent/ai/delivery/Option.java index b47071bf..2d9414a6 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/Option.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/Option.java @@ -1,57 +1,59 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Object model for option values in a {@link MultipleChoiceElement} - */ -@lombok.Getter -@lombok.Setter -@lombok.ToString -@lombok.EqualsAndHashCode -@lombok.NoArgsConstructor -public class Option { - - /** - * The display name of the option - * - * @param name Sets the display name of this. - * @return The name of the option. - */ - @JsonProperty("name") - String name; - - /** - * The codename of the option - * - * @param codename Sets the codename of this. - * @return The codename of the option. - */ - @JsonProperty("codename") - String codename; - -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; + +/** + * Object model for option values in a {@link MultipleChoiceElement} + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode +@lombok.NoArgsConstructor +public class Option { + + /** + * The display name of the option + * + * @param name Sets the display name of this. + * @return The name of the option. + */ + @JsonProperty("name") + String name; + + /** + * The codename of the option + * + * @param codename Sets the codename of this. + * @return The codename of the option. + */ + @JsonProperty("codename") + String codename; + +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/StronglyTypedContentItemConverter.java b/delivery-sdk/src/main/java/kontent/ai/delivery/StronglyTypedContentItemConverter.java index 6d72dd80..461d7637 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/StronglyTypedContentItemConverter.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/StronglyTypedContentItemConverter.java @@ -1,362 +1,363 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.madrobot.beans.BeanInfo; -import com.madrobot.beans.IntrospectionException; -import com.madrobot.beans.Introspector; -import com.madrobot.beans.PropertyDescriptor; -import io.github.classgraph.ClassGraph; -import io.github.classgraph.ClassInfoList; -import io.github.classgraph.ScanResult; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.*; -import java.util.*; - -@lombok.extern.slf4j.Slf4j -public class StronglyTypedContentItemConverter { - - private HashMap contentTypeToClassNameMapping = new HashMap<>(); - private HashMap classNameToContentTypeMapping = new HashMap<>(); - private HashMap typeNameToInlineResolverMapping = new HashMap<>(); - - protected StronglyTypedContentItemConverter() { - //protected constructor - } - - protected void registerType(String contentType, Class clazz) { - contentTypeToClassNameMapping.put(contentType, clazz.getName()); - classNameToContentTypeMapping.put(clazz.getName(), contentType); - } - - protected void registerType(Class clazz) { - ContentItemMapping clazzContentItemMapping = clazz.getAnnotation(ContentItemMapping.class); - if (clazzContentItemMapping == null) { - throw new IllegalArgumentException("Passed in class must be annotated with @ContentItemMapping, " + - "if this is not possible, please use registerType(String, Class)"); - } - registerType(clazzContentItemMapping.value(), clazz); - log.debug("Registered type for {}", clazz.getSimpleName()); - } - - protected String getContentType(Class tClass) { - if (classNameToContentTypeMapping.containsKey(tClass.getName())) { - return classNameToContentTypeMapping.get(tClass.getName()); - } - return null; - } - - protected void registerInlineContentItemsResolver(InlineContentItemsResolver resolver) { - typeNameToInlineResolverMapping.put(resolver.getType().getTypeName(), resolver); - } - - protected InlineContentItemsResolver getResolverForType(String contentType) { - if (contentTypeToClassNameMapping.containsKey(contentType) && - typeNameToInlineResolverMapping.containsKey(contentTypeToClassNameMapping.get(contentType))) { - return typeNameToInlineResolverMapping.get(contentTypeToClassNameMapping.get(contentType)); - } - return null; - } - - protected InlineContentItemsResolver getResolverForType(ContentItem contentItem) { - System system = contentItem.getSystem(); - if (system != null) { - return getResolverForType(system.getType()); - } - return null; - } - - /** - * Not working on Android platform because of JVM and Dalvik differences, please use {@link DeliveryClient#registerType(Class)} instead - * @param basePackage name of the base package - */ - protected void scanClasspathForMappings(String basePackage) { - try (ScanResult scanResult = new ClassGraph() - .enableAllInfo() - .acceptPackages(basePackage) - .scan()) { - ClassInfoList mappings = scanResult.getClassesWithAnnotation(ContentItemMapping.class.getName()); - mappings.loadClasses().forEach(classWithAnnotation -> { - ContentItemMapping contentItemMapping = classWithAnnotation.getAnnotation(ContentItemMapping.class); - registerType(contentItemMapping.value(), classWithAnnotation); - }); - - ClassInfoList inlineResolvers = scanResult.getSubclasses(InlineContentItemsResolver.class.getName()); - inlineResolvers.loadClasses(InlineContentItemsResolver.class).forEach(subclass -> { - try { - registerInlineContentItemsResolver(subclass.getConstructor().newInstance()); - } catch (NoSuchMethodException | - IllegalAccessException | - InvocationTargetException | - InstantiationException e) { - // No default constructor, no InlineContentItemsResolver. - } - }); - } - } - - Object convert(ContentItem item, Map linkedItems, String contentType) { - String className = contentTypeToClassNameMapping.get(contentType); - Class mappingClass; - try { - mappingClass = Class.forName(className); - } catch (ClassNotFoundException e) { - return item; - } - - if (mappingClass == null) { - return item; - } - - return convert(item, linkedItems, mappingClass); - } - - T convert(ContentItem item, Map linkedItems, Class tClass) { - if (tClass == Object.class) { - String className = contentTypeToClassNameMapping.get(item.getSystem().getType()); - if (className == null) { - return (T) item; - } - Class mappingClass = null; - try { - mappingClass = Class.forName(className); - } catch (ClassNotFoundException e) { - return (T) item; - } - if (mappingClass == null) { - return (T) item; - } - return (T) convert(item, linkedItems, mappingClass); - } - if (tClass == ContentItem.class) { - return (T) item; - } - T bean = null; - try { - //Invoke the default constructor - bean = tClass.getConstructor().newInstance(); - - //Get the bean properties - Field[] fields = tClass.getDeclaredFields(); - - //Inject mappings - for (Field field : fields) { - Object value = getValueForField(item, linkedItems, bean, field); - if (value != null) { - Optional propertyDescriptor = getPropertyDescriptor(bean, field); - if (propertyDescriptor.isPresent()) { - propertyDescriptor.get().getWriteMethod().invoke(bean, value); - } - } - } - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { - handleReflectionException(e); - } - //Return bean - return bean; - } - - private Object getValueForField( - ContentItem item, Map linkedItems, Object bean, Field field) { - //Inject System object - if (field.getType() == System.class) { - return item.getSystem(); - } - //Explicit checks - //Check to see if this is an explicitly mapped Element - ElementMapping elementMapping = field.getAnnotation(ElementMapping.class); - if (elementMapping != null && item.getElements().containsKey(elementMapping.value())) { - return item.getElements().get(elementMapping.value()).getValue(); - } - //Check to see if this is an explicitly mapped ContentItem - ContentItemMapping contentItemMapping = field.getAnnotation(ContentItemMapping.class); - if (contentItemMapping != null && - isListOrMap(field.getType()) && - item.getElements().containsKey(contentItemMapping.value()) && - item.getElements().get(contentItemMapping.value()) instanceof LinkedItem) { - LinkedItem linkedItemElement = - (LinkedItem) item.getElements().get(contentItemMapping.value()); - Map referencedLinkedItems = new LinkedHashMap<>(); - for (String codename : linkedItemElement.getValue()) { - referencedLinkedItems.put(codename, linkedItems.get(codename)); - } - return getCastedLinkedItemsForListOrMap(bean, field, referencedLinkedItems); - } - if (contentItemMapping != null && linkedItems.containsKey(contentItemMapping.value())) { - return getCastedLinkedItemsForField(field.getType(), contentItemMapping.value(), linkedItems); - } - - //Implicit checks - String candidateCodename = fromCamelCase(field.getName()); - //Check to see if this is an implicitly mapped Element - if (item.getElements().containsKey(candidateCodename)) { - return item.getElements().get(candidateCodename).getValue(); - } - //Check to see if this is an implicitly mapped ContentItem - if (linkedItems.containsKey(candidateCodename)) { - return getCastedLinkedItemsForField(field.getType(), candidateCodename, linkedItems); - } - - //Check to see if this is a collection of implicitly mapped ContentItem - if (isListOrMap(field.getType())) { - return getCastedLinkedItemsForListOrMap(bean, field, linkedItems); - } - return null; - } - - private Object getCastedLinkedItemsForField( - Class clazz, String codename, Map linkedItems) { - ContentItem linkedItemsItem = linkedItems.get(codename); - if (clazz == ContentItem.class) { - return linkedItemsItem; - } - Map linkedItemsForRecursion = - copyLinkedItemsWithExclusion(linkedItems, codename); - return convert(linkedItemsItem, linkedItemsForRecursion, clazz); - } - - private Object getCastedLinkedItemsForListOrMap( - Object bean, Field field, Map linkedItems) { - Type type = getType(bean, field); - if (type == null) { - // We have failed to get the type, probably due to a missing setter, skip this field - log.debug("Failed to get type from {} (probably due to a missing setter), {} skipped", bean, field); - return null; - } - if (type == ContentItem.class) { - return castCollection(field.getType(), linkedItems); - } - Class listClass = (Class) type; - String contentType = null; - ContentItemMapping clazzContentItemMapping = listClass.getAnnotation(ContentItemMapping.class); - if (clazzContentItemMapping != null) { - contentType = clazzContentItemMapping.value(); - } - if (contentType == null && classNameToContentTypeMapping.containsKey(listClass.getName())) { - contentType = classNameToContentTypeMapping.get(listClass.getName()); - } - if (contentType != null) { - HashMap convertedLinkedItems = new HashMap<>(); - for (Map.Entry entry : linkedItems.entrySet()) { - if (entry.getValue() != null && contentType.equals(entry.getValue().getSystem().getType())) { - Map linkedItemsForRecursion = - copyLinkedItemsWithExclusion(linkedItems, entry.getKey()); - convertedLinkedItems.put(entry.getKey(), - convert(entry.getValue(), linkedItemsForRecursion, listClass)); - } - } - return castCollection(field.getType(), convertedLinkedItems); - } - return null; - } - - private static String fromCamelCase(String s) { - String regex = "([a-z])([A-Z]+)"; - String replacement = "$1_$2"; - return s.replaceAll(regex, replacement).toLowerCase(); - } - - // This function copies the linked item map while excluding an item, useful for a recursive stack - protected Map copyLinkedItemsWithExclusion( - Map orig, String excludedContentItem) { - HashMap target = new HashMap<>(); - for (Map.Entry entry : orig.entrySet()) { - if (!excludedContentItem.equals(entry.getKey())) { - target.put(entry.getKey(), entry.getValue()); - } - } - return target; - } - - private static boolean isListOrMap(Class type) { - return List.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type); - } - - private static Object castCollection(Class type, Map items) { - if (List.class.isAssignableFrom(type)) { - return new ArrayList(items.values()); - } - if (Map.class.isAssignableFrom(type)) { - return items; - } - return items; - } - - private static Type getType(Object bean, Field field) { - //Because of type erasure, we will find the setter method and get the generic types off it's arguments - Optional propertyDescriptor = getPropertyDescriptor(bean, field); - if (!propertyDescriptor.isPresent()) { - //Likely no accessors - log.debug("Property descriptor for object {} with field {} is null", bean, field); - return null; - } - - Method writeMethod = propertyDescriptor.get().getWriteMethod(); - if (writeMethod == null) { - log.debug("No write method for property {}", propertyDescriptor); - return null; - } - Type[] actualTypeArguments = ((ParameterizedType) writeMethod.getGenericParameterTypes()[0]) - .getActualTypeArguments(); - - Type type = (Map.class.isAssignableFrom(field.getType())) ? actualTypeArguments[1] : actualTypeArguments[0]; - - log.debug("Got type {} from {}", - type.getTypeName(), - String.format("%s#%s", bean.getClass().getSimpleName(), field.getName())); - - return type; - } - - @NotNull - private static Optional getPropertyDescriptor(Object bean, Field field) { - BeanInfo beanInfo = null; - try { - beanInfo = Introspector.getBeanInfo(bean.getClass()); - } catch (IntrospectionException e) { - log.debug("IntrospectionException from com.madrobot.beans for object {} with field {} is null", bean, field); - return null; - } - PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); - Optional propertyDescriptor = Arrays.stream(properties).filter(descriptor -> descriptor.getName().equals(field.getName())).findFirst(); - return propertyDescriptor; - } - - private static void handleReflectionException(Exception ex) { - log.error("Reflection exception", ex); - if (ex instanceof NoSuchMethodException) { - throw new IllegalStateException("Method not found: " + ex.getMessage()); - } - if (ex instanceof IllegalAccessException) { - throw new IllegalStateException("Could not access method: " + ex.getMessage()); - } - if (ex instanceof RuntimeException) { - throw (RuntimeException) ex; - } - - throw new UndeclaredThrowableException(ex); - } -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.madrobot.beans.BeanInfo; +import com.madrobot.beans.IntrospectionException; +import com.madrobot.beans.Introspector; +import com.madrobot.beans.PropertyDescriptor; +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ClassInfoList; +import io.github.classgraph.ScanResult; +import org.jetbrains.annotations.NotNull; + +import java.io.Serializable; +import java.lang.reflect.*; +import java.util.*; + +@lombok.extern.slf4j.Slf4j +public class StronglyTypedContentItemConverter { + + private HashMap contentTypeToClassNameMapping = new HashMap<>(); + private HashMap classNameToContentTypeMapping = new HashMap<>(); + private HashMap typeNameToInlineResolverMapping = new HashMap<>(); + + protected StronglyTypedContentItemConverter() { + //protected constructor + } + + protected void registerType(String contentType, Class clazz) { + contentTypeToClassNameMapping.put(contentType, clazz.getName()); + classNameToContentTypeMapping.put(clazz.getName(), contentType); + } + + protected void registerType(Class clazz) { + ContentItemMapping clazzContentItemMapping = clazz.getAnnotation(ContentItemMapping.class); + if (clazzContentItemMapping == null) { + throw new IllegalArgumentException("Passed in class must be annotated with @ContentItemMapping, " + + "if this is not possible, please use registerType(String, Class)"); + } + registerType(clazzContentItemMapping.value(), clazz); + log.debug("Registered type for {}", clazz.getSimpleName()); + } + + protected String getContentType(Class tClass) { + if (classNameToContentTypeMapping.containsKey(tClass.getName())) { + return classNameToContentTypeMapping.get(tClass.getName()); + } + return null; + } + + protected void registerInlineContentItemsResolver(InlineContentItemsResolver resolver) { + typeNameToInlineResolverMapping.put(resolver.getType().getTypeName(), resolver); + } + + protected InlineContentItemsResolver getResolverForType(String contentType) { + if (contentTypeToClassNameMapping.containsKey(contentType) && + typeNameToInlineResolverMapping.containsKey(contentTypeToClassNameMapping.get(contentType))) { + return typeNameToInlineResolverMapping.get(contentTypeToClassNameMapping.get(contentType)); + } + return null; + } + + protected InlineContentItemsResolver getResolverForType(ContentItem contentItem) { + System system = contentItem.getSystem(); + if (system != null) { + return getResolverForType(system.getType()); + } + return null; + } + + /** + * Not working on Android platform because of JVM and Dalvik differences, please use {@link DeliveryClient#registerType(Class)} instead + * @param basePackage name of the base package + */ + protected void scanClasspathForMappings(String basePackage) { + try (ScanResult scanResult = new ClassGraph() + .enableAllInfo() + .acceptPackages(basePackage) + .scan()) { + ClassInfoList mappings = scanResult.getClassesWithAnnotation(ContentItemMapping.class.getName()); + mappings.loadClasses().forEach(classWithAnnotation -> { + ContentItemMapping contentItemMapping = classWithAnnotation.getAnnotation(ContentItemMapping.class); + registerType(contentItemMapping.value(), classWithAnnotation); + }); + + ClassInfoList inlineResolvers = scanResult.getSubclasses(InlineContentItemsResolver.class.getName()); + inlineResolvers.loadClasses(InlineContentItemsResolver.class).forEach(subclass -> { + try { + registerInlineContentItemsResolver(subclass.getConstructor().newInstance()); + } catch (NoSuchMethodException | + IllegalAccessException | + InvocationTargetException | + InstantiationException e) { + // No default constructor, no InlineContentItemsResolver. + } + }); + } + } + + Object convert(ContentItem item, Map linkedItems, String contentType) { + String className = contentTypeToClassNameMapping.get(contentType); + Class mappingClass; + try { + mappingClass = Class.forName(className); + } catch (ClassNotFoundException e) { + return item; + } + + if (mappingClass == null) { + return item; + } + + return convert(item, linkedItems, mappingClass); + } + + T convert(ContentItem item, Map linkedItems, Class tClass) { + if (tClass == Object.class) { + String className = contentTypeToClassNameMapping.get(item.getSystem().getType()); + if (className == null) { + return (T) item; + } + Class mappingClass = null; + try { + mappingClass = Class.forName(className); + } catch (ClassNotFoundException e) { + return (T) item; + } + if (mappingClass == null) { + return (T) item; + } + return (T) convert(item, linkedItems, mappingClass); + } + if (tClass == ContentItem.class) { + return (T) item; + } + T bean = null; + try { + //Invoke the default constructor + bean = tClass.getConstructor().newInstance(); + + //Get the bean properties + Field[] fields = tClass.getDeclaredFields(); + + //Inject mappings + for (Field field : fields) { + Object value = getValueForField(item, linkedItems, bean, field); + if (value != null) { + Optional propertyDescriptor = getPropertyDescriptor(bean, field); + if (propertyDescriptor.isPresent()) { + propertyDescriptor.get().getWriteMethod().invoke(bean, value); + } + } + } + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { + handleReflectionException(e); + } + //Return bean + return bean; + } + + private Object getValueForField( + ContentItem item, Map linkedItems, Object bean, Field field) { + //Inject System object + if (field.getType() == System.class) { + return item.getSystem(); + } + //Explicit checks + //Check to see if this is an explicitly mapped Element + ElementMapping elementMapping = field.getAnnotation(ElementMapping.class); + if (elementMapping != null && item.getElements().containsKey(elementMapping.value())) { + return item.getElements().get(elementMapping.value()).getValue(); + } + //Check to see if this is an explicitly mapped ContentItem + ContentItemMapping contentItemMapping = field.getAnnotation(ContentItemMapping.class); + if (contentItemMapping != null && + isListOrMap(field.getType()) && + item.getElements().containsKey(contentItemMapping.value()) && + item.getElements().get(contentItemMapping.value()) instanceof LinkedItem) { + LinkedItem linkedItemElement = + (LinkedItem) item.getElements().get(contentItemMapping.value()); + Map referencedLinkedItems = new LinkedHashMap<>(); + for (String codename : linkedItemElement.getValue()) { + referencedLinkedItems.put(codename, linkedItems.get(codename)); + } + return getCastedLinkedItemsForListOrMap(bean, field, referencedLinkedItems); + } + if (contentItemMapping != null && linkedItems.containsKey(contentItemMapping.value())) { + return getCastedLinkedItemsForField(field.getType(), contentItemMapping.value(), linkedItems); + } + + //Implicit checks + String candidateCodename = fromCamelCase(field.getName()); + //Check to see if this is an implicitly mapped Element + if (item.getElements().containsKey(candidateCodename)) { + return item.getElements().get(candidateCodename).getValue(); + } + //Check to see if this is an implicitly mapped ContentItem + if (linkedItems.containsKey(candidateCodename)) { + return getCastedLinkedItemsForField(field.getType(), candidateCodename, linkedItems); + } + + //Check to see if this is a collection of implicitly mapped ContentItem + if (isListOrMap(field.getType())) { + return getCastedLinkedItemsForListOrMap(bean, field, linkedItems); + } + return null; + } + + private Object getCastedLinkedItemsForField( + Class clazz, String codename, Map linkedItems) { + ContentItem linkedItemsItem = linkedItems.get(codename); + if (clazz == ContentItem.class) { + return linkedItemsItem; + } + Map linkedItemsForRecursion = + copyLinkedItemsWithExclusion(linkedItems, codename); + return convert(linkedItemsItem, linkedItemsForRecursion, clazz); + } + + private Object getCastedLinkedItemsForListOrMap( + Object bean, Field field, Map linkedItems) { + Type type = getType(bean, field); + if (type == null) { + // We have failed to get the type, probably due to a missing setter, skip this field + log.debug("Failed to get type from {} (probably due to a missing setter), {} skipped", bean, field); + return null; + } + if (type == ContentItem.class) { + return castCollection(field.getType(), linkedItems); + } + Class listClass = (Class) type; + String contentType = null; + ContentItemMapping clazzContentItemMapping = listClass.getAnnotation(ContentItemMapping.class); + if (clazzContentItemMapping != null) { + contentType = clazzContentItemMapping.value(); + } + if (contentType == null && classNameToContentTypeMapping.containsKey(listClass.getName())) { + contentType = classNameToContentTypeMapping.get(listClass.getName()); + } + if (contentType != null) { + HashMap convertedLinkedItems = new HashMap<>(); + for (Map.Entry entry : linkedItems.entrySet()) { + if (entry.getValue() != null && contentType.equals(entry.getValue().getSystem().getType())) { + Map linkedItemsForRecursion = + copyLinkedItemsWithExclusion(linkedItems, entry.getKey()); + convertedLinkedItems.put(entry.getKey(), + convert(entry.getValue(), linkedItemsForRecursion, listClass)); + } + } + return castCollection(field.getType(), convertedLinkedItems); + } + return null; + } + + private static String fromCamelCase(String s) { + String regex = "([a-z])([A-Z]+)"; + String replacement = "$1_$2"; + return s.replaceAll(regex, replacement).toLowerCase(); + } + + // This function copies the linked item map while excluding an item, useful for a recursive stack + protected Map copyLinkedItemsWithExclusion( + Map orig, String excludedContentItem) { + HashMap target = new HashMap<>(); + for (Map.Entry entry : orig.entrySet()) { + if (!excludedContentItem.equals(entry.getKey())) { + target.put(entry.getKey(), entry.getValue()); + } + } + return target; + } + + private static boolean isListOrMap(Class type) { + return List.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type); + } + + private static Object castCollection(Class type, Map items) { + if (List.class.isAssignableFrom(type)) { + return new ArrayList(items.values()); + } + if (Map.class.isAssignableFrom(type)) { + return items; + } + return items; + } + + private static Type getType(Object bean, Field field) { + //Because of type erasure, we will find the setter method and get the generic types off it's arguments + Optional propertyDescriptor = getPropertyDescriptor(bean, field); + if (!propertyDescriptor.isPresent()) { + //Likely no accessors + log.debug("Property descriptor for object {} with field {} is null", bean, field); + return null; + } + + Method writeMethod = propertyDescriptor.get().getWriteMethod(); + if (writeMethod == null) { + log.debug("No write method for property {}", propertyDescriptor); + return null; + } + Type[] actualTypeArguments = ((ParameterizedType) writeMethod.getGenericParameterTypes()[0]) + .getActualTypeArguments(); + + Type type = (Map.class.isAssignableFrom(field.getType())) ? actualTypeArguments[1] : actualTypeArguments[0]; + + log.debug("Got type {} from {}", + type.getTypeName(), + String.format("%s#%s", bean.getClass().getSimpleName(), field.getName())); + + return type; + } + + @NotNull + private static Optional getPropertyDescriptor(Object bean, Field field) { + BeanInfo beanInfo = null; + try { + beanInfo = Introspector.getBeanInfo(bean.getClass()); + } catch (IntrospectionException e) { + log.debug("IntrospectionException from com.madrobot.beans for object {} with field {} is null", bean, field); + return null; + } + PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); + Optional propertyDescriptor = Arrays.stream(properties).filter(descriptor -> descriptor.getName().equals(field.getName())).findFirst(); + return propertyDescriptor; + } + + private static void handleReflectionException(Exception ex) { + log.error("Reflection exception", ex); + if (ex instanceof NoSuchMethodException) { + throw new IllegalStateException("Method not found: " + ex.getMessage()); + } + if (ex instanceof IllegalAccessException) { + throw new IllegalStateException("Could not access method: " + ex.getMessage()); + } + if (ex instanceof RuntimeException) { + throw (RuntimeException) ex; + } + + throw new UndeclaredThrowableException(ex); + } +} diff --git a/delivery-sdk/src/main/java/kontent/ai/delivery/Taxonomy.java b/delivery-sdk/src/main/java/kontent/ai/delivery/Taxonomy.java index ced1a829..4c92c433 100644 --- a/delivery-sdk/src/main/java/kontent/ai/delivery/Taxonomy.java +++ b/delivery-sdk/src/main/java/kontent/ai/delivery/Taxonomy.java @@ -1,68 +1,69 @@ -/* - * MIT License - * - * Copyright (c) 2022 Kontent s.r.o. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package kontent.ai.delivery; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -/** - * Object model for a Taxonomy element - */ -@lombok.Getter -@lombok.Setter -@lombok.ToString -@lombok.EqualsAndHashCode -@lombok.NoArgsConstructor -public class Taxonomy { - - /** - * The display name of the taxonomy - * - * @param name Sets the name of this. - * @return The name of the taxonomy. - */ - @JsonProperty("name") - String name; - - /** - * The codename of the taxonomy - * - * @param codename Sets the codename of this. - * @return The codename of the taxonomy. - */ - @JsonProperty("codename") - String codename; - - /** - * A list of taxonomically descendant terms - * - * @param terms Sets the taxonomy terms of this. - * @return A list of taxonomically descendant terms. - */ - @JsonProperty("terms") - List terms; - -} +/* + * MIT License + * + * Copyright (c) 2022 Kontent s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package kontent.ai.delivery; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.List; + +/** + * Object model for a Taxonomy element + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode +@lombok.NoArgsConstructor +public class Taxonomy { + + /** + * The display name of the taxonomy + * + * @param name Sets the name of this. + * @return The name of the taxonomy. + */ + @JsonProperty("name") + String name; + + /** + * The codename of the taxonomy + * + * @param codename Sets the codename of this. + * @return The codename of the taxonomy. + */ + @JsonProperty("codename") + String codename; + + /** + * A list of taxonomically descendant terms + * + * @param terms Sets the taxonomy terms of this. + * @return A list of taxonomically descendant terms. + */ + @JsonProperty("terms") + List terms; + +} diff --git a/sample-app-spring-boot/build.gradle b/sample-app-spring-boot/build.gradle index 327d8cd9..404accde 100644 --- a/sample-app-spring-boot/build.gradle +++ b/sample-app-spring-boot/build.gradle @@ -32,6 +32,7 @@ configurations { dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-data-redis' developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/controllers/TestController.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/controllers/TestController.java new file mode 100644 index 00000000..e4eb510f --- /dev/null +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/controllers/TestController.java @@ -0,0 +1,36 @@ +package kontent.ai.delivery.sample.dancinggoat.controllers; + +import kontent.ai.delivery.ContentItem; +import kontent.ai.delivery.DeliveryClient; +import kontent.ai.delivery.sample.dancinggoat.models.Home; +import kontent.ai.delivery.sample.dancinggoat.springboot.TestService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +import java.io.Serializable; +import java.util.concurrent.ExecutionException; +import java.util.logging.Logger; + +@Controller +public class TestController implements Serializable { + @Autowired + DeliveryClient deliveryClient; + + @Autowired + TestService testService; + + @GetMapping("/test") + ResponseEntity getTest(Model model) throws ExecutionException, InterruptedException { + + ContentItem item = testService.fetchContentByCodeName("on_roasts", deliveryClient); + + ContentItem item2 = testService.fetchContentByCodeName("about_us", deliveryClient); + + return new ResponseEntity<>(item.getString("title") + " " + item2.getString("metadata__og_title"), HttpStatus.OK); + } +} diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/AboutUs.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/AboutUs.java index 396d986a..e6315dce 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/AboutUs.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/AboutUs.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.util.List; import kontent.ai.delivery.Asset; @@ -16,30 +17,33 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("about_us") -public class AboutUs { - @ElementMapping("metadata__og_description") - String metadataOgDescription; +public class AboutUs implements Serializable { + @ContentItemMapping("facts") + List facts; + + @ElementMapping("url_pattern") + String urlPattern; + + @ElementMapping("sitemap") + List sitemap; @ElementMapping("metadata__meta_title") String metadataMetaTitle; - @ElementMapping("metadata__og_title") - String metadataOgTitle; - @ElementMapping("metadata__meta_description") String metadataMetaDescription; - @ElementMapping("metadata__twitter_site") - String metadataTwitterSite; + @ElementMapping("metadata__og_title") + String metadataOgTitle; - @ElementMapping("url_pattern") - String urlPattern; + @ElementMapping("metadata__og_description") + String metadataOgDescription; - @ElementMapping("metadata__twitter_image") - List metadataTwitterImage; + @ElementMapping("metadata__og_image") + List metadataOgImage; - @ElementMapping("sitemap") - List sitemap; + @ElementMapping("metadata__twitter_site") + String metadataTwitterSite; @ElementMapping("metadata__twitter_creator") String metadataTwitterCreator; @@ -50,36 +54,41 @@ public class AboutUs { @ElementMapping("metadata__twitter_description") String metadataTwitterDescription; - @ElementMapping("metadata__og_image") - List metadataOgImage; - - @ContentItemMapping("facts") - List facts; + @ElementMapping("metadata__twitter_image") + List metadataTwitterImage; System system; - public String getMetadataOgDescription() { - return metadataOgDescription; + public List getFacts() { + return facts; } - public void setMetadataOgDescription(String metadataOgDescription) { - this.metadataOgDescription = metadataOgDescription; + public void setFacts(List facts) { + this.facts = facts; } - public String getMetadataMetaTitle() { - return metadataMetaTitle; + public String getUrlPattern() { + return urlPattern; } - public void setMetadataMetaTitle(String metadataMetaTitle) { - this.metadataMetaTitle = metadataMetaTitle; + public void setUrlPattern(String urlPattern) { + this.urlPattern = urlPattern; } - public String getMetadataOgTitle() { - return metadataOgTitle; + public List getSitemap() { + return sitemap; } - public void setMetadataOgTitle(String metadataOgTitle) { - this.metadataOgTitle = metadataOgTitle; + public void setSitemap(List sitemap) { + this.sitemap = sitemap; + } + + public String getMetadataMetaTitle() { + return metadataMetaTitle; + } + + public void setMetadataMetaTitle(String metadataMetaTitle) { + this.metadataMetaTitle = metadataMetaTitle; } public String getMetadataMetaDescription() { @@ -90,36 +99,36 @@ public void setMetadataMetaDescription(String metadataMetaDescription) { this.metadataMetaDescription = metadataMetaDescription; } - public String getMetadataTwitterSite() { - return metadataTwitterSite; + public String getMetadataOgTitle() { + return metadataOgTitle; } - public void setMetadataTwitterSite(String metadataTwitterSite) { - this.metadataTwitterSite = metadataTwitterSite; + public void setMetadataOgTitle(String metadataOgTitle) { + this.metadataOgTitle = metadataOgTitle; } - public String getUrlPattern() { - return urlPattern; + public String getMetadataOgDescription() { + return metadataOgDescription; } - public void setUrlPattern(String urlPattern) { - this.urlPattern = urlPattern; + public void setMetadataOgDescription(String metadataOgDescription) { + this.metadataOgDescription = metadataOgDescription; } - public List getMetadataTwitterImage() { - return metadataTwitterImage; + public List getMetadataOgImage() { + return metadataOgImage; } - public void setMetadataTwitterImage(List metadataTwitterImage) { - this.metadataTwitterImage = metadataTwitterImage; + public void setMetadataOgImage(List metadataOgImage) { + this.metadataOgImage = metadataOgImage; } - public List getSitemap() { - return sitemap; + public String getMetadataTwitterSite() { + return metadataTwitterSite; } - public void setSitemap(List sitemap) { - this.sitemap = sitemap; + public void setMetadataTwitterSite(String metadataTwitterSite) { + this.metadataTwitterSite = metadataTwitterSite; } public String getMetadataTwitterCreator() { @@ -146,20 +155,12 @@ public void setMetadataTwitterDescription(String metadataTwitterDescription) { this.metadataTwitterDescription = metadataTwitterDescription; } - public List getMetadataOgImage() { - return metadataOgImage; - } - - public void setMetadataOgImage(List metadataOgImage) { - this.metadataOgImage = metadataOgImage; - } - - public List getFacts() { - return facts; + public List getMetadataTwitterImage() { + return metadataTwitterImage; } - public void setFacts(List facts) { - this.facts = facts; + public void setMetadataTwitterImage(List metadataTwitterImage) { + this.metadataTwitterImage = metadataTwitterImage; } public System getSystem() { diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Accessory.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Accessory.java index a289f2e0..ee69c454 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Accessory.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Accessory.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.Double; import java.lang.String; import java.util.List; @@ -16,136 +17,120 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("accessory") -public class Accessory { - @ElementMapping("metadata__og_description") - String metadataOgDescription; +public class Accessory implements Serializable { + @ElementMapping("product_name") + String productName; - @ElementMapping("metadata__meta_title") - String metadataMetaTitle; + @ElementMapping("price") + Double price; - @ElementMapping("metadata__og_title") - String metadataOgTitle; + @ElementMapping("image") + List image; + + @ElementMapping("manufacturer") + String manufacturer; + + @ElementMapping("product_status") + List productStatus; + + @ElementMapping("short_description") + String shortDescription; @ElementMapping("long_description") String longDescription; + @ElementMapping("url_pattern") + String urlPattern; + + @ElementMapping("sitemap") + List sitemap; + + @ElementMapping("metadata__meta_title") + String metadataMetaTitle; + @ElementMapping("metadata__meta_description") String metadataMetaDescription; - @ElementMapping("metadata__twitter_site") - String metadataTwitterSite; + @ElementMapping("metadata__og_title") + String metadataOgTitle; - @ElementMapping("price") - Double price; + @ElementMapping("metadata__og_description") + String metadataOgDescription; - @ElementMapping("metadata__twitter_image") - List metadataTwitterImage; + @ElementMapping("metadata__og_image") + List metadataOgImage; + + @ElementMapping("metadata__twitter_site") + String metadataTwitterSite; @ElementMapping("metadata__twitter_creator") String metadataTwitterCreator; - @ElementMapping("url_pattern") - String urlPattern; - - @ElementMapping("short_description") - String shortDescription; - - @ElementMapping("manufacturer") - String manufacturer; - @ElementMapping("metadata__twitter_title") String metadataTwitterTitle; @ElementMapping("metadata__twitter_description") String metadataTwitterDescription; - @ElementMapping("metadata__og_image") - List metadataOgImage; - - @ElementMapping("sitemap") - List sitemap; - - @ElementMapping("product_status") - List productStatus; - - @ElementMapping("image") - List image; - - @ElementMapping("product_name") - String productName; + @ElementMapping("metadata__twitter_image") + List metadataTwitterImage; System system; - public String getMetadataOgDescription() { - return metadataOgDescription; - } - - public void setMetadataOgDescription(String metadataOgDescription) { - this.metadataOgDescription = metadataOgDescription; - } - - public String getMetadataMetaTitle() { - return metadataMetaTitle; - } - - public void setMetadataMetaTitle(String metadataMetaTitle) { - this.metadataMetaTitle = metadataMetaTitle; - } - - public String getMetadataOgTitle() { - return metadataOgTitle; + public String getProductName() { + return productName; } - public void setMetadataOgTitle(String metadataOgTitle) { - this.metadataOgTitle = metadataOgTitle; + public void setProductName(String productName) { + this.productName = productName; } - public String getLongDescription() { - return longDescription; + public Double getPrice() { + return price; } - public void setLongDescription(String longDescription) { - this.longDescription = longDescription; + public void setPrice(Double price) { + this.price = price; } - public String getMetadataMetaDescription() { - return metadataMetaDescription; + public List getImage() { + return image; } - public void setMetadataMetaDescription(String metadataMetaDescription) { - this.metadataMetaDescription = metadataMetaDescription; + public void setImage(List image) { + this.image = image; } - public String getMetadataTwitterSite() { - return metadataTwitterSite; + public String getManufacturer() { + return manufacturer; } - public void setMetadataTwitterSite(String metadataTwitterSite) { - this.metadataTwitterSite = metadataTwitterSite; + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; } - public Double getPrice() { - return price; + public List getProductStatus() { + return productStatus; } - public void setPrice(Double price) { - this.price = price; + public void setProductStatus(List productStatus) { + this.productStatus = productStatus; } - public List getMetadataTwitterImage() { - return metadataTwitterImage; + public String getShortDescription() { + return shortDescription; } - public void setMetadataTwitterImage(List metadataTwitterImage) { - this.metadataTwitterImage = metadataTwitterImage; + public void setShortDescription(String shortDescription) { + this.shortDescription = shortDescription; } - public String getMetadataTwitterCreator() { - return metadataTwitterCreator; + public String getLongDescription() { + return longDescription; } - public void setMetadataTwitterCreator(String metadataTwitterCreator) { - this.metadataTwitterCreator = metadataTwitterCreator; + public void setLongDescription(String longDescription) { + this.longDescription = longDescription; } public String getUrlPattern() { @@ -156,36 +141,44 @@ public void setUrlPattern(String urlPattern) { this.urlPattern = urlPattern; } - public String getShortDescription() { - return shortDescription; + public List getSitemap() { + return sitemap; } - public void setShortDescription(String shortDescription) { - this.shortDescription = shortDescription; + public void setSitemap(List sitemap) { + this.sitemap = sitemap; } - public String getManufacturer() { - return manufacturer; + public String getMetadataMetaTitle() { + return metadataMetaTitle; } - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; + public void setMetadataMetaTitle(String metadataMetaTitle) { + this.metadataMetaTitle = metadataMetaTitle; } - public String getMetadataTwitterTitle() { - return metadataTwitterTitle; + public String getMetadataMetaDescription() { + return metadataMetaDescription; } - public void setMetadataTwitterTitle(String metadataTwitterTitle) { - this.metadataTwitterTitle = metadataTwitterTitle; + public void setMetadataMetaDescription(String metadataMetaDescription) { + this.metadataMetaDescription = metadataMetaDescription; } - public String getMetadataTwitterDescription() { - return metadataTwitterDescription; + public String getMetadataOgTitle() { + return metadataOgTitle; } - public void setMetadataTwitterDescription(String metadataTwitterDescription) { - this.metadataTwitterDescription = metadataTwitterDescription; + public void setMetadataOgTitle(String metadataOgTitle) { + this.metadataOgTitle = metadataOgTitle; + } + + public String getMetadataOgDescription() { + return metadataOgDescription; + } + + public void setMetadataOgDescription(String metadataOgDescription) { + this.metadataOgDescription = metadataOgDescription; } public List getMetadataOgImage() { @@ -196,36 +189,44 @@ public void setMetadataOgImage(List metadataOgImage) { this.metadataOgImage = metadataOgImage; } - public List getSitemap() { - return sitemap; + public String getMetadataTwitterSite() { + return metadataTwitterSite; } - public void setSitemap(List sitemap) { - this.sitemap = sitemap; + public void setMetadataTwitterSite(String metadataTwitterSite) { + this.metadataTwitterSite = metadataTwitterSite; } - public List getProductStatus() { - return productStatus; + public String getMetadataTwitterCreator() { + return metadataTwitterCreator; } - public void setProductStatus(List productStatus) { - this.productStatus = productStatus; + public void setMetadataTwitterCreator(String metadataTwitterCreator) { + this.metadataTwitterCreator = metadataTwitterCreator; } - public List getImage() { - return image; + public String getMetadataTwitterTitle() { + return metadataTwitterTitle; } - public void setImage(List image) { - this.image = image; + public void setMetadataTwitterTitle(String metadataTwitterTitle) { + this.metadataTwitterTitle = metadataTwitterTitle; } - public String getProductName() { - return productName; + public String getMetadataTwitterDescription() { + return metadataTwitterDescription; } - public void setProductName(String productName) { - this.productName = productName; + public void setMetadataTwitterDescription(String metadataTwitterDescription) { + this.metadataTwitterDescription = metadataTwitterDescription; + } + + public List getMetadataTwitterImage() { + return metadataTwitterImage; + } + + public void setMetadataTwitterImage(List metadataTwitterImage) { + this.metadataTwitterImage = metadataTwitterImage; } public System getSystem() { diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Article.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Article.java index 45c786b0..34209693 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Article.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Article.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.time.ZonedDateTime; import java.util.List; @@ -17,51 +18,60 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("article") -public class Article { - @ElementMapping("metadata__og_description") - String metadataOgDescription; +public class Article implements Serializable { + @ElementMapping("title") + String title; - @ElementMapping("metadata__meta_title") - String metadataMetaTitle; + @ElementMapping("teaser_image") + List teaserImage; - @ElementMapping("personas") - List personas; + @ElementMapping("post_date") + ZonedDateTime postDate; + + @ElementMapping("summary") + String summary; @ElementMapping("body_copy") String bodyCopy; - @ElementMapping("metadata__og_title") - String metadataOgTitle; + @ContentItemMapping("related_articles") + List relatedArticles; - @ElementMapping("metadata__meta_description") - String metadataMetaDescription; + @ElementMapping("meta_keywords") + String metaKeywords; - @ElementMapping("metadata__twitter_site") - String metadataTwitterSite; + @ElementMapping("personas") + List personas; - @ElementMapping("post_date") - ZonedDateTime postDate; + @ElementMapping("meta_description") + String metaDescription; - @ElementMapping("meta_keywords") - String metaKeywords; + @ElementMapping("url_pattern") + String urlPattern; - @ElementMapping("teaser_image") - List teaserImage; + @ElementMapping("sitemap") + List sitemap; - @ElementMapping("metadata__twitter_image") - List metadataTwitterImage; + @ElementMapping("metadata__meta_title") + String metadataMetaTitle; - @ElementMapping("metadata__twitter_creator") - String metadataTwitterCreator; + @ElementMapping("metadata__meta_description") + String metadataMetaDescription; - @ElementMapping("title") - String title; + @ElementMapping("metadata__og_title") + String metadataOgTitle; - @ElementMapping("summary") - String summary; + @ElementMapping("metadata__og_description") + String metadataOgDescription; - @ElementMapping("sitemap") - List sitemap; + @ElementMapping("metadata__og_image") + List metadataOgImage; + + @ElementMapping("metadata__twitter_site") + String metadataTwitterSite; + + @ElementMapping("metadata__twitter_creator") + String metadataTwitterCreator; @ElementMapping("metadata__twitter_title") String metadataTwitterTitle; @@ -69,42 +79,41 @@ public class Article { @ElementMapping("metadata__twitter_description") String metadataTwitterDescription; - @ElementMapping("meta_description") - String metaDescription; - - @ElementMapping("metadata__og_image") - List metadataOgImage; + @ElementMapping("metadata__twitter_image") + List metadataTwitterImage; - @ContentItemMapping("related_articles") - List relatedArticles; + System system; - @ElementMapping("url_pattern") - String urlPattern; + public String getTitle() { + return title; + } - System system; + public void setTitle(String title) { + this.title = title; + } - public String getMetadataOgDescription() { - return metadataOgDescription; + public List getTeaserImage() { + return teaserImage; } - public void setMetadataOgDescription(String metadataOgDescription) { - this.metadataOgDescription = metadataOgDescription; + public void setTeaserImage(List teaserImage) { + this.teaserImage = teaserImage; } - public String getMetadataMetaTitle() { - return metadataMetaTitle; + public ZonedDateTime getPostDate() { + return postDate; } - public void setMetadataMetaTitle(String metadataMetaTitle) { - this.metadataMetaTitle = metadataMetaTitle; + public void setPostDate(ZonedDateTime postDate) { + this.postDate = postDate; } - public List getPersonas() { - return personas; + public String getSummary() { + return summary; } - public void setPersonas(List personas) { - this.personas = personas; + public void setSummary(String summary) { + this.summary = summary; } public String getBodyCopy() { @@ -115,140 +124,132 @@ public void setBodyCopy(String bodyCopy) { this.bodyCopy = bodyCopy; } - public String getMetadataOgTitle() { - return metadataOgTitle; - } - - public void setMetadataOgTitle(String metadataOgTitle) { - this.metadataOgTitle = metadataOgTitle; - } - - public String getMetadataMetaDescription() { - return metadataMetaDescription; + public List getRelatedArticles() { + return relatedArticles; } - public void setMetadataMetaDescription(String metadataMetaDescription) { - this.metadataMetaDescription = metadataMetaDescription; + public void setRelatedArticles(List relatedArticles) { + this.relatedArticles = relatedArticles; } - public String getMetadataTwitterSite() { - return metadataTwitterSite; + public String getMetaKeywords() { + return metaKeywords; } - public void setMetadataTwitterSite(String metadataTwitterSite) { - this.metadataTwitterSite = metadataTwitterSite; + public void setMetaKeywords(String metaKeywords) { + this.metaKeywords = metaKeywords; } - public ZonedDateTime getPostDate() { - return postDate; + public List getPersonas() { + return personas; } - public void setPostDate(ZonedDateTime postDate) { - this.postDate = postDate; + public void setPersonas(List personas) { + this.personas = personas; } - public String getMetaKeywords() { - return metaKeywords; + public String getMetaDescription() { + return metaDescription; } - public void setMetaKeywords(String metaKeywords) { - this.metaKeywords = metaKeywords; + public void setMetaDescription(String metaDescription) { + this.metaDescription = metaDescription; } - public List getTeaserImage() { - return teaserImage; + public String getUrlPattern() { + return urlPattern; } - public void setTeaserImage(List teaserImage) { - this.teaserImage = teaserImage; + public void setUrlPattern(String urlPattern) { + this.urlPattern = urlPattern; } - public List getMetadataTwitterImage() { - return metadataTwitterImage; + public List getSitemap() { + return sitemap; } - public void setMetadataTwitterImage(List metadataTwitterImage) { - this.metadataTwitterImage = metadataTwitterImage; + public void setSitemap(List sitemap) { + this.sitemap = sitemap; } - public String getMetadataTwitterCreator() { - return metadataTwitterCreator; + public String getMetadataMetaTitle() { + return metadataMetaTitle; } - public void setMetadataTwitterCreator(String metadataTwitterCreator) { - this.metadataTwitterCreator = metadataTwitterCreator; + public void setMetadataMetaTitle(String metadataMetaTitle) { + this.metadataMetaTitle = metadataMetaTitle; } - public String getTitle() { - return title; + public String getMetadataMetaDescription() { + return metadataMetaDescription; } - public void setTitle(String title) { - this.title = title; + public void setMetadataMetaDescription(String metadataMetaDescription) { + this.metadataMetaDescription = metadataMetaDescription; } - public String getSummary() { - return summary; + public String getMetadataOgTitle() { + return metadataOgTitle; } - public void setSummary(String summary) { - this.summary = summary; + public void setMetadataOgTitle(String metadataOgTitle) { + this.metadataOgTitle = metadataOgTitle; } - public List getSitemap() { - return sitemap; + public String getMetadataOgDescription() { + return metadataOgDescription; } - public void setSitemap(List sitemap) { - this.sitemap = sitemap; + public void setMetadataOgDescription(String metadataOgDescription) { + this.metadataOgDescription = metadataOgDescription; } - public String getMetadataTwitterTitle() { - return metadataTwitterTitle; + public List getMetadataOgImage() { + return metadataOgImage; } - public void setMetadataTwitterTitle(String metadataTwitterTitle) { - this.metadataTwitterTitle = metadataTwitterTitle; + public void setMetadataOgImage(List metadataOgImage) { + this.metadataOgImage = metadataOgImage; } - public String getMetadataTwitterDescription() { - return metadataTwitterDescription; + public String getMetadataTwitterSite() { + return metadataTwitterSite; } - public void setMetadataTwitterDescription(String metadataTwitterDescription) { - this.metadataTwitterDescription = metadataTwitterDescription; + public void setMetadataTwitterSite(String metadataTwitterSite) { + this.metadataTwitterSite = metadataTwitterSite; } - public String getMetaDescription() { - return metaDescription; + public String getMetadataTwitterCreator() { + return metadataTwitterCreator; } - public void setMetaDescription(String metaDescription) { - this.metaDescription = metaDescription; + public void setMetadataTwitterCreator(String metadataTwitterCreator) { + this.metadataTwitterCreator = metadataTwitterCreator; } - public List getMetadataOgImage() { - return metadataOgImage; + public String getMetadataTwitterTitle() { + return metadataTwitterTitle; } - public void setMetadataOgImage(List metadataOgImage) { - this.metadataOgImage = metadataOgImage; + public void setMetadataTwitterTitle(String metadataTwitterTitle) { + this.metadataTwitterTitle = metadataTwitterTitle; } - public List getRelatedArticles() { - return relatedArticles; + public String getMetadataTwitterDescription() { + return metadataTwitterDescription; } - public void setRelatedArticles(List relatedArticles) { - this.relatedArticles = relatedArticles; + public void setMetadataTwitterDescription(String metadataTwitterDescription) { + this.metadataTwitterDescription = metadataTwitterDescription; } - public String getUrlPattern() { - return urlPattern; + public List getMetadataTwitterImage() { + return metadataTwitterImage; } - public void setUrlPattern(String urlPattern) { - this.urlPattern = urlPattern; + public void setMetadataTwitterImage(List metadataTwitterImage) { + this.metadataTwitterImage = metadataTwitterImage; } public System getSystem() { diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Brewer.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Brewer.java index f90a397e..dee928f8 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Brewer.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Brewer.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.Double; import java.lang.String; import java.util.List; @@ -16,63 +17,63 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("brewer") -public class Brewer { +public class Brewer implements Serializable { @ElementMapping("product_name") String productName; - @ElementMapping("metadata__og_description") - String metadataOgDescription; + @ElementMapping("price") + Double price; - @ElementMapping("metadata__meta_title") - String metadataMetaTitle; + @ElementMapping("image") + List image; + + @ElementMapping("product_status") + List productStatus; + + @ElementMapping("short_description") + String shortDescription; @ElementMapping("long_description") String longDescription; - @ElementMapping("metadata__og_title") - String metadataOgTitle; + @ElementMapping("url_pattern") + String urlPattern; + + @ElementMapping("manufacturer") + List manufacturer; + + @ElementMapping("sitemap") + List sitemap; + + @ElementMapping("metadata__meta_title") + String metadataMetaTitle; @ElementMapping("metadata__meta_description") String metadataMetaDescription; - @ElementMapping("metadata__twitter_site") - String metadataTwitterSite; + @ElementMapping("metadata__og_title") + String metadataOgTitle; - @ElementMapping("price") - Double price; + @ElementMapping("metadata__og_description") + String metadataOgDescription; - @ElementMapping("manufacturer") - List manufacturer; + @ElementMapping("metadata__og_image") + List metadataOgImage; - @ElementMapping("metadata__twitter_image") - List metadataTwitterImage; + @ElementMapping("metadata__twitter_site") + String metadataTwitterSite; @ElementMapping("metadata__twitter_creator") String metadataTwitterCreator; - @ElementMapping("url_pattern") - String urlPattern; - - @ElementMapping("sitemap") - List sitemap; - - @ElementMapping("short_description") - String shortDescription; - - @ElementMapping("product_status") - List productStatus; - @ElementMapping("metadata__twitter_title") String metadataTwitterTitle; @ElementMapping("metadata__twitter_description") String metadataTwitterDescription; - @ElementMapping("metadata__og_image") - List metadataOgImage; - - @ElementMapping("image") - List image; + @ElementMapping("metadata__twitter_image") + List metadataTwitterImage; System system; @@ -84,60 +85,52 @@ public void setProductName(String productName) { this.productName = productName; } - public String getMetadataOgDescription() { - return metadataOgDescription; - } - - public void setMetadataOgDescription(String metadataOgDescription) { - this.metadataOgDescription = metadataOgDescription; - } - - public String getMetadataMetaTitle() { - return metadataMetaTitle; + public Double getPrice() { + return price; } - public void setMetadataMetaTitle(String metadataMetaTitle) { - this.metadataMetaTitle = metadataMetaTitle; + public void setPrice(Double price) { + this.price = price; } - public String getLongDescription() { - return longDescription; + public List getImage() { + return image; } - public void setLongDescription(String longDescription) { - this.longDescription = longDescription; + public void setImage(List image) { + this.image = image; } - public String getMetadataOgTitle() { - return metadataOgTitle; + public List getProductStatus() { + return productStatus; } - public void setMetadataOgTitle(String metadataOgTitle) { - this.metadataOgTitle = metadataOgTitle; + public void setProductStatus(List productStatus) { + this.productStatus = productStatus; } - public String getMetadataMetaDescription() { - return metadataMetaDescription; + public String getShortDescription() { + return shortDescription; } - public void setMetadataMetaDescription(String metadataMetaDescription) { - this.metadataMetaDescription = metadataMetaDescription; + public void setShortDescription(String shortDescription) { + this.shortDescription = shortDescription; } - public String getMetadataTwitterSite() { - return metadataTwitterSite; + public String getLongDescription() { + return longDescription; } - public void setMetadataTwitterSite(String metadataTwitterSite) { - this.metadataTwitterSite = metadataTwitterSite; + public void setLongDescription(String longDescription) { + this.longDescription = longDescription; } - public Double getPrice() { - return price; + public String getUrlPattern() { + return urlPattern; } - public void setPrice(Double price) { - this.price = price; + public void setUrlPattern(String urlPattern) { + this.urlPattern = urlPattern; } public List getManufacturer() { @@ -148,52 +141,68 @@ public void setManufacturer(List manufacturer) { this.manufacturer = manufacturer; } - public List getMetadataTwitterImage() { - return metadataTwitterImage; + public List getSitemap() { + return sitemap; } - public void setMetadataTwitterImage(List metadataTwitterImage) { - this.metadataTwitterImage = metadataTwitterImage; + public void setSitemap(List sitemap) { + this.sitemap = sitemap; } - public String getMetadataTwitterCreator() { - return metadataTwitterCreator; + public String getMetadataMetaTitle() { + return metadataMetaTitle; } - public void setMetadataTwitterCreator(String metadataTwitterCreator) { - this.metadataTwitterCreator = metadataTwitterCreator; + public void setMetadataMetaTitle(String metadataMetaTitle) { + this.metadataMetaTitle = metadataMetaTitle; } - public String getUrlPattern() { - return urlPattern; + public String getMetadataMetaDescription() { + return metadataMetaDescription; } - public void setUrlPattern(String urlPattern) { - this.urlPattern = urlPattern; + public void setMetadataMetaDescription(String metadataMetaDescription) { + this.metadataMetaDescription = metadataMetaDescription; } - public List getSitemap() { - return sitemap; + public String getMetadataOgTitle() { + return metadataOgTitle; } - public void setSitemap(List sitemap) { - this.sitemap = sitemap; + public void setMetadataOgTitle(String metadataOgTitle) { + this.metadataOgTitle = metadataOgTitle; } - public String getShortDescription() { - return shortDescription; + public String getMetadataOgDescription() { + return metadataOgDescription; } - public void setShortDescription(String shortDescription) { - this.shortDescription = shortDescription; + public void setMetadataOgDescription(String metadataOgDescription) { + this.metadataOgDescription = metadataOgDescription; } - public List getProductStatus() { - return productStatus; + public List getMetadataOgImage() { + return metadataOgImage; } - public void setProductStatus(List productStatus) { - this.productStatus = productStatus; + public void setMetadataOgImage(List metadataOgImage) { + this.metadataOgImage = metadataOgImage; + } + + public String getMetadataTwitterSite() { + return metadataTwitterSite; + } + + public void setMetadataTwitterSite(String metadataTwitterSite) { + this.metadataTwitterSite = metadataTwitterSite; + } + + public String getMetadataTwitterCreator() { + return metadataTwitterCreator; + } + + public void setMetadataTwitterCreator(String metadataTwitterCreator) { + this.metadataTwitterCreator = metadataTwitterCreator; } public String getMetadataTwitterTitle() { @@ -212,20 +221,12 @@ public void setMetadataTwitterDescription(String metadataTwitterDescription) { this.metadataTwitterDescription = metadataTwitterDescription; } - public List getMetadataOgImage() { - return metadataOgImage; - } - - public void setMetadataOgImage(List metadataOgImage) { - this.metadataOgImage = metadataOgImage; - } - - public List getImage() { - return image; + public List getMetadataTwitterImage() { + return metadataTwitterImage; } - public void setImage(List image) { - this.image = image; + public void setMetadataTwitterImage(List metadataTwitterImage) { + this.metadataTwitterImage = metadataTwitterImage; } public System getSystem() { diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Cafe.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Cafe.java index 0a12f239..c73419fd 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Cafe.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Cafe.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.util.List; import kontent.ai.delivery.Asset; @@ -15,42 +16,42 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("cafe") -public class Cafe { - @ElementMapping("phone") - String phone; +public class Cafe implements Serializable { + @ElementMapping("street") + String street; @ElementMapping("city") String city; - @ElementMapping("photo") - List photo; - - @ElementMapping("email") - String email; - @ElementMapping("country") String country; - @ElementMapping("street") - String street; - @ElementMapping("state") String state; @ElementMapping("zip_code") String zipCode; + @ElementMapping("phone") + String phone; + + @ElementMapping("email") + String email; + + @ElementMapping("photo") + List photo; + @ElementMapping("sitemap") List sitemap; System system; - public String getPhone() { - return phone; + public String getStreet() { + return street; } - public void setPhone(String phone) { - this.phone = phone; + public void setStreet(String street) { + this.street = street; } public String getCity() { @@ -61,22 +62,6 @@ public void setCity(String city) { this.city = city; } - public List getPhoto() { - return photo; - } - - public void setPhoto(List photo) { - this.photo = photo; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - public String getCountry() { return country; } @@ -85,14 +70,6 @@ public void setCountry(String country) { this.country = country; } - public String getStreet() { - return street; - } - - public void setStreet(String street) { - this.street = street; - } - public String getState() { return state; } @@ -109,6 +86,30 @@ public void setZipCode(String zipCode) { this.zipCode = zipCode; } + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public List getPhoto() { + return photo; + } + + public void setPhoto(List photo) { + this.photo = photo; + } + public List getSitemap() { return sitemap; } diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Coffee.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Coffee.java index 39ee3730..ba9a35ef 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Coffee.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Coffee.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.Double; import java.lang.String; import java.util.List; @@ -16,100 +17,116 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("coffee") -public class Coffee { - @ElementMapping("metadata__og_description") - String metadataOgDescription; +public class Coffee implements Serializable { + @ElementMapping("product_name") + String productName; - @ElementMapping("metadata__meta_title") - String metadataMetaTitle; + @ElementMapping("price") + Double price; - @ElementMapping("metadata__og_title") - String metadataOgTitle; + @ElementMapping("image") + List image; + + @ElementMapping("short_description") + String shortDescription; + + @ElementMapping("long_description") + String longDescription; @ElementMapping("product_status") List productStatus; - @ElementMapping("altitude") - String altitude; + @ElementMapping("farm") + String farm; - @ElementMapping("metadata__meta_description") - String metadataMetaDescription; + @ElementMapping("country") + String country; @ElementMapping("variety") String variety; - @ElementMapping("image") - List image; - - @ElementMapping("metadata__twitter_site") - String metadataTwitterSite; + @ElementMapping("altitude") + String altitude; @ElementMapping("url_pattern") String urlPattern; - @ElementMapping("price") - Double price; - - @ElementMapping("metadata__twitter_image") - List metadataTwitterImage; - - @ElementMapping("metadata__twitter_creator") - String metadataTwitterCreator; - - @ElementMapping("country") - String country; + @ElementMapping("processing") + List processing; @ElementMapping("sitemap") List sitemap; - @ElementMapping("metadata__twitter_title") - String metadataTwitterTitle; + @ElementMapping("metadata__meta_title") + String metadataMetaTitle; - @ElementMapping("short_description") - String shortDescription; + @ElementMapping("metadata__meta_description") + String metadataMetaDescription; - @ElementMapping("processing") - List processing; + @ElementMapping("metadata__og_title") + String metadataOgTitle; - @ElementMapping("metadata__twitter_description") - String metadataTwitterDescription; + @ElementMapping("metadata__og_description") + String metadataOgDescription; @ElementMapping("metadata__og_image") List metadataOgImage; - @ElementMapping("long_description") - String longDescription; + @ElementMapping("metadata__twitter_site") + String metadataTwitterSite; - @ElementMapping("farm") - String farm; + @ElementMapping("metadata__twitter_creator") + String metadataTwitterCreator; - @ElementMapping("product_name") - String productName; + @ElementMapping("metadata__twitter_title") + String metadataTwitterTitle; + + @ElementMapping("metadata__twitter_description") + String metadataTwitterDescription; + + @ElementMapping("metadata__twitter_image") + List metadataTwitterImage; System system; - public String getMetadataOgDescription() { - return metadataOgDescription; + public String getProductName() { + return productName; } - public void setMetadataOgDescription(String metadataOgDescription) { - this.metadataOgDescription = metadataOgDescription; + public void setProductName(String productName) { + this.productName = productName; } - public String getMetadataMetaTitle() { - return metadataMetaTitle; + public Double getPrice() { + return price; } - public void setMetadataMetaTitle(String metadataMetaTitle) { - this.metadataMetaTitle = metadataMetaTitle; + public void setPrice(Double price) { + this.price = price; } - public String getMetadataOgTitle() { - return metadataOgTitle; + public List getImage() { + return image; } - public void setMetadataOgTitle(String metadataOgTitle) { - this.metadataOgTitle = metadataOgTitle; + public void setImage(List image) { + this.image = image; + } + + public String getShortDescription() { + return shortDescription; + } + + public void setShortDescription(String shortDescription) { + this.shortDescription = shortDescription; + } + + public String getLongDescription() { + return longDescription; + } + + public void setLongDescription(String longDescription) { + this.longDescription = longDescription; } public List getProductStatus() { @@ -120,20 +137,20 @@ public void setProductStatus(List productStatus) { this.productStatus = productStatus; } - public String getAltitude() { - return altitude; + public String getFarm() { + return farm; } - public void setAltitude(String altitude) { - this.altitude = altitude; + public void setFarm(String farm) { + this.farm = farm; } - public String getMetadataMetaDescription() { - return metadataMetaDescription; + public String getCountry() { + return country; } - public void setMetadataMetaDescription(String metadataMetaDescription) { - this.metadataMetaDescription = metadataMetaDescription; + public void setCountry(String country) { + this.country = country; } public String getVariety() { @@ -144,20 +161,12 @@ public void setVariety(String variety) { this.variety = variety; } - public List getImage() { - return image; - } - - public void setImage(List image) { - this.image = image; - } - - public String getMetadataTwitterSite() { - return metadataTwitterSite; + public String getAltitude() { + return altitude; } - public void setMetadataTwitterSite(String metadataTwitterSite) { - this.metadataTwitterSite = metadataTwitterSite; + public void setAltitude(String altitude) { + this.altitude = altitude; } public String getUrlPattern() { @@ -168,36 +177,12 @@ public void setUrlPattern(String urlPattern) { this.urlPattern = urlPattern; } - public Double getPrice() { - return price; - } - - public void setPrice(Double price) { - this.price = price; - } - - public List getMetadataTwitterImage() { - return metadataTwitterImage; - } - - public void setMetadataTwitterImage(List metadataTwitterImage) { - this.metadataTwitterImage = metadataTwitterImage; - } - - public String getMetadataTwitterCreator() { - return metadataTwitterCreator; - } - - public void setMetadataTwitterCreator(String metadataTwitterCreator) { - this.metadataTwitterCreator = metadataTwitterCreator; - } - - public String getCountry() { - return country; + public List getProcessing() { + return processing; } - public void setCountry(String country) { - this.country = country; + public void setProcessing(List processing) { + this.processing = processing; } public List getSitemap() { @@ -208,36 +193,36 @@ public void setSitemap(List sitemap) { this.sitemap = sitemap; } - public String getMetadataTwitterTitle() { - return metadataTwitterTitle; + public String getMetadataMetaTitle() { + return metadataMetaTitle; } - public void setMetadataTwitterTitle(String metadataTwitterTitle) { - this.metadataTwitterTitle = metadataTwitterTitle; + public void setMetadataMetaTitle(String metadataMetaTitle) { + this.metadataMetaTitle = metadataMetaTitle; } - public String getShortDescription() { - return shortDescription; + public String getMetadataMetaDescription() { + return metadataMetaDescription; } - public void setShortDescription(String shortDescription) { - this.shortDescription = shortDescription; + public void setMetadataMetaDescription(String metadataMetaDescription) { + this.metadataMetaDescription = metadataMetaDescription; } - public List getProcessing() { - return processing; + public String getMetadataOgTitle() { + return metadataOgTitle; } - public void setProcessing(List processing) { - this.processing = processing; + public void setMetadataOgTitle(String metadataOgTitle) { + this.metadataOgTitle = metadataOgTitle; } - public String getMetadataTwitterDescription() { - return metadataTwitterDescription; + public String getMetadataOgDescription() { + return metadataOgDescription; } - public void setMetadataTwitterDescription(String metadataTwitterDescription) { - this.metadataTwitterDescription = metadataTwitterDescription; + public void setMetadataOgDescription(String metadataOgDescription) { + this.metadataOgDescription = metadataOgDescription; } public List getMetadataOgImage() { @@ -248,28 +233,44 @@ public void setMetadataOgImage(List metadataOgImage) { this.metadataOgImage = metadataOgImage; } - public String getLongDescription() { - return longDescription; + public String getMetadataTwitterSite() { + return metadataTwitterSite; } - public void setLongDescription(String longDescription) { - this.longDescription = longDescription; + public void setMetadataTwitterSite(String metadataTwitterSite) { + this.metadataTwitterSite = metadataTwitterSite; } - public String getFarm() { - return farm; + public String getMetadataTwitterCreator() { + return metadataTwitterCreator; } - public void setFarm(String farm) { - this.farm = farm; + public void setMetadataTwitterCreator(String metadataTwitterCreator) { + this.metadataTwitterCreator = metadataTwitterCreator; } - public String getProductName() { - return productName; + public String getMetadataTwitterTitle() { + return metadataTwitterTitle; } - public void setProductName(String productName) { - this.productName = productName; + public void setMetadataTwitterTitle(String metadataTwitterTitle) { + this.metadataTwitterTitle = metadataTwitterTitle; + } + + public String getMetadataTwitterDescription() { + return metadataTwitterDescription; + } + + public void setMetadataTwitterDescription(String metadataTwitterDescription) { + this.metadataTwitterDescription = metadataTwitterDescription; + } + + public List getMetadataTwitterImage() { + return metadataTwitterImage; + } + + public void setMetadataTwitterImage(List metadataTwitterImage) { + this.metadataTwitterImage = metadataTwitterImage; } public System getSystem() { diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/FactAboutUs.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/FactAboutUs.java index 2d602ef6..5b124bb0 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/FactAboutUs.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/FactAboutUs.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.util.List; import kontent.ai.delivery.Asset; @@ -15,28 +16,20 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("fact_about_us") -public class FactAboutUs { - @ElementMapping("description") - String description; - +public class FactAboutUs implements Serializable { @ElementMapping("title") String title; - @ElementMapping("sitemap") - List sitemap; + @ElementMapping("description") + String description; @ElementMapping("image") List image; - System system; - - public String getDescription() { - return description; - } + @ElementMapping("sitemap") + List sitemap; - public void setDescription(String description) { - this.description = description; - } + System system; public String getTitle() { return title; @@ -46,12 +39,12 @@ public void setTitle(String title) { this.title = title; } - public List getSitemap() { - return sitemap; + public String getDescription() { + return description; } - public void setSitemap(List sitemap) { - this.sitemap = sitemap; + public void setDescription(String description) { + this.description = description; } public List getImage() { @@ -62,6 +55,14 @@ public void setImage(List image) { this.image = image; } + public List getSitemap() { + return sitemap; + } + + public void setSitemap(List sitemap) { + this.sitemap = sitemap; + } + public System getSystem() { return system; } diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Grinder.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Grinder.java index aff53a80..2606188f 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Grinder.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Grinder.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.Double; import java.lang.String; import java.util.List; @@ -16,104 +17,112 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("grinder") -public class Grinder { - @ElementMapping("sitemap") - List sitemap; +public class Grinder implements Serializable { + @ElementMapping("product_name") + String productName; - @ElementMapping("metadata__og_description") - String metadataOgDescription; + @ElementMapping("price") + Double price; - @ElementMapping("metadata__meta_title") - String metadataMetaTitle; + @ElementMapping("image") + List image; - @ElementMapping("metadata__og_title") - String metadataOgTitle; + @ElementMapping("manufacturer") + String manufacturer; - @ElementMapping("price") - Double price; + @ElementMapping("product_status") + List productStatus; + + @ElementMapping("short_description") + String shortDescription; @ElementMapping("long_description") String longDescription; - @ElementMapping("short_description") - String shortDescription; + @ElementMapping("url_pattern") + String urlPattern; - @ElementMapping("manufacturer") - String manufacturer; + @ElementMapping("sitemap") + List sitemap; + + @ElementMapping("metadata__meta_title") + String metadataMetaTitle; @ElementMapping("metadata__meta_description") String metadataMetaDescription; - @ElementMapping("metadata__twitter_site") - String metadataTwitterSite; + @ElementMapping("metadata__og_title") + String metadataOgTitle; - @ElementMapping("product_status") - List productStatus; + @ElementMapping("metadata__og_description") + String metadataOgDescription; - @ElementMapping("metadata__twitter_image") - List metadataTwitterImage; + @ElementMapping("metadata__og_image") + List metadataOgImage; + + @ElementMapping("metadata__twitter_site") + String metadataTwitterSite; @ElementMapping("metadata__twitter_creator") String metadataTwitterCreator; - @ElementMapping("image") - List image; - @ElementMapping("metadata__twitter_title") String metadataTwitterTitle; - @ElementMapping("product_name") - String productName; - @ElementMapping("metadata__twitter_description") String metadataTwitterDescription; - @ElementMapping("url_pattern") - String urlPattern; - - @ElementMapping("metadata__og_image") - List metadataOgImage; + @ElementMapping("metadata__twitter_image") + List metadataTwitterImage; System system; - public List getSitemap() { - return sitemap; + public String getProductName() { + return productName; } - public void setSitemap(List sitemap) { - this.sitemap = sitemap; + public void setProductName(String productName) { + this.productName = productName; } - public String getMetadataOgDescription() { - return metadataOgDescription; + public Double getPrice() { + return price; } - public void setMetadataOgDescription(String metadataOgDescription) { - this.metadataOgDescription = metadataOgDescription; + public void setPrice(Double price) { + this.price = price; } - public String getMetadataMetaTitle() { - return metadataMetaTitle; + public List getImage() { + return image; } - public void setMetadataMetaTitle(String metadataMetaTitle) { - this.metadataMetaTitle = metadataMetaTitle; + public void setImage(List image) { + this.image = image; } - public String getMetadataOgTitle() { - return metadataOgTitle; + public String getManufacturer() { + return manufacturer; } - public void setMetadataOgTitle(String metadataOgTitle) { - this.metadataOgTitle = metadataOgTitle; + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; } - public Double getPrice() { - return price; + public List getProductStatus() { + return productStatus; } - public void setPrice(Double price) { - this.price = price; + public void setProductStatus(List productStatus) { + this.productStatus = productStatus; + } + + public String getShortDescription() { + return shortDescription; + } + + public void setShortDescription(String shortDescription) { + this.shortDescription = shortDescription; } public String getLongDescription() { @@ -124,20 +133,28 @@ public void setLongDescription(String longDescription) { this.longDescription = longDescription; } - public String getShortDescription() { - return shortDescription; + public String getUrlPattern() { + return urlPattern; } - public void setShortDescription(String shortDescription) { - this.shortDescription = shortDescription; + public void setUrlPattern(String urlPattern) { + this.urlPattern = urlPattern; } - public String getManufacturer() { - return manufacturer; + public List getSitemap() { + return sitemap; } - public void setManufacturer(String manufacturer) { - this.manufacturer = manufacturer; + public void setSitemap(List sitemap) { + this.sitemap = sitemap; + } + + public String getMetadataMetaTitle() { + return metadataMetaTitle; + } + + public void setMetadataMetaTitle(String metadataMetaTitle) { + this.metadataMetaTitle = metadataMetaTitle; } public String getMetadataMetaDescription() { @@ -148,44 +165,44 @@ public void setMetadataMetaDescription(String metadataMetaDescription) { this.metadataMetaDescription = metadataMetaDescription; } - public String getMetadataTwitterSite() { - return metadataTwitterSite; + public String getMetadataOgTitle() { + return metadataOgTitle; } - public void setMetadataTwitterSite(String metadataTwitterSite) { - this.metadataTwitterSite = metadataTwitterSite; + public void setMetadataOgTitle(String metadataOgTitle) { + this.metadataOgTitle = metadataOgTitle; } - public List getProductStatus() { - return productStatus; + public String getMetadataOgDescription() { + return metadataOgDescription; } - public void setProductStatus(List productStatus) { - this.productStatus = productStatus; + public void setMetadataOgDescription(String metadataOgDescription) { + this.metadataOgDescription = metadataOgDescription; } - public List getMetadataTwitterImage() { - return metadataTwitterImage; + public List getMetadataOgImage() { + return metadataOgImage; } - public void setMetadataTwitterImage(List metadataTwitterImage) { - this.metadataTwitterImage = metadataTwitterImage; + public void setMetadataOgImage(List metadataOgImage) { + this.metadataOgImage = metadataOgImage; } - public String getMetadataTwitterCreator() { - return metadataTwitterCreator; + public String getMetadataTwitterSite() { + return metadataTwitterSite; } - public void setMetadataTwitterCreator(String metadataTwitterCreator) { - this.metadataTwitterCreator = metadataTwitterCreator; + public void setMetadataTwitterSite(String metadataTwitterSite) { + this.metadataTwitterSite = metadataTwitterSite; } - public List getImage() { - return image; + public String getMetadataTwitterCreator() { + return metadataTwitterCreator; } - public void setImage(List image) { - this.image = image; + public void setMetadataTwitterCreator(String metadataTwitterCreator) { + this.metadataTwitterCreator = metadataTwitterCreator; } public String getMetadataTwitterTitle() { @@ -196,14 +213,6 @@ public void setMetadataTwitterTitle(String metadataTwitterTitle) { this.metadataTwitterTitle = metadataTwitterTitle; } - public String getProductName() { - return productName; - } - - public void setProductName(String productName) { - this.productName = productName; - } - public String getMetadataTwitterDescription() { return metadataTwitterDescription; } @@ -212,20 +221,12 @@ public void setMetadataTwitterDescription(String metadataTwitterDescription) { this.metadataTwitterDescription = metadataTwitterDescription; } - public String getUrlPattern() { - return urlPattern; - } - - public void setUrlPattern(String urlPattern) { - this.urlPattern = urlPattern; - } - - public List getMetadataOgImage() { - return metadataOgImage; + public List getMetadataTwitterImage() { + return metadataTwitterImage; } - public void setMetadataOgImage(List metadataOgImage) { - this.metadataOgImage = metadataOgImage; + public void setMetadataTwitterImage(List metadataTwitterImage) { + this.metadataTwitterImage = metadataTwitterImage; } public System getSystem() { diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/HeroUnit.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/HeroUnit.java index f05d699e..74d6d66f 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/HeroUnit.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/HeroUnit.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.util.List; import kontent.ai.delivery.Asset; @@ -15,10 +16,7 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("hero_unit") -public class HeroUnit { - @ElementMapping("sitemap") - List sitemap; - +public class HeroUnit implements Serializable { @ElementMapping("title") String title; @@ -28,15 +26,10 @@ public class HeroUnit { @ElementMapping("marketing_message") String marketingMessage; - System system; - - public List getSitemap() { - return sitemap; - } + @ElementMapping("sitemap") + List sitemap; - public void setSitemap(List sitemap) { - this.sitemap = sitemap; - } + System system; public String getTitle() { return title; @@ -62,6 +55,14 @@ public void setMarketingMessage(String marketingMessage) { this.marketingMessage = marketingMessage; } + public List getSitemap() { + return sitemap; + } + + public void setSitemap(List sitemap) { + this.sitemap = sitemap; + } + public System getSystem() { return system; } diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Home.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Home.java index f2df5cef..040d0ee3 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Home.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Home.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.util.List; import kontent.ai.delivery.Asset; @@ -16,36 +17,45 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("home") -public class Home { - @ElementMapping("metadata__og_description") - String metadataOgDescription; - - @ElementMapping("metadata__meta_title") - String metadataMetaTitle; - - @ElementMapping("metadata__og_title") - String metadataOgTitle; +public class Home implements Serializable { + @ContentItemMapping("hero_unit") + List heroUnit; @ContentItemMapping("articles") List articles; - @ContentItemMapping("hero_unit") - List heroUnit; + @ContentItemMapping("our_story") + List ourStory; + + @ContentItemMapping("cafes") + List cafes; + + @ElementMapping("contact") + String contact; + + @ElementMapping("url_pattern") + String urlPattern; + + @ElementMapping("sitemap") + List sitemap; + + @ElementMapping("metadata__meta_title") + String metadataMetaTitle; @ElementMapping("metadata__meta_description") String metadataMetaDescription; - @ElementMapping("metadata__twitter_site") - String metadataTwitterSite; + @ElementMapping("metadata__og_title") + String metadataOgTitle; - @ContentItemMapping("our_story") - List ourStory; + @ElementMapping("metadata__og_description") + String metadataOgDescription; - @ContentItemMapping("cafes") - List cafes; + @ElementMapping("metadata__og_image") + List metadataOgImage; - @ElementMapping("metadata__twitter_image") - List metadataTwitterImage; + @ElementMapping("metadata__twitter_site") + String metadataTwitterSite; @ElementMapping("metadata__twitter_creator") String metadataTwitterCreator; @@ -56,58 +66,73 @@ public class Home { @ElementMapping("metadata__twitter_description") String metadataTwitterDescription; - @ElementMapping("metadata__og_image") - List metadataOgImage; + @ElementMapping("metadata__twitter_image") + List metadataTwitterImage; - @ElementMapping("url_pattern") - String urlPattern; + System system; - @ElementMapping("sitemap") - List sitemap; + public List getHeroUnit() { + return heroUnit; + } - @ElementMapping("contact") - String contact; + public void setHeroUnit(List heroUnit) { + this.heroUnit = heroUnit; + } - System system; + public List getArticles() { + return articles; + } - public String getMetadataOgDescription() { - return metadataOgDescription; + public void setArticles(List articles) { + this.articles = articles; } - public void setMetadataOgDescription(String metadataOgDescription) { - this.metadataOgDescription = metadataOgDescription; + public List getOurStory() { + return ourStory; } - public String getMetadataMetaTitle() { - return metadataMetaTitle; + public void setOurStory(List ourStory) { + this.ourStory = ourStory; } - public void setMetadataMetaTitle(String metadataMetaTitle) { - this.metadataMetaTitle = metadataMetaTitle; + public List getCafes() { + return cafes; } - public String getMetadataOgTitle() { - return metadataOgTitle; + public void setCafes(List cafes) { + this.cafes = cafes; } - public void setMetadataOgTitle(String metadataOgTitle) { - this.metadataOgTitle = metadataOgTitle; + public String getContact() { + return contact; } - public List getArticles() { - return articles; + public void setContact(String contact) { + this.contact = contact; } - public void setArticles(List articles) { - this.articles = articles; + public String getUrlPattern() { + return urlPattern; } - public List getHeroUnit() { - return heroUnit; + public void setUrlPattern(String urlPattern) { + this.urlPattern = urlPattern; } - public void setHeroUnit(List heroUnit) { - this.heroUnit = heroUnit; + public List getSitemap() { + return sitemap; + } + + public void setSitemap(List sitemap) { + this.sitemap = sitemap; + } + + public String getMetadataMetaTitle() { + return metadataMetaTitle; + } + + public void setMetadataMetaTitle(String metadataMetaTitle) { + this.metadataMetaTitle = metadataMetaTitle; } public String getMetadataMetaDescription() { @@ -118,36 +143,36 @@ public void setMetadataMetaDescription(String metadataMetaDescription) { this.metadataMetaDescription = metadataMetaDescription; } - public String getMetadataTwitterSite() { - return metadataTwitterSite; + public String getMetadataOgTitle() { + return metadataOgTitle; } - public void setMetadataTwitterSite(String metadataTwitterSite) { - this.metadataTwitterSite = metadataTwitterSite; + public void setMetadataOgTitle(String metadataOgTitle) { + this.metadataOgTitle = metadataOgTitle; } - public List getOurStory() { - return ourStory; + public String getMetadataOgDescription() { + return metadataOgDescription; } - public void setOurStory(List ourStory) { - this.ourStory = ourStory; + public void setMetadataOgDescription(String metadataOgDescription) { + this.metadataOgDescription = metadataOgDescription; } - public List getCafes() { - return cafes; + public List getMetadataOgImage() { + return metadataOgImage; } - public void setCafes(List cafes) { - this.cafes = cafes; + public void setMetadataOgImage(List metadataOgImage) { + this.metadataOgImage = metadataOgImage; } - public List getMetadataTwitterImage() { - return metadataTwitterImage; + public String getMetadataTwitterSite() { + return metadataTwitterSite; } - public void setMetadataTwitterImage(List metadataTwitterImage) { - this.metadataTwitterImage = metadataTwitterImage; + public void setMetadataTwitterSite(String metadataTwitterSite) { + this.metadataTwitterSite = metadataTwitterSite; } public String getMetadataTwitterCreator() { @@ -174,36 +199,12 @@ public void setMetadataTwitterDescription(String metadataTwitterDescription) { this.metadataTwitterDescription = metadataTwitterDescription; } - public List getMetadataOgImage() { - return metadataOgImage; - } - - public void setMetadataOgImage(List metadataOgImage) { - this.metadataOgImage = metadataOgImage; - } - - public String getUrlPattern() { - return urlPattern; - } - - public void setUrlPattern(String urlPattern) { - this.urlPattern = urlPattern; - } - - public List getSitemap() { - return sitemap; - } - - public void setSitemap(List sitemap) { - this.sitemap = sitemap; - } - - public String getContact() { - return contact; + public List getMetadataTwitterImage() { + return metadataTwitterImage; } - public void setContact(String contact) { - this.contact = contact; + public void setMetadataTwitterImage(List metadataTwitterImage) { + this.metadataTwitterImage = metadataTwitterImage; } public System getSystem() { diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/HostedVideo.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/HostedVideo.java index 63ea0ff7..1ec4056c 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/HostedVideo.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/HostedVideo.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.util.List; import kontent.ai.delivery.ContentItemMapping; @@ -14,7 +15,7 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("hosted_video") -public class HostedVideo { +public class HostedVideo implements Serializable { @ElementMapping("video_id") String videoId; diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Office.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Office.java index 7c470746..bf197f1b 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Office.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Office.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.util.List; import kontent.ai.delivery.ContentItemMapping; @@ -14,58 +15,58 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("office") -public class Office { - @ElementMapping("state") - String state; +public class Office implements Serializable { + @ElementMapping("name") + String name; - @ElementMapping("email") - String email; + @ElementMapping("street") + String street; - @ElementMapping("phone") - String phone; + @ElementMapping("city") + String city; @ElementMapping("country") String country; - @ElementMapping("sitemap") - List sitemap; - - @ElementMapping("city") - String city; - - @ElementMapping("name") - String name; + @ElementMapping("state") + String state; @ElementMapping("zip_code") String zipCode; - @ElementMapping("street") - String street; + @ElementMapping("phone") + String phone; + + @ElementMapping("email") + String email; + + @ElementMapping("sitemap") + List sitemap; System system; - public String getState() { - return state; + public String getName() { + return name; } - public void setState(String state) { - this.state = state; + public void setName(String name) { + this.name = name; } - public String getEmail() { - return email; + public String getStreet() { + return street; } - public void setEmail(String email) { - this.email = email; + public void setStreet(String street) { + this.street = street; } - public String getPhone() { - return phone; + public String getCity() { + return city; } - public void setPhone(String phone) { - this.phone = phone; + public void setCity(String city) { + this.city = city; } public String getCountry() { @@ -76,44 +77,44 @@ public void setCountry(String country) { this.country = country; } - public List getSitemap() { - return sitemap; + public String getState() { + return state; } - public void setSitemap(List sitemap) { - this.sitemap = sitemap; + public void setState(String state) { + this.state = state; } - public String getCity() { - return city; + public String getZipCode() { + return zipCode; } - public void setCity(String city) { - this.city = city; + public void setZipCode(String zipCode) { + this.zipCode = zipCode; } - public String getName() { - return name; + public String getPhone() { + return phone; } - public void setName(String name) { - this.name = name; + public void setPhone(String phone) { + this.phone = phone; } - public String getZipCode() { - return zipCode; + public String getEmail() { + return email; } - public void setZipCode(String zipCode) { - this.zipCode = zipCode; + public void setEmail(String email) { + this.email = email; } - public String getStreet() { - return street; + public List getSitemap() { + return sitemap; } - public void setStreet(String street) { - this.street = street; + public void setSitemap(List sitemap) { + this.sitemap = sitemap; } public System getSystem() { diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Tweet.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Tweet.java index 632d68d5..1dff20dd 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Tweet.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/models/Tweet.java @@ -1,5 +1,6 @@ package kontent.ai.delivery.sample.dancinggoat.models; +import java.io.Serializable; import java.lang.String; import java.util.List; import kontent.ai.delivery.ContentItemMapping; @@ -14,7 +15,7 @@ * For further modifications of the class, create a separate file and extend this class. */ @ContentItemMapping("tweet") -public class Tweet { +public class Tweet implements Serializable { @ElementMapping("tweet_link") String tweetLink; diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/CachingConfig.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/CachingConfig.java new file mode 100644 index 00000000..a4034c76 --- /dev/null +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/CachingConfig.java @@ -0,0 +1,53 @@ +package kontent.ai.delivery.sample.dancinggoat.springboot; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.concurrent.ConcurrentMapCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +import java.time.Duration; + +@Configuration +@EnableCaching +public class CachingConfig { + /*@Bean + public CacheManager cacheManager() { + return new ConcurrentMapCacheManager("test"); + }*/ + + @Bean + public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.enable(JsonGenerator.Feature.IGNORE_UNKNOWN); + objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + objectMapper.registerModule(new JavaTimeModule()); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + + RedisSerializer serializer = new GenericJackson2JsonRedisSerializer(objectMapper); + + + RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig() + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(serializer)) + .entryTtl(Duration.ofMinutes(1)); + + return RedisCacheManager.builder(redisConnectionFactory) + .cacheDefaults(config) + .build(); + } +} \ No newline at end of file diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/KontentConfiguration.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/KontentConfiguration.java index 29d320c6..4b1d1f5e 100644 --- a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/KontentConfiguration.java +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/KontentConfiguration.java @@ -13,6 +13,7 @@ import org.springframework.web.client.RestTemplate; import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect; +import java.io.Serializable; import java.util.Arrays; import java.util.Map; diff --git a/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/TestService.java b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/TestService.java new file mode 100644 index 00000000..d89d4b24 --- /dev/null +++ b/sample-app-spring-boot/src/main/java/kontent/ai/delivery/sample/dancinggoat/springboot/TestService.java @@ -0,0 +1,34 @@ +package kontent.ai.delivery.sample.dancinggoat.springboot; + +import kontent.ai.delivery.ContentItem; +import kontent.ai.delivery.DeliveryClient; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import java.io.Serializable; + +@Component +public class TestService implements Serializable { + + @Cacheable(cacheNames = "test", key = "#contentName") //, key = "#contentName" + public ContentItem fetchContentByCodeName(String contentName, DeliveryClient deliveryClient) { + try { + simulateSlowService(); + ContentItem contentItem = deliveryClient.getItem(contentName, ContentItem.class).toCompletableFuture().get(); + return contentItem; + } catch (Exception exp) { + throw new RuntimeException("Error fetching content with codename = " + contentName, exp); + } + } + + + // Don't do this at home + private void simulateSlowService() { + try { + long time = 3000L; + Thread.sleep(time); + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + } +} diff --git a/sample-app-spring-boot/src/main/resources/application.properties b/sample-app-spring-boot/src/main/resources/application.properties new file mode 100644 index 00000000..77793395 --- /dev/null +++ b/sample-app-spring-boot/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.cache.type=redis +spring.redis.host=redis-17780.c277.us-east-1-3.ec2.cloud.redislabs.com +spring.redis.port=17780 +spring.redis.username=default +spring.redis.password=XXXXXXXXXX \ No newline at end of file