RM-581 (A user will receive notification of rejected records)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@46114 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-01-31 18:47:35 +00:00
parent 336ef19c99
commit d08b441438
8 changed files with 177 additions and 149 deletions

View File

@@ -1139,21 +1139,17 @@
</properties>
</aspect>
<!-- Aspect to hold the information about the original location of a record -->
<aspect name="rma:originalLocation">
<title>The original location of a record</title>
<!-- Aspect to hold the originating details of a record -->
<aspect name="rma:recordOriginatingDetails">
<title>The originating details of a record</title>
<properties>
<property name="rma:orgLocation">
<property name="rma:recordOrginalLocation">
<type>d:any</type>
</property>
</properties>
</aspect>
<!-- Aspect to hold the information about reject reason of a record -->
<aspect name="rma:rejectReasonRecord">
<title>The reject reason of a record</title>
<properties>
<property name="rma:rejectReason">
<property name="rma:recordCreationDate">
<type>d:date</type>
</property>
<property name="rma:recordUserId">
<type>d:text</type>
</property>
</properties>

View File

@@ -1101,6 +1101,7 @@
<property name="policyComponent" ref="policyComponent" />
<property name="dispositionService" ref="DispositionService" />
<property name="filePlanService" ref="FilePlanService" />
<property name="notificationService" ref="NotificationService"/>
</bean>
<bean id="RecordService" class="org.springframework.aop.framework.ProxyFactoryBean">

View File

@@ -116,7 +116,7 @@ public class HideRecordAction extends ActionExecuterAbstractBase implements Reco
else
{
// remove the child association
NodeRef originalLocation = (NodeRef) nodeService.getProperty(actionedUponNodeRef, PROP_ORIGINAL_LOCATION);
NodeRef originalLocation = (NodeRef) nodeService.getProperty(actionedUponNodeRef, PROP_RECORD_ORIGINAL_LOCATION);
List<ChildAssociationRef> parentAssocs = nodeService.getParentAssocs(actionedUponNodeRef);
for (ChildAssociationRef childAssociationRef : parentAssocs)
{

View File

@@ -232,10 +232,8 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel
public static final QName PROP_READERS = QName.createQName(RM_URI, "readers");
// Original location of a record
public static final QName ASPECT_ORIGINAL_LOCATION = QName.createQName(RM_URI, "originalLocation");
public static final QName PROP_ORIGINAL_LOCATION = QName.createQName(RM_URI, "orgLocation");
// Reject reason of a record
public static final QName ASPECT_REJECT_REASON_RECORD = QName.createQName(RM_URI, "rejectReasonRecord");
public static final QName PROP_REJECT_REASON = QName.createQName(RM_URI, "rejectReason");
public static final QName ASPECT_RECORD_ORIGINATING_DETAILS = QName.createQName(RM_URI, "recordOriginatingDetails");
public static final QName PROP_RECORD_ORIGINAL_LOCATION = QName.createQName(RM_URI, "recordOrginalLocation");
public static final QName PROP_RECORD_CREATION_DATE = QName.createQName(RM_URI, "recordCreationDate");
public static final QName PROP_RECORD_USER_ID = QName.createQName(RM_URI, "recordUserId");
}

View File

@@ -21,6 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.record;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -38,6 +39,7 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordServiceImpl;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.notification.EMailNotificationProvider;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
@@ -46,6 +48,8 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.notification.NotificationContext;
import org.alfresco.service.cmr.notification.NotificationService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -53,9 +57,11 @@ import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.mail.MailPreparationException;
/**
* Record service implementation
@@ -95,6 +101,9 @@ public class RecordServiceImpl implements RecordService,
/** File plan service */
private FilePlanService filePlanService;
/** Notification service */
private NotificationService notificationService;
/** Policy component */
private PolicyComponent policyComponent;
@@ -177,6 +186,14 @@ public class RecordServiceImpl implements RecordService,
this.filePlanService = filePlanService;
}
/**
* @param notificationService notification service
*/
public void setNotificationService(NotificationService notificationService)
{
this.notificationService = notificationService;
}
/**
* @param policyComponent policy component
*/
@@ -290,6 +307,9 @@ public class RecordServiceImpl implements RecordService,
nodeRef.toString());
}
// Save the id of the currently logged in user
final String userId = AuthenticationUtil.getRunAsUser();
// do the work of creating the record as the system user
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@@ -315,9 +335,11 @@ public class RecordServiceImpl implements RecordService,
nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
// Add the information about the original location
Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>(1);
aspectProperties.put(PROP_ORIGINAL_LOCATION, (Serializable) parentAssoc.getParentRef());
nodeService.addAspect(nodeRef, ASPECT_ORIGINAL_LOCATION, aspectProperties);
Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>(3);
aspectProperties.put(PROP_RECORD_ORIGINAL_LOCATION, (Serializable) parentAssoc.getParentRef());
aspectProperties.put(PROP_RECORD_USER_ID, userId);
aspectProperties.put(PROP_RECORD_CREATION_DATE, new Date());
nodeService.addAspect(nodeRef, ASPECT_RECORD_ORIGINATING_DETAILS, aspectProperties);
// make the document a record
makeRecord(nodeRef);
@@ -440,7 +462,7 @@ public class RecordServiceImpl implements RecordService,
public Void doWork() throws Exception
{
// first remove the secondary link association
NodeRef originalLocation = (NodeRef) nodeService.getProperty(nodeRef, PROP_ORIGINAL_LOCATION);
NodeRef originalLocation = (NodeRef) nodeService.getProperty(nodeRef, PROP_RECORD_ORIGINAL_LOCATION);
List<ChildAssociationRef> parentAssocs = nodeService.getParentAssocs(nodeRef);
for (ChildAssociationRef childAssociationRef : parentAssocs)
{
@@ -461,17 +483,31 @@ public class RecordServiceImpl implements RecordService,
// get the records primary parent association
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef);
// save the reject reason
Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>(1);
aspectProperties.put(PROP_REJECT_REASON, reason);
nodeService.addAspect(nodeRef, ASPECT_REJECT_REASON_RECORD, aspectProperties);
// move the record into the collaboration site
nodeService.moveNode(nodeRef, originalLocation, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
// remove all extended readers
extendedSecurityService.removeAllExtendedReaders(nodeRef);
// Send an email to the record creator
String recordCreator = (String) nodeService.getProperty(nodeRef, PROP_RECORD_USER_ID);
if (StringUtils.isNotBlank(recordCreator))
{
NotificationContext context = new NotificationContext();
context.addTo(recordCreator);
// FIXME: Subject -> i18n
context.setSubject("Record rejected");
// FIXME: Use email template
context.setBody(reason);
notificationService.sendNotification(EMailNotificationProvider.NAME, context);
}
else
{
throw new MailPreparationException("The id of the record creator cannot be found!");
}
return null;
}
});

