com.kenticocloud.delivery.ContentItemsListingResponse Maven / Gradle / Ivy
Show all versions of delivery-sdk-java Show documentation
/*
* MIT License
*
* Copyright (c) 2017
*
* 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 com.kenticocloud.delivery;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Content items listing response
*
* When you retrieve a list of content items from your project, the Delivery API returns a
* {@link ContentItemsListingResponse}
* @see DeliveryClient#getItems()
* @see DeliveryClient#getItems(List)
*/
public class ContentItemsListingResponse implements ModularContentProvider {
@JsonProperty("items")
List items;
@JsonProperty("modular_content")
Map modularContent;
@JsonProperty("pagination")
Pagination pagination;
@JsonIgnore
private StronglyTypedContentItemConverter stronglyTypedContentItemConverter;
ContentItemsListingResponse() {
//Default constructor
}
/**
* A list of content items
* @return list of {@link ContentItem} objects
*/
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
items.forEach(contentItem -> contentItem.setModularContentProvider(this));
}
/**
* A map of content items used in Modular content and Rich text elements
* @return map of {@link ContentItem} objects
*/
@Override
public Map getModularContent() {
return modularContent;
}
public void setModularContent(Map modularContent) {
this.modularContent = modularContent;
modularContent.values().forEach(contentItem -> contentItem.setModularContentProvider(this));
}
/**
* Information about the retrieved page
* @return the {@link Pagination} object identifying the current page
*/
public Pagination getPagination() {
return pagination;
}
void setPagination(Pagination pagination) {
this.pagination = pagination;
}
/**
* Returns a new instance of List<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.
* @param tClass The class which a new instance should be returned from
* @param The type of class
* @return An instance of List<T> with data mapped from the {@link ContentItem} list in this response.
*/
public List castTo(Class tClass) {
ArrayList tItems = new ArrayList<>();
for (ContentItem item : getItems()) {
tItems.add(stronglyTypedContentItemConverter.convert(item, getModularContent(),tClass));
}
return tItems;
}
void setStronglyTypedContentItemConverter(StronglyTypedContentItemConverter stronglyTypedContentItemConverter) {
this.stronglyTypedContentItemConverter = stronglyTypedContentItemConverter;
for (ContentItem item : getItems()) {
item.setStronglyTypedContentItemConverter(stronglyTypedContentItemConverter);
}
if (modularContent != null) {
for (ContentItem modularContentItem : modularContent.values()) {
modularContentItem.setStronglyTypedContentItemConverter(stronglyTypedContentItemConverter);
}
}
}
}