Search in sources :

Example 1 with NodeParameters

use of org.alfresco.repo.solr.NodeParameters in project alfresco-remote-api by Alfresco.

the class NodesGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    try {
        Content content = req.getContent();
        if (content == null) {
            throw new WebScriptException("Failed to convert request to String");
        }
        JSONObject o = new JSONObject(content.getContent());
        JSONArray aTxnIds = o.has("txnIds") ? o.getJSONArray("txnIds") : null;
        Long fromTxnId = o.has("fromTxnId") ? o.getLong("fromTxnId") : null;
        Long toTxnId = o.has("toTxnId") ? o.getLong("toTxnId") : null;
        Long fromNodeId = o.has("fromNodeId") ? o.getLong("fromNodeId") : null;
        Long toNodeId = o.has("toNodeId") ? o.getLong("toNodeId") : null;
        Set<QName> excludeAspects = null;
        if (o.has("excludeAspects")) {
            JSONArray aExcludeAspects = o.getJSONArray("excludeAspects");
            excludeAspects = new HashSet<QName>(aExcludeAspects.length());
            for (int i = 0; i < aExcludeAspects.length(); i++) {
                excludeAspects.add(QName.createQName(aExcludeAspects.getString(i).trim()));
            }
        }
        Set<QName> includeAspects = null;
        if (o.has("includeAspects")) {
            JSONArray aIncludeAspects = o.getJSONArray("includeAspects");
            includeAspects = new HashSet<QName>(aIncludeAspects.length());
            for (int i = 0; i < aIncludeAspects.length(); i++) {
                includeAspects.add(QName.createQName(aIncludeAspects.getString(i).trim()));
            }
        }
        Set<QName> excludeNodeTypes = null;
        if (o.has("excludeNodeTypes")) {
            JSONArray aExcludeNodeTypes = o.getJSONArray("excludeNodeTypes");
            excludeNodeTypes = new HashSet<QName>(aExcludeNodeTypes.length());
            for (int i = 0; i < aExcludeNodeTypes.length(); i++) {
                excludeNodeTypes.add(QName.createQName(aExcludeNodeTypes.getString(i).trim()));
            }
        }
        Set<QName> includeNodeTypes = null;
        if (o.has("includeNodeTypes")) {
            JSONArray aIncludeNodeTypes = o.getJSONArray("includeNodeTypes");
            includeNodeTypes = new HashSet<QName>(aIncludeNodeTypes.length());
            for (int i = 0; i < aIncludeNodeTypes.length(); i++) {
                includeNodeTypes.add(QName.createQName(aIncludeNodeTypes.getString(i).trim()));
            }
        }
        // 0 or Integer.MAX_VALUE => ignore
        int maxResults = o.has("maxResults") ? o.getInt("maxResults") : 0;
        String storeProtocol = o.has("storeProtocol") ? o.getString("storeProtocol") : null;
        String storeIdentifier = o.has("storeIdentifier") ? o.getString("storeIdentifier") : null;
        List<Long> txnIds = null;
        if (aTxnIds != null) {
            txnIds = new ArrayList<Long>(aTxnIds.length());
            for (int i = 0; i < aTxnIds.length(); i++) {
                txnIds.add(aTxnIds.getLong(i));
            }
        }
        String shardProperty = o.has("shardProperty") ? o.getString("shardProperty") : null;
        NodeParameters nodeParameters = new NodeParameters();
        nodeParameters.setTransactionIds(txnIds);
        nodeParameters.setFromTxnId(fromTxnId);
        nodeParameters.setToTxnId(toTxnId);
        nodeParameters.setFromNodeId(fromNodeId);
        nodeParameters.setToNodeId(toNodeId);
        nodeParameters.setExcludeAspects(excludeAspects);
        nodeParameters.setIncludeAspects(includeAspects);
        nodeParameters.setExcludeNodeTypes(excludeNodeTypes);
        nodeParameters.setIncludeNodeTypes(includeNodeTypes);
        nodeParameters.setShardProperty(shardProperty);
        StoreRef storeRef = null;
        if (AuthenticationUtil.isMtEnabled()) {
            // MT - use Java filter (post query) and then add tenant context for each node
            storeRef = new StoreRef(storeProtocol, storeIdentifier);
        } else {
            // non-MT - use DB filter (in query)
            nodeParameters.setStoreProtocol(storeProtocol);
            nodeParameters.setStoreIdentifier(storeIdentifier);
        }
        nodeParameters.setMaxResults(maxResults);
        WebNodeQueryCallback nodeQueryCallback = new WebNodeQueryCallback(maxResults, storeRef, tenantService, qnameDAO);
        solrTrackingComponent.getNodes(nodeParameters, nodeQueryCallback);
        Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
        List<NodeRecord> nodes = nodeQueryCallback.getNodes();
        model.put("nodes", nodes);
        if (logger.isDebugEnabled()) {
            logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
        }
        return model;
    } catch (IOException e) {
        throw new WebScriptException("IO exception parsing request", e);
    } catch (JSONException e) {
        throw new WebScriptException("Invalid JSON", e);
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) NodeParameters(org.alfresco.repo.solr.NodeParameters) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) Content(org.springframework.extensions.surf.util.Content) JSONObject(org.json.JSONObject)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 NodeParameters (org.alfresco.repo.solr.NodeParameters)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 QName (org.alfresco.service.namespace.QName)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Content (org.springframework.extensions.surf.util.Content)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1