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

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@46150 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-02-01 18:03:32 +00:00
parent 3ddc70cf74
commit 4bc75f4db9
9 changed files with 107 additions and 50 deletions

View File

@@ -44,7 +44,7 @@
</tr>
</table>
<div style="font-size: 14px; margin: 12px 0px 24px 0px; padding-top: 10px; border-top: 1px solid #aaaaaa;">
<p>Hello ${args.userName},</p>
<p>Hello ${args.recordCreator},</p>
<p>${args.rejectedPerson} has rejected the following record with this reason:</p>

View File

@@ -1143,13 +1143,29 @@
<aspect name="rma:recordOriginatingDetails">
<title>The originating details of a record</title>
<properties>
<property name="rma:recordOrginalLocation">
<type>d:any</type>
<property name="rma:recordOriginatingUserId">
<type>d:text</type>
</property>
<property name="rma:recordCreationDate">
<property name="rma:recordOriginatingCreationDate">
<type>d:date</type>
</property>
<property name="rma:recordUserId">
<property name="rma:recordOriginatingLocation">
<type>d:any</type>
</property>
</properties>
</aspect>
<!-- Aspect to hold the details of a record rejection -->
<aspect name="rma:recordRejectionDetails">
<title>The rejection details of a record</title>
<properties>
<property name="rma:recordRejectionUserId">
<type>d:text</type>
</property>
<property name="rma:recordRejectionDate">
<type>d:date</type>
</property>
<property name="rma:recordRejectionReason">
<type>d:text</type>
</property>
</properties>

View File

