Search in sources :

Example 96 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project SearchServices by Alfresco.

the class AclTracker method getFullNodesForDbTransaction.

public List<Node> getFullNodesForDbTransaction(Long txid) {
    try {
        GetNodesParameters gnp = new GetNodesParameters();
        ArrayList<Long> txs = new ArrayList<Long>();
        txs.add(txid);
        gnp.setTransactionIds(txs);
        gnp.setStoreProtocol(storeRef.getProtocol());
        gnp.setStoreIdentifier(storeRef.getIdentifier());
        return client.getNodes(gnp, Integer.MAX_VALUE);
    } catch (IOException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    } catch (JSONException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    } catch (AuthenticationException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    }
}
Also used : AuthenticationException(org.alfresco.httpclient.AuthenticationException) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 97 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project SearchServices by Alfresco.

the class AclTracker method checkRepoAndIndexConsistency.

/**
 * Checks the first and last TX time
 * @param state the state of this tracker
 * @throws AuthenticationException
 * @throws IOException
 * @throws JSONException
 */
private void checkRepoAndIndexConsistency(TrackerState state) throws AuthenticationException, IOException, JSONException {
    AclChangeSets firstChangeSets = null;
    if (state.getLastGoodChangeSetCommitTimeInIndex() == 0) {
        state.setCheckedLastAclTransactionTime(true);
        state.setCheckedFirstAclTransactionTime(true);
        log.info("No acl transactions found - no verification required");
        firstChangeSets = client.getAclChangeSets(null, 0L, null, 2000L, 1);
        if (!firstChangeSets.getAclChangeSets().isEmpty()) {
            AclChangeSet firstChangeSet = firstChangeSets.getAclChangeSets().get(0);
            long firstChangeSetCommitTime = firstChangeSet.getCommitTimeMs();
            state.setLastGoodChangeSetCommitTimeInIndex(firstChangeSetCommitTime);
            setLastChangeSetIdAndCommitTimeInTrackerState(firstChangeSets, state);
        }
    }
    if (!state.isCheckedFirstAclTransactionTime()) {
        firstChangeSets = client.getAclChangeSets(null, 0l, null, 2000L, 1);
        if (!firstChangeSets.getAclChangeSets().isEmpty()) {
            AclChangeSet firstAclChangeSet = firstChangeSets.getAclChangeSets().get(0);
            long firstAclTxId = firstAclChangeSet.getId();
            long firstAclTxCommitTime = firstAclChangeSet.getCommitTimeMs();
            int setSize = this.infoSrv.getAclTxDocsSize("" + firstAclTxId, "" + firstAclTxCommitTime);
            if (setSize == 0) {
                log.error("First acl transaction was not found with the correct timestamp.");
                log.error("SOLR has successfully connected to your repository  however the SOLR indexes and repository database do not match.");
                log.error("If this is a new or rebuilt database your SOLR indexes also need to be re-built to match the database.");
                log.error("You can also check your SOLR connection details in solrcore.properties.");
                throw new AlfrescoRuntimeException("Initial acl transaction not found with correct timestamp");
            } else if (setSize == 1) {
                state.setCheckedFirstTransactionTime(true);
                log.info("Verified first acl transaction and timestamp in index");
            } else {
                log.warn("Duplicate initial acl transaction found with correct timestamp");
            }
        }
    }
    // Checks that the last aclTxId in solr is <= last aclTxId in repo
    if (!state.isCheckedLastAclTransactionTime()) {
        if (firstChangeSets == null) {
            firstChangeSets = client.getAclChangeSets(null, 0l, null, 2000L, 1);
        }
        setLastChangeSetIdAndCommitTimeInTrackerState(firstChangeSets, state);
        Long maxChangeSetCommitTimeInRepo = firstChangeSets.getMaxChangeSetCommitTime();
        Long maxChangeSetIdInRepo = firstChangeSets.getMaxChangeSetId();
        if (maxChangeSetCommitTimeInRepo != null && maxChangeSetIdInRepo != null) {
            AclChangeSet maxAclTxInIndex = this.infoSrv.getMaxAclChangeSetIdAndCommitTimeInIndex();
            if (maxAclTxInIndex.getCommitTimeMs() > maxChangeSetCommitTimeInRepo) {
                log.error("Last acl transaction was found in index with timestamp later than that of repository.");
                log.error("Max Acl Tx In Index: " + maxAclTxInIndex.getId() + ", In Repo: " + maxChangeSetIdInRepo);
                log.error("Max Acl Tx Commit Time In Index: " + maxAclTxInIndex.getCommitTimeMs() + ", In Repo: " + maxChangeSetCommitTimeInRepo);
                log.error("SOLR has successfully connected to your repository  however the SOLR indexes and repository database do not match.");
                log.error("If this is a new or rebuilt database your SOLR indexes also need to be re-built to match the database.");
                log.error("You can also check your SOLR connection details in solrcore.properties.");
                throw new AlfrescoRuntimeException("Last acl transaction found in index with incorrect timestamp");
            } else {
                state.setCheckedLastAclTransactionTime(true);
                log.info("Verified last acl transaction timestamp in index less than or equal to that of repository.");
            }
        }
    }
}
Also used : AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AclChangeSets(org.alfresco.solr.client.AclChangeSets) AclChangeSet(org.alfresco.solr.client.AclChangeSet)

