Search in sources :

Example 11 with ActivityPostEntity

use of org.alfresco.repo.domain.activities.ActivityPostEntity in project alfresco-repository by Alfresco.

the class PostLookup method updatePosts.

private void updatePosts(List<ActivityPostEntity> activityPosts) throws SQLException {
    for (final ActivityPostEntity activityPost : activityPosts) {
        // MT share
        final String tenantDomain = activityPost.getTenantDomain();
        TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Object>() {

            public Object doWork() throws Exception {
                try {
                    postDAO.startTransaction();
                    ActivityPostEntity.STATUS status = ActivityPostEntity.STATUS.valueOf(activityPost.getStatus());
                    switch(status) {
                        case ERROR:
                        case PROCESSED:
                            postDAO.updatePostStatus(activityPost.getId(), status);
                            break;
                        case POSTED:
                            if (activityPost.getId() == null) {
                                // eg. rolled-up post
                                postDAO.insertPost(activityPost);
                            }
                            break;
                        case PENDING:
                            postDAO.updatePost(activityPost.getId(), activityPost.getSiteNetwork(), activityPost.getActivityData(), ActivityPostEntity.STATUS.POSTED);
                            // for debug output
                            activityPost.setStatus(ActivityPostEntity.STATUS.POSTED.toString());
                            break;
                        default:
                            throw new Exception("Unexpected status: " + status);
                    }
                    if (logger.isDebugEnabled()) {
                        logger.debug("Updated: " + activityPost);
                    }
                    postDAO.commitTransaction();
                } catch (SQLException e) {
                    logger.error("Exception during update of post: ", e);
                    throw new JobExecutionException(e);
                } catch (Exception e) {
                    // log error, but consume exception (skip this post)
                    logger.error("Skipping activity post " + activityPost.getId() + ": " + e);
                    postDAO.updatePostStatus(activityPost.getId(), ActivityPostEntity.STATUS.ERROR);
                    postDAO.commitTransaction();
                } finally {
                    postDAO.endTransaction();
                }
                return null;
            }
        }, tenantDomain);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) SQLException(java.sql.SQLException) TenantUtil(org.alfresco.repo.tenant.TenantUtil) JSONObject(org.json.JSONObject) ActivityPostEntity(org.alfresco.repo.domain.activities.ActivityPostEntity) SQLException(java.sql.SQLException) JSONException(org.json.JSONException) JobExecutionException(org.quartz.JobExecutionException) LockAcquisitionException(org.alfresco.repo.lock.LockAcquisitionException)

Aggregations

ActivityPostEntity (org.alfresco.repo.domain.activities.ActivityPostEntity)11 SQLException (java.sql.SQLException)6 JSONObject (org.json.JSONObject)6 Date (java.util.Date)5 JSONException (org.json.JSONException)5 LockAcquisitionException (org.alfresco.repo.lock.LockAcquisitionException)4 JobExecutionException (org.quartz.JobExecutionException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TenantUtil (org.alfresco.repo.tenant.TenantUtil)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Pair (org.alfresco.util.Pair)3 HashMap (java.util.HashMap)2 JSONTokener (org.json.JSONTokener)2 TemplateException (freemarker.template.TemplateException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1