@@ -116,11 +116,11 @@ public class HideRecordAction extends ActionExecuterAbstractBase implements Reco
else
{
// remove the child association
NodeRef originalLocation = (NodeRef) nodeService.getProperty(actionedUponNodeRef, PROP_RECORD_ORIGINAL_LOCATION);
NodeRef originatingLocation = (NodeRef) nodeService.getProperty(actionedUponNodeRef, PROP_RECORD_ORIGINATING_LOCATION);
List<ChildAssociationRef> parentAssocs = nodeService.getParentAssocs(actionedUponNodeRef);
for (ChildAssociationRef childAssociationRef : parentAssocs)
{
if (childAssociationRef.isPrimary() == false && childAssociationRef.getParentRef().equals(originalLocation))
if (childAssociationRef.isPrimary() == false && childAssociationRef.getParentRef().equals(originatingLocation))
{
nodeService.removeChildAssociation(childAssociationRef);
break;

View File

@@ -231,9 +231,15 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel
public static final QName ASPECT_EXTENDED_READERS = QName.createQName(RM_URI, "extendedReaders");
public static final QName PROP_READERS = QName.createQName(RM_URI, "readers");
// Original location of a record
// Originating details of a record
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");
public static final QName PROP_RECORD_ORIGINATING_USER_ID = QName.createQName(RM_URI, "recordOriginatingUserId");
public static final QName PROP_RECORD_ORIGINATING_CREATION_DATE = QName.createQName(RM_URI, "recordOriginatingCreationDate");
public static final QName PROP_RECORD_ORIGINATING_LOCATION = QName.createQName(RM_URI, "recordOriginatingLocation");
// Rejection details of a record
public static final QName ASPECT_RECORD_REJECTION_DETAILS = QName.createQName(RM_URI, "recordRejectionDetails");
public static final QName PROP_RECORD_REJECTION_USER_ID = QName.createQName(RM_URI, "recordRejectionUserId");
public static final QName PROP_RECORD_REJECTION_DATE = QName.createQName(RM_URI, "recordRejectionDate");
public static final QName PROP_RECORD_REJECTION_REASON = QName.createQName(RM_URI, "recordRejectionReason");
}

View File

@@ -308,49 +308,77 @@ public class RecordsManagementNotificationHelper implements RecordsManagementMod
* Sends record rejected email notification.
*
* @param record rejected record
* @param reason reason for rejection
* @param userId the user id who rejected the record
*/
public void recordRejectedEmailNotification(NodeRef record, String reason, String userId)
public void recordRejectedEmailNotification(NodeRef record)
{
ParameterCheck.mandatory("record", record);
ParameterCheck.mandatoryString("reason", reason);
ParameterCheck.mandatoryString("userId", userId);
String recordCreator = (String) nodeService.getProperty(record, PROP_RECORD_USER_ID);
if (StringUtils.isNotBlank(recordCreator) == true)
if (canSendRejectEmail(record) == true)
{
SiteInfo site = siteService.getSite(record);
if (site == null)
{
throw new AlfrescoRuntimeException("Could not find the site which should contain the node '" + record.toString() + "'.");
}
String site = siteService.getSite(record).getShortName();
String recordCreator = (String) nodeService.getProperty(record, PROP_RECORD_ORIGINATING_USER_ID);
String rejectReason = (String) nodeService.getProperty(record, PROP_RECORD_REJECTION_REASON);
String rejectedPerson = (String) nodeService.getProperty(record, PROP_RECORD_REJECTION_USER_ID);
Date rejectDate = (Date) nodeService.getProperty(record, PROP_RECORD_REJECTION_DATE);
Map<String, Serializable> args = new HashMap<String, Serializable>(6);
args.put("record", record);
args.put("site", site);
args.put("recordCreator", recordCreator);
args.put("rejectReason", rejectReason);
args.put("rejectedPerson", rejectedPerson);
args.put("rejectDate", rejectDate);
NotificationContext notificationContext = new NotificationContext();
notificationContext.addTo(recordCreator);
notificationContext.setSubject(I18NUtil.getMessage(MSG_SUBJECT_RECORD_REJECTED));
notificationContext.setBodyTemplate(getRejectedTemplate());
Map<String, Serializable> args = new HashMap<String, Serializable>(6);
args.put("site", site.getShortName());
args.put("record", record);
args.put("userName", recordCreator);
args.put("rejectReason", reason);
args.put("rejectDate", new Date());
args.put("rejectedPerson", userId);
notificationContext.setTemplateArgs(args);
notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext);
}
else
}
/**
* Helper method to check if the mandatory properties are set
*
* @param record rejected record
*/
private boolean canSendRejectEmail(NodeRef record)
{
boolean result = true;
String msg1 = "Unable to send record rejected email notification, because ";
String msg2 = " could not be found!";
if (siteService.getSite(record) == null)
{
if (logger.isWarnEnabled() == true)
{
logger.warn("Unable to send record rejected email notification, because notification user was empty.");
}
result = false;
logger.warn(msg1 + "the site which should contain the node '" + record.toString() + "'" + msg2);
}
if (StringUtils.isBlank((String) nodeService.getProperty(record, PROP_RECORD_ORIGINATING_USER_ID)) == true)
{
result = false;
logger.warn(msg1 + "the user, who created the record" + msg2);
}
if (StringUtils.isBlank((String) nodeService.getProperty(record, PROP_RECORD_REJECTION_REASON)) == true)
{
result = false;
logger.warn(msg1 + "the reason for rejection" + msg2);
}
if (StringUtils.isBlank((String) nodeService.getProperty(record, PROP_RECORD_REJECTION_USER_ID)) == true)
{
result = false;
logger.warn(msg1 + "the user, who rejected the record" + msg2);
}
if (((Date) nodeService.getProperty(record, PROP_RECORD_REJECTION_DATE)) == null)
{
result = false;
logger.warn(msg1 + "the date, when the record was rejected" + msg2);
}
return result;
}
/**

View File

@@ -330,11 +330,11 @@ public class RecordServiceImpl implements RecordService,
// move the document into the file plan
nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
// Add the information about the original location
// save the information about the originating details
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());
aspectProperties.put(PROP_RECORD_ORIGINATING_LOCATION, (Serializable) parentAssoc.getParentRef());
aspectProperties.put(PROP_RECORD_ORIGINATING_USER_ID, userId);
aspectProperties.put(PROP_RECORD_ORIGINATING_CREATION_DATE, new Date());
nodeService.addAspect(nodeRef, ASPECT_RECORD_ORIGINATING_DETAILS, aspectProperties);
// make the document a record
@@ -461,11 +461,11 @@ public class RecordServiceImpl implements RecordService,
public Void doWork() throws Exception
{
// first remove the secondary link association
NodeRef originalLocation = (NodeRef) nodeService.getProperty(nodeRef, PROP_RECORD_ORIGINAL_LOCATION);
NodeRef originatingLocation = (NodeRef) nodeService.getProperty(nodeRef, PROP_RECORD_ORIGINATING_LOCATION);
List<ChildAssociationRef> parentAssocs = nodeService.getParentAssocs(nodeRef);
for (ChildAssociationRef childAssociationRef : parentAssocs)
{
if (childAssociationRef.isPrimary() == false && childAssociationRef.getParentRef().equals(originalLocation))
if (childAssociationRef.isPrimary() == false && childAssociationRef.getParentRef().equals(originatingLocation))
{
nodeService.removeChildAssociation(childAssociationRef);
break;
@@ -483,13 +483,20 @@ public class RecordServiceImpl implements RecordService,
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef);
// move the record into the collaboration site
nodeService.moveNode(nodeRef, originalLocation, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
nodeService.moveNode(nodeRef, originatingLocation, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
// remove all extended readers
extendedSecurityService.removeAllExtendedReaders(nodeRef);
// Send an email to the record creator
notificationHelper.recordRejectedEmailNotification(nodeRef, reason, userId);
// save the information about the rejection details
Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>(3);
aspectProperties.put(PROP_RECORD_REJECTION_USER_ID, userId);
aspectProperties.put(PROP_RECORD_REJECTION_DATE, new Date());
aspectProperties.put(PROP_RECORD_REJECTION_REASON, reason);
nodeService.addAspect(nodeRef, ASPECT_RECORD_REJECTION_DETAILS, aspectProperties);
// send an email to the record creator
notificationHelper.recordRejectedEmailNotification(nodeRef);
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_RECORD_ORIGINAL_LOCATION));
assertNotNull(nodeService.getProperty(doc, PROP_RECORD_ORIGINATING_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_RECORD_ORIGINAL_LOCATION));
assertNotNull(nodeService.getProperty(dmDocument, PROP_RECORD_ORIGINATING_LOCATION));
// Check the parents. In this case the document should have two parents (doclib and fileplan)
assertTrue(nodeService.getParentAssocs(dmDocument).size() == 2);

View File

@@ -258,7 +258,7 @@ public class RecordServiceImplTest extends BaseRMTestCase
// show that the record has meta-data about it's original location
assertTrue(nodeService.hasAspect(dmDocument, ASPECT_RECORD_ORIGINATING_DETAILS));
assertEquals(originalLocation, nodeService.getProperty(dmDocument, PROP_RECORD_ORIGINAL_LOCATION));
assertEquals(originalLocation, nodeService.getProperty(dmDocument, PROP_RECORD_ORIGINATING_LOCATION));
assertFalse(originalLocation == nodeService.getPrimaryParent(dmDocument).getParentRef());
// show that the record is linked to it's original location
@@ -346,7 +346,7 @@ public class RecordServiceImplTest extends BaseRMTestCase
// show that the record has meta-data about it's original location
assertTrue(nodeService.hasAspect(dmDocument, ASPECT_RECORD_ORIGINATING_DETAILS));
assertEquals(originalLocation, nodeService.getProperty(dmDocument, PROP_RECORD_ORIGINAL_LOCATION));
assertEquals(originalLocation, nodeService.getProperty(dmDocument, PROP_RECORD_ORIGINATING_LOCATION));
assertFalse(originalLocation == nodeService.getPrimaryParent(dmDocument).getParentRef());
// show that the record is linked to it's original location