RM-5012 - fix write records created in current transaction

This commit is contained in:
Ana Bozianu
2017-05-16 15:53:29 +03:00
parent 49119d6d3b
commit d17121ff2c
6 changed files with 52 additions and 22 deletions

View File

@@ -27,20 +27,46 @@
package org.alfresco.module.org_alfresco_module_rm.capability.policy;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl;
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
import org.alfresco.service.cmr.repository.NodeRef;
import org.aopalliance.intercept.MethodInvocation;
import net.sf.acegisecurity.vote.AccessDecisionVoter;
public class WriteContentPolicy extends AbstractBasePolicy
{
protected TransactionalResourceHelper transactionalResourceHelper;
public void setTransactionalResourceHelper(TransactionalResourceHelper transactionalResourceHelper)
{
this.transactionalResourceHelper = transactionalResourceHelper;
}
@SuppressWarnings("rawtypes")
public int evaluate(
public int evaluate(
MethodInvocation invocation,
Class[] params,
ConfigAttributeDefinition cad)
{
NodeRef updatee = getTestNode(invocation, params, cad.getParameters().get(0), cad.isParent());
return getCapabilityService().getCapability("WriteContent").evaluate(updatee);
try{
NodeRef updatee = getTestNode(invocation, params, cad.getParameters().get(0), cad.isParent());
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS);
if(newRecords.contains(updatee))
{
return AccessDecisionVoter.ACCESS_GRANTED;
}
else
{
return getCapabilityService().getCapability("WriteContent").evaluate(updatee);
}
}
catch(Exception ex)
{
throw ex;
}
}
}

View File

@@ -1205,11 +1205,11 @@ public class RecordServiceImpl extends BaseBehaviourBean
disablePropertyEditableCheck();
try
{
authenticationUtil.runAsSystem(new RunAsWork<Void>()
{
authenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception {
@Override
public Void doWork() throws Exception {
Map<QName, Serializable> props = new HashMap<>();
if(!nodeService.hasAspect(document, ASPECT_RECORD_COMPONENT_ID))
@@ -1226,19 +1226,19 @@ public class RecordServiceImpl extends BaseBehaviourBean
props.put(PROP_IDENTIFIER, recordId);
props.put(PROP_ORIGIONAL_NAME, name);
}
nodeService.addAspect(document, RecordsManagementModel.ASPECT_RECORD, props);
nodeService.addAspect(document, RecordsManagementModel.ASPECT_RECORD, props);
// remove versionable aspect(s)
nodeService.removeAspect(document, RecordableVersionModel.ASPECT_VERSIONABLE);
// remove versionable aspect(s)
nodeService.removeAspect(document, RecordableVersionModel.ASPECT_VERSIONABLE);
// remove the owner
ownableService.setOwner(document, OwnableService.NO_OWNER);
appendIdentifierToName(nodeService, document);
return null;
}
});
// remove the owner
ownableService.setOwner(document, OwnableService.NO_OWNER);
appendIdentifierToName(nodeService, document);
return null;
}
});
}
finally
{