Index: core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/ExtendedData.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/ExtendedData.java (revision )
+++ core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/ExtendedData.java (revision )
@@ -0,0 +1,146 @@
+
+package org.onehippo.cms7.crisp.core.resource.jackson.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ *
Java class for extendedDataType complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType name="extendedDataType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="type" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="uri" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="description" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "extendedDataType", propOrder = {
+ "title",
+ "type",
+ "uri",
+ "description"
+})
+public class ExtendedData {
+
+ @XmlElement(required = true)
+ protected String title;
+ @XmlElement(required = true)
+ protected String type;
+ @XmlElement(required = true)
+ protected String uri;
+ @XmlElement(required = true)
+ protected String description;
+
+ /**
+ * Gets the value of the title property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * Sets the value of the title property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setTitle(String value) {
+ this.title = value;
+ }
+
+ /**
+ * Gets the value of the type property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Sets the value of the type property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setType(String value) {
+ this.type = value;
+ }
+
+ /**
+ * Gets the value of the uri property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * Sets the value of the uri property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setUri(String value) {
+ this.uri = value;
+ }
+
+ /**
+ * Gets the value of the description property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the value of the description property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setDescription(String value) {
+ this.description = value;
+ }
+
+}
Index: core/src/main/java/org/onehippo/cms7/crisp/core/resource/jackson/JacksonResourceBeanMapper.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/main/java/org/onehippo/cms7/crisp/core/resource/jackson/JacksonResourceBeanMapper.java (revision 76dc1ccc7b7efb23289f63c0a2500115668b30ad)
+++ core/src/main/java/org/onehippo/cms7/crisp/core/resource/jackson/JacksonResourceBeanMapper.java (revision )
@@ -15,12 +15,15 @@
*/
package org.onehippo.cms7.crisp.core.resource.jackson;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
import org.onehippo.cms7.crisp.api.resource.Resource;
import org.onehippo.cms7.crisp.api.resource.ResourceBeanMapper;
import org.onehippo.cms7.crisp.api.resource.ResourceException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
/**
* Mapper to convert a {@link JacksonResource} object to a bean.
*/
@@ -41,4 +44,12 @@
return objectMapper.convertValue(((JacksonResource) resource).getJsonNode(), beanType);
}
+ public List mapCollection(Resource resource, Class beanType) throws ResourceException {
+ return resource.getChildren().getCollection()
+ .stream()
+ .map(resourceItem -> map(resourceItem, beanType))
+ .collect(Collectors.toList());
+ }
+
+
}
Index: core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/Product.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/Product.java (revision )
+++ core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/Product.java (revision )
@@ -0,0 +1,151 @@
+
+package org.onehippo.cms7.crisp.core.resource.jackson.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+
+/**
+ * Java class for productType complex type.
+ *
+ *
The following schema fragment specifies the expected content contained within this class.
+ *
+ *
+ * <complexType name="productType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="SKU" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="description" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="extendedData" type="{}extendedDataType"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "productType", propOrder = {
+ "sku",
+ "description",
+ "name",
+ "extendedData"
+})
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Product {
+
+ @XmlElement(name = "SKU")
+ @JsonProperty("SKU")
+ protected String sku;
+ @XmlElement
+ protected String description;
+ @XmlElement
+ protected String name;
+ @XmlElement
+ protected ExtendedData extendedData;
+
+ /**
+ * Gets the value of the sku property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getSKU() {
+ return sku;
+ }
+
+ /**
+ * Sets the value of the sku property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setSKU(String value) {
+ this.sku = value;
+ }
+
+ /**
+ * Gets the value of the description property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the value of the description property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setDescription(String value) {
+ this.description = value;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+ /**
+ * Gets the value of the extendedData property.
+ *
+ * @return
+ * possible object is
+ * {@link ExtendedData }
+ *
+ */
+ public ExtendedData getExtendedData() {
+ return extendedData;
+ }
+
+ /**
+ * Sets the value of the extendedData property.
+ *
+ * @param value
+ * allowed object is
+ * {@link ExtendedData }
+ *
+ */
+ public void setExtendedData(ExtendedData value) {
+ this.extendedData = value;
+ }
+
+}
Index: core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/product.xsd
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/product.xsd (revision )
+++ core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/model/product.xsd (revision )
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: core/src/main/java/org/onehippo/cms7/crisp/core/resource/jdom/JdomResourceBeanMapper.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/main/java/org/onehippo/cms7/crisp/core/resource/jdom/JdomResourceBeanMapper.java (revision 76dc1ccc7b7efb23289f63c0a2500115668b30ad)
+++ core/src/main/java/org/onehippo/cms7/crisp/core/resource/jdom/JdomResourceBeanMapper.java (revision )
@@ -16,10 +16,13 @@
package org.onehippo.cms7.crisp.core.resource.jdom;
import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
import org.jdom2.transform.JDOMSource;
import org.onehippo.cms7.crisp.api.resource.Resource;
import org.onehippo.cms7.crisp.api.resource.ResourceBeanMapper;
+import org.onehippo.cms7.crisp.api.resource.ResourceCollection;
import org.onehippo.cms7.crisp.api.resource.ResourceException;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.XmlMappingException;
@@ -50,4 +53,10 @@
}
}
+ @Override
+ public List mapCollection(final Resource resourceCollection, final Class beanType) throws ResourceException {
+ throw new UnsupportedOperationException("Method unsupported exception");
+ }
+
+
}
Index: api/src/main/java/org/onehippo/cms7/crisp/api/resource/ResourceBeanMapper.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- api/src/main/java/org/onehippo/cms7/crisp/api/resource/ResourceBeanMapper.java (revision 76dc1ccc7b7efb23289f63c0a2500115668b30ad)
+++ api/src/main/java/org/onehippo/cms7/crisp/api/resource/ResourceBeanMapper.java (revision )
@@ -15,6 +15,8 @@
*/
package org.onehippo.cms7.crisp.api.resource;
+import java.util.List;
+
/**
* Mapper to convert a {@link Resource} object to a bean.
*/
@@ -22,6 +24,7 @@
/**
* Map a {@link Resource} object to a bean of {@code type}.
+ *
* @param resource a {@link Resource} object to convert
* @param beanType type of bean to which the {@link Resource} should be mapped
* @return a {@link Resource} object to a bean of {@code type}
@@ -29,4 +32,17 @@
*/
public T map(Resource resource, Class beanType) throws ResourceException;
+
+ /**
+ * Map a {@link Resource} array of objects to a list of {@code type};
+ *
+ * @param resourceCollection
+ * @param beanType
+ * @param
+ * @return
+ * @throws ResourceException
+ */
+ public List mapCollection(Resource resourceCollection, Class beanType) throws ResourceException;
+
+
}
Index: core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.xsd
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.xsd (revision )
+++ core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.xsd (revision )
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.xml (revision )
+++ core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.xml (revision )
@@ -0,0 +1,14 @@
+
+
+ 4150349
+ MultiSync X431BT - 109.22 cm (43 ") , 1920 x 480, 16:4, 500 cd/m², 3000:1, 8 ms
+ NEC MultiSync X431BT
+
+ NEC MultiSync X431BT
+ Link
+ Incentro-HIC-Site/-/products/4150349
+ MultiSync X431BT - 109.22 cm (43 ") , 1920 x 480, 16:4, 500 cd/m², 3000:1, 8 ms
+
+
+
+
Index: core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.json (revision )
+++ core/src/test/resources/org/onehippo/cms7/crisp/core/broker/product.json (revision )
@@ -0,0 +1,11 @@
+{
+ "SKU": "4150349",
+ "description": "MultiSync X431BT - 109.22 cm (43 \") , 1920 x 480, 16:4, 500 cd\/m\u00b2, 3000:1, 8 ms",
+ "name": "NEC MultiSync X431BT",
+ "extendedData": {
+ "title": "NEC MultiSync X431BT",
+ "type": "Link",
+ "uri": "Incentro-HIC-Site\/-\/products\/4150349",
+ "description": "MultiSync X431BT - 109.22 cm (43 \") , 1920 x 480, 16:4, 500 cd\/m\u00b2, 3000:1, 8 ms"
+ }
+}
Index: core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/JacksonResourceCollectionTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/JacksonResourceCollectionTest.java (revision )
+++ core/src/test/java/org/onehippo/cms7/crisp/core/resource/jackson/JacksonResourceCollectionTest.java (revision )
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2017 Hippo B.V. (http://www.onehippo.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onehippo.cms7.crisp.core.resource.jackson;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onehippo.cms7.crisp.api.resource.Resource;
+import org.onehippo.cms7.crisp.api.resource.ResourceBeanMapper;
+import org.onehippo.cms7.crisp.core.resource.jackson.model.Product;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class JacksonResourceCollectionTest {
+
+ private JsonNode rootNode;
+ private Resource rootResource;
+ private ObjectMapper objectMapper;
+ private ResourceBeanMapper resourceBeanMapper;
+
+ @Before
+ public void setUp() throws Exception {
+ InputStream input = null;
+
+ try {
+ objectMapper = new ObjectMapper();
+ input = getClass().getResourceAsStream("/org/onehippo/cms7/crisp/core/broker/products.json");
+ rootNode = objectMapper.readTree(input);
+ rootResource = new JacksonResource(rootNode);
+ } finally {
+ IOUtils.closeQuietly(input);
+ }
+
+ resourceBeanMapper = new JacksonResourceBeanMapper(objectMapper);
+ }
+
+
+ @Test
+ public void testBeanMappingCollection() throws Exception {
+ final List extends Product> productsList = resourceBeanMapper.mapCollection(rootResource, Product.class);
+ assertNotNull(productsList);
+ assertTrue(productsList.size() == 50);
+ assertTrue("4150349".equals(productsList.get(0).getSKU()));
+ }
+}