While I am trying to start the workflow from job scheduling getting database violation error:
ERROR [node.db.DeletedNodeCleanupWorker] [DefaultScheduler_Worker-10] Failed to purge nodes. If the purgable set is too large for the available DB resources
then the nodes can be purged manually as well.
Set log level to WARN for this class to get exception log:
Max commit time: 1486464301224
Error:
### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table "alf_node" violates foreign key constraint "fk_alf_nprop_n" on table "alf_node_properties"
Detail: Key (id)=(1584) is still referenced from table "alf_node_properties".
### The error may involve alfresco.node.delete_NodesByTxnCommitTime-Inline
### The error occurred while setting parameters
### Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table "alf_node" violates foreign key constraint "fk_alf_nprop_n" on table "alf_node_properties"
Detail: Key (id)=(1584) is still referenced from table "alf_node_properties".
; SQL []; ERROR: update or delete on table "alf_node" violates foreign key constraint "fk_alf_nprop_n" on table "alf_node_properties"
Detail: Key (id)=(1584) is still referenced from table "alf_node_properties".; nested exception is org.postgresql.util.PSQLException: ERROR: update or delete on table "alf_node" violates foreign key constraint "fk_alf_nprop_n" on table "alf_node_properties"
Detail: Key (id)=(1584) is still referenced from table "alf_node_properties".
my java code is there below please go through this and say that is there anything to change.
StartWfBeforeDocExpireJobs .java
public class StartWfBeforeDocExpireJobs extends AbstractScheduledLockedJob {
private static final Logger logger=Logger.getLogger(StartWfBeforeDocExpireJobs.class);
private static NodeService nodeService;
private static SearchService searchService;
private static WorkflowService workflowService;
private static AuthorityService authorityService;
private static AuthenticationComponent authenticationComponent;
private static TransactionService transactionService;
@SuppressWarnings("static-access")
@Override
public void executeJob(JobExecutionContext jobContext)
throws JobExecutionException {
// TODO Auto-generated method stub
setUp(jobContext);
this.authenticationComponent.setCurrentUser("admin");
expireDoc();
}
public void setUp(JobExecutionContext jobContext)
{
logger.debug("in StartWfBeforeDocExpireJobs");
StartWfBeforeDocExpireJobs.nodeService = ((NodeService)jobContext.getJobDetail().getJobDataMap().get("nodeService"));
StartWfBeforeDocExpireJobs.searchService = ((SearchService)jobContext.getJobDetail().getJobDataMap().get("searchService"));
StartWfBeforeDocExpireJobs.workflowService = ((WorkflowService)jobContext.getJobDetail().getJobDataMap().get("workflowService"));
StartWfBeforeDocExpireJobs.authorityService = ((AuthorityService)jobContext.getJobDetail().getJobDataMap().get("authorityService"));
StartWfBeforeDocExpireJobs.authenticationComponent = ((AuthenticationComponent)jobContext.getJobDetail().getJobDataMap().get("authenticationComponent"));
StartWfBeforeDocExpireJobs.transactionService = ((TransactionService)jobContext.getJobDetail().getJobDataMap().get("transactionService"));
logger.debug("end StartWfBeforeDocExpireJobs");
}
@SuppressWarnings({ "static-access", "unchecked" })
public void expireDoc()
{
@SuppressWarnings("rawtypes")
RetryingTransactionHelper.RetryingTransactionCallback txnWork = new RetryingTransactionHelper.RetryingTransactionCallback() {
public Object execute() throws Exception {
StartWfBeforeDocExpire stwfbfdocExp=new StartWfBeforeDocExpire(StartWfBeforeDocExpireJobs.nodeService,
StartWfBeforeDocExpireJobs.searchService, StartWfBeforeDocExpireJobs.workflowService,
StartWfBeforeDocExpireJobs.authorityService);
logger.debug("method:"+stwfbfdocExp);
stwfbfdocExp.StartWfBeforeDocExp();
return null;
}
};
this.transactionService.getRetryingTransactionHelper().doInTransaction(txnWork);
}
}
StartWfBeforeDocExpire.java
public class StartWfBeforeDocExpire {
private static Logger logger=Logger.getLogger(StartWfBeforeDocExpire.class);
private NodeService nodeService;
private static SearchService searchService;
private WorkflowService workflowService;
private AuthorityService authorityService;
private final String GROUP_NAME = "REVIEWERS";
private final String WORKFLOW_DESCRIPTION = "Request for approval";
private final String TASK_DESCRIPTION = "Check contents and review.";
private final String ACTIVITI_PARALLEL_GROUP_REVIEW_NAME = "activiti$activitiParallelGroupReview";
@SuppressWarnings("static-access")
public StartWfBeforeDocExpire(NodeService nodeService,SearchService searchService,WorkflowService workflowService,AuthorityService authorityService)
{
this.nodeService = nodeService;
this.searchService = searchService;
this.workflowService = workflowService;
this.authorityService = authorityService;
}
public void StartWfBeforeDocExp() throws Exception
{
try{
String query = "PATH:\"//app:company_home/st:sites/*/cm:documentLibrary//*\" ";
logger.debug("query: "+query);
List<NodeRef> nRef1 = luceneSearch(query,"cm:created",true);
if(nRef1!=null)
{
logger.debug("nodes found: "+nRef1.size());
for(NodeRef nRef:nRef1){
logger.debug("files:"+nRef);
List<WorkflowInstance> workflowInstances = workflowService.getActiveWorkflows();
logger.debug("workflowInstances:"+workflowInstances);
if(workflowInstances.isEmpty()){
startWorkflow1(nRef);
logger.debug("workflow started for selected document");
break;
}
}
}
}catch (Exception e) {
System.out.println("Error: "+e.getMessage());
e.printStackTrace();
throw e;
}
}
protected void startWorkflow1(NodeRef contentNodeRef) {
NodeRef workflowNodeRef = workflowService.createPackage(null);
Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowNodeRef);
// parameters.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, WORKFLOW_DESCRIPTION);
parameters.put(WorkflowModel.PROP_DESCRIPTION, TASK_DESCRIPTION);
parameters.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE,
authorityService.getAuthorityNodeRef("GROUP_" + GROUP_NAME));
parameters.put(WorkflowModel.PROP_PERCENT_COMPLETE, 50);
// Add zero or more items
nodeService.addChild(
workflowNodeRef,
contentNodeRef,
WorkflowModel.ASSOC_PACKAGE_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
QName.createValidLocalName(nodeService.getProperty(
contentNodeRef, ContentModel.PROP_NAME).toString())));
WorkflowDefinition wfDefinition =
workflowService.getDefinitionByName(ACTIVITI_PARALLEL_GROUP_REVIEW_NAME);
workflowService.startWorkflow(wfDefinition.getId(), parameters);
}
public static List<NodeRef> luceneSearch(String s,String sortField,Boolean isAsc) {
SearchParameters sp = new SearchParameters();
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
sp.addSort(sortField, isAsc);
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(s);
sp.setLimitBy(LimitBy.FINAL_SIZE);
org.alfresco.service.cmr.search.ResultSet rs=searchService.query(sp);
if(rs==null)return null;
if(rs.length()==0)return null;
return rs.getNodeRefs();
}
}