RM-7051 adding batch code

This commit is contained in:
Ross Gale
2019-11-17 22:07:31 +00:00
parent 098be4c2da
commit e603eaf0eb
7 changed files with 177 additions and 42 deletions

View File

@@ -8,7 +8,20 @@
<parameter property="idValue" jdbcType="BIGINT" javaType="java.lang.String"/>
</parameterMap>
<parameterMap id="parameter_MNT-20864_folderPatchPaging" type="map">
<parameter property="dispositionQnameId" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="folderQnameId" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="start" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="end" jdbcType="BIGINT" javaType="java.lang.Long"/>
</parameterMap>
<parameterMap id="parameter_MNT-20864_folderPatchCount" type="map">
<parameter property="dispositionQnameId" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="folderQnameId" jdbcType="BIGINT" javaType="java.lang.Long"/>
</parameterMap>
<resultMap id="result_NodeRefEntity" type="org.alfresco.module.org_alfresco_module_rm.query.NodeRefEntity">
<result property="row" column="row" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="protocol" column="protocol" jdbcType="VARCHAR" javaType="java.lang.String" />
<result property="identifier" column="identifier" jdbcType="VARCHAR" javaType="java.lang.String" />
<result property="uuid" column="uuid" jdbcType="VARCHAR" javaType="java.lang.String" />
@@ -29,23 +42,36 @@
<!-- Get list of node ids which reference given content url query used for RMv24DispositionInheritancePatch-->
<select id="select_RecordFoldersWithSchedules"
parameterMap="parameter_folderPatchPaging"
resultMap="result_NodeRefEntity">
select alfs.protocol, alfs.identifier, alfn.uuid
from alf_node alfn,
alf_store alfs
where alfn.id in (
select node_id
from alf_node_properties
where qname_id = (
select id
from alf_qname
where local_name = 'recordSearchHasDispositionSchedule')
and boolean_value = true )
and type_qname_id = (
select id
from alf_qname
where local_name = 'recordFolder')
and alfn.store_id = alfs.id
select * from (
select ROW_NUMBER() over (order by alfn.uuid) as rnum, alfn.id , alfs.protocol, alfs.identifier, alfn.uuid
from alf_node alfn,
alf_store alfs
where alfn.id in (
select node_id
from alf_node_properties
where qname_id = ?
and boolean_value = true )
and type_qname_id = ?
and alfn.store_id = alfs.id
order by alfn.uuid
) as foo where foo.rnum BETWEEN ? and ?
</select>
<select id="select_RecordFoldersWithSchedulesCount"
parameterMap="parameter_folderPatchCount"
resultType="java.lang.Integer">
select count(*) from
alf_node alfn,
alf_store alfs
where alfn.id in (
select node_id
from alf_node_properties
where qname_id = ?
and boolean_value = true )
and type_qname_id = ?
and alfn.store_id = alfs.id
</select>

View File

