mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
RM-7051 adding batch code
This commit is contained in:
@@ -8,7 +8,20 @@
|
|||||||
<parameter property="idValue" jdbcType="BIGINT" javaType="java.lang.String"/>
|
<parameter property="idValue" jdbcType="BIGINT" javaType="java.lang.String"/>
|
||||||
</parameterMap>
|
</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">
|
<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="protocol" column="protocol" jdbcType="VARCHAR" javaType="java.lang.String" />
|
||||||
<result property="identifier" column="identifier" 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" />
|
<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-->
|
<!-- Get list of node ids which reference given content url query used for RMv24DispositionInheritancePatch-->
|
||||||
<select id="select_RecordFoldersWithSchedules"
|
<select id="select_RecordFoldersWithSchedules"
|
||||||
|
parameterMap="parameter_folderPatchPaging"
|
||||||
resultMap="result_NodeRefEntity">
|
resultMap="result_NodeRefEntity">
|
||||||
select alfs.protocol, alfs.identifier, alfn.uuid
|
select * from (
|
||||||
from alf_node alfn,
|
select ROW_NUMBER() over (order by alfn.uuid) as rnum, alfn.id , alfs.protocol, alfs.identifier, alfn.uuid
|
||||||
alf_store alfs
|
from alf_node alfn,
|
||||||
where alfn.id in (
|
alf_store alfs
|
||||||
select node_id
|
where alfn.id in (
|
||||||
from alf_node_properties
|
select node_id
|
||||||
where qname_id = (
|
from alf_node_properties
|
||||||
select id
|
where qname_id = ?
|
||||||
from alf_qname
|
and boolean_value = true )
|
||||||
where local_name = 'recordSearchHasDispositionSchedule')
|
and type_qname_id = ?
|
||||||
and boolean_value = true )
|
and alfn.store_id = alfs.id
|
||||||
and type_qname_id = (
|
order by alfn.uuid
|
||||||
select id
|
) as foo where foo.rnum BETWEEN ? and ?
|
||||||
from alf_qname
|
</select>
|
||||||
where local_name = 'recordFolder')
|
|
||||||
and alfn.store_id = alfs.id
|
<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>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -237,6 +237,14 @@ public interface DispositionService
|
|||||||
*/
|
*/
|
||||||
void updateNextDispositionAction(NodeRef nodeRef);
|
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.
|
* Refreshes the disposition action details of the given node.
|
||||||
*
|
*
|
||||||
|
@@ -954,6 +954,34 @@ public class DispositionServiceImpl extends ServiceBaseImpl
|
|||||||
{
|
{
|
||||||
// Get this disposition instructions for the node
|
// Get this disposition instructions for the node
|
||||||
DispositionSchedule di = getDispositionSchedule(nodeRef);
|
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)
|
if (di != null)
|
||||||
{
|
{
|
||||||
// Get the current action node
|
// Get the current action node
|
||||||
|
@@ -31,11 +31,13 @@ import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagement
|
|||||||
|
|
||||||
import java.util.List;
|
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.DispositionSchedule;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
|
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.patch.AbstractModulePatch;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
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.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
@@ -52,7 +54,9 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
*/
|
*/
|
||||||
public class RMv24DispositionInheritancePatch extends AbstractModulePatch
|
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;
|
private DispositionService dispositionService;
|
||||||
|
|
||||||
@@ -90,30 +94,51 @@ public class RMv24DispositionInheritancePatch extends AbstractModulePatch
|
|||||||
@Override
|
@Override
|
||||||
public void applyInternal()
|
public void applyInternal()
|
||||||
{
|
{
|
||||||
logger.info("***********************recordsManagementQueryDAO.getNodeRefs()***************************");
|
logger.info("********************Patch start********************");
|
||||||
logger.info(recordsManagementQueryDAO.getRecordFoldersWithSchedules());
|
int maxNode = recordsManagementQueryDAO.getRecordFoldersWithSchedulesCount();
|
||||||
logger.info("***********************RMv24DispositionInheritancePatch***************************");
|
logger.info("nodes to update: "+ maxNode);
|
||||||
|
|
||||||
|
for (Long i = 0L; i < maxNode; i += BATCH_SIZE)
|
||||||
List<NodeRef> folders = recordsManagementQueryDAO.getRecordFoldersWithSchedules();
|
|
||||||
logger.info("folders: " + folders);
|
|
||||||
for (NodeRef folder : folders)
|
|
||||||
{
|
{
|
||||||
DispositionSchedule schedule = dispositionService.getDispositionSchedule(folder);
|
final Long finali = i;
|
||||||
logger.info("schedule: " + schedule);
|
int updatedRecords = transactionService.getRetryingTransactionHelper()
|
||||||
if (schedule.isRecordLevelDisposition())
|
.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Integer>()
|
||||||
{
|
|
||||||
List<NodeRef> records = recordService.getRecords(folder);
|
|
||||||
logger.info("records: " + records);
|
|
||||||
for (NodeRef record : records)
|
|
||||||
{
|
{
|
||||||
if (!nodeService.hasAspect(record, ASPECT_DISPOSITION_LIFECYCLE))
|
public Integer execute() throws Throwable
|
||||||
{
|
{
|
||||||
logger.info("updating record: " + record);
|
int recordCount = 0;
|
||||||
dispositionService.updateNextDispositionAction(record);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ package org.alfresco.module.org_alfresco_module_rm.query;
|
|||||||
*/
|
*/
|
||||||
public class NodeRefEntity
|
public class NodeRefEntity
|
||||||
{
|
{
|
||||||
|
private Long num;
|
||||||
private String protocol;
|
private String protocol;
|
||||||
private String identifier;
|
private String identifier;
|
||||||
private String uuid;
|
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()
|
public String getProtocol()
|
||||||
{
|
{
|
||||||
return protocol;
|
return protocol;
|
||||||
|
@@ -52,9 +52,18 @@ public interface RecordsManagementQueryDAO
|
|||||||
int getCountRmaIdentifier(String identifierValue);
|
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
|
* 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();
|
||||||
}
|
}
|
||||||
|
@@ -49,6 +49,7 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
{
|
{
|
||||||
private static final String COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier";
|
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 = "alfresco.query.rm.select_RecordFoldersWithSchedules";
|
||||||
|
private static final String SCHEDULED_FOLDERS_COUNT = "alfresco.query.rm.select_RecordFoldersWithSchedulesCount";
|
||||||
|
|
||||||
/** SQL session template */
|
/** SQL session template */
|
||||||
protected SqlSessionTemplate template;
|
protected SqlSessionTemplate template;
|
||||||
@@ -105,9 +106,16 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
* @see org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO#getRecordFoldersWithSchedules()
|
* @see org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO#getRecordFoldersWithSchedules()
|
||||||
*/
|
*/
|
||||||
@Override
|
@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<>();
|
List<NodeRef> results = new ArrayList<>();
|
||||||
|
|
||||||
@@ -120,4 +128,24 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
return results;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user