View File

@@ -89,7 +89,7 @@ public class HideRecordActionTest extends BaseRMTestCase
assertTrue(recordService.isRecord(doc));
// The record should have the original location information
assertNotNull(nodeService.getProperty(doc, PROP_ORIGINAL_LOCATION));
assertNotNull(nodeService.getProperty(doc, PROP_RECORD_ORIGINAL_LOCATION));
// Check the parents. In this case the document should have two parents (doclib and fileplan)
assertTrue(nodeService.getParentAssocs(doc).size() == 2);

View File

@@ -75,7 +75,7 @@ public class RejectActionTest extends BaseRMTestCase
assertTrue(recordService.isRecord(dmDocument));
// The record should have the original location information
assertNotNull(nodeService.getProperty(dmDocument, PROP_ORIGINAL_LOCATION));
assertNotNull(nodeService.getProperty(dmDocument, PROP_RECORD_ORIGINAL_LOCATION));
// Check the parents. In this case the document should have two parents (doclib and fileplan)
assertTrue(nodeService.getParentAssocs(dmDocument).size() == 2);
@@ -114,9 +114,6 @@ public class RejectActionTest extends BaseRMTestCase
// The "identifier" property should be removed
assertNull(nodeService.getProperty(dmDocument, PROP_IDENTIFIER));
// The reject reason should be saved
assertTrue(((String) nodeService.getProperty(dmDocument, PROP_REJECT_REASON)).equals(REJECT_REASON));
// The record should be removed from the file plan
assertTrue(nodeService.getParentAssocs(dmDocument).size() == 1);

View File

@@ -257,8 +257,8 @@ public class RecordServiceImplTest extends BaseRMTestCase
assertFalse(recordService.isFiled(dmDocument));
// show that the record has meta-data about it's original location
assertTrue(nodeService.hasAspect(dmDocument, ASPECT_ORIGINAL_LOCATION));
assertEquals(originalLocation, nodeService.getProperty(dmDocument, PROP_ORIGINAL_LOCATION));
assertTrue(nodeService.hasAspect(dmDocument, ASPECT_RECORD_ORIGINATING_DETAILS));
assertEquals(originalLocation, nodeService.getProperty(dmDocument, PROP_RECORD_ORIGINAL_LOCATION));
assertFalse(originalLocation == nodeService.getPrimaryParent(dmDocument).getParentRef());
// show that the record is linked to it's original location
@@ -345,8 +345,8 @@ public class RecordServiceImplTest extends BaseRMTestCase
assertFalse(recordService.isFiled(dmDocument));
// show that the record has meta-data about it's original location
assertTrue(nodeService.hasAspect(dmDocument, ASPECT_ORIGINAL_LOCATION));
assertEquals(originalLocation, nodeService.getProperty(dmDocument, PROP_ORIGINAL_LOCATION));
assertTrue(nodeService.hasAspect(dmDocument, ASPECT_RECORD_ORIGINATING_DETAILS));
assertEquals(originalLocation, nodeService.getProperty(dmDocument, PROP_RECORD_ORIGINAL_LOCATION));
assertFalse(originalLocation == nodeService.getPrimaryParent(dmDocument).getParentRef());
// show that the record is linked to it's original location