mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge branch 'master' into feature/RM-6302_EditDispositionSchedule
This commit is contained in:
@@ -27,8 +27,13 @@
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.audit;
|
||||
|
||||
import static org.alfresco.model.ContentModel.PROP_AUTHORITY_DISPLAY_NAME;
|
||||
import static org.alfresco.model.ContentModel.PROP_AUTHORITY_NAME;
|
||||
import static org.alfresco.model.ContentModel.PROP_USERNAME;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.audit.event.UserGroupMembershipUtils.PARENT_GROUP;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model.TYPE_DOD_5015_SITE;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.model.rma.type.RmSiteType.DEFAULT_SITE_NAME;
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@@ -1102,7 +1107,18 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
|
||||
}
|
||||
else if (params.getEvent() != null)
|
||||
{
|
||||
auditQueryParams.addSearchKey(RM_AUDIT_DATA_EVENT_NAME, params.getEvent());
|
||||
if (params.getEvent().equalsIgnoreCase(RM_AUDIT_EVENT_LOGIN_SUCCESS))
|
||||
{
|
||||
auditQueryParams.addSearchKey(RM_AUDIT_DATA_LOGIN_FULLNAME, null);
|
||||
}
|
||||
else if (params.getEvent().equalsIgnoreCase(RM_AUDIT_EVENT_LOGIN_FAILURE))
|
||||
{
|
||||
auditQueryParams.addSearchKey(RM_AUDIT_DATA_LOGIN_ERROR, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
auditQueryParams.addSearchKey(RM_AUDIT_DATA_EVENT_NAME, params.getEvent());
|
||||
}
|
||||
}
|
||||
|
||||
// Get audit entries
|
||||
@@ -1503,31 +1519,7 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
|
||||
json.put("fullName", entry.getFullName() == null ? "": entry.getFullName());
|
||||
json.put("nodeRef", entry.getNodeRef() == null ? "": entry.getNodeRef());
|
||||
|
||||
// TODO: Find another way for checking the event
|
||||
if (entry.getEvent().equals("Create Person") && entry.getNodeRef() != null)
|
||||
{
|
||||
NodeRef nodeRef = entry.getNodeRef();
|
||||
String userName = null;
|
||||
if(nodeService.exists(nodeRef))
|
||||
{
|
||||
userName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
|
||||
}
|
||||
json.put("nodeName", userName == null ? "": userName);
|
||||
json.put("createPerson", true);
|
||||
}
|
||||
else if (entry.getEvent().equals("Delete Person") && entry.getNodeRef() != null)
|
||||
{
|
||||
if (entry.getBeforeProperties() != null)
|
||||
{
|
||||
String userName = (String) entry.getBeforeProperties().get(ContentModel.PROP_USERNAME);
|
||||
json.put("nodeName", userName == null ? "" : userName);
|
||||
}
|
||||
json.put("deletePerson", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
json.put("nodeName", entry.getNodeName() == null ? "": entry.getNodeName());
|
||||
}
|
||||
setNodeName(entry, json);
|
||||
|
||||
// TODO: Find another way for checking the event
|
||||
if (entry.getEvent().equals("Delete RM Object"))
|
||||
@@ -1586,6 +1578,81 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a JSON object with a node name for an audit event.
|
||||
*
|
||||
* @param entry The audit event.
|
||||
* @param json The object to update.
|
||||
* @throws JSONException If there is a problem updating the JSON.
|
||||
*/
|
||||
private void setNodeName(RecordsManagementAuditEntry entry, JSONObject json) throws JSONException
|
||||
{
|
||||
String nodeName = null;
|
||||
if (entry.getNodeRef() != null)
|
||||
{
|
||||
// TODO: Find another way for checking the event
|
||||
switch (entry.getEvent())
|
||||
{
|
||||
case "Create Person":
|
||||
nodeName = getNodeName(entry.getAfterProperties(), PROP_USERNAME);
|
||||
// This is needed as older audit events (pre-2.7) were created without PROP_USERNAME being set.
|
||||
NodeRef nodeRef = entry.getNodeRef();
|
||||
if (nodeName == null && nodeService.exists(nodeRef))
|
||||
{
|
||||
nodeName = (String) nodeService.getProperty(nodeRef, PROP_USERNAME);
|
||||
}
|
||||
json.put("createPerson", true);
|
||||
break;
|
||||
|
||||
case "Delete Person":
|
||||
nodeName = getNodeName(entry.getBeforeProperties(), PROP_USERNAME);
|
||||
json.put("deletePerson", true);
|
||||
break;
|
||||
|
||||
case "Create User Group":
|
||||
nodeName = getNodeName(entry.getAfterProperties(), PROP_AUTHORITY_DISPLAY_NAME, PROP_AUTHORITY_NAME);
|
||||
break;
|
||||
|
||||
case "Delete User Group":
|
||||
nodeName = getNodeName(entry.getBeforeProperties(), PROP_AUTHORITY_DISPLAY_NAME, PROP_AUTHORITY_NAME);
|
||||
break;
|
||||
|
||||
case "Add To User Group":
|
||||
nodeName = getNodeName(entry.getAfterProperties(), PARENT_GROUP);
|
||||
break;
|
||||
|
||||
case "Remove From User Group":
|
||||
nodeName = getNodeName(entry.getBeforeProperties(), PARENT_GROUP);
|
||||
break;
|
||||
|
||||
default:
|
||||
nodeName = entry.getNodeName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
json.put("nodeName", nodeName == null ? "" : nodeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a node name using the first non-blank value from a properties object using a list of property names.
|
||||
*
|
||||
* @param properties The properties object.
|
||||
* @param propertyNames The names of the properties to use. Return the first value that is not empty.
|
||||
* @return The value of the property, or null if it's not there.
|
||||
*/
|
||||
private String getNodeName(Map<QName, Serializable> properties, QName... propertyNames)
|
||||
{
|
||||
for (QName propertyName : propertyNames)
|
||||
{
|
||||
String nodeName = (properties != null ? (String) properties.get(propertyName) : null);
|
||||
if (!isBlank(nodeName))
|
||||
{
|
||||
return nodeName;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to convert value to MLText
|
||||
*
|
||||
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.audit.event;
|
||||
|
||||
import static org.alfresco.module.org_alfresco_module_rm.audit.event.UserGroupMembershipUtils.makePropertiesMap;
|
||||
import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.EVERY_EVENT;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy;
|
||||
import org.alfresco.repo.policy.annotation.Behaviour;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourKind;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Add an authority to a user group.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 2.7
|
||||
*/
|
||||
@BehaviourBean(defaultType = "cm:authorityContainer")
|
||||
public class AddToUserGroupAuditEvent extends AuditEvent implements OnCreateChildAssociationPolicy
|
||||
{
|
||||
/** Node Service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* Sets the node service
|
||||
*
|
||||
* @param nodeService nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/** Behaviour to audit adding an authority to a user group. */
|
||||
@Override
|
||||
@Behaviour(kind = BehaviourKind.ASSOCIATION, notificationFrequency = EVERY_EVENT, assocType = "cm:member")
|
||||
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
|
||||
{
|
||||
Map<QName, Serializable> auditProperties = makePropertiesMap(childAssocRef, nodeService);
|
||||
recordsManagementAuditService.auditEvent(childAssocRef.getChildRef(), getName(), null, auditProperties, true);
|
||||
}
|
||||
}
|
@@ -27,11 +27,18 @@
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.audit.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
|
||||
import org.alfresco.repo.policy.annotation.Behaviour;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourKind;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Audits person creation.
|
||||
@@ -42,17 +49,30 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
@BehaviourBean
|
||||
public class CreatePersonAuditEvent extends AuditEvent implements OnCreateNodePolicy
|
||||
{
|
||||
/** Node Service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* Sets the node service
|
||||
*
|
||||
* @param nodeService nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy#onCreateNode(org.alfresco.service.cmr.repository.ChildAssociationRef)
|
||||
*/
|
||||
@Override
|
||||
@Behaviour
|
||||
(
|
||||
kind = BehaviourKind.CLASS,
|
||||
type = "cm:person"
|
||||
)
|
||||
@Behaviour(kind = BehaviourKind.CLASS, type = "cm:person")
|
||||
public void onCreateNode(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
recordsManagementAuditService.auditEvent(childAssocRef.getChildRef(), getName());
|
||||
Map<QName, Serializable> auditProperties = new HashMap<>();
|
||||
auditProperties.put(ContentModel.PROP_USERNAME,
|
||||
nodeService.getProperty(childAssocRef.getChildRef(), ContentModel.PROP_USERNAME));
|
||||
|
||||
recordsManagementAuditService.auditEvent(childAssocRef.getChildRef(), getName(), null, auditProperties);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.audit.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
|
||||
import org.alfresco.repo.policy.annotation.Behaviour;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourKind;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Audits user group creation.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 2.7
|
||||
*/
|
||||
@BehaviourBean
|
||||
public class CreateUserGroupAuditEvent extends AuditEvent implements OnCreateNodePolicy
|
||||
{
|
||||
/** Node Service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* Sets the node service
|
||||
*
|
||||
* @param nodeService nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/** Behaviour to audit user group creation. */
|
||||
@Override
|
||||
@Behaviour(kind = BehaviourKind.CLASS, type = "cm:authorityContainer")
|
||||
public void onCreateNode(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
Map<QName, Serializable> auditProperties = new HashMap<>();
|
||||
auditProperties.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME,
|
||||
nodeService.getProperty(childAssocRef.getChildRef(), ContentModel.PROP_AUTHORITY_DISPLAY_NAME));
|
||||
|
||||
recordsManagementAuditService.auditEvent(childAssocRef.getChildRef(), getName(), null, auditProperties);
|
||||
}
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.audit.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy;
|
||||
import org.alfresco.repo.policy.annotation.Behaviour;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourKind;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Audits user group deletion.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 2.7
|
||||
*/
|
||||
@BehaviourBean
|
||||
public class DeleteUserGroupAuditEvent extends AuditEvent implements BeforeDeleteNodePolicy
|
||||
{
|
||||
/** Node Service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* Sets the node service
|
||||
*
|
||||
* @param nodeService nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Behaviour that will audit user group deletion
|
||||
*
|
||||
* @param nodeRef the node to be deleted
|
||||
*/
|
||||
@Override
|
||||
@Behaviour(kind = BehaviourKind.CLASS, type = "cm:authorityContainer")
|
||||
public void beforeDeleteNode(NodeRef nodeRef)
|
||||
{
|
||||
// Retrieve the authority name property to be audited
|
||||
Map<QName, Serializable> auditProperties = new HashMap<>();
|
||||
auditProperties.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME,
|
||||
nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHORITY_DISPLAY_NAME));
|
||||
|
||||
//audit the property values before the delete event
|
||||
recordsManagementAuditService.auditEvent(nodeRef, getName(), auditProperties, null, true, false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.audit.event;
|
||||
|
||||
import static org.alfresco.module.org_alfresco_module_rm.audit.event.UserGroupMembershipUtils.makePropertiesMap;
|
||||
import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.EVERY_EVENT;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.node.NodeServicePolicies.OnDeleteChildAssociationPolicy;
|
||||
import org.alfresco.repo.policy.annotation.Behaviour;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourKind;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Remove an authority from a user group.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 2.7
|
||||
*/
|
||||
@BehaviourBean(defaultType = "cm:authorityContainer")
|
||||
public class RemoveFromUserGroupAuditEvent extends AuditEvent implements OnDeleteChildAssociationPolicy
|
||||
{
|
||||
/** Node Service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* Sets the node service
|
||||
*
|
||||
* @param nodeService nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/** Behaviour to audit removing an authority from a user group. */
|
||||
@Override
|
||||
@Behaviour(kind = BehaviourKind.ASSOCIATION, notificationFrequency = EVERY_EVENT, assocType = "cm:member")
|
||||
public void onDeleteChildAssociation(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
Map<QName, Serializable> auditProperties = makePropertiesMap(childAssocRef, nodeService);
|
||||
recordsManagementAuditService.auditEvent(childAssocRef.getChildRef(), getName(), auditProperties, null, true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.audit.event;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Utility class for creating audit events about user group membership.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 2.7
|
||||
*/
|
||||
public class UserGroupMembershipUtils
|
||||
{
|
||||
/** A QName to display for the parent group's name. */
|
||||
public static final QName PARENT_GROUP = QName.createQName(RecordsManagementModel.RM_URI, "Parent Group");
|
||||
/** A QName to display for a child group's name. */
|
||||
private static final QName CHILD_GROUP = QName.createQName(RecordsManagementModel.RM_URI, "Child Group");
|
||||
|
||||
/**
|
||||
* Create a properties map from the given cm:member association.
|
||||
*
|
||||
* @param childAssocRef The association to use.
|
||||
* @param nodeService The node service.
|
||||
* @return A map containing the names of the parent and child.
|
||||
*/
|
||||
public static Map<QName, Serializable> makePropertiesMap(ChildAssociationRef childAssocRef, NodeService nodeService)
|
||||
{
|
||||
Map<QName, Serializable> auditProperties = new HashMap<>();
|
||||
// Set exactly one of the child group property or the child user name property.
|
||||
String childGroupName = getUserGroupName(childAssocRef.getChildRef(), nodeService);
|
||||
if (!isBlank(childGroupName))
|
||||
{
|
||||
auditProperties.put(CHILD_GROUP, childGroupName);
|
||||
}
|
||||
String childUserName = (String) nodeService.getProperty(childAssocRef.getChildRef(), ContentModel.PROP_USERNAME);
|
||||
if (!isBlank(childUserName))
|
||||
{
|
||||
auditProperties.put(ContentModel.PROP_USERNAME, childUserName);
|
||||
}
|
||||
// Set the parent group name.
|
||||
auditProperties.put(PARENT_GROUP, getUserGroupName(childAssocRef.getParentRef(), nodeService));
|
||||
return auditProperties;
|
||||
}
|
||||
|
||||
/** Get a name that can be displayed for the user group. */
|
||||
private static String getUserGroupName(NodeRef nodeRef, NodeService nodeService)
|
||||
{
|
||||
String groupName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHORITY_DISPLAY_NAME);
|
||||
if (isBlank(groupName))
|
||||
{
|
||||
groupName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHORITY_NAME);
|
||||
}
|
||||
return groupName;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user