Search in sources :

Example 1 with SolrServletRequest

use of org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest in project SearchServices by Alfresco.

the class AlfrescoSolrUtils method addNode.

/**
 * @param core
 * @param dataModel
 * @param txid
 * @param dbid
 * @param aclid
 * @param type
 * @param aspects
 * @param properties
 * @param content
 * @param owner
 * @param parentAssocs
 * @param ancestors
 * @param paths
 * @param nodeRef
 * @param commit
 * @return
 * @throws IOException
 */
public static NodeRef addNode(SolrCore core, AlfrescoSolrDataModel dataModel, int txid, int dbid, int aclid, QName type, QName[] aspects, Map<QName, PropertyValue> properties, Map<QName, String> content, String owner, ChildAssociationRef[] parentAssocs, NodeRef[] ancestors, String[] paths, NodeRef nodeRef, boolean commit) throws IOException {
    SolrServletRequest solrQueryRequest = null;
    try {
        solrQueryRequest = new SolrServletRequest(core, null);
        AddUpdateCommand addDocCmd = new AddUpdateCommand(solrQueryRequest);
        addDocCmd.overwrite = true;
        addDocCmd.solrDoc = createDocument(dataModel, new Long(txid), new Long(dbid), nodeRef, type, aspects, properties, content, new Long(aclid), paths, owner, parentAssocs, ancestors);
        core.getUpdateHandler().addDoc(addDocCmd);
        if (commit) {
            core.getUpdateHandler().commit(new CommitUpdateCommand(solrQueryRequest, false));
        }
    } finally {
        solrQueryRequest.close();
    }
    return nodeRef;
}
Also used : SolrServletRequest(org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand)

Example 2 with SolrServletRequest

use of org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest in project SearchServices by Alfresco.

the class AlfrescoSolrUtils method addAcl.

/**
 * Add an acl.
 * @param core
 * @param dataModel
 * @param acltxid
 * @param aclId
 * @param maxReader
 * @param totalReader
 * @throws IOException
 */
public static void addAcl(SolrCore core, AlfrescoSolrDataModel dataModel, int acltxid, int aclId, int maxReader, int totalReader) throws IOException {
    SolrQueryRequest solrQueryRequest = new SolrServletRequest(core, null);
    AddUpdateCommand aclTxCmd = new AddUpdateCommand(solrQueryRequest);
    aclTxCmd.overwrite = true;
    SolrInputDocument aclTxSol = new SolrInputDocument();
    String aclTxId = AlfrescoSolrDataModel.getAclChangeSetDocumentId(new Long(acltxid));
    aclTxSol.addField(FIELD_SOLR4_ID, aclTxId);
    aclTxSol.addField(FIELD_VERSION, "0");
    aclTxSol.addField(FIELD_ACLTXID, acltxid);
    aclTxSol.addField(FIELD_INACLTXID, acltxid);
    aclTxSol.addField(FIELD_ACLTXCOMMITTIME, (new Date()).getTime());
    aclTxSol.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL_TX);
    aclTxCmd.solrDoc = aclTxSol;
    core.getUpdateHandler().addDoc(aclTxCmd);
    AddUpdateCommand aclCmd = new AddUpdateCommand(solrQueryRequest);
    aclCmd.overwrite = true;
    SolrInputDocument aclSol = new SolrInputDocument();
    String aclDocId = AlfrescoSolrDataModel.getAclDocumentId(AlfrescoSolrDataModel.DEFAULT_TENANT, new Long(aclId));
    aclSol.addField(FIELD_SOLR4_ID, aclDocId);
    aclSol.addField(FIELD_VERSION, "0");
    aclSol.addField(FIELD_ACLID, aclId);
    aclSol.addField(FIELD_INACLTXID, "" + acltxid);
    aclSol.addField(FIELD_READER, "GROUP_EVERYONE");
    aclSol.addField(FIELD_READER, "pig");
    for (int i = 0; i <= maxReader; i++) {
        aclSol.addField(FIELD_READER, "READER-" + (totalReader - i));
    }
    aclSol.addField(FIELD_DENIED, "something");
    aclSol.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL);
    aclCmd.solrDoc = aclSol;
    core.getUpdateHandler().addDoc(aclCmd);
}
Also used : SolrServletRequest(org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) AtomicLong(java.util.concurrent.atomic.AtomicLong) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Date(java.util.Date)

Example 3 with SolrServletRequest

use of org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest in project SearchServices by Alfresco.

the class AlfrescoSolrUtils method addStoreRoot.

/**
 * Add a store to root.
 * @param core
 * @param dataModel
 * @param rootNodeRef
 * @param txid
 * @param dbid
 * @param acltxid
 * @param aclid
 * @throws IOException
 */
public static void addStoreRoot(SolrCore core, AlfrescoSolrDataModel dataModel, NodeRef rootNodeRef, int txid, int dbid, int acltxid, int aclid) throws IOException {
    SolrServletRequest solrQueryRequest = null;
    try {
        solrQueryRequest = new SolrServletRequest(core, null);
        AddUpdateCommand addDocCmd = new AddUpdateCommand(solrQueryRequest);
        addDocCmd.overwrite = true;
        addDocCmd.solrDoc = createDocument(dataModel, new Long(txid), new Long(dbid), rootNodeRef, ContentModel.TYPE_STOREROOT, new QName[] { ContentModel.ASPECT_ROOT }, null, null, new Long(aclid), new String[] { "/" }, "system", null, null);
        core.getUpdateHandler().addDoc(addDocCmd);
        addAcl(solrQueryRequest, core, dataModel, acltxid, aclid, 0, 0);
        AddUpdateCommand txCmd = new AddUpdateCommand(solrQueryRequest);
        txCmd.overwrite = true;
        SolrInputDocument input = new SolrInputDocument();
        String id = AlfrescoSolrDataModel.getTransactionDocumentId(new Long(txid));
        input.addField(FIELD_SOLR4_ID, id);
        input.addField(FIELD_VERSION, "0");
        input.addField(FIELD_TXID, txid);
        input.addField(FIELD_INTXID, txid);
        input.addField(FIELD_TXCOMMITTIME, (new Date()).getTime());
        input.addField(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_TX);
        txCmd.solrDoc = input;
        core.getUpdateHandler().addDoc(txCmd);
        core.getUpdateHandler().commit(new CommitUpdateCommand(solrQueryRequest, false));
    } finally {
        solrQueryRequest.close();
    }
}
Also used : SolrServletRequest(org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) QName(org.alfresco.service.namespace.QName) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Date(java.util.Date)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)3 SolrServletRequest (org.alfresco.solr.AbstractAlfrescoSolrTests.SolrServletRequest)3 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)3 Date (java.util.Date)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)2 QName (org.alfresco.service.namespace.QName)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1