Example 98 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project SearchServices by Alfresco.

the class AclTracker method getAclsForDbAclTransaction.

/**
 * @param acltxid Long
 * @return List<Long>
 */
public List<Long> getAclsForDbAclTransaction(Long acltxid) {
    try {
        ArrayList<Long> answer = new ArrayList<Long>();
        AclChangeSets changeSet = client.getAclChangeSets(null, acltxid, null, acltxid + 1, 1);
        List<Acl> acls = client.getAcls(changeSet.getAclChangeSets(), null, Integer.MAX_VALUE);
        for (Acl acl : acls) {
            answer.add(acl.getId());
        }
        return answer;
    } catch (IOException e) {
        throw new AlfrescoRuntimeException("Failed to get acls", e);
    } catch (JSONException e) {
        throw new AlfrescoRuntimeException("Failed to get acls", e);
    } catch (AuthenticationException e) {
        throw new AlfrescoRuntimeException("Failed to get acls", e);
    }
}
Also used : AuthenticationException(org.alfresco.httpclient.AuthenticationException) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONException(org.json.JSONException) AclChangeSets(org.alfresco.solr.client.AclChangeSets) Acl(org.alfresco.solr.client.Acl) IOException(java.io.IOException)

Example 99 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.

the class BaseDetailsBean method approve.

/**
 * Event handler called to handle the approve step of the simple workflow
 *
 * @param event The event that was triggered
 */
public void approve(ActionEvent event) {
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String id = params.get("id");
    if (id == null || id.length() == 0) {
        throw new AlfrescoRuntimeException("approve called without an id");
    }
    final NodeRef docNodeRef = new NodeRef(Repository.getStoreRef(), id);
    try {
        RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
        RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                // call the service to perform the approve
                WorkflowUtil.approve(docNodeRef, getNodeService(), getCopyService());
                return null;
            }
        };
        txnHelper.doInTransaction(callback);
        // if this was called via the node details dialog we need to reset the node
        if (getNode() != null) {
            getNode().reset();
        }
        // also make sure the UI will get refreshed
        UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_APPROVE), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 100 with AlfrescoRuntimeException

use of org.alfresco.error.AlfrescoRuntimeException in project acs-community-packaging by Alfresco.

the class ActionInstanceEvaluator method getEvaluator.

/**
 * @return the ActionEvaluator to execute
 */
public ActionEvaluator getEvaluator() {
    if (this.evaluator == null) {
        Object objEvaluator;
        try {
            Class clazz = Class.forName(getEvaluatorClassName());
            objEvaluator = clazz.newInstance();
        } catch (Throwable err) {
            throw new AlfrescoRuntimeException("Unable to construct action evaluator: " + getEvaluatorClassName());
        }
        if (objEvaluator instanceof ActionEvaluator == false) {
            throw new AlfrescoRuntimeException("Must implement ActionEvaluator interface: " + getEvaluatorClassName());
        }
        this.evaluator = (ActionEvaluator) objEvaluator;
    }
    return this.evaluator;
}
Also used : ActionEvaluator(org.alfresco.web.action.ActionEvaluator) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)197 NodeRef (org.alfresco.service.cmr.repository.NodeRef)79 QName (org.alfresco.service.namespace.QName)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)32 ArrayList (java.util.ArrayList)31 JSONException (org.json.JSONException)23 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Serializable (java.io.Serializable)20 M2Model (org.alfresco.repo.dictionary.M2Model)18 JSONObject (org.json.JSONObject)15 Date (java.util.Date)14 Map (java.util.Map)12 FacesContext (javax.faces.context.FacesContext)12 InputStream (java.io.InputStream)10 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)10 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)10 JSONArray (org.json.JSONArray)10 List (java.util.List)8 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)8