// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/model/GeometrixxMediaContentType.java
// public interface GeometrixxMediaContentType {
// 
//     JSONObject getJson();
// 
//     SolrInputDocument getSolrDoc();
// 
// }
// 
// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/model/GeometrixxMediaPage.java
// @Model(adaptables = Resource.class, adapters = {GeometrixxMediaContentType.class, GeometrixxMediaPage.class})
// public class GeometrixxMediaPage implements GeometrixxMediaContentType{
// 
//     private static final Logger LOG = LoggerFactory.getLogger(GeometrixxMediaPage.class);
// 
//     private GeometrixxMediaPageContent pageContent;
// 
//     @Inject @Named("jcr:content")
//     private Resource jcrResource;
// 
//     @PostConstruct
//     public void init() throws SlingModelsException {
// 
//         pageContent = jcrResource.adaptTo(GeometrixxMediaPageContent.class);
// 
//     }
// 
//     public GeometrixxMediaPage(Resource resource) throws SlingModelsException {
// 
//         if (null == resource) {
//             LOG.debug("resource is null");
//             throw new SlingModelsException("Resource is null");
//         }
// 
//         if (ResourceUtil.isNonExistingResource(resource)) {
//             LOG.warn("Can't adapt non existent resource: '{}'", resource.getPath());
//             throw new SlingModelsException(
//                 "Can't adapt non existent resource." + resource.getPath());
//         }
// 
//     }
// 
//     @Override
//     public String toString() {
// 
//         final StringBuilder sb = new StringBuilder("GeometrixxMediaPage{");
//         if(null != pageContent){
//             sb.append(pageContent.toString());
//         }
//         sb.append('}');
//         return sb.toString();
//     }
// 
//     @Override
//     public JSONObject getJson() {
// 
//         return pageContent != null ? pageContent.getJson() : new JSONObject();
//     }
// 
//     @Override
//     public SolrInputDocument getSolrDoc() {
// 
//         return pageContent != null ? pageContent.getSolrDoc() : null;
//     }
// }


import com.day.cq.search.PredicateGroup;
import com.day.cq.search.Query;
import com.day.cq.search.QueryBuilder;
import com.day.cq.search.result.Hit;
import com.day.cq.search.result.SearchResult;
import com.headwire.aemsolrsearch.geometrixxmedia.model.GeometrixxMediaContentType;
import com.headwire.aemsolrsearch.geometrixxmedia.model.GeometrixxMediaPage;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.*;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.jcr.api.SlingRepository;
import org.json.simple.JSONArray;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
        JSONArray solrDocs = new JSONArray();

        final String slingResourceType = getSlingResourceType(request);

        if (StringUtils.isEmpty(slingResourceType)) {
            response.getWriter().write(solrDocs.toJSONString());
            return;
        }

        Map<String, String> params = new HashMap<String, String>();
        params.put("path", "/content/geometrixx-media");
        params.put("type", "cq:PageContent");
        params.put("property", "sling:resourceType");
        params.put("property.value", slingResourceType);
        params.put("p.offset", "0");
        params.put("p.limit", "50");

        Session session = null;

        try {
            session = repository.loginAdministrative(null);
            Query query = queryBuilder.createQuery(PredicateGroup.create(params), session);
            SearchResult results = query.getResult();

            LOG.info("Found '{}' matches for query", results.getTotalMatches());

            for (Hit hit: results.getHits()) {

                // The query returns the jcr:content node, so we need its parent.
                Resource page = hit.getResource().getParent();
// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/model/GeometrixxMediaContentType.java
// public interface GeometrixxMediaContentType {
// 
//     JSONObject getJson();
// 
//     SolrInputDocument getSolrDoc();
// 
// }
// 
// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/model/GeometrixxMediaPage.java
// @Model(adaptables = Resource.class, adapters = {GeometrixxMediaContentType.class, GeometrixxMediaPage.class})
// public class GeometrixxMediaPage implements GeometrixxMediaContentType{
// 
//     private static final Logger LOG = LoggerFactory.getLogger(GeometrixxMediaPage.class);
// 
//     private GeometrixxMediaPageContent pageContent;
// 
//     @Inject @Named("jcr:content")
//     private Resource jcrResource;
// 
//     @PostConstruct
//     public void init() throws SlingModelsException {
// 
//         pageContent = jcrResource.adaptTo(GeometrixxMediaPageContent.class);
// 
//     }
// 
//     public GeometrixxMediaPage(Resource resource) throws SlingModelsException {
// 
//         if (null == resource) {
//             LOG.debug("resource is null");
//             throw new SlingModelsException("Resource is null");
//         }
// 
//         if (ResourceUtil.isNonExistingResource(resource)) {
//             LOG.warn("Can't adapt non existent resource: '{}'", resource.getPath());
//             throw new SlingModelsException(
//                 "Can't adapt non existent resource." + resource.getPath());
//         }
// 
//     }
// 
//     @Override
//     public String toString() {
// 
//         final StringBuilder sb = new StringBuilder("GeometrixxMediaPage{");
//         if(null != pageContent){
//             sb.append(pageContent.toString());
//         }
//         sb.append('}');
//         return sb.toString();
//     }
// 
//     @Override
//     public JSONObject getJson() {
// 
//         return pageContent != null ? pageContent.getJson() : new JSONObject();
//     }
// 
//     @Override
//     public SolrInputDocument getSolrDoc() {
// 
//         return pageContent != null ? pageContent.getSolrDoc() : null;
//     }
// }


// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/servlets/SolrBulkUpdateHandler.java
import com.day.cq.search.PredicateGroup;
import com.day.cq.search.Query;
import com.day.cq.search.QueryBuilder;
import com.day.cq.search.result.Hit;
import com.day.cq.search.result.SearchResult;
import com.headwire.aemsolrsearch.geometrixxmedia.model.GeometrixxMediaContentType;
import com.headwire.aemsolrsearch.geometrixxmedia.model.GeometrixxMediaPage;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.*;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.jcr.api.SlingRepository;
import org.json.simple.JSONArray;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

        JSONArray solrDocs = new JSONArray();

        final String slingResourceType = getSlingResourceType(request);

        if (StringUtils.isEmpty(slingResourceType)) {
            response.getWriter().write(solrDocs.toJSONString());
            return;
        }

        Map<String, String> params = new HashMap<String, String>();
        params.put("path", "/content/geometrixx-media");
        params.put("type", "cq:PageContent");
        params.put("property", "sling:resourceType");
        params.put("property.value", slingResourceType);
        params.put("p.offset", "0");
        params.put("p.limit", "50");

        Session session = null;

        try {
            session = repository.loginAdministrative(null);
            Query query = queryBuilder.createQuery(PredicateGroup.create(params), session);
            SearchResult results = query.getResult();

            LOG.info("Found '{}' matches for query", results.getTotalMatches());

            for (Hit hit: results.getHits()) {

                // The query returns the jcr:content node, so we need its parent.
                Resource page = hit.getResource().getParent();
                GeometrixxMediaContentType contentType = page.adaptTo(GeometrixxMediaPage.class);