com.adobe.cq.screens.impl.aemio.ScreensRootModel Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2016 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
************************************************************************/
package com.adobe.cq.screens.impl.aemio;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
import com.adobe.cq.screens.binding.ScreensConstants;
import com.adobe.cq.screens.impl.rest.ScreensResourceProvider;
import com.adobe.granite.haf.annotations.ApiEntities;
import com.adobe.granite.haf.annotations.ApiLink;
import com.adobe.granite.haf.annotations.ApiModel;
import com.adobe.granite.haf.annotations.ApiProperty;
import com.adobe.granite.haf.annotations.ApiRoot;
import com.adobe.granite.rest.Constants;
import com.day.cq.wcm.api.NameConstants;
@Model(adaptables = Resource.class)
@ApiModel(category = ScreensModelLookup.CATEGORY, type={"aem-io/screens/root"}, modelLookup = ScreensModelLookup.class)
@ApiRoot(baseResource = ScreensModelLookup.CONTENT_ROOT)
public class ScreensRootModel {
@Inject
@Self
protected Resource baseResource;
@ApiLink(rel = "root")
public String root = "/api/screens.json";
@ApiLink(rel = "devices")
public String devices = "/api/" + ScreensResourceProvider.TYPE + "/devices" + Constants.EXT_JSON;
@ApiLink(rel = "registration")
public String registration = "/api/" + ScreensResourceProvider.TYPE + "/registration" + Constants.EXT_JSON;
@ApiProperty
public String getTitle() {
return ResourceUtil.getValueMap(baseResource).get(NameConstants.PN_TITLE, String.class);
}
@ApiProperty
public String getDescription() {
return ResourceUtil.getValueMap(baseResource).get(NameConstants.PN_DESCRIPTION, String.class);
}
@ApiEntities
public Iterator projects() {
List projects = new ArrayList();
Resource jcrContent;
for (Resource res : baseResource.getChildren()) {
jcrContent = res.getChild(NameConstants.NN_CONTENT);
if (jcrContent != null && jcrContent.isResourceType(ScreensConstants.RT_PROJECT)) {
projects.add(res);
}
}
return projects.iterator();
}
}