RM: Fix failing unit tests

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@48440 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2013-03-21 06:27:19 +00:00
parent 5943d7ad46
commit 096c74aaa9
6 changed files with 48 additions and 25 deletions

View File

@@ -14,7 +14,7 @@
<!-- Create record action --> <!-- Create record action -->
<bean id="create-record" parent="action-executer" class="org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction"> <bean id="create-record" parent="action-executer" class="org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction">
<property name="recordsManagementService" ref="RecordsManagementService"/> <property name="filePlanAuthenticationService" ref="FilePlanAuthenticationService"/>
<property name="recordService" ref="RecordService" /> <property name="recordService" ref="RecordService" />
<property name="nodeService" ref="NodeService" /> <property name="nodeService" ref="NodeService" />
<property name="filePlanService" ref="FilePlanService" /> <property name="filePlanService" ref="FilePlanService" />

View File

@@ -22,12 +22,13 @@ import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanAuthenticationService;
import org.alfresco.repo.action.ParameterDefinitionImpl; import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -57,9 +58,6 @@ public class CreateRecordAction extends ActionExecuterAbstractBase
public static final String PARAM_FILE_PLAN = "file-plan"; public static final String PARAM_FILE_PLAN = "file-plan";
public static final String PARAM_HIDE_RECORD = "hide-record"; public static final String PARAM_HIDE_RECORD = "hide-record";
/** Records management service */
private RecordsManagementService recordsManagementService;
/** Record service */ /** Record service */
private RecordService recordService; private RecordService recordService;
@@ -72,13 +70,8 @@ public class CreateRecordAction extends ActionExecuterAbstractBase
/** Dictionary service */ /** Dictionary service */
private DictionaryService dictionaryService; private DictionaryService dictionaryService;
/** /** File plan authentication service */
* @param recordsManagementService records management service private FilePlanAuthenticationService filePlanAuthenticationService;
*/
public void setRecordsManagementService(RecordsManagementService recordsManagementService)
{
this.recordsManagementService = recordsManagementService;
}
/** /**
* @param recordService record service * @param recordService record service
@@ -104,12 +97,22 @@ public class CreateRecordAction extends ActionExecuterAbstractBase
this.filePlanService = filePlanService; this.filePlanService = filePlanService;
} }
@Override /**
* @param dictionaryService dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService) public void setDictionaryService(DictionaryService dictionaryService)
{ {
this.dictionaryService = dictionaryService; this.dictionaryService = dictionaryService;
} }
/**
* @param filePlanAuthenticationService file plan authentication service
*/
public void setFilePlanAuthenticationService(FilePlanAuthenticationService filePlanAuthenticationService)
{
this.filePlanAuthenticationService = filePlanAuthenticationService;
}
/** /**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/ */
@@ -163,16 +166,22 @@ public class CreateRecordAction extends ActionExecuterAbstractBase
NodeRef filePlan = (NodeRef)action.getParameterValue(PARAM_FILE_PLAN); NodeRef filePlan = (NodeRef)action.getParameterValue(PARAM_FILE_PLAN);
if (filePlan == null) if (filePlan == null)
{ {
List<NodeRef> filePlans = recordsManagementService.getFilePlans(); // TODO .. eventually make the file plan parameter required
if (filePlans.size() == 1) filePlan = filePlanAuthenticationService.runAsRmAdmin(new RunAsWork<NodeRef>()
{ {
filePlan = filePlans.get(0); @Override
} public NodeRef doWork() throws Exception
else {
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
}
});
// if the file plan is still null, raise an exception
if (filePlan == null)
{ {
if (logger.isDebugEnabled() == true) if (logger.isDebugEnabled() == true)
{ {
logger.debug("Can not create record, because the default file plan can not be determined."); logger.debug("Can not create record, because the default file plan can not be determined. Make sure at least one file plan has been created.");
} }
throw new AlfrescoRuntimeException("Can not create record, because the default file plan can not be determined."); throw new AlfrescoRuntimeException("Can not create record, because the default file plan can not be determined.");
} }

View File

@@ -33,6 +33,9 @@ import com.hazelcast.impl.Node;
*/ */
public interface FilePlanService public interface FilePlanService
{ {
/** Default RM site id. Can be used with {@link FilePlanService#getFilePlanBySiteId(String)} to get the file plan node. */
public static final String DEFAULT_RM_SITE_ID = "rm";
/** /**
* Indicates whether the given node is file plan node or not. * Indicates whether the given node is file plan node or not.
* *

View File

@@ -113,13 +113,14 @@ public class RoleDeclarativeWebScript extends DeclarativeWebScript
if (filePlan == null) if (filePlan == null)
{ {
// Assume we are in a legacy repository and we will grab the default file plan // Assume we are in a legacy repository and we will grab the default file plan
filePlan = filePlanService.getFilePlanBySiteId("rm"); filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
} }
return filePlan; return filePlan;
} }
/** /**
* Create role items
* *
* @param filePlan * @param filePlan
* @param roles * @param roles
@@ -131,6 +132,7 @@ public class RoleDeclarativeWebScript extends DeclarativeWebScript
} }
/** /**
* Create role items
* *
* @param filePlan * @param filePlan
* @param roles * @param roles
@@ -159,6 +161,7 @@ public class RoleDeclarativeWebScript extends DeclarativeWebScript
} }
/** /**
* Create authority items
* *
* @param authorities * @param authorities
* @return * @return
@@ -177,7 +180,7 @@ public class RoleDeclarativeWebScript extends DeclarativeWebScript
} }
/** /**
* Role item utility class * Role Item Helper Class
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.1 * @since 2.1
@@ -239,6 +242,12 @@ public class RoleDeclarativeWebScript extends DeclarativeWebScript
} }
} }
/**
* Authority Item Helper Class
*
* @author Roy Wetherall
* @since 2.1
*/
public class AuthorityItem public class AuthorityItem
{ {
private String name; private String name;

View File

@@ -69,6 +69,7 @@ public class CreateRecordActionTest extends BaseRMTestCase
Action action = dmActionService.createAction(CreateRecordAction.NAME); Action action = dmActionService.createAction(CreateRecordAction.NAME);
action.setParameterValue(CreateRecordAction.PARAM_HIDE_RECORD, false); action.setParameterValue(CreateRecordAction.PARAM_HIDE_RECORD, false);
action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
dmActionService.executeAction(action, dmDocument); dmActionService.executeAction(action, dmDocument);
return null; return null;
@@ -76,10 +77,10 @@ public class CreateRecordActionTest extends BaseRMTestCase
public void test(Void result) throws Exception public void test(Void result) throws Exception
{ {
assertTrue(recordService.isRecord(dmDocument));
assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(dmDocument, RMPermissionModel.READ_RECORDS)); assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(dmDocument, RMPermissionModel.READ_RECORDS));
assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS)); assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS));
assertTrue(recordService.isRecord(dmDocument));
}; };
}, },
dmCollaborator); dmCollaborator);

View File

@@ -69,6 +69,7 @@ public class RejectActionTest extends BaseRMTestCase
{ {
// Create a record from the document // Create a record from the document
Action createAction = rmActionService.createAction(CreateRecordAction.NAME); Action createAction = rmActionService.createAction(CreateRecordAction.NAME);
createAction.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
rmActionService.executeAction(createAction, dmDocument); rmActionService.executeAction(createAction, dmDocument);
// Check if the document is a record now // Check if the document is a record now