@@ -237,6 +237,14 @@ public interface DispositionService
*/
void updateNextDispositionAction(NodeRef nodeRef);
/**
* Updates the next disposition action
*
* @param nodeRef node reference
* @param DispositionSchedule the schedule to be applied
*/
void updateNextDispositionAction(NodeRef nodeRef, DispositionSchedule dispositionSchedule);
/**
* Refreshes the disposition action details of the given node.
*

View File

@@ -954,6 +954,34 @@ public class DispositionServiceImpl extends ServiceBaseImpl
{
// Get this disposition instructions for the node
DispositionSchedule di = getDispositionSchedule(nodeRef);
updateNextDispositionAction(nodeRef, di);
return null;
}
};
AuthenticationUtil.runAsSystem(runAsWork);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService#updateNextDispositionAction(NodeRef)
*/
@Override
public void updateNextDispositionAction(final NodeRef nodeRef, final DispositionSchedule di)
{
RunAsWork<Void> runAsWork = new RunAsWork<Void>()
{
/**
* @see org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork#doWork()
*/
@Override
public Void doWork()
{
if (di != null)
{
// Get the current action node

View File

@@ -31,11 +31,13 @@ import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagement
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionActionDefinition;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
import org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch;
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
@@ -52,7 +54,9 @@ import org.apache.commons.logging.LogFactory;
*/
public class RMv24DispositionInheritancePatch extends AbstractModulePatch
{
private static Log logger = LogFactory.getLog(RMv24DispositionInheritancePatch.class);
private static final Log logger = LogFactory.getLog(RMv24DispositionInheritancePatch.class);
private static final long BATCH_SIZE = 5L;
private DispositionService dispositionService;
@@ -90,30 +94,51 @@ public class RMv24DispositionInheritancePatch extends AbstractModulePatch
@Override
public void applyInternal()
{
logger.info("***********************recordsManagementQueryDAO.getNodeRefs()***************************");
logger.info(recordsManagementQueryDAO.getRecordFoldersWithSchedules());
logger.info("***********************RMv24DispositionInheritancePatch***************************");
logger.info("********************Patch start********************");
int maxNode = recordsManagementQueryDAO.getRecordFoldersWithSchedulesCount();
logger.info("nodes to update: "+ maxNode);
List<NodeRef> folders = recordsManagementQueryDAO.getRecordFoldersWithSchedules();
logger.info("folders: " + folders);
for (NodeRef folder : folders)
for (Long i = 0L; i < maxNode; i += BATCH_SIZE)
{
DispositionSchedule schedule = dispositionService.getDispositionSchedule(folder);
logger.info("schedule: " + schedule);
if (schedule.isRecordLevelDisposition())
{
List<NodeRef> records = recordService.getRecords(folder);
logger.info("records: " + records);
for (NodeRef record : records)
final Long finali = i;
int updatedRecords = transactionService.getRetryingTransactionHelper()
.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Integer>()
{
if (!nodeService.hasAspect(record, ASPECT_DISPOSITION_LIFECYCLE))
public Integer execute() throws Throwable
{
logger.info("updating record: " + record);
dispositionService.updateNextDispositionAction(record);
int recordCount = 0;
logger.info("********************Patch start********************");
logger.info("********************Query start********************");
logger.info(finali);
logger.info(finali + BATCH_SIZE);
logger.info(recordsManagementQueryDAO.getRecordFoldersWithSchedules(finali, finali + BATCH_SIZE));
List<NodeRef> folders = recordsManagementQueryDAO.getRecordFoldersWithSchedules(finali, finali + BATCH_SIZE);
logger.info("********************Query end********************");
for (NodeRef folder : folders)
{
DispositionSchedule schedule = dispositionService.getDispositionSchedule(folder);
if (schedule.isRecordLevelDisposition())
{
List<NodeRef> records = recordService.getRecords(folder);
for (NodeRef record : records)
{
if (!nodeService.hasAspect(record, ASPECT_DISPOSITION_LIFECYCLE))
{
logger.info("updating record: " + record);
dispositionService.updateNextDispositionAction(record, schedule);
recordCount ++;
}
}
}
}
logger.info("********************Patch end********************");
return recordCount;
}
}
}
}, false, true);
logger.info("....completed: "+ updatedRecords);
}
}
}

View File

@@ -34,6 +34,7 @@ package org.alfresco.module.org_alfresco_module_rm.query;
*/
public class NodeRefEntity
{
private Long num;
private String protocol;
private String identifier;
private String uuid;
@@ -45,6 +46,16 @@ public class NodeRefEntity
{
}
public Long getNum()
{
return num;
}
public void setNum(Long num)
{
this.num = num;
}
public String getProtocol()
{
return protocol;

View File

@@ -52,9 +52,18 @@ public interface RecordsManagementQueryDAO
int getCountRmaIdentifier(String identifierValue);
/**
* Returns a list of nodeRef for all record folders in the system
* Returns a number of nodeRefs for record folders in the system
* that have the property recordSearchHasDispositionSchedule:true
* @return List of nodeRefs
* (used for MNT-20864)
* @param start long - the first result row to return
* @param end long - the last result row to return
* @return list of node refs
*/
public List<NodeRef> getRecordFoldersWithSchedules();
public List<NodeRef> getRecordFoldersWithSchedules(Long start, Long end);
/**
* Returns the count of record folders with a schedule applied (used for MNT-20864)
* @return the number of record folders with a disposition schedule
*/
public int getRecordFoldersWithSchedulesCount();
}

View File

@@ -49,6 +49,7 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
{
private static final String COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier";
private static final String SCHEDULED_FOLDERS = "alfresco.query.rm.select_RecordFoldersWithSchedules";
private static final String SCHEDULED_FOLDERS_COUNT = "alfresco.query.rm.select_RecordFoldersWithSchedulesCount";
/** SQL session template */
protected SqlSessionTemplate template;
@@ -105,9 +106,16 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
* @see org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO#getRecordFoldersWithSchedules()
*/
@Override
public List<NodeRef> getRecordFoldersWithSchedules()
public List<NodeRef> getRecordFoldersWithSchedules(Long start, Long end)
{
List<NodeRefEntity> entities = template.selectList(SCHEDULED_FOLDERS);
Map<String, Object> params = new HashMap<String, Object>(2);
params.put("dispositionQnameId", qnameDAO.getQName(PROP_RS_HAS_DISPOITION_SCHEDULE)
.getFirst());
params.put("folderQnameId",qnameDAO.getQName(TYPE_RECORD_FOLDER).getFirst());
params.put("start", start);
params.put("end", end);
List<NodeRefEntity> entities = template.selectList(SCHEDULED_FOLDERS, params);
List<NodeRef> results = new ArrayList<>();
@@ -120,4 +128,24 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
return results;
}
public int getRecordFoldersWithSchedulesCount()
{
int result = 0;
Map<String, Object> params = new HashMap<String, Object>(2);
params.put("dispositionQnameId", qnameDAO.getQName(PROP_RS_HAS_DISPOITION_SCHEDULE)
.getFirst());
params.put("folderQnameId", qnameDAO.getQName(TYPE_RECORD_FOLDER)
.getFirst());
Integer count = template.selectOne(SCHEDULED_FOLDERS_COUNT, params);
if (count != null)
{
result = count;
}
return result;
}
}